From 0f831db8df9c2e4adc7feca636967a0fb1cd5e29 Mon Sep 17 00:00:00 2001 From: duheng <2784771470@qq.com> Date: 星期三, 05 三月 2025 09:20:00 +0800 Subject: [PATCH] 修改登录界面 --- HStation.RevitDev/RevitDataExport/Utility/CacheUtil.cs | 148 +++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 129 insertions(+), 19 deletions(-) diff --git a/HStation.RevitDev/RevitDataExport/Utility/CacheUtil.cs b/HStation.RevitDev/RevitDataExport/Utility/CacheUtil.cs index 0b43d1c..1844723 100644 --- a/HStation.RevitDev/RevitDataExport/Utility/CacheUtil.cs +++ b/HStation.RevitDev/RevitDataExport/Utility/CacheUtil.cs @@ -9,6 +9,9 @@ using System.Linq; using System.Windows.Forms; using Autodesk.Revit.UI; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; +using System.Net.Http; +using System.Net.Http.Headers; namespace HStation.RevitDev.RevitDataExport.Utility { @@ -34,21 +37,6 @@ { GlobalResource.LastFilePath = doc.PathName; - ExportModelHelper exportModelHelper = new ExportModelHelper(doc); - var revitJson = exportModelHelper.Export(); - - var dir = Path.GetDirectoryName(GlobalResource.ExportFilePath); - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } - - if (File.Exists(GlobalResource.ExportFilePath)) - { - File.Delete(GlobalResource.ExportFilePath); - } - - File.WriteAllText(GlobalResource.ExportFilePath, revitJson); var record = new ConfigRecord { FilePath = GlobalResource.LastFilePath, @@ -56,7 +44,7 @@ }; if (!File.Exists(GlobalResource.RecordFilePath)) { - File.Create(GlobalResource.RecordFilePath); + File.Create(GlobalResource.RecordFilePath).Close(); } var cache = File.ReadAllText(GlobalResource.RecordFilePath); @@ -77,6 +65,116 @@ var config = Newtonsoft.Json.JsonConvert.SerializeObject(records); File.WriteAllText(GlobalResource.RecordFilePath, config); + + ExportModelHelper exportModelHelper = new ExportModelHelper(doc); + var revitJson = exportModelHelper.Export(); + + var dir = Path.GetDirectoryName(GlobalResource.ExportFilePath); + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + + if (File.Exists(GlobalResource.ExportFilePath)) + { + File.Delete(GlobalResource.ExportFilePath); + } + + File.WriteAllText(GlobalResource.ExportFilePath, revitJson); + } + + public static bool UploadFile(Document _doc, string desc, out string err) + { + err = ""; + var tempDir = Path.Combine(Path.GetDirectoryName(GlobalResource.BinDirectory), "temp"); //"d:\\temp"; + if (!Directory.Exists(tempDir)) + Directory.CreateDirectory(tempDir); + var structFile = tempDir + "\\struct.json"; + var modelFile = tempDir + "\\model.rvt"; + var settingFile = tempDir + "\\setting.json"; + var otherFile = tempDir + "\\struct_others.json"; + var title = _doc.Title + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".ywrvt"; + var zipFilePath = tempDir + "\\" + title; + try + { + + if (File.Exists(structFile)) File.Delete(structFile); + + if (File.Exists(modelFile)) File.Delete(modelFile); + if (!File.Exists(settingFile)) File.Create(settingFile).Close(); + if (!File.Exists(otherFile)) File.Create(otherFile).Close(); + File.Copy(_doc.PathName, modelFile); + File.SetAttributes(modelFile, FileAttributes.Normal); + File.Copy(GlobalResource.ExportFilePath, structFile); + File.SetAttributes(structFile, FileAttributes.Normal); + var strConfig = File.ReadAllText(GlobalResource.SettingFilePath); + var ret = Newtonsoft.Json.JsonConvert.DeserializeObject<ConfigSettingModel>(strConfig); + var notContains = new List<string>() { "绠¢亾闄勪欢", "绠¢亾", "绠′欢 ", "绠¢亾闄勪欢", "绠¢亾绯荤粺" }; + var c3 = new Autodesk.Revit.DB.FilteredElementCollector(_doc).WhereElementIsNotElementType();//.WhereElementIsElementType(); + var c4 = new Autodesk.Revit.DB.FilteredElementCollector(_doc).WhereElementIsElementType(); + + c3.Concat(c4); + var r = c3.Where(c => c.Category != null && !notContains.Any(c.Category.Name.Contains)).Select(c => new { ID = c.Id.ToString(), Name = c.Name, CategoryName = c.Category.Name, CategoryID = c.Category.Id.ToString() }).Distinct().ToList(); + var t = JsonHelper.ToJson(r); + File.WriteAllText(otherFile, t); + + var setting = new SettingsViewModel() { Version = "1" }; + File.WriteAllText(settingFile, JsonHelper.ToJson(setting)); + + var files = new string[] { structFile, modelFile, settingFile, otherFile }; + ZipFiles(files, zipFilePath); + + File.Delete(structFile); + File.Delete(otherFile); + File.Delete(modelFile); + File.Delete(settingFile); + File.Delete(otherFile); + using (var client = new HttpClient()) + { + var content = new MultipartFormDataContent(); + //content.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data"); + content.Add(new StringContent("寰幆姘碦evit"), "UploadUserName"); + content.Add(new StringContent(""), "FileCode"); + content.Add(new StringContent(desc), "Description"); + content.Add(new ByteArrayContent(File.ReadAllBytes(zipFilePath)), "File", title); + try + { + var res = client.PostAsync(ret.UploadUrl, content).Result.Content.ReadAsStringAsync().Result; + var result = JsonHelper.ToObject<HttpResultViewModel>(res); + File.Delete(zipFilePath); + if (result.Code == 0) + return true; + else + { + err = "涓婁紶澶辫触锛岃妫�鏌ョ綉缁滆缃�";// result.Message; + return false; + } + } + catch (Exception ex) + { + err = "涓婁紶閿欒锛岃妫�鏌ョ綉缁滆缃�!"; + File.Delete(zipFilePath); + File.Delete(structFile); + File.Delete(otherFile); + File.Delete(modelFile); + File.Delete(settingFile); + File.Delete(otherFile); + return false; + } + + } + } + catch (Exception ex) + { + File.Delete(structFile); + File.Delete(otherFile); + File.Delete(modelFile); + File.Delete(settingFile); + File.Delete(otherFile); + File.Delete(zipFilePath); + err = "涓婁紶澶辫触锛岃妫�鏌ョ綉缁滆缃�";// JsonHelper.ToJson(ex); + return false; + } } public static bool ExportZipFile(Document _doc, out string err) @@ -92,6 +190,7 @@ var modelFile = tempDir + "\\model.rvt"; var settingFile = tempDir + "\\setting.json"; var otherFile = tempDir + "\\struct_others.json"; + var userFile = GlobalResource.LoginUserFilePath; try { @@ -102,7 +201,9 @@ if (!File.Exists(settingFile)) File.Create(settingFile).Close(); if (!File.Exists(otherFile)) File.Create(otherFile).Close(); File.Copy(_doc.PathName, modelFile); + File.SetAttributes(modelFile, FileAttributes.Normal); File.Copy(GlobalResource.ExportFilePath, structFile); + File.SetAttributes(structFile, FileAttributes.Normal); var notContains = new List<string>() { "绠¢亾闄勪欢", "绠¢亾", "绠′欢 ", "绠¢亾闄勪欢", "绠¢亾绯荤粺" }; var c3 = new Autodesk.Revit.DB.FilteredElementCollector(_doc).WhereElementIsNotElementType();//.WhereElementIsElementType(); @@ -110,13 +211,14 @@ c3.Concat(c4); var r = c3.Where(c => c.Category != null && !notContains.Any(c.Category.Name.Contains)).Select(c => new { ID = c.Id.ToString(), Name = c.Name, CategoryName = c.Category.Name, CategoryID = c.Category.Id.ToString() }).Distinct().ToList(); + var t = JsonHelper.ToJson(r); File.WriteAllText(otherFile, t); var setting = new SettingsViewModel() { Version = "1" }; File.WriteAllText(settingFile, JsonHelper.ToJson(setting)); - var files = new string[] { structFile, modelFile, settingFile, otherFile }; + var files = new string[] { structFile, modelFile, settingFile, otherFile, userFile }; ZipFiles(files, zipFilePath); File.Delete(structFile); @@ -210,7 +312,15 @@ { if (document == null) { return; } - var ids = GlobalResource.RevitModels.GetOtherIds()?.Select(x => new ElementId(int.Parse(x))).ToList(); + //var ids = GlobalResource.RevitModels.GetOtherIds()?.Select(x => new ElementId(int.Parse(x))).ToList(); + var notContains = new List<string>() { "鍥句緥鏋勪欢", "妤兼澘", "澧�", "鏍忔潌鎵舵墜", "妤兼" }; + var nameContains = new List<string>() { "娣峰嚌鍦熷簳搴�" }; + var c3 = new Autodesk.Revit.DB.FilteredElementCollector(document).WhereElementIsNotElementType();//.WhereElementIsElementType(); + var c4 = new Autodesk.Revit.DB.FilteredElementCollector(document).WhereElementIsElementType(); + + c3.Concat(c4); + //var ids = c3.Where(c => c.Category != null && !notContains.Any(c.Category.Name.Contains)).Select(c => new ElementId(int.Parse(c.Id.ToString()))).Distinct().ToList(); + var ids = c3.Where(c => (c.Category != null && notContains.Any(c.Category.Name.Contains)) || nameContains.Any(c.Name.Contains)).Select(c => new ElementId(int.Parse(c.Id.ToString()))).Distinct().ToList(); if (ids.Count == 0) { return; @@ -234,7 +344,7 @@ } catch (Exception ex) { - TaskDialog.Show("閿欒", "鏄鹃殣澶辫触锛屽彲鑳藉瓨鍦ㄤ笉鑳借缃殣钘忕殑鏋勪欢锛�"); + //TaskDialog.Show("閿欒", "鏄鹃殣澶辫触锛屽彲鑳藉瓨鍦ㄤ笉鑳借缃殣钘忕殑鏋勪欢锛�"); } } } -- Gitblit v1.9.3