using DevExpress.XtraScheduler.VCalendar;
|
|
namespace HStation.WinFrmUI
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class ImportXhsProjectHelper
|
{
|
private const string _tempFolder = "ImportProjectTemp";//导入项目临时文件夹
|
|
|
/// <summary>
|
/// 导入
|
/// </summary>
|
/// <param name="vm">通用视图Model</param>
|
/// <param name="feedBackMsg">信息反馈</param>
|
/// <param name="feedBackProgress">进度反馈</param>
|
/// <returns></returns>
|
public static async Task<bool> Import(ImportXhsProjectViewModel vm, Action<string> feedBackMsg, Action<int, int> feedBackProgress)
|
{
|
|
#region 临时文件处理
|
|
var tempFolder = Path.Combine(Yw.Service.ConfigHelper.DataPath, HStation.Settings.XhsParasHelper.Xhs.DataFolder, _tempFolder);
|
//如果存在临时文件夹
|
if (Directory.Exists(tempFolder))
|
{
|
//删除临时文件夹及子目录与文件
|
Directory.Delete(tempFolder, true);
|
}
|
//创建临时文件夹
|
Directory.CreateDirectory(tempFolder);
|
|
#endregion
|
|
#region 压缩文件解析
|
|
feedBackMsg?.Invoke("正在解析模型文件...");
|
var bol = Yw.FileFolderZipHelper.UnZip(vm.ZipFile, tempFolder, null);
|
if (!bol)
|
{
|
feedBackMsg?.Invoke("模型文件解析失败!!!");
|
return bol;
|
}
|
|
var tempFolderInfo = new DirectoryInfo(tempFolder);
|
var allFileInfoList = tempFolderInfo.GetFiles();
|
if (allFileInfoList == null || allFileInfoList.Count() < 1)
|
{
|
feedBackMsg?.Invoke("模型文件解析失败!!!");
|
return bol;
|
}
|
|
feedBackMsg?.Invoke("模型文件解析成功。。。");
|
|
feedBackProgress?.Invoke(100, 10);
|
|
#endregion
|
|
#region 水力结构文件
|
|
feedBackMsg?.Invoke("正在解析水力结构文件...");
|
var jsonFileInfo = allFileInfoList.Where(x => x.Extension == ".json").FirstOrDefault();
|
if (jsonFileInfo == null)
|
{
|
feedBackMsg?.Invoke("水力结构文件解析失败!!!");
|
return false;
|
}
|
|
var jsonText = File.ReadAllText(jsonFileInfo.FullName);
|
var revitModel = JsonHelper.Json2Object<HStation.Model.RevitModel>(jsonText);
|
var hydroInfo = HStation.Hydro.ParseHelper.FromRevit(revitModel);
|
if (hydroInfo == null)
|
{
|
feedBackMsg?.Invoke("水力结构文件解析失败!!!");
|
return false;
|
}
|
|
var bllHydro = new Lazy<Yw.BLL.HydroModelInfo>(() => new Yw.BLL.HydroModelInfo());
|
var hydroId = await bllHydro.Value.Save(hydroInfo);
|
if (hydroId < 1)
|
{
|
feedBackMsg?.Invoke("水力结构保存失败!!!");
|
return false;
|
}
|
|
feedBackMsg?.Invoke("水力结构文件解析成功。。。");
|
|
feedBackProgress?.Invoke(100, 20);
|
|
vm.HydroID = hydroId;
|
|
#endregion
|
|
#region 创建保存项目
|
|
feedBackMsg?.Invoke("正在创建项目...");
|
|
var bllXhsProject = new Lazy<BLL.XhsProjectExtensions>(() => new BLL.XhsProjectExtensions());
|
|
var project = new AddXhsProjectExtensionsInput();
|
project.NO = vm.NO;
|
project.Name = vm.Name;
|
project.Address = vm.Address;
|
project.Customer = vm.Customer;
|
project.Flags = vm.Flags;
|
project.TagName = vm.TagName;
|
project.Description = vm.Description;
|
|
project.SiteList = new List<AddXhsProjectSiteExtensionsInput>() {
|
new AddXhsProjectSiteExtensionsInput(){
|
Name=vm.Name,
|
Description=vm.Description
|
}
|
};
|
|
var projectId = await bllXhsProject.Value.Insert(project);
|
if (projectId < 1)
|
{
|
feedBackMsg?.Invoke("项目创建失败!!!");
|
return false;
|
}
|
|
feedBackMsg?.Invoke("项目创建成功。。。");
|
|
vm.ProjectID = projectId;
|
|
feedBackProgress?.Invoke(100, 25);
|
|
#endregion
|
|
#region 关联水力模型
|
|
var bllXhsProjectSite = new Lazy<BLL.XhsProjectSite>(() => new BLL.XhsProjectSite());
|
var allProjectSiteList = await bllXhsProjectSite.Value.GetByProjectID(projectId);
|
var projectSiteId = allProjectSiteList.First().ID;
|
|
vm.ProjectSiteID = projectSiteId;
|
|
feedBackMsg?.Invoke("正在关联水力模型...");
|
|
var hydroRelation = new Yw.Dto.AddHydroModelRelationInput();
|
hydroRelation.ObjectType = HStation.Xhs.DataType.XhsProjectSite;
|
hydroRelation.ObjectID = projectSiteId;
|
hydroRelation.ModelID = hydroId;
|
hydroRelation.Purpose = Yw.Hydro.Purpose.Simulation;
|
hydroRelation.Content = null;
|
hydroRelation.Description = null;
|
|
var bllHydroRelation = new Lazy<Yw.BLL.HydroModelRelation>(() => new Yw.BLL.HydroModelRelation());
|
var hydroRelationId = await bllHydroRelation.Value.Insert(hydroRelation);
|
if (hydroRelationId < 1)
|
{
|
feedBackMsg?.Invoke("关联水力模型失败!!!");
|
return false;
|
}
|
|
feedBackMsg?.Invoke("关联水力成功。。。");
|
|
vm.HydroRelationID = hydroRelationId;
|
|
feedBackProgress?.Invoke(100, 30);
|
|
#endregion
|
|
#region 设置地图位置
|
|
feedBackMsg?.Invoke("正在设置地图位置...");
|
|
if (vm.Location != null)
|
{
|
var mapInfo = new Yw.Dto.AddMapInfoInput();
|
mapInfo.ObjectType = HStation.Xhs.DataType.XhsProject;
|
mapInfo.ObjectID = projectId;
|
mapInfo.ObjectName = project.Name;
|
mapInfo.Purpose = Yw.Map.Purpose.Location;
|
mapInfo.Kind = Yw.Map.Kind.Gaodei;
|
mapInfo.Shape = Yw.Map.Shape.Marker;
|
mapInfo.Position = vm.Location.ToJson();
|
|
var mapInfoId = await new Yw.BLL.MapInfo().Insert(mapInfo);
|
if (mapInfoId < 1)
|
{
|
feedBackMsg?.Invoke("设置地图位置失败!!!");
|
}
|
else
|
{
|
feedBackMsg?.Invoke("设置地图位置成功。。。");
|
}
|
}
|
else
|
{
|
feedBackMsg?.Invoke("设置地图位置失败!!!");
|
}
|
|
feedBackMsg?.Invoke("设置地图位置完成。。。");
|
|
feedBackProgress?.Invoke(100, 40);
|
|
#endregion
|
|
#region 上传Revit模型
|
|
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);
|
if (bimfaceId < 1)
|
{
|
feedBackMsg?.Invoke("Revit模型文件上传失败!!!");
|
return true;
|
}
|
|
feedBackMsg?.Invoke("解析Revit模型文件成功。。。");
|
|
feedBackProgress?.Invoke(100, 60);
|
|
vm.BimfaceId = bimfaceId;
|
|
#endregion
|
|
#region 保存Bimface文件
|
|
feedBackMsg?.Invoke("正在保存Bimface文件...");
|
|
var bllBimfaceFile = new Yw.BLL.BimfaceFile();
|
|
var bimfaceFile = new Yw.Dto.AddBimfaceFileInput();
|
bimfaceFile.BimfaceId = bimfaceId.ToString();
|
bimfaceFile.Name = vm.Name;
|
bimfaceFile.ModelType = (int)Yw.Bimface.eModelType.File;
|
bimfaceFile.FileStatus = (int)Yw.Bimface.eFileStatus.UploadSucceed;
|
bimfaceFile.FormatType = (int)Yw.Bimface.eFormatType._3D;
|
bimfaceFile.FileSuffix = rvtFileInfo.Extension;
|
bimfaceFile.FileSize = string.Format("{0}MB", System.Math.Ceiling(rvtFileInfo.Length / 1024.0 / 1024.0));
|
|
var bimfaceFileId = await bllBimfaceFile.Insert(bimfaceFile);
|
if (bimfaceFileId < 1)
|
{
|
feedBackMsg?.Invoke("Bimface文件保存失败!!!");
|
return true;
|
}
|
|
feedBackMsg?.Invoke("Bimface文件保存成功。。。");
|
|
feedBackProgress?.Invoke(100, 70);
|
|
vm.BimfaceFileID = bimfaceFileId;
|
|
#endregion
|
|
#region 关联Bimface文件
|
|
feedBackMsg?.Invoke("正在关联Bimface文件...");
|
|
var bllBimfaceRelation = new Yw.BLL.BimfaceFileRelation();
|
var bimfaceRelation = new Yw.Dto.AddBimfaceFileRelationInput();
|
bimfaceRelation.ObjectType = HStation.Xhs.DataType.XhsProject;
|
bimfaceRelation.ObjectID = projectId;
|
bimfaceRelation.BimfaceFileID = bimfaceFileId;
|
bimfaceRelation.Purpose = HStation.Xhs.Purpose.Simulation;
|
bimfaceRelation.Description = vm.Description;
|
|
var bimfaceRelationId = await bllBimfaceRelation.Insert(bimfaceRelation);
|
if (bimfaceRelationId < 1)
|
{
|
feedBackMsg?.Invoke("Bimface文件关联失败!!!");
|
return true;
|
}
|
feedBackMsg?.Invoke("Bimface文件关联成功。。。");
|
|
feedBackProgress?.Invoke(100, 80);
|
|
vm.BimfaceFileRelationID = bimfaceRelationId;
|
#endregion
|
|
#region 发起bimface转换
|
|
feedBackMsg?.Invoke("正在进行Bimface模型轻量化...");
|
var bimfaceTranslateStatus = await Yw.WinFrmUI.BimfaceHelper.TranslateRvtFile(bimfaceId);
|
if (bimfaceTranslateStatus != Yw.BIMFace.eTranslateStatus.Success)
|
{
|
await Yw.WinFrmUI.BimfaceHelper.WaitFileTranslateStatusUntilSuccess(bimfaceId, 3000);
|
}
|
feedBackMsg?.Invoke("Bimface模型轻量化完成。。。");
|
|
feedBackProgress?.Invoke(100, 90);
|
#endregion
|
|
#region 更新状态
|
|
feedBackMsg?.Invoke("正在更新Bimface文件状态...");
|
bol = await bllBimfaceFile.UpdateFileStatus(bimfaceFileId, (int)Yw.Bimface.eFileStatus.ConvertSucceed);
|
|
if (bol)
|
{
|
feedBackMsg?.Invoke("正在Bimface文件状态更新成功。。。");
|
}
|
else
|
{
|
feedBackMsg?.Invoke("正在Bimface文件状态更新失败!!!");
|
}
|
|
feedBackProgress?.Invoke(100, 100);
|
|
#endregion
|
|
return true;
|
|
}
|
|
|
}
|
}
|