partial void DeleteDicPropertyKindGroup(DicPropertyKindGroup instance);
partial void InsertDicPropertyKindGroup(DicPropertyKindGroup instance);
partial void UpdateDicPropertyKindGroup(DicPropertyKindGroup instance);
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(); }