Пример #1
0
 public static AppConfig Deserialize(XDocument doc)
 {
     #region --- Calling Contract... ---
     if (doc == null)
     {
         Error?.Invoke("Document is null!");
         return(null);
     }
     //
     XElement rootElem = doc.Element(AppCfgElemNm);
     if (rootElem == null)
     {
         Error?.Invoke($"Document does not contains a <{AppCfgElemNm}> element!");
         return(null);
     }
     #endregion
     //
     AppConfig cfg = new AppConfig();
     // List of Recently Opened Files...
     XElement rofCollElem = rootElem.Element(RofCollElemNm);
     if (rofCollElem == null)
     {
         Info?.Invoke($"There is no DataStore configuration: <{RofCollElemNm}> element!");
         return(cfg);
     }
     //
     IEnumerable <XElement> rofElemList = rofCollElem.Elements(RofElemNm);
     foreach (XElement rofElem in rofElemList)
     {
         RecentlyOpenedFile rof = new RecentlyOpenedFile();
         string             ts  = (rofElem.Attribute(TsAttrNm)?.Value);
         if (ts != null)
         {
             DateTime date = DateTime.ParseExact(ts, TIMESTAMP_FORMATSTR, System.Globalization.CultureInfo.InvariantCulture);
             rof.Timestamp = date;
         }
         else
         {
             rof.Timestamp = DateTime.MinValue;
         }
         rof.Name   = Path.GetFileName((rofElem.Attribute(FnmAttrNm)?.Value));
         rof.Path   = (rofElem.Attribute(PnmAttrNm)?.Value);
         rof.Pinned = GetBooleanAttribute((rofElem.Attribute(PinAttrNm)?.Value), false);
         if (File.Exists(rof.FullQualifiedName()))
         {
             rof.Available = true;
             rof.Enabled   = true;
         }
         else
         {
             rof.Available = false;
             rof.Enabled   = false;
         }
         //
         cfg.RecentlyOpenedFileList.Add(rof);
     }
     //
     return(cfg);
 }
Пример #2
0
        public void AddRecentlyOpenedFile(string fqn)
        {
            //foreach( RecentlyOpenedFile rof in this.RecentlyOpenedFileList )
            //{
            //   if( string.Compare( rof.FullQualifiedName( ), fqn, StringComparison.Ordinal ) == 0 )
            //   {
            //      rof.Timestamp = DateTime.Now;
            //      return;
            //   }
            //}
            RecentlyOpenedFile newRof = new RecentlyOpenedFile();

            newRof.Name      = System.IO.Path.GetFileName(fqn);
            newRof.Path      = System.IO.Path.GetDirectoryName(fqn);
            newRof.Available = true;
            newRof.Enabled   = true;
            newRof.Timestamp = DateTime.Now;
            this.RecentlyOpenedFileList.Add(newRof);
        }