Пример #1
0
        private void SaveTrackerProcessesToStorage()
        {
            var list = new List <QuestItem>();

            foreach (var tracker in availableTrackers)
            {
                var item = new QuestItem
                {
                    Id         = tracker.Id,
                    Type       = tracker.Type,
                    Name       = tracker.Name,
                    IsTracking = tracker.IsTracking
                };

                DateTime dT;
                questsStartTracking.TryGetValue(tracker.Id, out dT);
                item.TrackingStart = dT;

                item.ProcessStorageString = tracker.SerializeData();

                list.Add(item);
            }

            QuestFS.SaveQuests(list.ToArray());
        }
Пример #2
0
        public static QuestItem[] GetQuests()
        {
            try
            {
                if (!Directory.Exists(Path.GetDirectoryName(StoragePath)))
                {
                    return(new QuestItem[0]);
                }

                if (!File.Exists(StoragePath))
                {
                    return(new QuestItem[0]);
                }

                var items = new List <QuestItem>();

                XElement.Load(StoragePath)
                .Descendants("Quest")
                .ToList()
                .ForEach(e => items.Add(QuestItem.Deserialize(e.Value)));

                return(items.ToArray());
            }
            catch (Exception e)
            {
                MessageBox.Show($"QuestTracker error: \r\n{e}");

                return(new QuestItem[0]);
            }
        }
Пример #3
0
        public static QuestItem Deserialize(string data)
        {
            var result = new QuestItem();

            try
            {
                data.Split(new[] {"###"}, StringSplitOptions.None).Into(i => result.Id = int.Parse(i),
                                                                        i => result.Name = i,
                                                                        i => result.Type = (QuestType)int.Parse(i),
                                                                        i => result.IsTracking = bool.Parse(i),
                                                                        i => result.TrackingStart = DateTime.Parse(i),
                                                                        i => result.ProcessStorageString = i
                    );
            }
            catch
            {
                // ignored
            }
            return result;
        }
Пример #4
0
        public static QuestItem Deserialize(string data)
        {
            var result = new QuestItem();

            try
            {
                data.Split(new[] { "###" }, StringSplitOptions.None).Into(i => result.Id                   = int.Parse(i),
                                                                          i => result.Name                 = i,
                                                                          i => result.Type                 = (QuestType)int.Parse(i),
                                                                          i => result.IsTracking           = bool.Parse(i),
                                                                          i => result.TrackingStart        = DateTime.Parse(i),
                                                                          i => result.ProcessStorageString = i
                                                                          );
            }
            catch
            {
                // ignored
            }
            return(result);
        }
Пример #5
0
        public static void SaveQuests(QuestItem[] items)
        {
            try
            {
                if (!Directory.Exists(Path.GetDirectoryName(StoragePath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(StoragePath));

                var root = new XElement("Quests");

                foreach (var item in items)
                {
                    root.Add(new XElement("Quest",
                                          new XAttribute("Id", item.Id),
                                          item.Serialize()));
                }

                root.Save(StoragePath);
            }
            catch (Exception e)
            {
                MessageBox.Show($"QuestTracker error: \r\n{e}");
            }
        }
Пример #6
0
        private void SaveTrackerProcessesToStorage()
        {
            var list = new List<QuestItem>();

            foreach (var tracker in availableTrackers)
            {
                var item = new QuestItem
                           {
                               Id = tracker.Id,
                               Type = tracker.Type,
                               Name = tracker.Name,
                               IsTracking = tracker.IsTracking
                           };

                DateTime dT;
                questsStartTracking.TryGetValue(tracker.Id, out dT);
                item.TrackingStart = dT;

                item.ProcessStorageString = tracker.SerializeData();

                list.Add(item);
            }

            QuestFS.SaveQuests(list.ToArray());
        }