namespace HStation.WinFrmUI
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class ImportXhsProjectHelper
|
{
|
private const string _tempFolder = "project-import-temp";
|
|
|
/// <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 tempFolderPath = Path.Combine(Yw.Service.ConfigHelper.DataPath, HStation.Settings.XhsParasHelper.Xhs.DataFolder, _tempFolder);
|
var bol = Yw.FileFolderZipHelper.UnZip(vm.ZipFile, tempFolderPath, null);
|
if (!bol)
|
{
|
feedBackMsg?.Invoke("模型文件解析失败");
|
return bol;
|
}
|
|
var tempDirectoryInfo = new DirectoryInfo(tempFolderPath);
|
var allFileInfoList = tempDirectoryInfo.GetFiles();
|
if (allFileInfoList == null || allFileInfoList.Count() < 1)
|
{
|
feedBackMsg?.Invoke("模型文件解析失败");
|
return bol;
|
}
|
|
#endregion
|
|
#region 水力模型
|
|
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 hydroId = HStation.Hydro.ParseHelper.FromRevit(revitModel);
|
if (hydroId < 1)
|
{
|
feedBackMsg?.Invoke("水力结构文件解析失败");
|
return false;
|
}
|
|
|
#endregion
|
|
#region 创建项目
|
|
var bllXhsProject = 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.Insert(project);
|
if (projectId < 1)
|
{
|
feedBackMsg?.Invoke("项目创建失败");
|
return false;
|
}
|
|
#endregion
|
|
#region 关联模型
|
|
|
|
#endregion
|
|
#region 地图位置
|
|
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("保存地图定位信息成功");
|
}
|
}
|
|
#endregion
|
|
#region 上传模型
|
|
var rvtFileInfo = allFileInfoList.Where(x => x.Extension == ".rvt").FirstOrDefault();
|
if (rvtFileInfo == null)
|
{
|
feedBackMsg?.Invoke("Revit模型文件解析失败");
|
return false;
|
}
|
|
var bimfaceId = await Yw.WinFrmUI.BimfaceHelper.UploadFile(rvtFileInfo.FullName);
|
if (bimfaceId < 1)
|
{
|
feedBackMsg?.Invoke("Revit模型文件上传失败");
|
return false;
|
}
|
|
|
|
#endregion
|
|
#region 保存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文件信息保存失败");
|
}
|
else
|
{
|
feedBackMsg?.Invoke("BIMFACE文件信息保存成功");
|
}
|
|
#endregion
|
|
#region 关联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关联失败");
|
}
|
else
|
{
|
feedBackMsg?.Invoke("BIMFACE关联成功");
|
}
|
|
#endregion
|
|
#region 发起bimface转换
|
|
var bimfaceTranslateStatus = await Yw.WinFrmUI.BimfaceHelper.TranslateRvtFile(bimfaceId);
|
if (bimfaceTranslateStatus != Yw.BIMFace.eTranslateStatus.Success)
|
{
|
await Yw.WinFrmUI.BimfaceHelper.WaitFileTranslateStatusUntilSuccess(bimfaceId, 3000);
|
}
|
|
#endregion
|
|
#region 更新状态
|
|
bol = await bllBimfaceFile.UpdateFileStatus(bimfaceFileId, (int)Yw.Bimface.eFileStatus.ConvertSucceed);
|
|
feedBackMsg?.Invoke("文件状态更新");
|
|
#endregion
|
|
return true;
|
|
}
|
|
|
}
|
}
|