public void TestNoneCloneableDataOperation()
        {
            lastEvent = null;

            testComponent1.Subscribe(this, EventType.Warning);

            IDataOperation nonCloneableDataOperation = new NoneCloneableDataOperation("nonCloneableDataOperation");

            Link link_a = new Link();

            link_a.ID = "Link a with NoneCloneableDataOperations";
            link_a.SourceComponent = testComponent1;
            link_a.TargetComponent = testComponent2;
            link_a.AddDataOperation(nonCloneableDataOperation);
            testComponent1.AddLink(link_a);
            testComponent2.AddLink(link_a);

            Link link_b = new Link();

            link_b.ID = "Link b with NoneCloneableDataOperations";
            link_b.SourceComponent = testComponent1;
            link_b.TargetComponent = testComponent2;
            link_b.AddDataOperation(nonCloneableDataOperation);

            lastEvent = null;
            testComponent2.AddLink(link_b);
            Assert.IsTrue(lastEvent == null, "lastEvent==null");
            testComponent1.AddLink(link_b);
            Assert.IsTrue(lastEvent != null, "lastEvent!=null");
            Assert.IsTrue(lastEvent.Type == EventType.Warning, "EventType.Warning");
            Assert.IsTrue(lastEvent.Description.ToLower().Contains("clone"), "clone");
        }
Esempio n. 2
0
        public void Init()
        {
            TestComponent sourceComponent  = new TestComponent();
            ElementSet    sourceElementSet = new ElementSet("SourceElementSet",
                                                            "SourceElementSetID", ElementType.XYPoint, new SpatialReference("SourceRef"));

            TestComponent targetComponent  = new TestComponent2();
            ElementSet    targetElementSet = new ElementSet("TargetElementSet",
                                                            "TargetElementSetID", ElementType.XYPoint, new SpatialReference("TargetRef"));

            ArrayList dataOperations = new ArrayList();

            dataOperations.Add(new DataOperation("dataOperation"));

            link1 = new Link(sourceComponent, sourceElementSet, new Quantity("SourceQuantity"),
                             targetComponent, targetElementSet, new Quantity("TargetQuantity"), "Link description", "Link1",
                             dataOperations);
            link2 = new Link();
            link2.SourceComponent  = sourceComponent;
            link2.SourceElementSet = sourceElementSet;
            link2.SourceQuantity   = new Quantity("SourceQuantity");
            link2.TargetComponent  = targetComponent;
            link2.TargetElementSet = targetElementSet;
            link2.TargetQuantity   = new Quantity("TargetQuantity");
            link2.Description      = "Link description";
            link2.ID = "Link2";
            link2.AddDataOperation(new DataOperation("dataOperation"));
        }
        public void AddLink(ILink link)
        {
            DHI.OpenMI.Backbone.Link locallink = new Link();
            AlteredLinks.Add(link.ID, locallink);

            //Mikeshe is the source. Create new local dataoperations.
            if (link.SourceComponent == this)
            {
                locallink.SourceComponent = MsheOrg;
                for (int i = 0; i < link.DataOperationsCount; i++)
                {
                    ElementMapper em   = new ElementMapper();
                    string        desc = "";
                    for (int j = 0; j < link.GetDataOperation(i).ArgumentCount; j++)
                    {
                        if (link.GetDataOperation(i).GetArgument(j).Key == "Description")
                        {
                            desc = link.GetDataOperation(i).GetArgument(j).Value;
                        }
                    }

                    em.Initialise(desc, link.SourceElementSet, link.TargetElementSet);
                    mappers.Add(link.ID, em);
                }
            }
            else
            {
                locallink.SourceComponent = link.SourceComponent;
            }

            //Mike she is the target. Copy the dataoperations
            if (link.TargetComponent == this)
            {
                locallink.TargetComponent = MsheOrg;
                for (int i = 0; i < link.DataOperationsCount; i++)
                {
                    locallink.AddDataOperation(link.GetDataOperation(i));
                }
            }
            else
            {
                locallink.TargetComponent = link.TargetComponent;
            }

            locallink.ID = link.ID;
            locallink.SourceElementSet = link.SourceElementSet;
            locallink.SourceQuantity   = link.SourceQuantity;

            locallink.TargetElementSet = link.TargetElementSet;
            locallink.TargetQuantity   = link.TargetQuantity;



            MsheOrg.AddLink(locallink);
        }
Esempio n. 4
0
        private void buttonApply_Click(object sender, System.EventArgs e)
        {
            // get checked items
            IQuantity   providerQuantity, acceptorQuantity;
            IElementSet providerElementSet, acceptorElementSet;

            IDataOperation[] providerDataOperations, acceptorDataOperations;

            providerExchangeItemSelector.GetCheckedExchangeItem(out providerQuantity, out providerElementSet, out providerDataOperations);
            acceptorExchangeItemSelector.GetCheckedExchangeItem(out acceptorQuantity, out acceptorElementSet, out acceptorDataOperations);

            // check wheather all needed informations are avaliable
            if (providerElementSet == null)
            {
                MessageBox.Show("No Output Exchange Item selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (acceptorElementSet == null)
            {
                MessageBox.Show("No Input Exchange Item selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (_uilink.AcceptingModel.ModelID == CompositionManager.TriggerModelID &&
                _uilink.Links.Count >= 1 &&
                listLinks.SelectedIndex == 0)
            {
                MessageBox.Show("Trigger can have only one link.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (!CheckIfDataOperationsAreValid())
            {
                switch (MessageBox.Show("Selected combination of DataOperations is invalid. Adding such link to LinkableComponents may\nway to unexpected result, maybe whole application will crash. If you are sure what you do,\nclick 'Yes', but in this case it's STRONGLY recommended to save your project before you proceed.\n\nDo you really want to continue ?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
                {
                case DialogResult.Yes:
                    break;

                default:
                    return;
                }
            }

            Debug.Assert(providerQuantity != null && acceptorQuantity != null);
            Debug.Assert(listLinks.SelectedIndex >= 0);

            int linkID;

            // TODO: shouldn't be this functionallity in UIConnection class ???
            //       - only problem with unique linkID

            if (listLinks.SelectedIndex == 0)
            {
                // Creating new link, so create new ID for it
                linkID = ++_startingLinkID;
            }
            else
            {
                // Modifying existing link, use its previous ID
                string oldLinkID = ((ILink)_uilink.Links[listLinks.SelectedIndex - 1]).ID;
                linkID = int.Parse(oldLinkID);

                // Remove this link from both LinkableComponents
                _uilink.AcceptingModel.LinkableComponent.RemoveLink(oldLinkID);
                _uilink.ProvidingModel.LinkableComponent.RemoveLink(oldLinkID);
            }

            // Create a new link even if modifing existing one.
            // That's because if some DataOperations were not selected,
            // we wouldn't be able to remove them from the link
            Link link = new Link(
                _uilink.ProvidingModel.LinkableComponent,
                providerElementSet,
                providerQuantity,
                _uilink.AcceptingModel.LinkableComponent,
                acceptorElementSet,
                acceptorQuantity,
                linkID.ToString());

            // add DataOperations
            foreach (IDataOperation dataOperation in providerDataOperations)
            {
                // set all changed writeable Arguments to dataOperation from property box
                if (_propertyManagerCache.Contains(dataOperation))
                {
                    for (int i = 0; i < dataOperation.ArgumentCount; i++)
                    {
                        IArgument argument = dataOperation.GetArgument(i);

                        if (!argument.ReadOnly)
                        {
                            string newValue = ((Oatc.OpenMI.Gui.Controls.PropertyManager)_propertyManagerCache[dataOperation]).GetProperty(argument.Key);
                            if (argument.Value != newValue)
                            {
                                argument.Value = newValue;
                            }
                        }
                    }
                }

                link.AddDataOperation(dataOperation);
            }

            // add/set new link to list
            if (listLinks.SelectedIndex == 0)
            {
                _uilink.Links.Add(link);
            }
            else
            {
                _uilink.Links[listLinks.SelectedIndex - 1] = link;
            }

            // ...and add new link to both LinkableComponents
            _uilink.ProvidingModel.LinkableComponent.AddLink(link);
            _uilink.AcceptingModel.LinkableComponent.AddLink(link);

            UpdateListLinks();
            UpdateViewElementSetButton();

            _shouldBeSaved = true;
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public void LinearTimeInterpolation()
        {
            Console.Write("Begin Linear Interpolation Test...");

            //create the his component
            DbReader his = new DbReader();

            IArgument[] arguments = new IArgument[1];
            arguments[0] = new Argument("DbPath", @"..\data\cuahsi-his\demo.db", true, "Database");
            his.Initialize(arguments);

            //create a trigger component
            Trigger trigger = new Trigger();

            trigger.Initialize(null);

            //link the two components
            Link link = new Link();

            link.ID = "link-1";
            link.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet;
            link.TargetQuantity   = trigger.GetInputExchangeItem(0).Quantity;
            link.TargetComponent  = trigger;


            link.SourceElementSet = his.GetOutputExchangeItem(1).ElementSet;
            link.SourceQuantity   = his.GetOutputExchangeItem(1).Quantity;
            link.TargetComponent  = his;


            //Spatial interpolation
            IDataOperation dataOp = (his).GetOutputExchangeItem(0).GetDataOperation(7);

            link.AddDataOperation(dataOp);


            //run configuration
            his.AddLink(link);

            trigger.Validate();
            his.Validate();

            //prepare
            his.Prepare();

            DateTime dt = Convert.ToDateTime("2009-08-20T21:40:00");

            SmartBuffer _smartBuffer = new SmartBuffer();

            //Add all values to buffer in 10min intervals
            Console.Write("Storing values in the smart buffer (10min resolution)... ");
            while (dt <= Convert.ToDateTime("2009-08-21T02:00:00"))
            {
                ITimeStamp time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(dt));
                ScalarSet  scalarset = (ScalarSet)his.GetValues(time_stmp, "link-1");

                if (scalarset.Count == 0)
                {
                    int       f         = his.GetOutputExchangeItem(1).ElementSet.ElementCount;
                    ArrayList zeroArray = new ArrayList();
                    for (int i = 0; i <= f - 1; i++)
                    {
                        zeroArray.Add(0.0);
                    }

                    double[] zeros = (double[])zeroArray.ToArray(typeof(double));

                    scalarset = new ScalarSet(zeros);
                }

                _smartBuffer.AddValues(time_stmp, scalarset);

                dt = dt.AddMinutes(10);
            }
            Console.WriteLine("done.\n\n");

            //request values from the smart buffer at 5min intervals
            dt = Convert.ToDateTime("2009-08-20T21:40:00");
            while (dt <= Convert.ToDateTime("2009-08-21T02:00:00"))
            {
                ITimeStamp time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(dt));

                //Get values at requested time
                ScalarSet scalarset = (ScalarSet)_smartBuffer.GetValues(time_stmp);

                Console.WriteLine("GetValues: " + dt.ToString("s"));


                //loop through interpolated values
                int i = 0;
                foreach (double d in scalarset.data)
                {
                    Console.WriteLine(link.SourceElementSet.GetElementID(i).ToString() + " " + d.ToString());
                    ++i;
                }
                dt = dt.AddMinutes(5);
            }

            Console.Write("done. \n");
        }
    public void AddLink(ILink link)
    {
      DHI.OpenMI.Backbone.Link locallink = new Link();
      AlteredLinks.Add(link.ID, locallink);

      //Mikeshe is the source. Create new local dataoperations.
      if (link.SourceComponent == this)
      {
        locallink.SourceComponent = MsheOrg;
        for (int i = 0; i < link.DataOperationsCount; i++)
        {
          ElementMapper em = new ElementMapper();
          string desc="";
          for (int j=0;j<link.GetDataOperation(i).ArgumentCount;j++)
            if (link.GetDataOperation(i).GetArgument(j).Key=="Description")
              desc = link.GetDataOperation(i).GetArgument(j).Value;

          em.Initialise(desc, link.SourceElementSet, link.TargetElementSet);
          mappers.Add(link.ID, em);
        }
      }
      else
        locallink.SourceComponent = link.SourceComponent;

      //Mike she is the target. Copy the dataoperations
      if (link.TargetComponent == this)
      {
        locallink.TargetComponent = MsheOrg;
        for (int i = 0; i < link.DataOperationsCount; i++)
          locallink.AddDataOperation(link.GetDataOperation(i));
      }
      else
        locallink.TargetComponent = link.TargetComponent;

      locallink.ID = link.ID;
      locallink.SourceElementSet = link.SourceElementSet;
      locallink.SourceQuantity = link.SourceQuantity;

      locallink.TargetElementSet = link.TargetElementSet;
      locallink.TargetQuantity = link.TargetQuantity;



     

      MsheOrg.AddLink(locallink);

    }