Пример #1
0
 partial void DeleteDicSystemKind(DicSystemKind instance);
Пример #2
0
 partial void UpdateDicSystemKind(DicSystemKind instance);
Пример #3
0
 public static string GetDescription(DicSystemKind sk)
 {
     return string.Format("Хранилище свойств для типа системы {0}", sk);
 }
Пример #4
0
 partial void InsertDicSystemKind(DicSystemKind instance);
Пример #5
0
        public static void Initialize(LocoDataContext db, Stream DocumentStream)
        {
            if (!db.DatabaseExists()) db.CreateDatabase();
            XElement XRoot = XDocument.Load(DocumentStream).Root;

            foreach (XElement XValue in XRoot.Element("ValueTypes").Elements("ValueType"))
                db.DicValueType.InsertOnSubmit(new DicValueType { Name = (String)XValue.Attribute("Name"), TypeName = (String)XValue.Attribute("TypeName") });

            db.SubmitChanges();

            foreach (XElement xDictionary in XRoot.Elements("Dictionary"))
            {
                var dic =
                    new DicDictionaryKind
                    {
                        Name = (String)xDictionary.Attribute("Name"),
                        AllowCustomValues = (bool?)xDictionary.Attribute("AllowCustomValues") ?? false,
                        DictionaryValue = new EntitySet<DictionaryValue>()
                    };
                dic.DictionaryValue.AddRange(xDictionary.Elements("Record").Select(xRecord =>
                                                                                   new DictionaryValue
                                                                                   {
                                                                                       Name = (String)xRecord.Attribute("Name"),
                                                                                       Value = (String)xRecord.Attribute("Value")
                                                                                   }));
                db.DicDictionaryKind.InsertOnSubmit(dic);
            }
            db.SubmitChanges();

            foreach (XElement XPropertyKindGroup in XRoot.Element("PropertyKinds").Elements("Group"))
            {
                var pg = new DicPropertyKindGroup { Name = (string)XPropertyKindGroup.Attribute("Name") };
                db.DicPropertyKindGroup.InsertOnSubmit(pg);
                foreach (XElement XPropertyKind in XPropertyKindGroup.Elements("PropertyKind"))
                {
                    var pk =
                        new DicPropertyKind
                        {
                            Name = (String)XPropertyKind.Attribute("Name"),
                            Uid = (int)XPropertyKind.Attribute("Uid"),
                            Key = (String)XPropertyKind.Attribute("Key"),
                            Group = pg,
                            Storage = GetPropertyStorage(XPropertyKind),
                            DisplayIndex = (int?)XPropertyKind.Attribute("DisplayIndex") ?? 100,
                            CustomizationDepth =
                                (PropertyHolderDepth)
                                Enum.Parse(typeof (PropertyHolderDepth), (String)XPropertyKind.Attribute("CustomizationDepth") ?? "RootLevel"),
                            Сustomizeable = (Boolean?)XPropertyKind.Attribute("Customizable") ?? true,
                            StringFormat = (String)XPropertyKind.Attribute("StringFormat"),
                            DicValueType = db.DicValueType.First(testc => testc.Name == (String)XPropertyKind.Attribute("Type")),
                            DicDictionaryKind = XPropertyKind.Attribute("Dictionary") != null
                                                    ? db.DicDictionaryKind.First(d => d.Name == (String)XPropertyKind.Attribute("Dictionary"))
                                                    : null
                        };
                    db.DicPropertyKind.InsertOnSubmit(pk);
                }
            }
            db.SubmitChanges();

            var RootHolder = new PropertiesHolder
                             {
                                 Depth = PropertyHolderDepth.RootLevel,
                                 Description = "Глобальное хранилище свойств"
                             };
            RootHolder.PropertyTargetValues.AddRange(GetProperties(db, XRoot.Element("GlobalProperties")));

            foreach (XElement XSystemKind in XRoot.Elements("SystemKind"))
            {
                var sk = new DicSystemKind
                         {
                             Name = (String)XSystemKind.Attribute("Name")
                         };
                sk.PropertiesHolder.PropertyTargetValues.AddRange(GetProperties(db, XSystemKind));

                foreach (XElement XLocomotiveKind in XSystemKind.Elements("LocomotiveKind"))
                {
                    var lk = new DicLocomotiveKind
                             {
                                 Name = (String)XLocomotiveKind.Attribute("Name"),
                                 Uid = (int)XLocomotiveKind.Attribute("Uid"),
                                 DicSystemKind = sk
                             };
                    lk.PropertiesHolder.PropertyTargetValues.AddRange(GetProperties(db, XLocomotiveKind));

                    foreach (XElement XLocomotive in XLocomotiveKind.Elements("Locomotive"))
                    {
                        var l = new Locomotive
                                {
                                    Number = (int)XLocomotive.Attribute("Number"),
                                    Section = (String)XLocomotive.Attribute("Section"),
                                    DicLocomotiveKind = lk
                                };

                        // Добавляем свойство, содержащее номер локомотива
                        //l.PropertiesHolder.PropertyTargetValues.Add(
                        //    new PropertyTargetValue()
                        //    {
                        //        DicPropertyKind = db.DicPropertyKind.First(pk => pk.Key == "loc number"),
                        //        StartDate = DateTime.Now,
                        //        PropertyValueObject = l.Number
                        //    });

                        l.PropertiesHolder.PropertyTargetValues.AddRange(GetProperties(db, XLocomotive));

                        db.Locomotive.InsertOnSubmit(l);
                    }

                    db.DicLocomotiveKind.InsertOnSubmit(lk);
                }

                db.DicSystemKind.InsertOnSubmit(sk);
            }
            db.SubmitChanges();
        }