Exemple #1
0
 public DefaultsTabViewModel()
 {
     foreach (var def in DefaultsProvider.Default.Defaults.Defaults)
     {
         if (def.Category == "FaseCyclus")
         {
             FaseCyclusDefaults.Add(def);
         }
         if (def.Category == "Detector")
         {
             DetectorDefaults.Add(def);
         }
         if (def.Category == "Other")
         {
             OtherDefaults.Add(def);
         }
     }
     if (FaseCyclusDefaults.Count > 0)
     {
         SelectedFaseCyclusDefault = FaseCyclusDefaults[0];
     }
     if (DetectorDefaults.Count > 0)
     {
         SelectedDetectorDefault = DetectorDefaults[0];
     }
     if (OtherDefaults.Count > 0)
     {
         SelectedOtherDefault = OtherDefaults[0];
     }
 }
 private void RefreshDefaults()
 {
     FaseCyclusDefaults.Clear();
     DetectorDefaults.Clear();
     OtherDefaults.Clear();
     SelectedFaseCyclusDefault = null;
     SelectedDetectorDefault   = null;
     SelectedOtherDefault      = null;
     if (DefaultsProvider.Default.Defaults == null)
     {
         return;
     }
     foreach (var def in DefaultsProvider.Default.Defaults.Defaults)
     {
         if (def.Category == "FaseCyclus")
         {
             FaseCyclusDefaults.Add(def);
         }
         if (def.Category == "Detector")
         {
             DetectorDefaults.Add(def);
         }
         if (def.Category == "Other")
         {
             OtherDefaults.Add(def);
         }
     }
     if (FaseCyclusDefaults.Count > 0)
     {
         SelectedFaseCyclusDefault = FaseCyclusDefaults[0];
     }
     if (DetectorDefaults.Count > 0)
     {
         SelectedDetectorDefault = DetectorDefaults[0];
     }
     if (OtherDefaults.Count > 0)
     {
         SelectedOtherDefault = OtherDefaults[0];
     }
 }
Exemple #3
0
        private TLCGenDefaultsModel DeserializeDefaultsFile(string filename)
        {
            var defaults = new TLCGenDefaultsModel();
            var doc      = new XmlDocument();
            var reader   =
                XmlReader.Create(
                    filename,
                    new XmlReaderSettings()
            {
                IgnoreComments = true
            });

            doc.Load(reader);
            reader.Dispose();
            var defs = doc.DocumentElement?.SelectSingleNode("Defaults");

            if (defs == null)
            {
                return(null);
            }
            foreach (XmlNode def in defs.ChildNodes)
            {
                var x = def.SelectSingleNode("DataType");
                var t = x.InnerText;
                                #warning this corrects old files; should be removed at a point in the future (@24-1-2018)
                if (t.EndsWith(",TLCGen.Model"))
                {
                    t = t.Replace(",TLCGen.Model", ",TLCGen.Dependencies");
                }
                var type  = Type.GetType(t);
                var xRoot = new XmlRootAttribute
                {
                    ElementName = "Data",
                    IsNullable  = true
                };
                if (type == null)
                {
                    continue;
                }
                var ser = new XmlSerializer(type, xRoot);
                // http://stackoverflow.com/questions/1563473/xmlnode-to-objects
                var o    = ser.Deserialize(new XmlNodeReader(def.SelectSingleNode("Data")));
                var item = new TLCGenDefaultModel
                {
                    DefaultName = def.SelectSingleNode("DefaultName")?.InnerText,
                    DataType    = def.SelectSingleNode("DataType")?.InnerText,
                    Category    = def.SelectSingleNode("Category")?.InnerText
                };
                var n1 = def.SelectSingleNode("Selector1");
                if (n1 != null)
                {
                    item.Selector1 = n1.InnerText;
                }
                var n2 = def.SelectSingleNode("Selector2");
                if (n2 != null)
                {
                    item.Selector2 = n2.InnerText;
                }
                item.Data = o;
                defaults.Defaults.Add(item);
            }
            return(defaults);
        }