コード例 #1
0
        internal static bool Load(string modelSystem, XTMFRuntime runtime, out ModelSystem?ms, ref string?error)
        {
            using var stream = new MemoryStream(Encoding.Unicode.GetBytes(modelSystem));
            var header = ModelSystemHeader.CreateRunHeader(runtime);

            ms = Load(stream, runtime.Modules, header, ref error);
            return(ms != null);
        }
コード例 #2
0
 private static ModelSystem?Load(Stream rawStream, ModuleRepository modules, ModelSystemHeader modelSystemHeader, ref string?error)
 {
     try
     {
         var modelSystem = new ModelSystem(modelSystemHeader);
         using var stream = new MemoryStream();
         rawStream.CopyTo(stream);
         var reader     = new Utf8JsonReader(stream.GetBuffer().AsSpan());
         var typeLookup = new Dictionary <int, Type>();
         var nodes      = new Dictionary <int, Node>();
         while (reader.Read())
         {
             if (reader.TokenType == JsonTokenType.PropertyName)
             {
                 if (reader.ValueTextEquals(TypesProperty))
                 {
                     if (!LoadTypes(typeLookup, ref reader, ref error))
                     {
                         return(null);
                     }
                 }
                 else if (reader.ValueTextEquals(BoundariesProperty))
                 {
                     if (!LoadBoundaries(modules, typeLookup, nodes, ref reader, modelSystem.GlobalBoundary, ref error))
                     {
                         return(null);
                     }
                     break;
                 }
                 else
                 {
                     error = $"Unknown token found '{reader.GetString()}'";
                     return(null);
                 }
             }
         }
         return(modelSystem);
     }
     catch (JsonException e)
     {
         error = e.Message;
     }
     catch (IOException e)
     {
         error = e.Message;
     }
     return(null);
 }
コード例 #3
0
        internal static bool Load(ProjectSession session, ModelSystemHeader modelSystemHeader, out ModelSystemSession?msSession, out CommandError?error)
        {
            // the parameters are have already been vetted
            var    path        = modelSystemHeader.ModelSystemPath;
            var    info        = new FileInfo(path);
            string?errorString = null;

            error = null;

            try
            {
                ModelSystem?ms;
                if (info.Exists)
                {
                    using var rawStream = File.OpenRead(modelSystemHeader.ModelSystemPath);
                    ms = Load(rawStream, session.GetModuleRepository(), modelSystemHeader, ref errorString);
                }
                else
                {
                    ms = new ModelSystem(modelSystemHeader);
                }
                if (ms == null)
                {
                    msSession = null;
                    // Give a generic error message if one was not already supplied.
                    error = new CommandError(errorString ?? "Unable to create a model system session for the given header.");
                    return(false);
                }
                msSession = new ModelSystemSession(session, ms);
                error     = null;
                return(true);
            }
            catch (IOException e)
            {
                error     = new CommandError(e.Message);
                msSession = null;
                return(false);
            }
        }
コード例 #4
0
 /// <summary>
 /// Create a new model system with the given header information.
 /// </summary>
 /// <param name="header">The header to create a new model system for.</param>
 public ModelSystem(ModelSystemHeader header)
 {
     Header = header;
     header.PropertyChanged += Header_PropertyChanged;
     GlobalBoundary          = new Boundary(GlobalBoundaryName);
 }