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); }