public static MyProject Deserialize(string xml, string projectPath) { xml = MyBaseConversion.ConvertOldFileVersioning(xml); xml = MyBaseConversion.ConvertOldModuleNames(xml); xml = CheckUsedModulesAndConvert(xml); YAXSerializer serializer = MyProject.GetSerializer(); MyPathSerializer.ReferencePath = projectPath; MyProject loadedProject = (MyProject)serializer.Deserialize(xml); MyPathSerializer.ReferencePath = String.Empty; DumpSerializerErrors(serializer); if (loadedProject == null) { throw new YAXException("Cannot deserialize project."); } loadedProject.World.FinalizeTasksDeserialization(); loadedProject.m_nodeCounter = loadedProject.Network.UpdateAfterDeserialization(0, loadedProject); if (loadedProject.World.Id > loadedProject.m_nodeCounter) { loadedProject.m_nodeCounter = loadedProject.World.Id; } loadedProject.m_nodeCounter++; loadedProject.ConnectWorld(); return(loadedProject); }
/// <summary> /// Deserializes the project from a given string. /// </summary> /// <param name="xml">The input string for deserialization.</param> /// <param name="projectPath">Project path for correct lookup of items like state data.</param> /// <param name="restoreModelOnly">If set to true, only the model is deserialized, but not observers etc.</param> /// <param name="strict">Fails when referenced modules are not found</param> /// <returns>A deserialized project.</returns> public static MyProject Deserialize(string xml, string projectPath, bool restoreModelOnly = false, bool strict = false) { xml = MyBaseConversion.ConvertOldFileVersioning(xml); xml = MyBaseConversion.ConvertOldModuleNames(xml); try { xml = CheckUsedModulesAndConvert(xml); } catch (Exception e) { if (strict) { throw; } MyLog.ERROR.WriteLine(e.Message); } YAXSerializer serializer = MyProject.GetSerializer(); MyPathSerializer.ReferencePath = projectPath; MyProject loadedProject = (MyProject)serializer.Deserialize(xml); MyPathSerializer.ReferencePath = String.Empty; DumpSerializerErrors(serializer); if (loadedProject == null) { throw new YAXException("Cannot deserialize project."); } loadedProject.FileName = projectPath; loadedProject.World.FinalizeTasksDeserialization(); loadedProject.World.UpdateAfterDeserialization(); loadedProject.m_nodeCounter = loadedProject.Network.UpdateAfterDeserialization(0, loadedProject); if (loadedProject.World.Id > loadedProject.m_nodeCounter) { loadedProject.m_nodeCounter = loadedProject.World.Id; } loadedProject.m_nodeCounter++; loadedProject.ConnectWorld(); if (!restoreModelOnly) { loadedProject.Restore(); } return(loadedProject); }
public string Serialize(string projectPath) { if (ReadOnly) { throw new InvalidOperationException("Project was not loaded correctly. Save is not allowed."); } Network.PrepareConnections(); UsedModules = ScanForUsedModules(); StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + System.Environment.NewLine); MyPathSerializer.ReferencePath = projectPath; // needed for conversion of absolute paths to relative ones sb.Append(MyProject.GetSerializer().Serialize(this)); MyPathSerializer.ReferencePath = String.Empty; return(sb.ToString()); }
public static string MakeDataFolderFromFileName(string path) { return(Path.Combine(Path.GetDirectoryName(path), MyProject.MakeNameFromPath(path) + ".statedata")); }