/// <summary> /// Will save the current alignment to a persistent file as XML. /// </summary> /// <param name="fileName">The file name</param> /// <returns>A log message</returns> public LogMessage SaveTo(string fileName) { try { TheAxisAlignment.SaveToFile(fileName); } catch (Exception e) { return(LogMessage.BySeverityAndMessage(fileName, LogSeverity.Error, LogReason.Saved, "Error while saving '{0}': {1}", fileName, e.Message)); } return(LogMessage.BySeverityAndMessage(fileName, LogSeverity.Info, LogReason.Saved, "Saved '{0}'.", fileName)); }
#pragma warning restore CS1591 /// <summary> /// Saves the settings to file as XML. /// </summary> /// <param name="fileName">The file name</param> /// <param name="settings">The settings</param> /// <returns>A log message</returns> public static LogMessage SaveAs(SceneBuildSettings settings, string fileName) { try { settings.Preferences.SaveTo(fileName); return(LogMessage.BySeverityAndMessage(fileName, LogSeverity.Info, LogReason.Saved, "Saved {0}", fileName)); } catch (Exception e) { return(LogMessage.BySeverityAndMessage(fileName, LogSeverity.Error, LogReason.Saved, "{0}: {1} ({2})", e, e.Message, fileName)); } }
/// <summary> /// Exports the current component scene to the given format indicated by the extension. /// </summary> /// <param name="scene">The scene</param> /// <param name="unitScale">The scale</param> /// <param name="transform">The axes transform</param> /// <param name="formatID">The format ID (one of <see cref="exportAsFormats"/>)</param> /// <param name="canonicalSeparator">The canonical fragment separator</param> /// <returns>The exported scene</returns> public static ComponentScene Export(ComponentScene scene, UnitScale unitScale, CRSTransform transform, string formatID, string canonicalSeparator) { if (null == scene) { throw new ArgumentNullException(nameof(scene)); } var format = exportAsFormats.FirstOrDefault(f => f.ID == formatID); if (null == format) { throw new ArgumentException($"Unknown format ID {formatID}."); } var qualifier = BuildQualifierByExtension(scene.Qualifier, format.Extension); var fileName = GetFilePathName(qualifier, canonicalSeparator, true); using (var monitor = scene.CreateProgressMonitor(LogReason.Saved)) { try { var exp = new TRexAssimp.TRexAssimpExport(new TRexAssimp.TRexAssimpPreferences(transform, unitScale)); monitor.NotifyProgressEstimateUpdate(1); monitor.NotifyOnProgressChange(0, "Start exporting"); if (!exp.ExportTo(scene.SceneModel, fileName, format)) { monitor.State.MarkBroken(); scene.OnActionLogged( LogMessage.ByErrorMessage(scene.Name, LogReason.Saved, "An error occured while exporting to '{0}'. {1}", fileName, exp.StatusMessage)); } else { monitor.NotifyOnProgressChange(1, "Exported"); scene.OnActionLogged( LogMessage.BySeverityAndMessage(scene.Name, LogSeverity.Info, LogReason.Saved, "Scene exported to '{0}'.", fileName)); } } catch (Exception e) { monitor.State.MarkBroken(); scene.Logger?.LogError(e, "An exception has been caught: {0}", e.Message); scene.OnActionLogged( LogMessage.ByErrorMessage(scene.Name, LogReason.Saved, "Exception '{0}' thrown while exporting to '{1}'.", e.Message, fileName)); } monitor.State.MarkTerminated(); monitor.NotifyOnProgressEnd(); } return(scene); }
private static IEnumerable <LogMessage> TransformLogToMessage(string storeName, IEnumerable <TransformLogEntry> logEntries, LogReason filter = LogReason.Any) { foreach (var entry in logEntries) { var action = TransformActionToActionType(entry.performed); if (LogReason.None != (filter & action)) { yield return(LogMessage.BySeverityAndMessage( storeName, LogSeverity.Info, action, "#{0} {1}", entry.handle.EntityLabel.ToString() ?? "(not set)", entry.handle.EntityExpressType.Name ?? "(type unknown)")); } } }
#pragma warning restore CS1591 /// <summary> /// Saves the current component model as it is to JSON or binary format. /// </summary> /// <param name="scene">The scene to save</param> /// <param name="formatID">The desired format ID (<see cref="saveAsFormats"/>) to use</param> /// <param name="canonicalSeparator">Canonical fragment seperator.</param> /// <returns>The saved scene</returns> public static ComponentScene Save(ComponentScene scene, string formatID, string canonicalSeparator) { if (null == scene) { throw new ArgumentNullException(nameof(scene)); } var format = saveAsFormats.FirstOrDefault(f => f.ID == formatID); if (null == format) { throw new ArgumentException($"Unknown format ID {formatID}."); } var qualifier = BuildQualifierByExtension(scene.Qualifier, format.Extension); var fileName = GetFilePathName(qualifier, canonicalSeparator, true); using (var monitor = scene.CreateProgressMonitor(LogReason.Saved)) { try { monitor.NotifyProgressEstimateUpdate(1); monitor.NotifyOnProgressChange(0, "Start saving"); switch (format.Extension) { case "scene": using (var binStream = File.Create(fileName)) { var binScene = scene.SceneModel.ToByteArray(); binStream.Write(binScene, 0, binScene.Length); } break; case "json": using (var textStream = File.CreateText(fileName)) { var json = new JsonFormatter(new JsonFormatter.Settings(false)).Format(scene.SceneModel); textStream.Write(json); } break; default: var msg = $"Unknown implementation of format '{format.Extension}'."; scene.OnActionLogged(LogMessage.ByErrorMessage(scene.Name, LogReason.Saved, msg)); monitor.State.MarkBroken(); throw new ArgumentException(msg); } scene.OnActionLogged( LogMessage.BySeverityAndMessage(scene.Name, LogSeverity.Info, LogReason.Saved, "Scene save to '{0}'.", fileName)); monitor.NotifyOnProgressChange(1, "Saved file"); } catch (Exception e) { monitor.State.MarkBroken(); scene.Logger?.LogError(e, "An exception has been caught: {0}", e.Message); scene.OnActionLogged( LogMessage.ByErrorMessage(scene.Name, LogReason.Saved, "Exception '{0}' thrown while saving to '{1}'.", e.Message, fileName)); } monitor.State.MarkTerminated(); monitor.NotifyOnProgressEnd(); } return(scene); }
public static IfcModel BySourceAndTransform(IfcModel source, IfcTransform transform, string nameAddon, object objFilterMask) { if (null == source) { throw new ArgumentNullException(nameof(source)); } if (null == transform) { throw new ArgumentNullException(nameof(transform)); } if (null == nameAddon) { nameAddon = transform.Mark; } LogReason filterMask = DynamicArgumentDelegation.TryCastEnumOrDefault(objFilterMask, LogReason.Any); if (null == transform.CancellationSource) { transform.CancellationSource = new CancellationTokenSource(); } return(IfcStore.ByTransform(source, (model, node) => { log.LogInformation("Starting '{1}' ({0}) on {2} ...", node.GetHashCode(), transform.transformDelegate.Name, node.Name); try { using (var task = transform.transformDelegate.Run(model, node.CreateProgressMonitor(LogReason.Transformed))) { task.Wait(transform.TimeOutMillis, transform.CancellationSource.Token); log.LogInformation("Finalized '{1}' ({0}) on {2}.", node.GetHashCode(), transform.transformDelegate.Name, node.Name); if (task.IsCompleted) { if (node is ProgressingTask np) { np.OnProgressEnded(LogReason.Changed, false); } using (var result = task.Result) { switch (result.ResultCode) { case TransformResult.Code.Finished: var name = $"{transform.transformDelegate.Name}({node.Name})"; node.OnActionLogged(TransformLogToMessage(name, result.Log, filterMask).ToArray()); return result.Target; case TransformResult.Code.Canceled: node.OnActionLogged(LogMessage.BySeverityAndMessage( node.Name, LogSeverity.Error, LogReason.Any, "Canceled by user request ({0}).", node.Name)); break; case TransformResult.Code.ExitWithError: node.OnActionLogged(LogMessage.BySeverityAndMessage( node.Name, LogSeverity.Error, LogReason.Any, "Caught error ({0}): {1}", node.Name, result.Cause)); break; } } } else { if (node is ProgressingTask np) { np.OnProgressEnded(LogReason.Changed, true); } node.OnActionLogged(LogMessage.BySeverityAndMessage( node.Name, LogSeverity.Error, LogReason.Changed, $"Task incompletely terminated (Status {task.Status}).")); } return null; } } catch (Exception thrownOnExec) { log.LogError("{0} '{1}'\n{2}", thrownOnExec, thrownOnExec.Message, thrownOnExec.StackTrace); throw new Exception("Exception while executing task"); } }, nameAddon)); }