Пример #1
0
 /// <summary>
 /// Load a model system that has been saved into a string
 /// </summary>
 /// <param name="modelSystemAsText">The model system stored as a string.</param>
 /// <param name="modelSystem">The model system loaded</param>
 /// <param name="error">A description of the error if the operation fails.</param>
 /// <returns>True if the model system was loaded, false otherwise with a description of the failure in error.</returns>
 public bool LoadDetachedModelSystemFromString(string modelSystemAsText, out ModelSystem modelSystem, ref string error)
 {
     using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(modelSystemAsText)))
     {
         stream.Seek(0, SeekOrigin.Begin);
         modelSystem = ModelSystem.LoadDetachedModelSystem(stream, Runtime.Configuration, ref error);
         return(modelSystem != null);
     }
 }
Пример #2
0
 /// <summary>
 /// Load a model system that has been saved in a file
 /// </summary>
 /// <param name="fileName">The path of the file to load.</param>
 /// <param name="modelSystem">The resulting model system if successful.</param>
 /// <param name="error">A description of the error if the operation fails.</param>
 /// <returns>True if the model system was loaded, false otherwise with a description of the failure in error.</returns>
 public bool LoadDetachedModelSystemFromFile(string fileName, out ModelSystem modelSystem, ref string error)
 {
     try
     {
         FileInfo fileInfo = new FileInfo(fileName);
         if (!fileInfo.Exists)
         {
             error       = $"File does not exist '{fileName}'";
             modelSystem = null;
             return(false);
         }
         using (var stream = fileInfo.OpenRead())
         {
             modelSystem = ModelSystem.LoadDetachedModelSystem(stream, Runtime.Configuration, ref error);
             return(modelSystem != null);
         }
     }
     catch (IOException e)
     {
         error       = e.Message;
         modelSystem = null;
         return(false);
     }
 }