Example #1
0
        public static ILink CreateLink(ILinkableComponent sourceComponent, string sourceQuantityID, string sourceElementSetID, ILinkableComponent targetComponent, string targetQuantityID, string targetElementSetID, string[] dataOperationIDs)
        {
            string linkID = sourceComponent.ComponentID + "(" + sourceQuantityID + ", " + sourceElementSetID + ") to " + targetComponent.ComponentID + "(" + targetQuantityID + ", " + targetElementSetID + ")";

            int outputExchangeItemIndex = -1;

            for (int i = 0; i < sourceComponent.OutputExchangeItemCount; i++)
            {
                if (sourceComponent.GetOutputExchangeItem(i).Quantity.ID == sourceQuantityID && sourceComponent.GetOutputExchangeItem(i).ElementSet.ID == sourceElementSetID)
                {
                    outputExchangeItemIndex = i;
                }
            }

            if (outputExchangeItemIndex < 0)
            {
                throw new Exception("Exception in LinkFactory.CreateLink, failed to find output exchange item for " + sourceQuantityID + ", " + sourceElementSetID + " during creation of link: " + linkID);
            }

            int inputExchangeItemIndex = -1;

            for (int i = 0; i < targetComponent.InputExchangeItemCount; i++)
            {
                if (targetComponent.GetInputExchangeItem(i).Quantity.ID == targetQuantityID && targetComponent.GetInputExchangeItem(i).ElementSet.ID == targetElementSetID)
                {
                    inputExchangeItemIndex = i;
                }
            }

            if (inputExchangeItemIndex < 0)
            {
                throw new Exception("Exception in LinkFactory.CreateLink, failed to find input exchange item for " + targetQuantityID + ", " + targetElementSetID + " during creation of link: " + linkID);
            }


            Link link = new Link();

            link.ID               = linkID;
            link.Description      = linkID;
            link.SourceComponent  = sourceComponent;
            link.SourceQuantity   = sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).Quantity;
            link.SourceElementSet = sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).ElementSet;
            link.TargetComponent  = targetComponent;
            link.TargetQuantity   = targetComponent.GetInputExchangeItem(inputExchangeItemIndex).Quantity;
            link.TargetElementSet = targetComponent.GetInputExchangeItem(inputExchangeItemIndex).ElementSet;

            bool dataOperationWasFound = false;

            for (int n = 0; n < dataOperationIDs.Length; n++)
            {
                dataOperationWasFound = false;
                for (int i = 0; i < sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).DataOperationCount; i++)
                {
                    if (sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).GetDataOperation(i).ID == dataOperationIDs[n])
                    {
                        link.AddDataOperation(sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).GetDataOperation(i));
                        dataOperationWasFound = true;
                    }
                }
                if (!dataOperationWasFound)
                {
                    throw new Exception("failed to find dataOperation: " + dataOperationIDs[n] + " during creation of link: " + linkID);
                }
            }

            return((ILink)link);
        }
        public static ILink CreateLink(ILinkableComponent sourceComponent, string sourceQuantityID, string sourceElementSetID, ILinkableComponent targetComponent, string targetQuantityID, string targetElementSetID, string[] dataOperationIDs)
        {
            string linkID = sourceComponent.ComponentID + "(" + sourceQuantityID + ", " + sourceElementSetID + ") to " + targetComponent.ComponentID + "(" + targetQuantityID + ", " + targetElementSetID + ")";

            int outputExchangeItemIndex = -1;
            for (int i = 0; i < sourceComponent.OutputExchangeItemCount; i++)
            {
                if (sourceComponent.GetOutputExchangeItem(i).Quantity.ID == sourceQuantityID && sourceComponent.GetOutputExchangeItem(i).ElementSet.ID == sourceElementSetID)
                {
                    outputExchangeItemIndex = i;
                }
            }

            if (outputExchangeItemIndex < 0)
            {
                throw new Exception("Exception in LinkFactory.CreateLink, failed to find output exchange item for " + sourceQuantityID + ", " + sourceElementSetID + " during creation of link: " + linkID);
            }

            int inputExchangeItemIndex = -1;
            for (int i = 0; i < targetComponent.InputExchangeItemCount; i++)
            {
                if (targetComponent.GetInputExchangeItem(i).Quantity.ID == targetQuantityID && targetComponent.GetInputExchangeItem(i).ElementSet.ID == targetElementSetID)
                {
                    inputExchangeItemIndex = i;
                }
            }

            if (inputExchangeItemIndex < 0)
            {
                throw new Exception("Exception in LinkFactory.CreateLink, failed to find input exchange item for " + targetQuantityID + ", " + targetElementSetID + " during creation of link: " + linkID);
            }


            Link link = new Link();
            link.ID = linkID;
            link.Description = linkID;
            link.SourceComponent = sourceComponent;
            link.SourceQuantity = sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).Quantity;
            link.SourceElementSet = sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).ElementSet;
            link.TargetComponent = targetComponent;
            link.TargetQuantity = targetComponent.GetInputExchangeItem(inputExchangeItemIndex).Quantity;
            link.TargetElementSet = targetComponent.GetInputExchangeItem(inputExchangeItemIndex).ElementSet;

            bool dataOperationWasFound = false;

            for (int n = 0; n < dataOperationIDs.Length; n++)
            {
                dataOperationWasFound = false;
                for (int i = 0; i < sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).DataOperationCount; i++)
                {
                    if (sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).GetDataOperation(i).ID == dataOperationIDs[n])
                    {
                        link.AddDataOperation(sourceComponent.GetOutputExchangeItem(outputExchangeItemIndex).GetDataOperation(i));
                        dataOperationWasFound = true;
                    }
                }
                if (!dataOperationWasFound)
                {
                    throw new Exception("failed to find dataOperation: " + dataOperationIDs[n] + " during creation of link: " + linkID);
                }
            }

            return (ILink)link;
        }
Example #3
0
 public void GetOutputExchangeItem()
 {
     Assert.AreEqual("BaseGrid", gwModelLC.GetOutputExchangeItem(0).ElementSet.ID);
     Assert.AreEqual(ElementType.XYPolygon, gwModelLC.GetOutputExchangeItem(0).ElementSet.ElementType);
 }