| | |
| | | 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
|
| | | {
|
| | |
| | | {
|
| | | 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,
|
| | |
| | |
|
| | | 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)
|
| | |
| | | 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
|
| | | {
|
| | | var title = _doc.Title + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".ywrvt";
|
| | | var zipFilePath = tempDir + "\\" + title;
|
| | | |
| | | 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>() { "管道附件", "管道", "管件 ", "管道附件", "管道系统" };
|
| | |
| | | using (var client = new HttpClient())
|
| | | {
|
| | | var content = new MultipartFormDataContent();
|
| | | //content.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
|
| | | content.Add(new StringContent("循环水Revit"), "UploadUserName");
|
| | | content.Add(new StringContent(""), "FileCode");
|
| | | content.Add(new StringContent(desc), "Description");
|
| | | content.Add(new ByteArrayContent(File.ReadAllBytes(zipFilePath)), "File", title);
|
| | | 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
|
| | | try
|
| | | {
|
| | | err = result.Message;
|
| | | 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(modelFile);
|
| | | File.Delete(settingFile);
|
| | | File.Delete(otherFile);
|
| | | err = JsonHelper.ToJson(ex);
|
| | | File.Delete(zipFilePath);
|
| | | err = "上传失败,请检查网络设置";// JsonHelper.ToJson(ex);
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
| | | 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();
|