using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; using Tango.BL.Entities; using Tango.Core; using System.Data.Entity; using Tango.Core.Threading; namespace Tango.BL { public partial class ObservablesStaticCollections : ExtendedObject { private bool _initialized; private ObservablesContext db; private static ObservablesStaticCollections _instance; /// /// Gets the singleton instance. /// public static ObservablesStaticCollections Instance { get { if (_instance == null) { _instance = new ObservablesStaticCollections(); } return _instance; } } private ObservablesStaticCollections() { } public ObservablesStaticCollections(ObservablesContext context) { db = context; } public ObservablesContext Context { get { return db; } } /// /// Initializes this instance. /// public void Initialize() { if (!_initialized) { db = ObservablesContext.CreateDefault(); TaskSequencer sequencer = new TaskSequencer(); WindingMethods = db.WindingMethods.ToObservableCollection(); ColorSpaces = db.ColorSpaces.ToObservableCollection(); SpoolTypes = db.SpoolTypes.ToObservableCollection(); EventTypes = db.EventTypes.ToObservableCollection(); HardwareBlowerTypes = db.HardwareBlowerTypes.ToObservableCollection(); HardwareBlowers = db.HardwareBlowers.ToObservableCollection(); HardwareBreakSensorTypes = db.HardwareBreakSensorTypes.ToObservableCollection(); HardwareBreakSensors = db.HardwareBreakSensors.ToObservableCollection(); HardwareDancerTypes = db.HardwareDancerTypes.ToObservableCollection(); HardwareDancers = db.HardwareDancers.ToObservableCollection(); HardwareMotorTypes = db.HardwareMotorTypes.ToObservableCollection(); HardwareMotors = db.HardwareMotors.ToObservableCollection(); HardwarePidControlTypes = db.HardwarePidControlTypes.ToObservableCollection(); HardwarePidControls = db.HardwarePidControls.ToObservableCollection(); HardwareSpeedSensorTypes = db.HardwareSpeedSensorTypes.ToObservableCollection(); HardwareSpeedSensors = db.HardwareSpeedSensors.ToObservableCollection(); HardwareWinderTypes = db.HardwareWinderTypes.ToObservableCollection(); HardwareWinders = db.HardwareWinders.ToObservableCollection(); TechControllers = db.TechControllers.ToObservableCollection(); TechDispensers = db.TechDispensers.ToObservableCollection(); TechIos = db.TechIos.ToObservableCollection(); TechMonitors = db.TechMonitors.ToObservableCollection(); TechValves = db.TechValves.ToObservableCollection(); TechHeaters = db.TechHeaters.ToObservableCollection(); Machines = db.Machines.Include(x => x.Organization).ToObservableCollection(); Users = db.Users.Where(x => !x.Deleted).Include(x => x.Contact).ToObservableCollection(); MachineVersions = db.MachineVersions.ToObservableCollection(); //Load later... Task.Factory.StartNew(() => { LiquidTypes = db.LiquidTypes.ToObservableCollection(); DispenserTypes = db.DispenserTypes.ToObservableCollection(); MidTankTypes = db.MidTankTypes.ToObservableCollection(); CartridgeTypes = db.CartridgeTypes.ToObservableCollection(); IdsPackFormulas = db.IdsPackFormulas.ToObservableCollection(); Rmls = db.Rmls.ToObservableCollection(); LiquidTypesRmls = db.LiquidTypesRmls.ToObservableCollection(); foreach (var machine in Machines) { ObservablesContextAdapter adapter = new ObservablesContextAdapter(db); adapter.GetConfiguration(x => x.Guid == machine.ConfigurationGuid); } }); _initialized = true; } //InitCollectionSources(); } /// /// Creates a collection view from the specified observable collection. /// /// /// The collection. /// private ICollectionView CreateCollectionView(ObservableCollection collection) { var view = CollectionViewSource.GetDefaultView(collection); return view; } } }