예제 #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            LocoDataContext Loco = new LocoDataContext();
            //Loco.Log = Console.Out;

            var F = new LocoRibbonSliceFactory();
            var gF = new LocoRibbonGradientSliceFactory();

            DateTime ethalonDT = DateTime.Now.AddDays(-5);
            Random r = new Random();

            dg.Lines = new System.Collections.ObjectModel.ObservableCollection<DiagramLine>()
            {
                new Ribbon(
                    Loco.PropertyCurrentValue.Where(pv => pv.LocomotiveId == 1 && pv.PropertyKindId == 6),
                    F) { Header = "Свойство 6" },
                new Ribbon(
                    Loco.PropertyCurrentValue.Where(pv => pv.LocomotiveId == 1 && pv.PropertyKindId == 7),
                    F) { Header = "Свойство 7" },
                new Chart(
                    Loco.PropertyCurrentValue.Where(pv => pv.LocomotiveId == 1 && pv.PropertyKindId == 6),
                    new LocoPropertyChartBarFactory() { BarForeground = Brushes.DarkGreen, Min = 10, Max = 80 }),
                new Chart(
                    Loco.PropertyCurrentValue.Where(pv => pv.LocomotiveId == 1 && pv.PropertyKindId == 7),
                    new LocoPropertyChartBarFactory() { BarForeground = Brushes.DarkOrange, Min = 10, Max = 80 }),
                new Ribbon(
                    Loco.PropertyCurrentValue.Where(pv => pv.LocomotiveId == 1 && pv.PropertyKindId == 7),
                    gF),
                new TimeAxis()
            };
        }
        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);
        }
예제 #3
0
 public static void Initialize(LocoDataContext db, String FileName)
 {
     using (var fs = new FileStream(FileName, FileMode.Open))
     {
         Initialize(db, fs);
     }
 }
예제 #4
0
 public PropertiesHolder GetParentHolder(LocoDataContext db)
 {
     switch(Depth)
     {
         case PropertyHolderDepth.LocomotiveLevel: return Locomotive.DicLocomotiveKind.PropertiesHolder;
         case PropertyHolderDepth.KindLevel: return DicLocomotiveKind.DicSystemKind.PropertiesHolder;
         case PropertyHolderDepth.SystemLevel: return GetRootHolder(db);
         default: return null;
     }
 }
예제 #5
0
 /// <summary>Собирает последовательность свойств для этого контейнера с учётом наследования на указанное время</summary>
 public IQueryable<PropertyTargetValue> AgregateTargetProperties(LocoDataContext db, DateTime OnTime)
 {
     int[] parents = GetParentHolders(db, true).Select(h => h.Id).ToArray();
     IQueryable<PropertyTargetValue> res =
         db.PropertyTargetValue.Where(
             pv =>
             parents.Contains(pv.PropertyHolderId)
             && (pv.StartDate <= OnTime && (pv.EndDate == null || pv.EndDate > OnTime)))
           .GroupBy(p => p.PropertyKindId)
           .Select(g => g.OrderByDescending(p => p.PropertiesHolder.Depth).First());
     return res;
 }
예제 #6
0
파일: Program.cs 프로젝트: NpoSaut/LocoBase
        static void Main(string[] args)
        {
            var Loco = new LocoDataContext();
            Loco.Log = Console.Out;

            var locomotive = Loco.Locomotive.First();

            Random r = new Random();
            DateTime dt = Loco.ServiceAction.OrderByDescending(sa => sa.ReportDate).First().ReportDate;
            while ((dt = dt.AddHours(4 * r.NextDouble())) < DateTime.Now)
            {
                locomotive.ServiceActions.Add(
                    new ServiceAction()
                    {
                        ActionDate = dt,
                        SyncDate = dt,
                        ReportDate = dt,
                        PropertiesRead = true,
                        PropertyCurrentValue = new System.Data.Linq.EntitySet<PropertyCurrentValue>()
                        {
                            new PropertyCurrentValue()
                            {
                                PropertyKindId = r.Next(6, 8),
                                PropertyValue = r.Next(40, 80).ToString()
                            },
                            //new PropertyCurrentValue()
                            //{
                            //    PropertyKindId = 7,
                            //    PropertyValue = r.Next(30, 60).ToString()
                            //}
                        }
                    });
                Loco.SubmitChanges();
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("done");

            Console.ResetColor();
            Console.ReadLine();
        }
예제 #7
0
 /// <summary>
 /// Значение текущих свойств в заданное время
 /// </summary>
 public IQueryable<PropertyTargetValue> GetTargetProperties(LocoDataContext db, DateTime OnTime)
 {
     return
         this.PropertiesHolder.AgregateTargetProperties(db, OnTime)
             .OrderBy(p => p.PropertyKindId);
 }
예제 #8
0
 /// <summary>
 /// Значение текущих свойств в заданное время
 /// </summary>
 public IQueryable<PropertyTargetValue> GetTargetProperties(LocoDataContext db)
 {
     return GetTargetProperties(db, DateTime.Now);
 }
예제 #9
0
 /// <summary>
 /// Возвращает последовательность родительских контейнеров в порядке от наиболее локального к наиболее глобальному предку
 /// </summary>
 /// <param name="db">Контекст данных</param>
 /// <param name="IncludeSelf">Включает текущий контейнер как первый член последовательности</param>
 /// <returns>Последовательность предков данного контейнера в порядке от наиболее локального к наиболее глобальному</returns>
 public IEnumerable<PropertiesHolder> GetParentHolders(LocoDataContext db, bool IncludeSelf = false)
 {
     if (IncludeSelf) yield return this;
     PropertiesHolder h = this;
     while ((h = h.GetParentHolder(db)) != null)
         yield return h;
 }
예제 #10
0
 public static PropertiesHolder GetRootHolder(LocoDataContext db)
 {
     return db.PropertiesHolder.FirstOrDefault(h => h.Depth == 0);
 }
예제 #11
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();
        }
예제 #12
0
        private static PropertyTargetValue GetPropertyTargetValue(LocoDataContext db, XElement XProperty)
        {
            DicPropertyKind kind = db.DicPropertyKind.First(pk => pk.Name == (String)XProperty.Attribute("Name"));
            string value = kind.DicDictionaryKind != null
                               ? kind.DicDictionaryKind.DictionaryValue.Single(dv => dv.Name == (String)XProperty.Attribute("Value")).Value
                               : (String)XProperty.Attribute("Value");

            return new PropertyTargetValue
                   {
                       DicPropertyKind = kind,
                       StartDate = DateTime.Now,
                       PropertyValue = value,
                   };
        }
예제 #13
0
 private static IEnumerable<PropertyTargetValue> GetProperties(LocoDataContext db, XElement XHolder)
 {
     foreach (XElement XProperty in XHolder.Elements("Property"))
         yield return GetPropertyTargetValue(db, XProperty);
 }
예제 #14
0
 public static void Initialize(LocoDataContext db)
 {
     Assembly assembly = Assembly.GetExecutingAssembly();
     Stream documentStream = assembly.GetManifestResourceStream("LocoSql.Initials.xml");
     Initialize(db, documentStream);
 }
예제 #15
0
파일: Loco.cs 프로젝트: NpoSaut/LocoBase
 public static DicPropertyKind GetPropertyKindByKey(LocoDataContext db, string Key)
 {
     return db.DicPropertyKind.SingleOrDefault(p => p.Key == Key);
 }
예제 #16
0
        /// <summary>Загружает информацию о локомотиве из базы</summary>
        private void LoadLocomotive(LocomotiveModel LoadingLocomotive, LocoDataContext db)
        {
            Locomotive loc = db.Locomotive.First(l => l.Id == LoadingLocomotive.Id);

            var xxx = loc
                .GetTargetProperties(db)
                .Select(
                    p =>
                    new
                    {
                        PropertyValue = p,
                        p.DicPropertyKind,
                        p.DicPropertyKind.Storage,
                        p.DicPropertyKind.DicValueType,
                        p.DicPropertyKind.Group,
                    })
                .ToList();

            Properties =
                xxx.Select(x =>
                           new PropertyModel(x.DicPropertyKind.Id, x.DicPropertyKind.Name, x.Group.Name,
                                             PropertyEncoding.GetEncoder(x.DicValueType.TypeName),
                                             x.Storage != null
                                                 ? new PropertyPlacement(x.Storage.StorageIndex, x.Storage.Offset, x.Storage.Length)
                                                 : null,
                                             DisplayIndex: x.DicPropertyKind.DisplayIndex,
                                             TargetValue: x.PropertyValue.GetPropertyValueObject(PropertyValueBase.GetPropertyType(x.DicValueType)),
                                             StringFormat: x.DicPropertyKind.StringFormat,
                                             DictionaryValues: db.GetDictionaryValues(x.DicPropertyKind) != null
                                                                   ? db.GetDictionaryValues(x.DicPropertyKind).ToDictionary(
                                                                       dv => PropertyValueBase.GetPropertyValueObject(PropertyValueBase.GetPropertyType(x.DicValueType), dv.Value),
                                                                       dv => dv.Key)
                                                                   : null))
                   .ToList();

            Properties.Add(SystemProperties.LocomotiveNumberProperty.GetPropertyModel(LoadingLocomotive.Number));
            Properties.Add(SystemProperties.SectionNumberProperty.GetPropertyModel(LoadingLocomotive.Section ?? ""));
            Properties.Add(SystemProperties.CombinedLocomotiveNumberProperty.GetPropertyModel(
                SystemProperties.CombineLocomotiveNumber(LoadingLocomotive.Number, LoadingLocomotive.Section)));
            Properties.Add(SystemProperties.KindUidProperty.GetPropertyModel(LoadingLocomotive.KindUid));

            Stores = Properties.Where(p => p.Placement != null)
                               .GroupBy(p => p.Placement.StorageIndex)
                               .ToDictionary(pg => pg.Key, pg => new StorageModel(pg.Key, pg.ToArray()));
        }
예제 #17
0
 /// <summary>Получает последовательность целевых свойств для данного контейнера на указанное время</summary>
 public IQueryable<PropertyTargetValue> GetTargetProperties(LocoDataContext db, DateTime OnTime)
 {
     var xxx = db.PropertyTargetValue.Where(pv => pv.StartDate <= OnTime && (pv.EndDate == null || pv.EndDate > OnTime));
     return xxx;
 }
 public LocoDataContext GetContext()
 {
     var db = new LocoDataContext(Settings.Default.LocoConnectionString);
     //db.Log = Console.Out;
     return db;
 }