Example #1
0
        public static DataStoreConfig Load(string filename)
        {
            if (!File.Exists(filename))
            {
                Error?.Invoke($"File {filename} does not exist!");
                return(null);
            }

            try
            {
                XDocument       doc      = XDocument.Load(filename, LoadOptions.None);
                DataStoreConfig dsConfig = DataStoreConfig.Deserialize(doc);
                if (dsConfig != null)
                {
                    Info?.Invoke($"File '{filename}' loaded!");
                    return(dsConfig);
                }
                Error?.Invoke($"Load error @ '{filename}'!");
                return(null);
            } catch (Exception ex)
            {
                Error?.Invoke($"Load exceptions @ '{filename}'!");
                Error?.Invoke(ex.Message);
                Error?.Invoke(ex.StackTrace);
                return(null);
            }
        }
Example #2
0
 public static DataStoreConfig Deserialize(XDocument doc)
 {
     #region --- Calling Contract... ---
     if (doc == null)
     {
         Error?.Invoke("Document is null!");
         return(null);
     }
     //
     XElement dsCfgElem = doc.Element(DsCfgElemNm);
     if (dsCfgElem == null)
     {
         Error?.Invoke($"Document does not contains a <{DsCfgElemNm}> element!");
         return(null);
     }
     #endregion
     //
     DataStoreConfig cfg = new DataStoreConfig();
     // Default StagePathDir
     cfg.DefaultStgDirVal = (dsCfgElem.Element(StgDirElemNm)?.Value);
     if (string.IsNullOrWhiteSpace(cfg.DefaultStgDirVal))
     {
         Error?.Invoke($"Document does not contains a <{StgDirElemNm}> element!");
     }
     // List of DataStores...
     XElement dsCollElem = dsCfgElem.Element(DsCollElemNm);
     if (dsCollElem == null)
     {
         Error?.Invoke($"There is no DataStore configuration: <{DsCollElemNm}> element!");
         return(cfg);
     }
     //
     IEnumerable <XElement> dsElemList = dsCollElem.Elements(DsElemNm);
     foreach (XElement dsElem in dsElemList)
     {
         DataStore ds = new DataStore();
         ds.Name   = (dsElem.Attribute(NmAttrNm)?.Value);
         ds.Active = GetBooleanAttribute((dsElem.Attribute(ActvAttrNm)?.Value), false);
         ds.LoadDefaultDatabaseOnly = GetBooleanAttribute((dsElem.Attribute(LddoAttrNm)?.Value), false);
         ds.LoadSystemObjects       = GetBooleanAttribute((dsElem.Attribute(LsoAttrNm)?.Value), false);
         ds.LoadWithFields          = GetBooleanAttribute((dsElem.Attribute(WfAttrNm)?.Value), false);
         ds.StagePathDir            = (dsElem.Element(StgDirElemNm)?.Value);
         if (ds.StagePathDir == null)
         {
             ds.StagePathDir = cfg.DefaultStgDirVal;
         }
         //
         XElement csElem = dsElem.Element(CsElemNm);
         if (csElem == null)
         {
             cfg.DataStoreList.Add(ds);
             continue;
         }
         ds.ProviderName     = (csElem.Attribute(PnAttrNm)?.Value);
         ds.ConnectionString = (csElem.Element(ConnStrElemNm)?.Value);
         cfg.DataStoreList.Add(ds);
     }
     if (cfg.DataStoreList.Count == 0)
     {
         Warn?.Invoke($"There is no DataStore configuration: <{DsElemNm}> element!");
     }
     //
     return(cfg);
 }