Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="root"></param>
        /// <param name="watcher"></param>
        /// <param name="includeFilter">Predicate for "where" clause of direct children of root.</param>
        public ConnectionsVM(IRelatable root, ChangeWatcher watcher, TECCatalogs catalogs, IEnumerable <TECLocation> locations = null,
                             Func <ITECObject, bool> filterPredicate = null)
        {
            if (filterPredicate == null)
            {
                filterPredicate = item => true;
            }
            this.filterPredicate = filterPredicate;

            ConnectableFilter.basePredicate = connectable =>
            {
                if (!connectable.IsConnected() && connectable.AvailableProtocols.Count == 0)
                {
                    return(false);
                }
                if (connectable == SelectedController)
                {
                    return(false);
                }
                return(true);
            };

            this.InterlocksVM = new InterlocksVM(root, watcher, catalogs, filterPredicate);

            this.root      = root;
            this.Catalogs  = catalogs;
            this.Locations = locations != null ? new ObservableCollection <TECLocation>(locations) : new ObservableCollection <TECLocation>();
            if (this.Catalogs.ConduitTypes.Count > 0)
            {
                this.DefaultConduitType = this.Catalogs.ConduitTypes[0];
            }

            watcher.Changed += parentChanged;
            new DirectRelationshipChangedFilter(watcher).DirectRelationshipChanged += parentScopeChanged;

            this.rootConnectableGroup = new FilteredConnectablesGroup("root", this.ConnectableFilter);
            this.rootControllerGroup  = new FilteredConnectablesGroup("root", this.ControllerFilter);

            repopulateGroups(null, root, addConnectable);

            SelectProtocolCommand          = new RelayCommand(selectProtocolExecute, selectProtocolCanExecute);
            CancelProtocolSelectionCommand = new RelayCommand(cancelProtocolSelectionExecute);

            ConnectionDropHandler = new NetworkConnectionDropTarget(this);

            this.ControllerFilter.FilterChanged += () =>
            { if (SelectedControllerGroup?.PassesFilter == false)
              {
                  SelectedControllerGroup = null;
              }
            };
            this.ConnectableFilter.FilterChanged += () =>
            { if (SelectedConnectableGroup?.PassesFilter == false)
              {
                  SelectedConnectableGroup = null;
              }
            };

            DeleteCommand = new RelayCommand <IControllerConnection>(deleteConnectionExecute, canDeleteConnection);
        }
Ejemplo n.º 2
0
        private static void linkSystemToCatalogs(TECSystem system, TECCatalogs catalogs)
        {
            //Should assume linking a typical system with potential instances, controllers and panels.

            linkScopeChildrenToCatalogs(system, catalogs);
            if (system is TECTypical typical)
            {
                foreach (TECSystem instance in typical.Instances)
                {
                    linkSystemToCatalogs(instance, catalogs);
                }
            }

            foreach (TECController controller in system.Controllers)
            {
                linkControllerToCatalogs(controller, catalogs);
            }
            foreach (TECPanel panel in system.Panels)
            {
                linkPanelToCatalogs(panel, catalogs);
            }
            foreach (TECEquipment equip in system.Equipment)
            {
                linkEquipmentToCatalogs(equip, catalogs);
            }
        }
Ejemplo n.º 3
0
        public static TECTypical CreateTestTypical(TECCatalogs catalogs)
        {
            TECTypical outScope = new TECTypical();

            outScope.Tags.Add(catalogs.Tags[0]);
            outScope.ProposeEquipment = true;
            var panel = CreateTestPanel(true, catalogs);

            outScope.Panels.Add(panel);
            var equipment = CreateTestEquipment(true, catalogs);

            outScope.Equipment.Add(equipment);

            var controller = CreateTestController(true, catalogs);

            outScope.AddController(controller);

            ConnectEquipmentToController(equipment, controller);
            panel.Controllers.Add(controller);

            var scopeBranch = new TECScopeBranch(true);

            outScope.ScopeBranches.Add(scopeBranch);

            var tecMisc  = CreateTestMisc(CostType.TEC, true);
            var elecMisc = CreateTestMisc(CostType.Electrical, true);

            outScope.MiscCosts.Add(tecMisc);
            outScope.MiscCosts.Add(elecMisc);

            outScope.AssociatedCosts.Add(catalogs.AssociatedCosts[0]);

            return(outScope);
        }
Ejemplo n.º 4
0
        public void UpdateInstanceConnectionsTest()
        {
            Random      rand     = new Random();
            TECCatalogs catalogs = ModelCreation.TestCatalogs(rand);
            TECTypical  typical  = ModelCreation.TestTypical(catalogs, rand);

            typical.AddInstance();

            foreach (var controller in typical.Controllers)
            {
                foreach (var connection in controller.ChildrenConnections)
                {
                    connection.Length = 324;
                }
            }

            typical.UpdateInstanceConnections();

            foreach (var instance in typical.Instances)
            {
                foreach (var controller in instance.Controllers)
                {
                    foreach (var connection in controller.ChildrenConnections)
                    {
                        Assert.AreEqual(324, connection.Length);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void AssignSecondaryProperties(TECScope scope, TECCatalogs catalogs)
        {
            if (scope.Tags.Count == 0)
            {
                scope.Tags.Add(catalogs.Tags[0]);
            }
            bool tecAdded  = false;
            bool elecAdded = false;

            foreach (TECAssociatedCost cost in catalogs.AssociatedCosts)
            {
                if (cost.Type == CostType.TEC)
                {
                    if (!tecAdded)
                    {
                        scope.AssociatedCosts.Add(cost);
                        tecAdded = true;
                    }
                }
                else if (cost.Type == CostType.Electrical)
                {
                    if (!elecAdded)
                    {
                        scope.AssociatedCosts.Add(cost);
                        elecAdded = true;
                    }
                }
                if (tecAdded && elecAdded)
                {
                    break;
                }
            }
        }
        public void CopyProvidedControllerTest()
        {
            //Arrange
            TECCatalogs           catalogs   = ModelCreation.TestCatalogs(rand);
            TECProvidedController controller = ModelCreation.TestProvidedController(catalogs, rand);
            TECProvidedController copy       = controller.CopyController(new Dictionary <Guid, Guid>()) as TECProvidedController;

            //TECTagged
            Assert.AreEqual(controller.Name, copy.Name);
            Assert.AreEqual(controller.Description, copy.Description);
            Assert.IsTrue(controller.Tags.SequenceEqual(copy.Tags));

            //TECScope
            Assert.IsTrue(controller.AssociatedCosts.SequenceEqual(copy.AssociatedCosts));

            //TECLocated
            Assert.AreEqual(controller.Location, copy.Location);

            //TECController
            Assert.AreEqual(controller.IsServer, copy.IsServer);

            //TECFBOController
            Assert.AreEqual(controller.Type, copy.Type);
            Assert.IsTrue(controller.IOModules.SequenceEqual(copy.IOModules));
        }
        public void CopyFBOControllerTest()
        {
            //Arrange
            TECCatalogs      catalogs   = ModelCreation.TestCatalogs(rand);
            TECFBOController controller = ModelCreation.TestFBOController(catalogs, rand);
            TECFBOController copy       = controller.CopyController(new Dictionary <Guid, Guid>()) as TECFBOController;

            //TECTagged
            Assert.AreEqual(controller.Name, copy.Name);
            Assert.AreEqual(controller.Description, copy.Description);
            Assert.IsTrue(controller.Tags.SequenceEqual(copy.Tags));

            //TECScope
            Assert.IsTrue(controller.AssociatedCosts.SequenceEqual(copy.AssociatedCosts));

            //TECLocated
            Assert.AreEqual(controller.Location, copy.Location);

            //TECController
            Assert.AreEqual(controller.IsServer, copy.IsServer);

            //TECFBOController
            foreach (TECPoint point in controller.Points)
            {
                Assert.IsTrue(copy.Points.Any(pointCopy =>
                {
                    return(pointCopy.Label == point.Label &&
                           pointCopy.Type == point.Type &&
                           pointCopy.Quantity == point.Quantity);
                }));
            }
        }
Ejemplo n.º 8
0
        public static TECScopeTemplates TestScopeTemplates(TECCatalogs catalogs, Random rand)
        {
            TECScopeTemplates templates = new TECScopeTemplates();

            //Parameters
            rand.RepeatAction(() => templates.Parameters.Add(TestParameters(rand)), 5);

            //Systems
            rand.RepeatAction(() => templates.SystemTemplates.Add(TestSystem(catalogs, rand)), 10);

            //Equipment
            rand.RepeatAction(() => templates.EquipmentTemplates.Add(TestEquipment(catalogs, rand)), 10);

            //SubScope
            rand.RepeatAction(() => templates.SubScopeTemplates.Add(TestSubScope(catalogs, rand)), 10);

            //Controllers
            rand.RepeatAction(() => templates.ControllerTemplates.Add(TestProvidedController(catalogs, rand)), 10);

            //Misc Costs
            rand.RepeatAction(() => templates.MiscCostTemplates.Add(TestMisc(catalogs, rand, CostType.TEC)), 10);
            rand.RepeatAction(() => templates.MiscCostTemplates.Add(TestMisc(catalogs, rand, CostType.Electrical)), 10);

            //Panels
            rand.RepeatAction(() => templates.PanelTemplates.Add(TestPanel(catalogs, rand)), 10);

            return(templates);
        }
Ejemplo n.º 9
0
        public SystemHierarchyVM(TECScopeManager scopeManager, bool canEdit)
        {
            IsTemplates = scopeManager is TECTemplates;
            CanEdit     = canEdit;

            AddSystemCommand      = new RelayCommand(addSystemExecute, canAddSystem);
            AddEquipmentCommand   = new RelayCommand <TECSystem>(addEquipmentExecute, canAddEquipment);
            AddSubScopeCommand    = new RelayCommand <TECEquipment>(addSubScopeExecute, canAddSubScope);
            AddPointCommand       = new RelayCommand <TECSubScope>(addPointExecute, canAddPoint);
            AddControllerCommand  = new RelayCommand <TECSystem>(addControllerExecute, canAddController);
            AddPanelCommand       = new RelayCommand <TECSystem>(addPanelExecute, canAddPanel);
            AddMiscCommand        = new RelayCommand <TECSystem>(addMiscExecute, canAddMisc);
            AddInterlockCommand   = new RelayCommand <IInterlockable>(addInterlockExecute, canAddInterlock);
            BackCommand           = new RelayCommand <object>(backExecute);
            AddScopeBranchCommand = new RelayCommand <TECScopeBranch>(addBranchExecute);

            DeleteSystemCommand     = new RelayCommand <TECSystem>(deleteSystemExecute, canDeleteSystem);
            DeleteEquipmentCommand  = new RelayCommand <TECEquipment>(deleteEquipmentExecute, canDeleteEquipment);
            DeleteSubScopeCommand   = new RelayCommand <TECSubScope>(deleteSubScopeExecute, canDeleteSubScope);
            DeleteDeviceCommand     = new RelayCommand <IEndDevice>(deleteDeviceExecute, canDeleteDevice);
            DeletePointCommand      = new RelayCommand <TECPoint>(deletePointExecute, canDeletePoint);
            DeletePanelCommand      = new RelayCommand <TECPanel>(deletePanelExecute, canDeletePanel);
            DeleteControllerCommand = new RelayCommand <TECController>(deleteControllerExecute, canDeleteController);
            DeleteInterlockCommand  = new RelayCommand <TECInterlockConnection>(deleteInterlockExecute, canDeleteInterlock);
            catalogs          = scopeManager.Catalogs;
            this.scopeManager = scopeManager;
        }
Ejemplo n.º 10
0
 private static void linkEquipmentToCatalogs(TECEquipment equip, TECCatalogs catalogs)
 {
     linkScopeChildrenToCatalogs(equip, catalogs);
     foreach (TECSubScope subScope in equip.SubScope)
     {
         linkSubScopeToCatalogs(subScope, catalogs);
     }
 }
Ejemplo n.º 11
0
        public static TECSystem TestSystem(TECCatalogs catalogs, Random rand)
        {
            TECSystem sys = new TECSystem();

            sys.Description = "Test System";
            sys.AssignRandomSystemProperties(catalogs, rand);
            return(sys);
        }
Ejemplo n.º 12
0
        public static TECPanel TestPanel(TECCatalogs catalogs, Random rand)
        {
            TECPanel panel = new TECPanel(catalogs.PanelTypes.RandomElement(rand));

            panel.Description = "Test Panel";
            panel.AssignRandomScopeProperties(catalogs, rand);
            return(panel);
        }
Ejemplo n.º 13
0
        public static TECFBOController TestFBOController(TECCatalogs catalogs, Random rand)
        {
            TECFBOController controller = new TECFBOController(catalogs);

            controller.Description = "Test FBO Controller";
            controller.AssignRandomScopeProperties(catalogs, rand);
            return(controller);
        }
Ejemplo n.º 14
0
        public static TECProvidedController TestProvidedController(TECCatalogs catalogs, Random rand)
        {
            TECProvidedController controller = new TECProvidedController(catalogs.ControllerTypes.RandomElement(rand));

            controller.Description = "Test Provided Controller";
            controller.AssignRandomScopeProperties(catalogs, rand);
            return(controller);
        }
Ejemplo n.º 15
0
        public static TECElectricalMaterial TestElectricalMaterial(TECCatalogs catalogs, Random rand, string type)
        {
            TECElectricalMaterial mat = new TECElectricalMaterial();

            mat.Description = string.Format("Test {0}", type);
            mat.AssignRandomElectricalMaterialProperties(catalogs, rand);
            return(mat);
        }
Ejemplo n.º 16
0
        public static TECAssociatedCost TestCost(TECCatalogs catalogs, Random rand, CostType type)
        {
            TECAssociatedCost cost = new TECAssociatedCost(type);

            cost.Description = string.Format("Test Associated {0} Cost", type);
            cost.AssignRandomCostProperties(catalogs, rand);
            return(cost);
        }
Ejemplo n.º 17
0
 public PropertiesVM(TECCatalogs catalogs, TECScopeManager scopeManager)
 {
     IsTemplates  = scopeManager is TECTemplates;
     TemplateText = "Instance Template";
     DeleteConnectionTypeCommand         = new RelayCommand <TECObject>(deleteConnectionTypeExecute, canDeleteConnectionType);
     DeleteProtocolConnectionTypeCommand = new RelayCommand <TECConnectionType>(deleteProtocolConnectionTypeExecute, canDeleteProtocolConnectionType);
     Refresh(catalogs, scopeManager);
 }
Ejemplo n.º 18
0
        public static TECTypical TestTypical(TECCatalogs catalogs, Random rand)
        {
            TECTypical typ = new TECTypical();

            typ.Description = "Typical";
            typ.AssignRandomSystemProperties(catalogs, rand);
            return(typ);
        }
Ejemplo n.º 19
0
        private static void linkSubScopeToCatalogs(TECSubScope ss, TECCatalogs catalogs)
        {
            linkScopeChildrenToCatalogs(ss, catalogs);
            var devices = new List <IEndDevice>(catalogs.Devices);

            devices.AddRange(catalogs.Valves);
            linkSubScopeToDevices(ss, devices);
        }
Ejemplo n.º 20
0
        public static TECPoint CreateTestPoint(bool isTypical, TECCatalogs catalogs)
        {
            TECPoint point = new TECPoint(isTypical);

            point.Type     = (IOType)Enum.GetNames(typeof(IOType)).Length;
            point.Quantity = 2;
            return(point);
        }
Ejemplo n.º 21
0
        public static TECPanelType TestPanelType(TECCatalogs catalogs, Random rand)
        {
            TECManufacturer man  = catalogs.Manufacturers.RandomElement(rand);
            TECPanelType    type = new TECPanelType(man);

            type.Description = string.Format("Test Panel Type");
            type.AssignRandomCostProperties(catalogs, rand);
            return(type);
        }
Ejemplo n.º 22
0
        public static TECMisc TestMisc(TECCatalogs catalogs, Random rand, CostType type)
        {
            TECMisc misc = new TECMisc(type);

            misc.Description = string.Format("Test Misc {0}", type.ToString());
            misc.Quantity    = rand.Next(1, 10);
            misc.AssignRandomCostProperties(catalogs, rand);
            return(misc);
        }
Ejemplo n.º 23
0
        public static TECPanel CreateTestPanel(bool isTypical, TECCatalogs catalogs)
        {
            var panelType = catalogs.PanelTypes[0];

            var panel = new TECPanel(panelType, isTypical);

            panel.Tags.Add(catalogs.Tags[0]);
            return(panel);
        }
Ejemplo n.º 24
0
        public static TECController CreateTestController(bool isTypical, TECCatalogs catalogs)
        {
            var type = catalogs.ControllerTypes[0];

            var controller = new TECProvidedController(type, isTypical);

            controller.Tags.Add(catalogs.Tags[0]);
            return(controller);
        }
Ejemplo n.º 25
0
        public static TECValve CreateTestValve(TECCatalogs catalogs)
        {
            TECValve valve = new TECValve(catalogs.Manufacturers[0], catalogs.Devices[0]);

            valve.Price = 52.62;
            valve.AssociatedCosts.Add(catalogs.AssociatedCosts[0]);
            valve.Tags.Add(catalogs.Tags[0]);
            return(valve);
        }
Ejemplo n.º 26
0
        public static TECEquipment TestEquipment(TECCatalogs catalogs, Random rand)
        {
            TECEquipment equip = new TECEquipment();

            equip.Description = "Test Equipment";
            equip.AssignRandomScopeProperties(catalogs, rand);
            rand.RepeatAction(() => equip.SubScope.Add(TestSubScope(catalogs, rand)), 5);
            return(equip);
        }
Ejemplo n.º 27
0
        public void TestInitialize()
        {
            rand = new Random(0);
            TECCatalogs catalogs = ModelCreation.TestCatalogs(rand);

            bid          = new TECBid();
            bid.Catalogs = catalogs;
            cw           = new ChangeWatcher(bid);
        }
Ejemplo n.º 28
0
 public ScopeCollectionsTabVM(TECScopeManager manager)
 {
     Templates               = manager.Templates;
     this.catalogs           = manager.Catalogs;
     SearchCollectionCommand = new RelayCommand(SearchCollectionExecute, SearchCanExecute);
     EndSearchCommand        = new RelayCommand(EndSearchExecute);
     SearchString            = "";
     CollectionTypes         = new Dictionary <AllSearchableObjects, string>(UIHelpers.SearchSelectorList);
     SearchCollectionExecute();
 }
Ejemplo n.º 29
0
        public static TECValve TestValve(TECCatalogs catalogs, Random rand)
        {
            TECManufacturer man   = catalogs.Manufacturers.RandomElement(rand);
            TECDevice       dev   = catalogs.Devices.RandomElement(rand);
            TECValve        valve = new TECValve(man, dev);

            valve.Description = string.Format("Test Valve");
            valve.AssignRandomCostProperties(catalogs, rand);
            return(valve);
        }
Ejemplo n.º 30
0
 public void Refresh(TECCatalogs catalogs, TECScopeManager scopeManager)
 {
     Catalogs = catalogs;
     if (scopeManager is TECBid bid)
     {
         Locations  = bid.Locations;
         Parameters = bid.Parameters;
     }
     this.ScopeManager = scopeManager;
 }