private PropertiesEditorViewModel CreateViewModel(PropertiesHolder TargetHolder,
                                                          Func<PropertyTargetValue, bool> IsCustomizedPredicate,
                                                          LocoDataContext Context, IPropertiesSubmitter submitter)
        {
            PropertiesHolder parentHolder = TargetHolder.GetParentHolder(Context);
            List<int> parentProperties = parentHolder != null
                                             ? parentHolder.AgregateTargetProperties(Context)
                                                           .Where(pv => pv.PropertyValue != null)
                                                           .Select(pv => pv.PropertyKindId)
                                                           .ToList()
                                             : new List<int>();

            var xxx = TargetHolder.AgregateTargetProperties(Context)
                                  .Select(
                                      p =>
                                      new
                                      {
                                          property = new EditablePropertyViewModel(p.DicPropertyKind.Name, p.DicPropertyKind.DicValueType.TypeName,
                                                                                   p.DicPropertyKind.StringFormat, p.PropertyKindId, p.PropertyValue,
                                                                                   Context.GetDictionaryValues(p.DicPropertyKind),
                                                                                   p.DicPropertyKind.Сustomizeable,
                                                                                   parentProperties.Contains(p.PropertyKindId)),
                                          isDefined = IsCustomizedPredicate(p)
                                      })
                                  .ToList()
                                  .Where(px => _customizabilityValidator.CanPropertyBeCustomized(px.property))
                                  .ToList();

            List<EditablePropertyViewModel> customizedProperties = xxx.Where(x => x.isDefined).Select(x => x.property).ToList();
            List<CustomizeablePropertyViewModel> decustomisedProperties =
                xxx.Where(x => !x.isDefined).Select(x => new CustomizeablePropertyViewModel(x.property)).ToList();
            return new PropertiesEditorViewModel(customizedProperties, decustomisedProperties, submitter);
        }
 /// <summary>Закрывает действие всех указанных в коллекции <paramref name="ChangedProperties" />
 /// </summary>
 protected void ClosePropertiesLocalValues(IList<EditablePropertyViewModel> ChangedProperties, PropertiesHolder holder)
 {
     IEnumerable<PropertyTargetValue> valuesToClose =
         ChangedProperties
             .Where(p => p.IsMarkedForDecustomization)
             .Join(holder.PropertyTargetValues, p => p.PropertyKindId, v => v.PropertyKindId, (p, v) => v);
     foreach (PropertyTargetValue value in valuesToClose)
         value.EndDate = DateTime.Now;
 }
 /// <summary>Сохраняет изменения в свойствах</summary>
 protected void SavePropertiesToHolder(IList<EditablePropertyViewModel> ChangedProperties, PropertiesHolder holder)
 {
     holder.PropertyTargetValues.AddRange(
         ChangedProperties
             .Where(p => p.IsModified)
             .Select(p =>
                     new PropertyTargetValue
                     {
                         PropertyKindId = p.PropertyKindId,
                         StartDate = DateTime.Now,
                         PropertyValue = p.Value.ValueObject.ToString()
                     }));
 }
예제 #4
0
 partial void DeletePropertiesHolder(PropertiesHolder instance);
예제 #5
0
 partial void UpdatePropertiesHolder(PropertiesHolder instance);
예제 #6
0
 partial void InsertPropertiesHolder(PropertiesHolder instance);
예제 #7
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();
        }