public static void ConnectEquipmentToController(TECEquipment equipment, TECController controller)
 {
     foreach (TECSubScope subscope in equipment.SubScope)
     {
         controller.Connect(subscope, (subscope as IConnectable).AvailableProtocols.First());
     }
 }
Exemple #2
0
        public void RemoveInstanceWithGlobalConnectionToController()
        {
            TECBid bid = new TECBid();

            bid.Catalogs = ModelCreation.TestCatalogs(rand);

            TECControllerType type = bid.Catalogs.ControllerTypes.RandomElement(rand);

            TECController controller = new TECProvidedController(type);

            bid.AddController(controller);

            TECTypical    typical           = new TECTypical();
            TECController typicalController = new TECProvidedController(type);

            typical.AddController(typicalController);

            bid.Systems.Add(typical);
            TECSystem     system             = typical.AddInstance();
            TECController instanceController = typical.GetInstancesFromTypical(typicalController).First();

            Assert.IsTrue(controller.CanConnect(instanceController));

            IControllerConnection connection = controller.Connect(instanceController, instanceController.AvailableProtocols.First());

            Assert.IsTrue(connection is TECNetworkConnection);

            typical.Instances.Remove(system);

            Assert.IsTrue((connection as TECNetworkConnection).Children.Count == 0);
        }
Exemple #3
0
        public void SaveAs_Bid_SubScopeConnection()
        {
            //Arrange
            TECController          expectedConnectedController = null;
            TECHardwiredConnection expectedConnection          = null;

            foreach (TECController controller in expectedBid.Controllers)
            {
                foreach (IControllerConnection connection in controller.ChildrenConnections)
                {
                    if (connection is TECHardwiredConnection)
                    {
                        expectedConnectedController = controller;
                        expectedConnection          = connection as TECHardwiredConnection;
                        break;
                    }
                }
                if (expectedConnectedController != null)
                {
                    break;
                }
            }
            TECController          actualConnectedController = actualBid.FindChild(expectedConnectedController.Guid) as TECController;
            TECHardwiredConnection actualConnection          = actualConnectedController.FindChild(expectedConnection.Guid) as TECHardwiredConnection;

            //Assert
            Assert.AreEqual(expectedConnection.Guid, actualConnection.Guid);
            Assert.AreEqual(expectedConnection.ConduitType.Guid, actualConnection.ConduitType.Guid);
            Assert.AreEqual(expectedConnection.Length, actualConnection.Length, DELTA);
            Assert.AreEqual(expectedConnection.ParentController.Guid, actualConnection.ParentController.Guid);
            Assert.AreEqual(expectedConnection.Child.Guid, actualConnection.Child.Guid);
            Assert.IsTrue(compareCosts(expectedConnection.CostBatch, actualConnection.CostBatch));
            //Assert.IsFalse(actualConnection.IsTypical);
        }
Exemple #4
0
        /// <summary>
        /// Returns true if all the items can be connected, in some way, to the provided controller
        /// </summary>
        /// <param name="items"></param>
        /// <param name="controller"></param>
        /// <returns></returns>
        public static bool CanConnectToController(IEnumerable <IConnectable> items, TECController controller)
        {
            var connectables = items
                               .Where(x => x.GetParentConnection() == null || x.AvailableProtocols.Count == 0);

            if (connectables.Count() == 0)
            {
                return(false);
            }

            var availableIO = controller.AvailableIO + ExistingNetworkIO(controller);

            foreach (var connectable in connectables.Where(x => x.AvailableProtocols.Count == 1))
            {
                var protocol = connectable.AvailableProtocols.First();

                if (protocol is TECProtocol netProtocol)
                {
                    if (!availableIO.Contains(netProtocol))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!availableIO.Remove(connectable.HardwiredIO))
                    {
                        return(false);
                    }
                }
            }

            foreach (var connectable in connectables.Where(x => x.AvailableProtocols.Count > 1))
            {
                var canConnect = false;
                foreach (var protocol in connectable.AvailableProtocols)
                {
                    if (protocol is TECProtocol networkProtocol)
                    {
                        if (availableIO.Contains(networkProtocol))
                        {
                            canConnect = true;
                            break;
                        }
                    }
                }
                if (canConnect == false)
                {
                    if (!(connectable.AvailableProtocols.Any(x => x is TECHardwiredProtocol) && availableIO.Remove(connectable.HardwiredIO)))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemple #5
0
        /// <summary>
        /// Returns the io which make up existing network connections on a controller
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        public static IOCollection ExistingNetworkIO(TECController controller)
        {
            IOCollection existingNetwork = new IOCollection();

            foreach (TECNetworkConnection connection in controller.ChildrenConnections.Where(x => x is TECNetworkConnection))
            {
                existingNetwork.Add(connection.NetworkProtocol);
            }
            return(existingNetwork);
        }
 public static IControllerConnection FindConnectionInController(TECController controller, IControllerConnection reference)
 {
     foreach (IControllerConnection connection in controller.ChildrenConnections)
     {
         if (connection.Guid == reference.Guid)
         {
             return(connection);
         }
     }
     return(null);
 }
Exemple #7
0
 private static void linkControllerToCatalogs(TECController controller, TECCatalogs catalogs)
 {
     if (controller is TECProvidedController provided)
     {
         linkProvidedControllerToControllerType(provided, catalogs.ControllerTypes);
     }
     foreach (IControllerConnection connection in controller.ChildrenConnections)
     {
         linkConnectionToCatalogs(connection, catalogs);
     }
     linkScopeChildrenToCatalogs(controller, catalogs);
 }
Exemple #8
0
 private void setup(IEnumerable <TECControllerType> controllerTypes)
 {
     Quantity                = 1;
     noneControllerType      = new TECControllerType(new TECManufacturer());
     noneControllerType.Name = "Select Controller Type";
     toAdd           = new TECProvidedController(noneControllerType);
     ControllerTypes = new List <TECControllerType>(controllerTypes);
     ControllerTypes.Insert(0, noneControllerType);
     AddCommand   = new RelayCommand(addExecute, addCanExecute);
     SelectedType = noneControllerType;
     //PropertiesVM = new PropertiesVM()
 }
        public void Load_Templates_SystemTypicalController()
        {
            //Arrange
            Guid   expectedGuid        = new Guid("1bb86714-2512-4fdd-a80f-46969753d8a0");
            string expectedName        = "Typical Controller";
            string expectedDescription = "Typical Controller Description";

            TECController actualController = null;

            foreach (TECSystem system in actualTemplates.Templates.SystemTemplates)
            {
                foreach (TECController controller in system.Controllers)
                {
                    if (controller.Guid == expectedGuid)
                    {
                        actualController = controller;
                        break;
                    }
                }
            }

            Guid expectedConnectionGuid = new Guid("5723e279-ac5c-4ee0-ae01-494a0c524b5c");
            Guid expectedIOGuid         = new Guid("fbae3851-3320-4e94-a674-ddec86bc4964");

            //bool hasIO = false;
            //foreach (TECIO io in actualController.IO)
            //{
            //    if (io.Guid == expectedIOGuid)
            //    {
            //        hasIO = true;
            //        break;
            //    }
            //}

            bool hasConnection = false;

            foreach (IControllerConnection conn in actualController.ChildrenConnections)
            {
                if (conn.Guid == expectedConnectionGuid)
                {
                    hasConnection = true;
                }
            }

            //Assert
            Assert.AreEqual(expectedName, actualController.Name);
            Assert.AreEqual(expectedDescription, actualController.Description);
            //Assert.IsTrue(hasIO, "IO not loaded");
            Assert.IsTrue(hasConnection, "Connection not loaded");
            testForTag(actualController);
            testForCosts(actualController);
        }
Exemple #10
0
        private bool canChangeType(TECController arg)
        {
            if (arg is TECProvidedController provided)
            {
                IEnumerable <TECControllerType> types = Bid != null ? Bid.Catalogs.ControllerTypes : Templates.Catalogs.ControllerTypes;

                return(provided != null && types.Any(x => provided.CanChangeType(x)));
            }
            else
            {
                return(false);
            }
        }
        public void Controller_AddSubScope()
        {
            TECCatalogs   catalogs   = ModelCreation.TestCatalogs(rand);
            TECController controller = ModelCreation.TestProvidedController(catalogs, rand);
            TECSubScope   subScope   = new TECSubScope();
            TECDevice     dev        = catalogs.Devices.First();

            subScope.Devices.Add(dev);

            controller.Connect(subScope, subScope.AvailableProtocols.First(y => controller.AvailableProtocols.Contains(y)));

            Assert.AreEqual(1, controller.ChildrenConnections.Count, "Connection not added to controller");
            Assert.AreNotEqual(null, subScope.Connection, "Connection not added to subscope");
        }
Exemple #12
0
        public void RemoveInstanceWithGlobalConnectionToSubScope()
        {
            TECBid bid = new TECBid();

            bid.Catalogs = ModelCreation.TestCatalogs(rand);

            TECController controller = ModelCreation.TestProvidedController(bid.Catalogs, rand);

            bid.AddController(controller);

            TECTypical   typical   = new TECTypical();
            TECEquipment equipment = new TECEquipment();
            TECSubScope  subScope  = new TECSubScope();
            TECDevice    device    = null;

            foreach (TECDevice item in bid.Catalogs.Devices)
            {
                foreach (TECProtocol prot in item.PossibleProtocols)
                {
                    if (controller.AvailableProtocols.Contains(prot))
                    {
                        device = item;
                        break;
                    }
                }
                if (device != null)
                {
                    break;
                }
            }
            if (device == null)
            {
                throw new NullReferenceException("Device is Null");
            }
            subScope.Devices.Add(device);
            equipment.SubScope.Add(subScope);
            typical.Equipment.Add(equipment);

            bid.Systems.Add(typical);
            TECSystem             system           = typical.AddInstance();
            TECSubScope           instanceSubScope = typical.GetInstancesFromTypical(subScope).First(x => x.AvailableProtocols.Any(y => y is TECProtocol && controller.AvailableProtocols.Contains(y)));
            IControllerConnection connection       = controller.Connect(instanceSubScope, instanceSubScope.AvailableProtocols.First(y => controller.AvailableProtocols.Contains(y)));

            Assert.IsTrue(connection is TECNetworkConnection);

            typical.Instances.Remove(system);

            Assert.IsTrue((connection as TECNetworkConnection).Children.Count == 0);
        }
Exemple #13
0
        public void AddController()
        {
            //Arrange
            TECController controller = ModelCreation.TestProvidedController(bid.Catalogs, rand);

            controller.AssignRandomScopeProperties(bid.Catalogs, rand);

            MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw);

            //Act
            bid.AddController(controller);

            //Assert
            AssertMaterialVMMatchesCostBatch(matVM, controller.CostBatch);
        }
        public void GetObjectPathTest()
        {
            //Arrange
            TECBid        bid           = ModelCreation.TestBid(rand);
            TECSystem     sys           = bid.Systems[0];
            TECEquipment  equip         = sys.Equipment[0];
            TECSubScope   ss            = equip.SubScope[0];
            TECPoint      point         = ss.Points[0];
            TECController bidController = bid.Controllers[0];
            TECController sysController = sys.Controllers[0];

            //Act
            List <ITECObject> bidToPointPath         = bid.GetObjectPath(point);
            List <ITECObject> bidToBidControllerPath = bid.GetObjectPath(bidController);
            List <ITECObject> bidToSysControllerPath = bid.GetObjectPath(sysController);
            List <ITECObject> sysToControllerPath    = sys.GetObjectPath(sysController);
            List <ITECObject> noPath = sys.GetObjectPath(bidController);

            //Assert

            //Bid to Point Path
            Assert.AreEqual(bid, bidToPointPath[0]);
            Assert.AreEqual(sys, bidToPointPath[1]);
            Assert.AreEqual(equip, bidToPointPath[2]);
            Assert.AreEqual(ss, bidToPointPath[3]);
            Assert.AreEqual(point, bidToPointPath[4]);

            Assert.AreEqual(5, bidToPointPath.Count);

            //Bid to Bid Controller Path
            Assert.AreEqual(bid, bidToBidControllerPath[0]);
            Assert.AreEqual(bidController, bidToBidControllerPath[1]);

            Assert.AreEqual(2, bidToBidControllerPath.Count);

            //Bid to System Controller Path
            Assert.AreEqual(bid, bidToSysControllerPath[0]);
            Assert.AreEqual(sys, bidToSysControllerPath[1]);
            Assert.AreEqual(sysController, bidToSysControllerPath[2]);

            Assert.AreEqual(3, bidToSysControllerPath.Count);

            //System to Controller Path
            Assert.AreEqual(sys, sysToControllerPath[0]);
            Assert.AreEqual(sysController, sysToControllerPath[1]);

            Assert.AreEqual(2, sysToControllerPath.Count);
        }
        public void Controller_RemoveSubScope()
        {
            //Arrange
            TECCatalogs   catalogs   = ModelCreation.TestCatalogs(rand);
            TECController controller = ModelCreation.TestProvidedController(catalogs, rand);
            TECSubScope   subScope   = new TECSubScope();
            TECDevice     dev        = catalogs.Devices.First();

            subScope.Devices.Add(dev);

            controller.Connect(subScope, subScope.AvailableProtocols.First(y => controller.AvailableProtocols.Contains(y)));

            //Act
            TECNetworkConnection netConnect = controller.Disconnect(subScope);

            //Assert
            Assert.AreEqual(0, netConnect.Children.Count(), "SubScope not removed from connection");
            Assert.AreEqual(null, subScope.Connection, "Connection not removed from subscope");
        }
Exemple #16
0
        private CostBatch removeController(TECController controller)
        {
            CostBatch deltas = new CostBatch();

            if (controller is TECProvidedController provided)
            {
                deltas += (ControllerSummaryVM.RemoveHardware(provided.Type));
                foreach (TECIOModule module in provided.IOModules)
                {
                    deltas += (removeIOModule(module));
                }
            }
            foreach (ICost cost in controller.AssociatedCosts)
            {
                deltas += (ControllerSummaryVM.RemoveCost(cost));
            }
            foreach (IControllerConnection connection in controller.ChildrenConnections)
            {
                deltas += (removeConnection(connection));
            }
            return(deltas);
        }
Exemple #17
0
        public void Update(IEnumerable <IConnectable> toConnect)
        {
            this.toConnect    = new List <IConnectable>(toConnect);
            ParentControllers = getCompatibleControllers(controllers);
            if (!ParentControllers.Contains(SelectedController))
            {
                SelectedController = null;
            }
            if (SelectedController == null)
            {
                if (ParentControllers.Count > 0)
                {
                    Connect            = true;
                    SelectedController = ParentControllers.First();
                }
                else
                {
                    Connect = false;
                }
            }

            RaisePropertyChanged("ParentControllers");
        }
Exemple #18
0
        public void RemoveControllerFromTypicalWithInstanceConnections()
        {
            TECBid bid = new TECBid();

            bid.Catalogs = ModelCreation.TestCatalogs(rand);
            TECTypical    system     = ModelCreation.TestTypical(bid.Catalogs, rand);
            TECController controller = system.Controllers[0];
            TECEquipment  equipment  = system.Equipment[0];
            TECSubScope   subScope   = new TECSubScope();

            subScope.Devices.Add(bid.Catalogs.Devices.First());
            equipment.SubScope.Add(subScope);
            controller.Connect(subScope, subScope.AvailableProtocols.First());
            bid.Systems.Add(system);
            TECSystem instance = system.AddInstance();

            TECController instanceController = system.TypicalInstanceDictionary.GetInstances(controller)[0] as TECController;
            TECSubScope   instanceSubScope   = system.TypicalInstanceDictionary.GetInstances(subScope)[0] as TECSubScope;

            system.RemoveController(controller);

            Assert.IsFalse(instance.Controllers.Contains(instanceController));
            Assert.IsTrue(instanceSubScope.Connection == null);
        }
        internal static void GenerateReport(string path, TECBid bid, bool openOnComplete = true)
        {
            XLWorkbook   workbook  = new XLWorkbook();
            IXLWorksheet worksheet = workbook.Worksheets.Add("Summary");

            worksheet.Cell(1, 2).Value = "Quantity";
            worksheet.Cell(1, 2).Style.Border.BottomBorder = XLBorderStyleValues.Thick;
            worksheet.Cell(1, 3).Value = "Price";
            worksheet.Cell(1, 3).Style.Border.BottomBorder = XLBorderStyleValues.Thick;
            worksheet.Cell(1, 4).Value = "Unit Price";
            worksheet.Cell(1, 4).Style.Border.BottomBorder = XLBorderStyleValues.Thick;

            worksheet.Cell(2, 1).Value = "Systems";
            worksheet.Cell(2, 1).Style.Border.BottomBorder = XLBorderStyleValues.Thin;

            int x = 3;

            for (int i = 0; i < bid.Systems.Count; i++, x++)
            {
                TECTypical   typical        = bid.Systems[i];
                TECEstimator systemEstimate = new TECEstimator(typical, bid.Parameters, bid.ExtraLabor, bid.Duration, new ChangeWatcher(typical));
                worksheet.Cell(x, 1).Value = typical.Name;
                worksheet.Cell(x, 2).Value = typical.Instances.Count;
                worksheet.Cell(x, 3).Value = systemEstimate.TotalPrice;
                worksheet.Cell(x, 3).Style.NumberFormat.Format = "$ #,##0.00";
                worksheet.Cell(x, 4).Value = typical.Instances.Count > 0 ? systemEstimate.TotalPrice / typical.Instances.Count : 0;
                worksheet.Cell(x, 4).Style.NumberFormat.Format = "$ #,##0.00";
            }
            x++;

            worksheet.Cell(x, 1).Value = "BMS Network";
            worksheet.Cell(x, 1).Style.Border.BottomBorder = XLBorderStyleValues.Thin;
            x++;

            for (int i = 0; i < bid.Controllers.Count; i++, x++)
            {
                TECController controller     = bid.Controllers[i];
                TECEstimator  systemEstimate = new TECEstimator(controller, bid.Parameters, bid.ExtraLabor, bid.Duration, new ChangeWatcher(controller));
                worksheet.Cell(x, 1).Value = controller.Name;
                worksheet.Cell(x, 2).Value = "1";
                worksheet.Cell(x, 3).Value = systemEstimate.TotalPrice;
                worksheet.Cell(x, 3).Style.NumberFormat.Format = "$ #,##0.00";
            }
            for (int i = 0; i < bid.Panels.Count; i++, x++)
            {
                TECPanel     typical        = bid.Panels[i];
                TECEstimator systemEstimate = new TECEstimator(typical, bid.Parameters, bid.ExtraLabor, bid.Duration, new ChangeWatcher(typical));
                worksheet.Cell(x, 1).Value = typical.Name;
                worksheet.Cell(x, 2).Value = "1";
                worksheet.Cell(x, 3).Value = systemEstimate.TotalPrice;
                worksheet.Cell(x, 3).Style.NumberFormat.Format = "$ #,##0.00";
            }
            x++;

            worksheet.Cell(x, 1).Value = "Miscellaneous";
            worksheet.Cell(x, 1).Style.Border.BottomBorder = XLBorderStyleValues.Thin;
            x++;

            for (int i = 0; i < bid.MiscCosts.Count; i++, x++)
            {
                TECMisc      typical        = bid.MiscCosts[i];
                TECEstimator systemEstimate = new TECEstimator(typical, bid.Parameters, bid.ExtraLabor, bid.Duration, new ChangeWatcher(typical));
                worksheet.Cell(x, 1).Value = typical.Name;
                worksheet.Cell(x, 2).Value = typical.Quantity;
                worksheet.Cell(x, 3).Value = systemEstimate.TotalPrice;
                worksheet.Cell(x, 3).Style.NumberFormat.Format = "$ #,##0.00";
            }
            TECEstimator extraLaborEstimate = new TECEstimator(bid.ExtraLabor, bid.Parameters, bid.ExtraLabor, bid.Duration, new ChangeWatcher(bid.ExtraLabor));

            worksheet.Cell(x, 1).Value = "Other Labor";
            worksheet.Cell(x, 2).Value = "1";
            worksheet.Cell(x, 3).Value = extraLaborEstimate.TotalPrice;
            worksheet.Cell(x, 3).Style.NumberFormat.Format = "$ #,##0.00";
            x += 2;

            worksheet.Cell(x, 2).Value = "Total: ";
            worksheet.Cell(x, 2).Style.Border.BottomBorder = XLBorderStyleValues.Thick;

            worksheet.Cell(x, 3).FormulaA1 = "=SUM(C3:C" + (x - 1) + ")";
            worksheet.Cell(x, 3).Style.NumberFormat.Format = "$ #,##0.00";

            worksheet.Columns().AdjustToContents();
            workbook.SaveAs(path);


            if (openOnComplete)
            {
                System.Diagnostics.Process.Start(path);
            }
        }
Exemple #20
0
 public ControllerInPanel(TECController controller, TECPanel panel) : base(Guid.NewGuid())
 {
     _controller = controller;
     _panel      = panel;
 }
Exemple #21
0
 private void deleteControllerExecute(TECController controller)
 {
     deleteControllerMethod(controller);
 }
Exemple #22
0
 public TECControllerMock(TECController controllerSource, Dictionary <Guid, Guid> guidDictionary = null) : base(controllerSource, guidDictionary)
 {
 }
 public static TECController FindControllerInController(IEnumerable <TECController> controllers, TECController reference)
 {
     foreach (TECController controller in controllers)
     {
         if (controller.Guid == reference.Guid)
         {
             return(controller);
         }
     }
     return(null);
 }
Exemple #24
0
        /// <summary>
        /// Connects all items to the controller. Existing network connections will be added to where possible
        /// </summary>
        /// <param name="items"></param>
        /// <param name="controller"></param>
        /// <returns></returns>
        public static List <IControllerConnection> ConnectToController(IEnumerable <IConnectable> items, TECController controller, ConnectionProperties properties)
        {
            var connectables = items
                               .Where(x => x.GetParentConnection() == null);

            var availableIO = controller.AvailableIO + ExistingNetworkIO(controller);
            List <IControllerConnection> connections = new List <IControllerConnection>();

            if (!CanConnectToController(items, controller))
            {
                return(connections);
            }
            foreach (var connectable in connectables)
            {
                var protocols = connectable.AvailableProtocols;
                if (protocols.Count == 1)
                {
                    var connection = controller.Connect(connectable, protocols.First());
                    if (connection == null)
                    {
                        throw new Exception("Connection was Null");
                    }
                    connections.Add(connection);
                    connection.UpdateFromProperties(properties);
                }
                else
                {
                    var connected = false;
                    foreach (var protocol in connectable.AvailableProtocols
                             .Where(x => x is TECProtocol networkProtocol && availableIO.Contains(networkProtocol)))
                    {
                        connected = true;
                        var connection = controller.Connect(connectable, protocol);
                        if (connection == null)
                        {
                            throw new Exception("Connection was Null");
                        }
                        connections.Add(connection);
                        connection.UpdateFromProperties(properties);
                        break;
                    }
                    if (!connected && connectable.AvailableProtocols.Any(x => x is TECHardwiredProtocol) &&
                        availableIO.Contains(connectable.HardwiredIO))
                    {
                        var connection = controller.Connect(connectable, connectable.AvailableProtocols.First(x => x is TECHardwiredProtocol));
                        connection.UpdateFromProperties(properties);
                        connections.Add(connection);
                    }
                }
            }

            if (controller is TECProvidedController pController)
            {
                pController.OptimizeModules();
            }
            return(connections.Distinct().ToList());
        }