private static AbstractPersistentData Deserialize(string filePath, string importedBuildPath)
        {
            var deserializer = new IPersistentDataDeserializer[]
            {
                new PersistentDataDeserializerUpTo230(), new PersistentDataDeserializerCurrent()
            };
            var xmlString = File.ReadAllText(filePath);
            var version   = XmlSerializationUtils.DeserializeString <XmlPersistentDataVersion>(xmlString).AppVersion;
            IPersistentDataDeserializer suitableDeserializer;

            if (version == null)
            {
                suitableDeserializer = deserializer.FirstOrDefault(c => c.MinimumDeserializableVersion == null);
            }
            else
            {
                var v = new Version(version);
                suitableDeserializer = deserializer.FirstOrDefault(c =>
                                                                   v.CompareTo(c.MinimumDeserializableVersion) >= 0 &&
                                                                   v.CompareTo(c.MaximumDeserializableVersion) <= 0);
            }
            if (suitableDeserializer == null)
            {
                throw new Exception(
                          $"No converter available that can deserialize a PersistentData file with version {version}");
            }
            var data = new PersistentData(suitableDeserializer, importedBuildPath);

            suitableDeserializer.DeserializePersistentDataFile(xmlString);
            return(data);
        }
Пример #2
0
        public override void DeserializePersistentDataFile(string xmlString)
        {
            var obj = XmlSerializationUtils.DeserializeString <XmlPersistentData>(xmlString);

            PersistentData.Options = obj.Options;
            obj.StashBookmarks?.ForEach(PersistentData.StashBookmarks.Add);
            obj.LeagueStashes?.ForEach(l => PersistentData.LeagueStashes[l.Name] = l.Bookmarks);

            _currentBuildPath  = obj.CurrentBuildPath;
            _selectedBuildPath = obj.SelectedBuildPath;
        }
        public override void DeserializePersistentDataFile(string xmlString)
        {
            var obj = XmlSerializationUtils.DeserializeString <XmlPersistentData>(xmlString);

            PersistentData.Options      = obj.Options;
            PersistentData.CurrentBuild = ConvertFromXmlBuild(obj.CurrentBuild) ?? CreateDefaultCurrentBuild();
            obj.StashBookmarks?.ForEach(PersistentData.StashBookmarks.Add);
            PersistentData.RootBuild.Builds.AddRange(obj.Builds.Select(ConvertFromXmlBuild));

            if (!SelectCurrentBuildByName(PersistentData.CurrentBuild.Name))
            {
                PersistentData.RootBuild.Builds.Add(PersistentData.CurrentBuild);
            }
            RenameBuilds();
        }
Пример #4
0
 /// <summary>
 /// Imports the build given as a xml string. <see cref="IPersistentData.SaveBuild"/> may be
 /// called by this method.
 /// </summary>
 public Task <PoEBuild?> ImportBuildFromStringAsync(string buildXml)
 {
     return(ImportBuildAsync(
                () => Task.FromResult(XmlSerializationUtils.DeserializeString <XmlBuild>(buildXml))));
 }