using Autofac; using Bro.Common.Base; using Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace Bro.M071.Process { internal class KeyNameDictConverter : StringConverter { public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { return new StandardValuesCollection(config.KeyNameCollection); } } return base.GetStandardValues(context); ; } } internal class SnapshotPointConverter : ComboBoxItemTypeConvert { public override Hashtable GetConvertHash(ITypeDescriptorContext context) { Hashtable table = new Hashtable(); using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { config.SnapshotPointCollection.Where(u => u.IsEnabled).ToList().ForEach(s => { if (s.CameraOp?.OpConfig is CameraOprerationConfigBase cameraOpConfig) { if (!string.IsNullOrWhiteSpace(cameraOpConfig?.AlgorithemPath)) { table[s.Id] = s.Name; } } }); } } return table; } } internal class KeyAlgorithemConverter : ComboBoxItemTypeConvert { public override Hashtable GetConvertHash(ITypeDescriptorContext context) { Hashtable table = new Hashtable(); using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { config.KeyAlgorithemCollection.ForEach(s => { table[s.Id] = s.Name; }); } } return table; } } internal class KeyResultConverter : ComboBoxItemTypeConvert { public override Hashtable GetConvertHash(ITypeDescriptorContext context) { Hashtable table = new Hashtable(); using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { config.KeyResultCollection.ForEach(s => { table[s.Id] = s.Name; }); } } return table; } } //internal class KeyUnitConverter : ComboBoxItemTypeConvert //{ // public override Hashtable GetConvertHash(ITypeDescriptorContext context) // { // Hashtable table = new Hashtable(); // using (var scope = GlobalVar.Container.BeginLifetimeScope()) // { // IProcessConfig iConfig = scope.Resolve(); // if (iConfig is M071Config config) // { // config.KeyUnitCollection.ForEach(s => // { // table[s.Id] = s.Key; // }); // } // } // return table; // } //} internal class KeyUnitResultConverter : ComboBoxItemTypeConvert { public override Hashtable GetConvertHash(ITypeDescriptorContext context) { Hashtable table = new Hashtable(); using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { var resultIds = config.KeyUnitCollection.Where(u => u.IsEnabled && u.Key == (context.Instance as KeyUnitBind).Key).Select(u => u.KeyResultId).ToList(); var result = config.KeyResultCollection.Where(u => resultIds.Contains(u.Id)).SelectMany(u => u.Results).ToList(); if (result != null && result.Count > 0) { result.ForEach(r => { table.Add(r, r); }); table.Add("All", "All"); } } } return table; } } internal class MeasureTypeConverter : StringConverter { public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { return new StandardValuesCollection(config.MeasureTypeCollection.Select(u => u.Code).ToList()); } } return base.GetStandardValues(context); ; } } }