| | |
| | | using DevExpress.XtraScheduler.VCalendar; |
| | | using DevExpress.XtraEditors; |
| | | using static DevExpress.XtraEditors.XtraInputBox; |
| | | using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; |
| | | |
| | | namespace HStation.WinFrmUI |
| | | { |
| | |
| | | public static async Task<bool> Import(ImportXhsProjectViewModel vm, Action<string> feedBackMsg, Action<int, int> feedBackProgress) |
| | | { |
| | | |
| | | #region 临时文件处理 |
| | | #region 第一步 临时文件处理(进度5%) |
| | | |
| | | feedBackMsg?.Invoke("开始导入项目..."); |
| | | |
| | | //临时文件夹路径 |
| | | var tempFolder = Path.Combine(Yw.Service.ConfigHelper.DataPath, HStation.Settings.XhsParasHelper.Xhs.DataFolder, _tempFolder); |
| | |
| | | //创建临时文件夹 |
| | | Directory.CreateDirectory(tempFolder); |
| | | |
| | | feedBackProgress?.Invoke(100, 5); |
| | | |
| | | #endregion |
| | | |
| | | #region 压缩文件解析 |
| | | #region 第二步 压缩文件解析 (进度10%) |
| | | |
| | | feedBackMsg?.Invoke("正在解析模型文件..."); |
| | | var bol = Yw.FileFolderZipHelper.UnZip(vm.ZipFile, tempFolder, null); |
| | | if (!bol) |
| | | { |
| | | feedBackMsg?.Invoke("模型文件解析失败!!!"); |
| | | return bol; |
| | | return false; |
| | | } |
| | | |
| | | var tempFolderInfo = new DirectoryInfo(tempFolder); |
| | | var allFileInfoList = tempFolderInfo.GetFiles(); |
| | | if (allFileInfoList == null || allFileInfoList.Count() < 1) |
| | | { |
| | | feedBackMsg?.Invoke("模型文件解析失败!!!"); |
| | | return bol; |
| | | feedBackMsg?.Invoke("模型文件格式错误!!!"); |
| | | return false; |
| | | } |
| | | |
| | | feedBackMsg?.Invoke("模型文件解析成功。。。"); |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region 水力结构文件 |
| | | #region 第三步 解析水力结构文件 (进度15%) |
| | | |
| | | feedBackMsg?.Invoke("正在解析水力结构文件..."); |
| | | var jsonFileInfo = allFileInfoList.Where(x => x.Extension == ".json").FirstOrDefault(); |
| | | if (jsonFileInfo == null) |
| | | { |
| | | feedBackMsg?.Invoke("水力结构文件解析失败!!!"); |
| | | feedBackMsg?.Invoke("水力结构文件格式错误!!!"); |
| | | return false; |
| | | } |
| | | |
| | | var jsonText = File.ReadAllText(jsonFileInfo.FullName); |
| | | var revitModel = JsonHelper.Json2Object<HStation.Model.RevitModel>(jsonText); |
| | | if (revitModel == null) |
| | | { |
| | | feedBackMsg?.Invoke("水力结构文件格式错误!!!"); |
| | | return false; |
| | | } |
| | | |
| | | var hydroInfo = HStation.Hydro.ParseHelper.FromRevit(revitModel); |
| | | if (hydroInfo == null) |
| | | { |
| | |
| | | return false; |
| | | } |
| | | |
| | | var bllHydro = new Lazy<Yw.BLL.HydroModelInfo>(() => new Yw.BLL.HydroModelInfo()); |
| | | var hydroId = await bllHydro.Value.Save(hydroInfo); |
| | | var bllHydroInfo = new Yw.BLL.HydroModelInfo(); |
| | | var hydroId = await bllHydroInfo.Save(hydroInfo); |
| | | if (hydroId < 1) |
| | | { |
| | | feedBackMsg?.Invoke("水力结构保存失败!!!"); |
| | | feedBackMsg?.Invoke("水力结构信息保存失败!!!"); |
| | | return false; |
| | | } |
| | | |
| | | feedBackMsg?.Invoke("水力结构文件解析成功。。。"); |
| | | |
| | | feedBackProgress?.Invoke(100, 20); |
| | | feedBackProgress?.Invoke(100, 15); |
| | | |
| | | vm.HydroID = hydroId; |
| | | |
| | | #endregion |
| | | |
| | | #region 创建保存项目 |
| | | #region 第四步 创建项目(进度 20%) |
| | | |
| | | feedBackMsg?.Invoke("正在创建项目..."); |
| | | |
| | | var bllXhsProject = new Lazy<BLL.XhsProjectExtensions>(() => new BLL.XhsProjectExtensions()); |
| | | var bllXhsProjectExtensions = new Lazy<BLL.XhsProjectExtensions>(() => new BLL.XhsProjectExtensions()); |
| | | |
| | | var project = new AddXhsProjectExtensionsInput(); |
| | | project.NO = vm.NO; |
| | |
| | | } |
| | | }; |
| | | |
| | | var projectId = await bllXhsProject.Value.Insert(project); |
| | | var projectId = await bllXhsProjectExtensions.Value.Insert(project); |
| | | if (projectId < 1) |
| | | { |
| | | feedBackMsg?.Invoke("项目创建失败!!!"); |
| | |
| | | |
| | | vm.ProjectID = projectId; |
| | | |
| | | feedBackProgress?.Invoke(100, 25); |
| | | feedBackProgress?.Invoke(100, 20); |
| | | |
| | | #endregion |
| | | |
| | | #region 关联水力模型 |
| | | #region 第五步 关联水力结构模型(进度 25%) |
| | | |
| | | var bllXhsProjectSite = new Lazy<BLL.XhsProjectSite>(() => new BLL.XhsProjectSite()); |
| | | var allProjectSiteList = await bllXhsProjectSite.Value.GetByProjectID(projectId); |
| | | var projectSiteId = allProjectSiteList.First().ID; |
| | | var bllXhsProjectSite = new BLL.XhsProjectSiteStd(); |
| | | var projectSite = await bllXhsProjectSite.GetDefaultByProjectID(projectId); |
| | | if (projectSite == null) |
| | | { |
| | | feedBackMsg?.Invoke("项目站信息错误..."); |
| | | return false; |
| | | } |
| | | |
| | | vm.ProjectSiteID = projectSiteId; |
| | | var projectSiteId = projectSite.ID; |
| | | vm.ProjectSiteID = projectSite.ID; |
| | | |
| | | feedBackMsg?.Invoke("正在关联水力模型..."); |
| | | feedBackMsg?.Invoke("正在关联水力结构模型..."); |
| | | |
| | | var hydroRelation = new Yw.Dto.AddHydroModelRelationInput(); |
| | | hydroRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite; |
| | |
| | | hydroRelation.Content = null; |
| | | hydroRelation.Description = null; |
| | | |
| | | var bllHydroRelation = new Lazy<Yw.BLL.HydroModelRelation>(() => new Yw.BLL.HydroModelRelation()); |
| | | var hydroRelationId = await bllHydroRelation.Value.Insert(hydroRelation); |
| | | var bllHydroRelation = new Yw.BLL.HydroModelRelation(); |
| | | var hydroRelationId = await bllHydroRelation.Insert(hydroRelation); |
| | | if (hydroRelationId < 1) |
| | | { |
| | | feedBackMsg?.Invoke("关联水力模型失败!!!"); |
| | | feedBackMsg?.Invoke("关联水力结构模型失败!!!"); |
| | | return false; |
| | | } |
| | | |
| | | feedBackMsg?.Invoke("关联水力成功。。。"); |
| | | |
| | | vm.HydroRelationID = hydroRelationId; |
| | | |
| | | feedBackProgress?.Invoke(100, 30); |
| | | feedBackMsg?.Invoke("关联水力结构模型成功。。。"); |
| | | |
| | | feedBackProgress?.Invoke(100, 25); |
| | | |
| | | #endregion |
| | | |
| | | #region 设置地图位置 |
| | | #region 第六步 设置地图位置(进度 30%) |
| | | |
| | | feedBackMsg?.Invoke("正在设置地图位置..."); |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | vm.MapInfoID = mapInfoId; |
| | | feedBackMsg?.Invoke("设置地图位置成功。。。"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | feedBackMsg?.Invoke("设置地图位置失败!!!"); |
| | | feedBackMsg?.Invoke("未设置地图位置信息!!!"); |
| | | } |
| | | |
| | | feedBackMsg?.Invoke("设置地图位置完成。。。"); |
| | | |
| | | feedBackProgress?.Invoke(100, 40); |
| | | feedBackProgress?.Invoke(100, 30); |
| | | |
| | | #endregion |
| | | |
| | | #region 上传Revit模型 |
| | | #region 第七步 上传Revit模型文件(进度 45%) |
| | | |
| | | feedBackMsg?.Invoke("正在解析Revit模型文件..."); |
| | | var rvtFileInfo = allFileInfoList.Where(x => x.Extension == ".rvt").FirstOrDefault(); |
| | | if (rvtFileInfo == null) |
| | | { |
| | | feedBackMsg?.Invoke("Revit模型文件解析失败!!!"); |
| | | } |
| | | |
| | | //var bimfaceId = await Yw.WinFrmUI.BimfaceHelper.UploadFile(rvtFileInfo.FullName); |
| | | var bimfaceId = 10000869537010; |
| | | if (bimfaceId < 1) |
| | | { |
| | | feedBackMsg?.Invoke("Revit模型文件上传失败!!!"); |
| | | feedBackMsg?.Invoke("项目导入结束。。。"); |
| | | return true; |
| | | } |
| | | |
| | | feedBackMsg?.Invoke("解析Revit模型文件成功。。。"); |
| | | |
| | | |
| | | |
| | | feedBackProgress?.Invoke(100, 60); |
| | | var bimfaceId = await Yw.WinFrmUI.BimfaceHelper.UploadFile(rvtFileInfo.FullName);//上传 |
| | | //var bimfaceId = 10000869537010; //测试用例 |
| | | if (bimfaceId < 1) |
| | | { |
| | | feedBackMsg?.Invoke("Revit模型文件上传失败!!!"); |
| | | feedBackMsg?.Invoke("项目导入结束。。。"); |
| | | return true; |
| | | } |
| | | |
| | | vm.BimfaceId = bimfaceId; |
| | | |
| | | feedBackMsg?.Invoke("解析Revit模型文件成功。。。"); |
| | | |
| | | feedBackProgress?.Invoke(100, 45); |
| | | |
| | | #endregion |
| | | |
| | | #region 保存Bimface文件 |
| | | #region 第八步 保存Bimface文件 (进度 50%) |
| | | |
| | | feedBackMsg?.Invoke("正在保存Bimface文件..."); |
| | | |
| | | var bllBimfaceFile = new Yw.BLL.BimfaceFile(); |
| | | |
| | | var bimfaceFile = new Yw.Dto.AddBimfaceFileInput(); |
| | | bimfaceFile.BimfaceId = bimfaceId.ToString(); |
| | |
| | | bimfaceFile.FileSuffix = rvtFileInfo.Extension; |
| | | bimfaceFile.FileSize = string.Format("{0}MB", System.Math.Ceiling(rvtFileInfo.Length / 1024.0 / 1024.0)); |
| | | |
| | | var bllBimfaceFile = new Yw.BLL.BimfaceFile(); |
| | | var bimfaceFileId = await bllBimfaceFile.Insert(bimfaceFile); |
| | | if (bimfaceFileId < 1) |
| | | { |
| | | feedBackMsg?.Invoke("Bimface文件保存失败!!!"); |
| | | feedBackMsg?.Invoke("项目导入结束。。。"); |
| | | return true; |
| | | } |
| | | vm.BimfaceFileID = bimfaceFileId; |
| | | |
| | | feedBackMsg?.Invoke("Bimface文件保存成功。。。"); |
| | | |
| | | feedBackProgress?.Invoke(100, 70); |
| | | |
| | | vm.BimfaceFileID = bimfaceFileId; |
| | | feedBackProgress?.Invoke(100, 50); |
| | | |
| | | #endregion |
| | | |
| | | #region 关联Bimface文件 |
| | | #region 第九步 关联Bimface文件(进度 55%) |
| | | |
| | | feedBackMsg?.Invoke("正在关联Bimface文件..."); |
| | | |
| | | var bllBimfaceRelation = new Yw.BLL.BimfaceFileRelation(); |
| | | var bimfaceRelation = new Yw.Dto.AddBimfaceFileRelationInput(); |
| | | bimfaceRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite; |
| | | bimfaceRelation.ObjectID = projectSiteId; |
| | |
| | | bimfaceRelation.Purpose = Yw.Bimface.Purpose.Simulation; |
| | | bimfaceRelation.Description = vm.Description; |
| | | |
| | | var bllBimfaceRelation = new Yw.BLL.BimfaceFileRelation(); |
| | | var bimfaceRelationId = await bllBimfaceRelation.Insert(bimfaceRelation); |
| | | if (bimfaceRelationId < 1) |
| | | { |
| | | feedBackMsg?.Invoke("Bimface文件关联失败!!!"); |
| | | feedBackMsg?.Invoke("项目导入结束。。。"); |
| | | return true; |
| | | } |
| | | feedBackMsg?.Invoke("Bimface文件关联成功。。。"); |
| | | |
| | | feedBackProgress?.Invoke(100, 80); |
| | | |
| | | vm.BimfaceFileRelationID = bimfaceRelationId; |
| | | feedBackMsg?.Invoke("Bimface文件关联成功。。。"); |
| | | feedBackProgress?.Invoke(100, 55); |
| | | |
| | | #endregion |
| | | |
| | | #region 发起bimface转换 |
| | | #region 第九步 发起bimface转换(进度 80%) |
| | | |
| | | feedBackMsg?.Invoke("正在进行Bimface模型轻量化..."); |
| | | //var bimfaceTranslateStatus = await Yw.WinFrmUI.BimfaceHelper.TranslateRvtFile(bimfaceId); |
| | | //if (bimfaceTranslateStatus != Yw.BIMFace.eTranslateStatus.Success) |
| | | //{ |
| | | // await Yw.WinFrmUI.BimfaceHelper.WaitFileTranslateStatusUntilSuccess(bimfaceId, 3000); |
| | | //} |
| | | await Yw.WinFrmUI.BimfaceHelper.WaitFileTranslateStatusUntilSuccess(bimfaceId, 3000); |
| | | feedBackMsg?.Invoke("Bimface模型轻量化完成。。。"); |
| | | var bimfaceTranslateStatus = await Yw.WinFrmUI.BimfaceHelper.TranslateRvtFile(bimfaceId);//发起转换 |
| | | //var bimfaceTranslateStatus = Yw.BIMFace.eTranslateStatus.Processing;//测试代码 |
| | | feedBackProgress?.Invoke(100, 60); |
| | | if (bimfaceTranslateStatus != Yw.BIMFace.eTranslateStatus.Success) |
| | | { |
| | | var dlgResult = XtraMessageBox.Show("Bimface模型轻量化需要一定的时间,是否继续等待?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question); |
| | | if (dlgResult == DialogResult.Yes) |
| | | { |
| | | await Yw.WinFrmUI.BimfaceHelper.WaitFileTranslateStatusUntilSuccess(bimfaceId, 3000); |
| | | vm.BimfaceConverted = true; |
| | | feedBackMsg?.Invoke("Bimface模型轻量化完成。。。"); |
| | | } |
| | | else |
| | | { |
| | | feedBackMsg?.Invoke("跳过Bimface模型轻量化等待。。。"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | vm.BimfaceConverted = true; |
| | | feedBackMsg?.Invoke("Bimface模型轻量化完成。。。"); |
| | | } |
| | | |
| | | feedBackProgress?.Invoke(100, 80); |
| | | |
| | | #endregion |
| | | |
| | | #region 第十步 更新Bimface文件状态(进度 90%) |
| | | |
| | | feedBackMsg?.Invoke("正在更新Bimface文件状态..."); |
| | | bol = await bllBimfaceFile.UpdateFileStatus(bimfaceFileId, (int)Yw.Bimface.eFileStatus.ConvertSucceed); |
| | | if (bol) |
| | | { |
| | | feedBackMsg?.Invoke("Bimface文件状态更新成功。。。"); |
| | | } |
| | | else |
| | | { |
| | | feedBackMsg?.Invoke("Bimface文件状态更新失败!!!"); |
| | | feedBackMsg?.Invoke("项目导入结束。。。"); |
| | | return true; |
| | | } |
| | | |
| | | feedBackProgress?.Invoke(100, 90); |
| | | |
| | | #endregion |
| | | |
| | | #region 更新文件状态 |
| | | #region 第十一步 项目发布(进度 100%) |
| | | |
| | | feedBackMsg?.Invoke("正在更新Bimface文件状态..."); |
| | | bol = await bllBimfaceFile.UpdateFileStatus(bimfaceFileId, (int)Yw.Bimface.eFileStatus.ConvertSucceed); |
| | | |
| | | if (bol) |
| | | feedBackMsg?.Invoke("正在发布项目..."); |
| | | var bllXhsProject = new BLL.XhsProject(); |
| | | bol = await bllXhsProject.Publish(projectId); |
| | | if (!bol) |
| | | { |
| | | feedBackMsg?.Invoke("正在Bimface文件状态更新成功。。。"); |
| | | feedBackMsg?.Invoke("项目发布失败..."); |
| | | } |
| | | else |
| | | { |
| | | feedBackMsg?.Invoke("正在Bimface文件状态更新失败!!!"); |
| | | vm.IsPublished = true; |
| | | feedBackMsg?.Invoke("项目发布成功..."); |
| | | } |
| | | |
| | | feedBackProgress?.Invoke(100, 100); |
| | | |
| | | feedBackMsg?.Invoke("项目导入结束。。。"); |
| | | return true; |
| | | #endregion |
| | | |
| | | return true; |
| | | |
| | | |
| | | } |
| | | |