Esempio n. 1
0
        public static Tuple <HierarchyConfigData, Guid> Deserialize(XElement xelem)
        {
            var hcd = new HierarchyConfigData();

            var guid = Guid.Parse(xelem.Attribute("id").Value);

            {
                var dir = xelem.Element("directories");
                if (dir == null)
                {
                    throw new Exception("Missing <directories> element");
                }

                if (XElementExtensions.ParseBool(dir.Attribute("null").Value))
                {
                    hcd = null;
                }
                else
                {
                    var dat = HierarchyConfigEntry.Deserialize(dir.Elements().Single());
                    hcd.Entry = dat;
                }
            }
            {
                var dir = xelem.Element("selectednote");
                if (dir == null)
                {
                    throw new Exception("Missing <selectednote> element");
                }

                if (XElementExtensions.ParseBool(dir.Attribute("null").Value))
                {
                    hcd.SelectedNote = null;
                }
                else
                {
                    hcd.SelectedNote = dir.Value;
                }
            }
            {
                var dir = xelem.Element("selectedpath");
                if (dir == null)
                {
                    throw new Exception("Missing <selectedpath> element");
                }

                if (XElementExtensions.ParseBool(dir.Attribute("null").Value))
                {
                    hcd.SelectedFolder = null;
                }
                else
                {
                    hcd.SelectedFolder = DirectoryPath.Deserialize(dir.Elements());
                }
            }

            return(Tuple.Create(hcd, guid));
        }
Esempio n. 2
0
 public HierarchyConfigData Get(Guid id)
 {
     lock (_masterLock)
     {
         if (_data.ContainsKey(id))
         {
             return(_data[id]);
         }
         return(_data[id] = new HierarchyConfigData());
     }
 }
Esempio n. 3
0
        public void UpdateAndRequestSave(Guid account, HierarchicalWrapper_Folder folders, DirectoryPath selectedFolderPath, string selectedNote)
        {
            LoggerSingleton.Inst.Trace("HierarchyConfigCache", $"Request Save (full)");

            var dat = new HierarchyConfigData
            {
                SelectedFolder = selectedFolderPath,
                SelectedNote   = selectedNote,
                Entry          = folders.ToHCEntry()
            };

            lock (_masterLock)
            {
                _data[account] = dat;
            }
            invSave.Request();
        }
Esempio n. 4
0
        public static HierarchyConfigCache LoadFromFile(string path)
        {
            try
            {
                if (!File.Exists(path))
                {
                    LoggerSingleton.Inst.Trace("HierarchyConfigCache", $"Load '{path}' (file not found)");
                    return(new HierarchyConfigCache(path, string.Empty));
                }

                var xml = File.ReadAllText(path);

                LoggerSingleton.Inst.Trace("HierarchyConfigCache", $"Load '{path}'", xml);

                var hcc = new HierarchyConfigCache(path, xml);

                var xdoc = XDocument.Parse(xml);
                if (xdoc.Root.Name != "cache")
                {
                    throw new Exception("Missing <cache> element");
                }

                var data = xdoc.Root.Element("data");
                if (data == null)
                {
                    throw new Exception("Missing <data> element");
                }

                foreach (var acc in data.Elements("account"))
                {
                    var d = HierarchyConfigData.Deserialize(acc);
                    hcc._data[d.Item2] = d.Item1;
                }

                return(hcc);
            }
            catch (Exception e)
            {
                LoggerSingleton.Inst.Error("HierarchyConfigCache", $"Could not load HierarchyConfig from file '{path}'", e);
                var hce = new HierarchyConfigCache(path, string.Empty);
                hce.ForceSaveNow();
                return(hce);
            }
        }