bool IExportControl.Run() { var filePath = txtTargetPath.Text; if (string.IsNullOrEmpty(filePath)) { ShowMessageBox(Strings.MessageSelectOutputPathFirst); return(false); } #if !R2014 if (CustomExporter.IsRenderingSupported() == false && ShowConfirmBox(Strings.ExportWillFailBecauseMaterialLib) == false) { return(false); } #endif if (File.Exists(filePath) && ShowConfirmBox(Strings.OutputFileExistedWarning) == false) { return(false); } var homePath = InnerApp.GetHomePath(); if (InnerApp.CheckHomeFolder(homePath) == false && ShowConfirmBox(Strings.HomeFolderIsInvalid) == false) { return(false); } var visualStyle = cbVisualStyle.SelectedItem as VisualStyleInfo; if (visualStyle != null) { foreach (var p in visualStyle.Features) { _Features.FirstOrDefault(x => x.Type == p.Key)?.ChangeSelected(_Features, p.Value); } } var levelOfDetail = (cbLevelOfDetail.SelectedItem as ComboItemInfo) ?? _LevelOfDetailDefault; #region 更新界面选项到 _Features void SetFeature(FeatureType featureType, bool selected) { _Features.FirstOrDefault(x => x.Type == featureType)?.ChangeSelected(_Features, selected); } SetFeature(FeatureType.Export2DViewAll, rb2DViewsAll.Checked); SetFeature(FeatureType.Export2DViewOnlySheet, rb2DViewsOnlySheet.Checked); SetFeature(FeatureType.GenerateThumbnail, cbGenerateThumbnail.Checked); //SetFeature(FeatureType.GenerateElementData, cbGeneratePropDbJson.Checked); SetFeature(FeatureType.GenerateModelsDb, cbGeneratePropDbSqlite.Checked); SetFeature(FeatureType.GenerateLeaflet, cbGenerateLeaflet.Checked); SetFeature(FeatureType.GenerateDwgDrawing, cbGenerateDwg.Checked); SetFeature(FeatureType.RegroupForLink, cbRegroupForLink.Checked); SetFeature(FeatureType.Force2DViewUseWireframe, cbForce2DViewUseWireframe.Checked); SetFeature(FeatureType.ExportGrids, cbIncludeGrids.Checked); SetFeature(FeatureType.ExportRooms, cbIncludeRooms.Checked); SetFeature(FeatureType.ExcludeProperties, cbExcludeElementProperties.Checked); SetFeature(FeatureType.ExcludeLines, cbExcludeLines.Checked); SetFeature(FeatureType.ExcludePoints, cbExcludeModelPoints.Checked); SetFeature(FeatureType.OnlySelected, cbExcludeUnselectedElements.Checked); SetFeature(FeatureType.ConsolidateGroup, cbConsolidateArrayGroup.Checked); SetFeature(FeatureType.ConsolidateAssembly, cbConsolidateAssembly.Checked); SetFeature(FeatureType.UseLevelCategory, rbGroupByLevelDefault.Checked); SetFeature(FeatureType.UseNwLevelCategory, rbGroupByLevelNavisworks.Checked); SetFeature(FeatureType.UseBoundLevelCategory, rbGroupByLevelBoundingBox.Checked); SetFeature(FeatureType.UseCurrentViewport, cbUseCurrentViewport.Checked); #endregion var isCanncelled = false; using (var session = LicenseConfig.Create()) { if (session.IsValid == false) { LicenseConfig.ShowDialog(session, ParentForm); return(false); } #region 保存设置 var config = _LocalConfig; config.Features = _Features.Where(x => x.Selected).Select(x => x.Type).ToList(); config.LastTargetPath = txtTargetPath.Text; config.VisualStyle = visualStyle?.Key; config.LevelOfDetail = levelOfDetail?.Value ?? -1; _Config.Save(); #endregion var sw = Stopwatch.StartNew(); try { var setting = new ExportSetting(); setting.LevelOfDetail = config.LevelOfDetail; setting.ExportType = ExportType.Zip; setting.OutputPath = config.LastTargetPath; setting.Features = _Features.Where(x => x.Selected && x.Enabled).Select(x => x.Type).ToList(); setting.SelectedElementIds = _ElementIds?.Where(x => x.Value).Select(x => x.Key).ToList(); setting.Selected2DViewIds = rb2DViewCustom.Checked ? _ViewIds : null; setting.Oem = LicenseConfig.GetOemInfo(homePath); var hasSuccess = false; using (var progress = new ProgressExHelper(this.ParentForm, Strings.MessageExporting)) { var cancellationToken = progress.GetCancellationToken(); #if !DEBUG //在有些 Revit 会遇到时不时无法转换的问题,循环多次重试, 应该可以成功 for (var i = 0; i < 5; i++) { try { StartExport(_UIDocument, _View, setting, progress.GetProgressCallback(), cancellationToken); hasSuccess = true; break; } catch (Autodesk.Revit.Exceptions.ExternalApplicationException) { Application.DoEvents(); } catch (IOException ex) { ShowMessageBox("文件保存失败: " + ex.Message); hasSuccess = true; break; } } #endif //如果之前多次重试仍然没有成功, 这里再试一次,如果再失败就会给出稍后重试的提示 if (hasSuccess == false) { StartExport(_UIDocument, _View, setting, progress.GetProgressCallback(), cancellationToken); } isCanncelled = cancellationToken.IsCancellationRequested; } sw.Stop(); var ts = sw.Elapsed; ExportDuration = new TimeSpan(ts.Days, ts.Hours, ts.Minutes, ts.Seconds); //去掉毫秒部分 Debug.WriteLine(Strings.MessageOperationSuccessAndElapsedTime, ExportDuration); if (isCanncelled == false) { { ShowMessageBox(string.Format(Strings.MessageExportSuccess, ExportDuration)); } } } catch (IOException ex) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(string.Format(Strings.MessageFileSaveFailure, ex.Message)); } catch (Autodesk.Revit.Exceptions.ExternalApplicationException) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(Strings.MessageOperationFailureAndTryLater); } catch (Exception ex) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(ex.ToString()); } } return(isCanncelled == false); }
bool IExportControl.Run() { var siteInfo = GetSiteInfo(); if (siteInfo == null) { ShowMessageBox(Strings.SiteLocationInvalid); return(false); } var filePath = txtTargetPath.Text; if (string.IsNullOrEmpty(filePath)) { ShowMessageBox(Strings.MessageSelectOutputPathFirst); return(false); } if (Autodesk.Navisworks.Api.Application.ActiveDocument.Models.Count == 0) { ShowMessageBox(Strings.SceneIsEmpty); return(false); } if (File.Exists(filePath) && ShowConfigBox(Strings.OutputFileExistedWarning) == false) { return(false); } var visualStyle = cbVisualStyle.SelectedItem as VisualStyleInfo; if (visualStyle != null) { foreach (var p in visualStyle.Features) { _Features.FirstOrDefault(x => x.Type == p.Key)?.ChangeSelected(_Features, p.Value); } } #region 更新界面选项到 _Features void SetFeature(FeatureType featureType, bool selected) { _Features.FirstOrDefault(x => x.Type == featureType)?.ChangeSelected(_Features, selected); } //SetFeature(FeatureType.ExportGrids, cbIncludeGrids.Checked); SetFeature(FeatureType.ExcludeLines, cbExcludeLines.Checked); SetFeature(FeatureType.ExcludePoints, cbExcludeModelPoints.Checked); SetFeature(FeatureType.OnlySelected, cbExcludeUnselectedElements.Checked); SetFeature(FeatureType.UseGoogleDraco, cbUseDraco.Checked); SetFeature(FeatureType.ExtractShell, cbUseExtractShell.Checked); SetFeature(FeatureType.GenerateModelsDb, cbGeneratePropDbSqlite.Checked); SetFeature(FeatureType.ExportSvfzip, cbExportSvfzip.Checked); SetFeature(FeatureType.EnableQuantizedAttributes, cbEnableQuantizedAttributes.Checked); SetFeature(FeatureType.EnableTextureWebP, cbEnableTextureWebP.Checked); #endregion var isCancelled = false; using (var session = LicenseConfig.Create()) { if (session.IsValid == false) { LicenseConfig.ShowDialog(session, ParentForm); return(false); } #region 保存设置 var config = _LocalConfig; config.Features = _Features.Where(x => x.Selected).Select(x => x.Type).ToList(); config.LastTargetPath = txtTargetPath.Text; config.VisualStyle = visualStyle?.Key; config.Mode = rbModeBasic.Checked ? 0 : 1; _Config.Save(); #endregion var sw = Stopwatch.StartNew(); try { var setting = new ExportSetting(); setting.OutputPath = config.LastTargetPath; setting.Mode = config.Mode; setting.Features = _Features.Where(x => x.Selected && x.Enabled).Select(x => x.Type).ToList(); setting.Site = siteInfo; setting.Oem = LicenseConfig.GetOemInfo(App.GetHomePath()); using (var progress = new ProgressExHelper(ParentForm, Strings.MessageExporting)) { var cancellationToken = progress.GetCancellationToken(); StartExport(setting, progress.GetProgressCallback(), cancellationToken); isCancelled = cancellationToken.IsCancellationRequested; } sw.Stop(); var ts = sw.Elapsed; ExportDuration = new TimeSpan(ts.Days, ts.Hours, ts.Minutes, ts.Seconds); //去掉毫秒部分 Debug.WriteLine(Strings.MessageOperationSuccessAndElapsedTime, ExportDuration); if (isCancelled == false) { if (config.AutoOpenAllow && config.AutoOpenAppName != null) { Process.Start(config.AutoOpenAppName, config.LastTargetPath); } else { ShowMessageBox(string.Format(Strings.MessageExportSuccess, ExportDuration)); } } } catch (IOException ex) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(string.Format(Strings.MessageFileSaveFailure, ex.Message)); } catch (Exception ex) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(ex.ToString()); } } return(isCancelled == false); }
public override int Execute(params string[] args) { using (var log = new RuntimeLog()) using (var session = LicenseConfig.Create()) { try { if (args == null || args.Length != 1) { log.Log(@"Fail", @"Startup", $@"传入参数数量: {args?.Length ?? -1}"); return(101); } var jobConfigFilePath = args[0]; var jobConfig = JobConfig.Load(jobConfigFilePath); if (jobConfig == null) { log.Log(@"Fail", @"Startup", @"任务设置加载失败"); return(102); } if (session.IsValid == false) { log.Log(@"Fail", @"Startup", @"授权无效!"); #region 保存授权无效信息文件 try { var filePath = Path.Combine(jobConfig.OutputPath, @"License Invalid.txt"); File.WriteAllText(filePath, @"未检测到有效的授权, 请检查授权期限是否已过期, 如使用 USBKEY 请确认 USBKEY 是否已正确插入 USB 接口!", Encoding.UTF8); } catch { // ignored } #endregion return(110); } const string SOURCE_NAME = @"Nw"; //这个数据源名称不可修改,是和 CLI 里的设置对应的 Router.SetProgressPhase(SOURCE_NAME, 1.0); var progress = 0; var ret = StartExport(jobConfig, log, x => { var newProgress = x; if (newProgress > progress) { progress = newProgress; Router.SetProgressValue(SOURCE_NAME, newProgress); } }); if (!ret) { return(103); } Router.SetProgressValue(SOURCE_NAME, 100); } catch (Exception ex) { log.Log(@"Exception", @"Startup", ex.ToString()); return(100); } } return(0); }
private void btnLicense_Click(object sender, EventArgs e) { LicenseConfig.ShowDialog(this); }
/// <summary> /// GetInstallConfig - Returns configuration stored in DotNetNuke.Install.Config /// </summary> /// <returns>ConnectionConfig object. Null if information is not present in the config file</returns> public InstallConfig GetInstallConfig() { var installConfig = new InstallConfig(); //Load Template var installTemplate = new XmlDocument(); Upgrade.GetInstallTemplate(installTemplate); //Parse the root node XmlNode rootNode = installTemplate.SelectSingleNode("//dotnetnuke"); if (rootNode != null) { installConfig.Version = XmlUtils.GetNodeValue(rootNode.CreateNavigator(), "version"); installConfig.InstallCulture = XmlUtils.GetNodeValue(rootNode.CreateNavigator(), "installCulture") ?? Localization.Localization.SystemLocale; } //Parse the scripts node XmlNode scriptsNode = installTemplate.SelectSingleNode("//dotnetnuke/scripts"); if (scriptsNode != null) { foreach (XmlNode scriptNode in scriptsNode) { if (scriptNode != null) { installConfig.Scripts.Add(scriptNode.InnerText); } } } //Parse the connection node XmlNode connectionNode = installTemplate.SelectSingleNode("//dotnetnuke/connection"); if (connectionNode != null) { var connectionConfig = new ConnectionConfig(); //Build connection string from the file connectionConfig.Server = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "server"); connectionConfig.Database = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "database"); connectionConfig.File = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "file"); connectionConfig.Integrated = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "integrated").ToLower() == "true"; connectionConfig.User = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "user"); connectionConfig.Password = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "password"); connectionConfig.RunAsDbowner = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "runasdbowner").ToLower() == "true"; connectionConfig.Qualifier = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "qualifier"); connectionConfig.UpgradeConnectionString = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "upgradeconnectionstring"); installConfig.Connection = connectionConfig; } //Parse the superuser node XmlNode superUserNode = installTemplate.SelectSingleNode("//dotnetnuke/superuser"); if (superUserNode != null) { var superUserConfig = new SuperUserConfig(); superUserConfig.FirstName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "firstname"); superUserConfig.LastName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "lastname"); superUserConfig.UserName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "username"); superUserConfig.Password = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "password"); superUserConfig.Email = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "email"); superUserConfig.Locale = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "locale"); superUserConfig.UpdatePassword = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "updatepassword").ToLower() == "true"; installConfig.SuperUser = superUserConfig; } //Parse the license node XmlNode licenseNode = installTemplate.SelectSingleNode("//dotnetnuke/license"); if (licenseNode != null) { var licenseConfig = new LicenseConfig(); licenseConfig.AccountEmail = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "accountEmail"); licenseConfig.InvoiceNumber = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "invoiceNumber"); licenseConfig.WebServer = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "webServer"); licenseConfig.LicenseType = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "licenseType"); if (!String.IsNullOrEmpty(XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "trial"))) { licenseConfig.TrialRequest = bool.Parse(XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "trial")); } installConfig.License = licenseConfig; } //Parse the settings node XmlNode settingsNode = installTemplate.SelectSingleNode("//dotnetnuke/settings"); if (settingsNode != null) { foreach (XmlNode settingNode in settingsNode.ChildNodes) { if (settingNode != null && !string.IsNullOrEmpty(settingNode.Name)) { bool settingIsSecure = false; if (settingNode.Attributes != null) { XmlAttribute secureAttrib = settingNode.Attributes["Secure"]; if ((secureAttrib != null)) { if (secureAttrib.Value.ToLower() == "true") { settingIsSecure = true; } } } installConfig.Settings.Add(new HostSettingConfig { Name = settingNode.Name, Value = settingNode.InnerText, IsSecure = settingIsSecure }); } } } var folderMappingsNode = installTemplate.SelectSingleNode("//dotnetnuke/" + FolderMappingsConfigController.Instance.ConfigNode); installConfig.FolderMappingsSettings = (folderMappingsNode != null)? folderMappingsNode.InnerXml : String.Empty; //Parse the portals node XmlNodeList portalsNode = installTemplate.SelectNodes("//dotnetnuke/portals/portal"); if (portalsNode != null) { foreach (XmlNode portalNode in portalsNode) { if (portalNode != null) { var portalConfig = new PortalConfig(); portalConfig.PortalName = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "portalname"); XmlNode adminNode = portalNode.SelectSingleNode("administrator"); if (adminNode != null) { portalConfig.AdminFirstName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "firstname"); portalConfig.AdminLastName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "lastname"); portalConfig.AdminUserName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "username"); portalConfig.AdminPassword = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "password"); portalConfig.AdminEmail = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "email"); } portalConfig.Description = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "description"); portalConfig.Keywords = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "keywords"); portalConfig.TemplateFileName = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "templatefile"); portalConfig.IsChild = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "ischild").ToLower() == "true"; ; portalConfig.HomeDirectory = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "homedirectory"); //Get the Portal Alias XmlNodeList portalAliases = portalNode.SelectNodes("portalaliases/portalalias"); if (portalAliases != null) { foreach (XmlNode portalAliase in portalAliases) { if (!string.IsNullOrEmpty(portalAliase.InnerText)) { portalConfig.PortAliases.Add(portalAliase.InnerText); } } } installConfig.Portals.Add(portalConfig); } } } return(installConfig); }
private async Task <Account> UpdateTemplate(CreateOrUpdateGeneralTemplateCommand command, CancellationToken cancellationToken) { var accountTemplate = await _context.Set <Account>() .Include(x => x.Billing) .Include(x => x.Contact) .Include(x => x.LicenseConfig) .Include(x => x.MachineConfig) .Include(x => x.BackupConfig) .FirstOrDefaultAsync(x => x.IsTemplate && x.Id == command.Id, cancellationToken); if (accountTemplate == null) { throw new EntityNotFoundException(nameof(Account), command.Id); } var instanceSettingsTemplate = accountTemplate.MachineConfig; if (instanceSettingsTemplate != null) { Mapper.Map(command, instanceSettingsTemplate); } else { instanceSettingsTemplate = new MachineConfig() { IsTemplate = true }; Mapper.Map(command, instanceSettingsTemplate); accountTemplate.MachineConfig = instanceSettingsTemplate; } var licenseTemplate = accountTemplate.LicenseConfig; if (licenseTemplate != null) { Mapper.Map(command, licenseTemplate); } else { licenseTemplate = new LicenseConfig() { IsTemplate = true }; Mapper.Map(command, licenseTemplate); accountTemplate.LicenseConfig = licenseTemplate; } var backupSettingsTemplate = accountTemplate.BackupConfig; if (backupSettingsTemplate != null) { Mapper.Map(command, backupSettingsTemplate); } else { backupSettingsTemplate = new BackupConfig() { IsTemplate = true }; Mapper.Map(command, backupSettingsTemplate); accountTemplate.BackupConfig = backupSettingsTemplate; } Mapper.Map(command, accountTemplate); return(accountTemplate); }
public Step3(Settings settings, LicenseConfig config) { Settings = settings; LicenseConfig = config; }
bool IExportControl.Run() { var siteInfo = GetSiteInfo(); if (siteInfo == null) { ShowMessageBox(Strings.SiteLocationInvalid); return(false); } var filePath = txtTargetPath.Text; if (string.IsNullOrEmpty(filePath)) { ShowMessageBox(Strings.MessageSelectOutputPathFirst); return(false); } #if !R2014 if (CustomExporter.IsRenderingSupported() == false && ShowConfirmBox(Strings.ExportWillFailBecauseMaterialLib) == false) { return(false); } #endif if (File.Exists(filePath) && ShowConfirmBox(Strings.OutputFileExistedWarning) == false) { return(false); } var homePath = InnerApp.GetHomePath(); if (InnerApp.CheckHomeFolder(homePath) == false && ShowConfirmBox(Strings.HomeFolderIsInvalid) == false) { return(false); } var visualStyle = cbVisualStyle.SelectedItem as VisualStyleInfo; if (visualStyle != null) { foreach (var p in visualStyle.Features) { _Features.FirstOrDefault(x => x.Type == p.Key)?.ChangeSelected(_Features, p.Value); } } var levelOfDetail = (cbLevelOfDetail.SelectedItem as ComboItemInfo) ?? _LevelOfDetailDefault; #region 更新界面选项到 _Features void SetFeature(FeatureType featureType, bool selected) { _Features.FirstOrDefault(x => x.Type == featureType)?.ChangeSelected(_Features, selected); } //SetFeature(FeatureType.ExportGrids, cbIncludeGrids.Checked); SetFeature(FeatureType.ExcludeLines, cbExcludeLines.Checked); SetFeature(FeatureType.ExcludePoints, cbExcludeModelPoints.Checked); SetFeature(FeatureType.OnlySelected, cbExcludeUnselectedElements.Checked && _HasElementSelected); SetFeature(FeatureType.UseGoogleDraco, cbUseDraco.Checked); //SetFeature(FeatureType.ExtractShell, cbUseExtractShell.Checked); SetFeature(FeatureType.GenerateModelsDb, cbGeneratePropDbSqlite.Checked); SetFeature(FeatureType.ExportSvfzip, cbExportSvfzip.Checked); SetFeature(FeatureType.EnableQuantizedAttributes, cbEnableQuantizedAttributes.Checked); SetFeature(FeatureType.EnableTextureWebP, cbEnableTextureWebP.Checked); SetFeature(FeatureType.GenerateThumbnail, cbGenerateThumbnail.Checked); SetFeature(FeatureType.EnableUnlitMaterials, cbEnableUnlitMaterials.Checked); SetFeature(FeatureType.AutoAlignOriginToSiteCenter, cbAlignOriginToSiteCenter.Checked); SetFeature(FeatureType.EnableEmbedGeoreferencing, !rbGeoreferencingNone.Checked); #endregion var isCancelled = false; using (var session = LicenseConfig.Create()) { if (session.IsValid == false) { LicenseConfig.ShowDialog(session, ParentForm); return(false); } #region 保存设置 var config = _LocalConfig; config.Features = _Features.Where(x => x.Selected).Select(x => x.Type).ToList(); config.LastTargetPath = txtTargetPath.Text; config.VisualStyle = visualStyle?.Key; config.LevelOfDetail = levelOfDetail?.Value ?? -1; config.GeoreferencingData = 2; config.GeoreferencingDetails = siteInfo.Clone(); if (rbGeoreferencingNone.Checked) { config.GeoreferencingData = 0; } else if (rbGeoreferencingCustom.Checked) { config.GeoreferencingData = 1; } else { config.GeoreferencingData = 2; } if (rbModeShellMesh.Checked) { config.Mode = 2; } else if (rbModeShellElement.Checked) { config.Mode = 3; } else { config.Mode = 0; } _Config.Save(); #endregion var sw = Stopwatch.StartNew(); try { var setting = new ExportSetting(); setting.LevelOfDetail = config.LevelOfDetail; setting.OutputPath = config.LastTargetPath; setting.Mode = config.Mode; setting.Features = _Features.Where(x => x.Selected && x.Enabled).Select(x => x.Type).ToList(); setting.SelectedElementIds = _ElementIds?.Where(x => x.Value).Select(x => x.Key).ToList(); setting.Site = siteInfo; setting.Oem = LicenseConfig.GetOemInfo(homePath); setting.PreExportSeedFeatures = InnerApp.GetPreExportSeedFeatures(@"3DTiles"); var hasSuccess = false; using (var progress = new ProgressExHelper(this.ParentForm, Strings.MessageExporting)) { var cancellationToken = progress.GetCancellationToken(); #if !DEBUG //在有些 Revit 会遇到时不时无法转换的问题,循环多次重试, 应该可以成功 for (var i = 0; i < 5; i++) { try { StartExport(_UIDocument, _View, setting, progress.GetProgressCallback(), cancellationToken); hasSuccess = true; break; } catch (Autodesk.Revit.Exceptions.ExternalApplicationException) { Application.DoEvents(); } catch (IOException ex) { ShowMessageBox("文件保存失败: " + ex.Message); hasSuccess = true; break; } } #endif //如果之前多次重试仍然没有成功, 这里再试一次,如果再失败就会给出稍后重试的提示 if (hasSuccess == false) { StartExport(_UIDocument, _View, setting, progress.GetProgressCallback(), cancellationToken); } isCancelled = cancellationToken.IsCancellationRequested; } sw.Stop(); var ts = sw.Elapsed; ExportDuration = new TimeSpan(ts.Days, ts.Hours, ts.Minutes, ts.Seconds); //去掉毫秒部分 Debug.WriteLine(Strings.MessageOperationSuccessAndElapsedTime, ExportDuration); if (isCancelled == false) { ShowMessageBox(string.Format(Strings.MessageExportSuccess, ExportDuration)); } } catch (IOException ex) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(string.Format(Strings.MessageFileSaveFailure, ex.Message)); } catch (Autodesk.Revit.Exceptions.ExternalApplicationException) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(Strings.MessageOperationFailureAndTryLater); } catch (Exception ex) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(ex.ToString()); } } return(isCancelled == false); }
bool IExportControl.Run() { var filePath = txtTargetPath.Text; if (string.IsNullOrEmpty(filePath)) { ShowMessageBox(Strings.MessageSelectOutputPathFirst); return(false); } if (File.Exists(filePath) && ShowConfirmBox(Strings.OutputFileExistedWarning) == false) { return(false); } var homePath = InnerApp.GetHomePath(); if (InnerApp.CheckHomeFolder(homePath) == false && ShowConfirmBox(Strings.HomeFolderIsInvalid) == false) { return(false); } var visualStyle = cbVisualStyle.SelectedItem as VisualStyleInfo; if (visualStyle != null) { foreach (var p in visualStyle.Features) { _Features.FirstOrDefault(x => x.Type == p.Key)?.ChangeSelected(_Features, p.Value); } } var levelOfDetail = (cbLevelOfDetail.SelectedItem as ComboItemInfo) ?? _LevelOfDetailDefault; #region 更新界面选项到 _Features void SetFeature(FeatureType featureType, bool selected) { _Features.FirstOrDefault(x => x.Type == featureType)?.ChangeSelected(_Features, selected); } //SetFeature(FeatureType.ExportGrids, cbIncludeGrids.Checked); SetFeature(FeatureType.ExcludeLines, cbExcludeLines.Checked); SetFeature(FeatureType.ExcludePoints, cbExcludeModelPoints.Checked); SetFeature(FeatureType.OnlySelected, cbExcludeUnselectedElements.Checked && _HasSelectElements); SetFeature(FeatureType.UseGoogleDraco, cbUseDraco.Checked); SetFeature(FeatureType.ExtractShell, cbUseExtractShell.Checked); SetFeature(FeatureType.GenerateModelsDb, cbGeneratePropDbSqlite.Checked); SetFeature(FeatureType.ExportSvfzip, cbExportSvfzip.Checked); SetFeature(FeatureType.GenerateThumbnail, cbGenerateThumbnail.Checked); SetFeature(FeatureType.EnableAutomaticSplit, cbEnableAutomaticSplit.Checked); SetFeature(FeatureType.AllowRegroupNodes, cbAllowRegroupNodes.Checked); #endregion var isCanncelled = false; using (var session = LicenseConfig.Create()) { if (session.IsValid == false) { LicenseConfig.ShowDialog(session, ParentForm); return(false); } #region 保存设置 var config = _LocalConfig; config.Features = _Features.Where(x => x.Selected).Select(x => x.Type).ToList(); config.LastTargetPath = txtTargetPath.Text; config.AutoOpenAppName = string.Empty; config.VisualStyle = visualStyle?.Key; config.LevelOfDetail = levelOfDetail?.Value ?? -1; _Config.Save(); #endregion var sw = Stopwatch.StartNew(); try { var setting = new ExportSetting(); setting.LevelOfDetail = config.LevelOfDetail; setting.OutputPath = config.LastTargetPath; setting.Features = _Features.Where(x => x.Selected && x.Enabled).Select(x => x.Type).ToList(); setting.Site = ExporterHelper.GetSiteInfo(_View.GetRootModel()) ?? SiteInfo.CreateDefault(); setting.Oem = LicenseConfig.GetOemInfo(InnerApp.GetHomePath()); setting.PreExportSeedFeatures = InnerApp.GetPreExportSeedFeatures(@"glTF"); using (var progress = new ProgressExHelper(this.ParentForm, Strings.MessageExporting)) { var cancellationToken = progress.GetCancellationToken(); try { StartExport(_View, setting, progress.GetProgressCallback(), cancellationToken); } catch (IOException ex) { ShowMessageBox(string.Format(Strings.MessageFileSaveFailure, ex.ToString())); } isCanncelled = cancellationToken.IsCancellationRequested; } sw.Stop(); var ts = sw.Elapsed; ExportDuration = new TimeSpan(ts.Days, ts.Hours, ts.Minutes, ts.Seconds); //去掉毫秒部分 Debug.WriteLine(Strings.MessageOperationSuccessAndElapsedTime, ExportDuration); if (isCanncelled == false) { ShowMessageBox(string.Format(Strings.MessageExportSuccess, ExportDuration)); } } catch (IOException ex) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(string.Format(Strings.MessageFileSaveFailure, ex.Message)); } //catch (Autodesk.Dgn.Exceptions.ExternalApplicationException) //{ // sw.Stop(); // Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); // ShowMessageBox(Strings.MessageOperationFailureAndTryLater); //} catch (Exception ex) { sw.Stop(); Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed); ShowMessageBox(ex.ToString()); } } return(isCanncelled == false); }