private bool Save(ref string?error, Stream saveTo, bool leaveOpen) { try { using var writer = new Utf8JsonWriter(saveTo); var typeDictionary = GlobalBoundary.GetUsedTypes(); writer.WriteStartObject(); WriteTypes(writer, typeDictionary); WriteBoundaries(writer, typeDictionary); writer.WriteEndObject(); return(true); } catch (IOException e) { error = e.Message; return(false); } finally { if (!leaveOpen) { saveTo.Dispose(); } } }
/// <summary> /// Check to see if the given boundary is within the model system. /// </summary> /// <param name="boundary"></param> /// <returns></returns> internal bool Contains(Boundary boundary) { lock (_modelSystemLock) { if (GlobalBoundary == boundary) { return(true); } return(GlobalBoundary.Contains(boundary)); } }
private void WriteBoundaries(Utf8JsonWriter writer, Dictionary <Type, int> typeDictionary) { int index = 0; writer.WritePropertyName(BoundariesProperty); writer.WriteStartArray(); Dictionary <Node, int> nodeDictionary = new Dictionary <Node, int>(); GlobalBoundary.Save(ref index, nodeDictionary, typeDictionary, writer); writer.WriteEndArray(); }
/// <summary> /// Generate the concrete model system for execution. /// </summary> /// <param name="runtime">The XTMF run time that we are executing within.</param> /// <param name="error">An error message if it can not be constructed.</param> /// <returns>True if it was created, false with message otherwise.</returns> internal bool Construct(XTMFRuntime runtime, ref string?error) { return(GlobalBoundary.ConstructModules(runtime, ref error) && GlobalBoundary.ConstructLinks(ref error)); }
/// <summary> /// Check that all requirements have been met when constructing the model system. /// </summary> /// <param name="moduleName">The name of the module that is causing the validation error.</param> /// <param name="error">An error message if the validation fails.</param> /// <returns>True if the validation passes, false otherwise with an error message.</returns> internal bool Validate(ref string?moduleName, ref string?error) { return(GlobalBoundary.Validate(ref moduleName, ref error)); }