コード例 #1
0
ファイル: LinkTest.cs プロジェクト: XiBeichuan/hydronumerics
		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"));
		}
コード例 #2
0
		public void GetValues4A()
		{
			//This test is: RiverModel --> GWModel --> Trigger
			//Testing: Georeferenced links
			RiverModelLC riverModel = new RiverModelLC();
			GWModelLC    gWModel    = new GWModelLC();
			Trigger      trigger    = new Trigger();

			riverModel.Initialize(new Argument[0]);
			gWModel.Initialize(new Argument[0]);

			Link riverGWLink = new Link();
			riverGWLink.ID = "RiverGWLink";
			riverGWLink.SourceComponent = riverModel;
			riverGWLink.SourceElementSet = riverModel.GetOutputExchangeItem(6).ElementSet;
			riverGWLink.SourceQuantity   = riverModel.GetOutputExchangeItem(0).Quantity;
			riverGWLink.TargetComponent  = gWModel;
			riverGWLink.TargetElementSet = gWModel.GetInputExchangeItem(0).ElementSet;
			riverGWLink.TargetQuantity   = gWModel.GetInputExchangeItem(0).Quantity;

			int dataOperationIndex = -9;
			for (int i = 0; i < riverModel.GetOutputExchangeItem(6).DataOperationCount; i++)
			{
				if (riverModel.GetOutputExchangeItem(6).GetDataOperation(i).ID == "ElementMapper501")
				{
					dataOperationIndex = i;
				}
			}

			if (dataOperationIndex < 0)
			{
				throw new Exception("failed to find dataOperation");
			}
			
			riverGWLink.AddDataOperation(riverModel.GetOutputExchangeItem(6).GetDataOperation(dataOperationIndex));

			Link triggerLink = new Link();
			triggerLink.ID = "RiverGWLink";
			triggerLink.SourceComponent = gWModel;
			triggerLink.SourceElementSet = gWModel.GetOutputExchangeItem(0).ElementSet;
			triggerLink.SourceQuantity   = gWModel.GetOutputExchangeItem(0).Quantity;
			triggerLink.TargetComponent  = trigger;
			triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet;
			triggerLink.TargetQuantity   = trigger.GetInputExchangeItem(0).Quantity;

			riverModel.AddLink(riverGWLink);
			gWModel.AddLink(riverGWLink);
			gWModel.AddLink(triggerLink);
			trigger.AddLink(triggerLink);

			riverModel.Prepare();
			gWModel.Prepare();

			double firstTriggerGetValuesTime = riverModel.TimeHorizon.Start.ModifiedJulianDay;
			TimeStamp[] triggerTimes = new TimeStamp[2];
			triggerTimes[0] = new TimeStamp(firstTriggerGetValuesTime + 12.1);
			triggerTimes[1] = new TimeStamp(firstTriggerGetValuesTime + 16.7);
	
			trigger.Run(triggerTimes);

			double x0 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(0);
			Assert.AreEqual(0.0,x0);

			double x1 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(1);
			Assert.AreEqual(105.0/16.0,x1);

			double x2 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(2);
			Assert.AreEqual(7.5,x2);

			double x3 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(3);
			Assert.AreEqual(5.0+35.0/16.0,x3);

			riverModel.Finish();
			gWModel.Finish();

			riverModel.Dispose();
			gWModel.Dispose();

		}
コード例 #3
0
		public void SmartBufferDataOperationTest()
		{
			// Running with one instances of riverModelLC linked ID-based to trigger
			// using the SmartBufferDataOperation.

			try
			{
				ILinkableComponent riverModelLC = new RiverModelLC();
				Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger trigger = new Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger();
	
				Argument[] riverArguments = new Argument[2];
				riverArguments[0] = new Argument("ModelID","RiverModel",true,"argument");
				riverArguments[1] = new Argument("TimeStepLength","3600",true,"A time step length of 1 hour");

				riverModelLC.Initialize(riverArguments);
				trigger.Initialize(new Argument[0]);

				Link link = new Link(riverModelLC, riverModelLC.GetOutputExchangeItem(2).ElementSet,riverModelLC.GetOutputExchangeItem(2).Quantity,trigger,trigger.GetInputExchangeItem(0).ElementSet,trigger.GetInputExchangeItem(0).Quantity,"LinkID");

				//add linear conversion data operation
				bool dataOperationWasFound = false;
				int dataOperationIndex = -9;
				for (int i = 0; i < riverModelLC.GetOutputExchangeItem(2).DataOperationCount; i++)
				{
					if (riverModelLC.GetOutputExchangeItem(2).GetDataOperation(i).ID == new SmartBufferDataOperation().ID)
					{
						dataOperationWasFound = true;
						dataOperationIndex = i;
					}
				}
				Assert.AreEqual(true,dataOperationWasFound);
				IDataOperation smartBufferDataOperation = riverModelLC.GetOutputExchangeItem(2).GetDataOperation(dataOperationIndex);
				bool key_A_WasFound = false;
				bool key_B_WasFound = false;
				bool key_Type_WasFound = false;

				for (int i = 0; i < smartBufferDataOperation.ArgumentCount; i++)
				{
					if ( smartBufferDataOperation.GetArgument(i).Key == "Relaxation Factor")
					{
						smartBufferDataOperation.GetArgument(i).Value = "0.7";
						key_A_WasFound = true;
						Assert.AreEqual(false,smartBufferDataOperation.GetArgument(i).ReadOnly);
					}
					if ( smartBufferDataOperation.GetArgument(i).Key == "Do Extended Data Validation")
					{
						smartBufferDataOperation.GetArgument(i).Value = "False";
						key_B_WasFound = true;
						Assert.AreEqual(false,smartBufferDataOperation.GetArgument(i).ReadOnly);
					}

					if ( smartBufferDataOperation.GetArgument(i).Key == "Type")
					{
						key_Type_WasFound = true;
						Assert.AreEqual(true,smartBufferDataOperation.GetArgument(i).ReadOnly);
					}
				}

				Assert.AreEqual(true,key_A_WasFound);
				Assert.AreEqual(true,key_B_WasFound);
				Assert.AreEqual(true,key_Type_WasFound);
				Assert.AreEqual("Buffering and temporal extrapolation",smartBufferDataOperation.ID);

				link.AddDataOperation(smartBufferDataOperation);

				riverModelLC.AddLink(link);
				trigger.AddLink(link);

				riverModelLC.Prepare();

				Assert.AreEqual(0.7,((SmartOutputLink)((RiverModelLC) riverModelLC).SmartOutputLinks[0]).SmartBuffer.RelaxationFactor);
				Assert.AreEqual(false,((SmartOutputLink)((RiverModelLC) riverModelLC).SmartOutputLinks[0]).SmartBuffer.DoExtendedDataVerification);

				riverModelLC.Finish();
				riverModelLC.Dispose();
				
			}
			catch (System.Exception e)
			{
				ExceptionHandler.WriteException(e);
				throw (e);
			}
		}
コード例 #4
0
		public void LinearConvertionDataOperation()
		{
			// Running with one instances of riverModelLC linked ID-based to trigger
			// using the linearConversionDataOperation.

			try
			{
				ILinkableComponent riverModelLC = new RiverModelLC();
				Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger trigger = new Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger();
	
				Argument[] riverArguments = new Argument[2];
				riverArguments[0] = new Argument("ModelID","RiverModel",true,"argument");
				riverArguments[1] = new Argument("TimeStepLength","3600",true,"A time step length of 1 hour");

				riverModelLC.Initialize(riverArguments);
				trigger.Initialize(new Argument[0]);

				Link link = new Link(riverModelLC, riverModelLC.GetOutputExchangeItem(2).ElementSet,riverModelLC.GetOutputExchangeItem(2).Quantity,trigger,trigger.GetInputExchangeItem(0).ElementSet,trigger.GetInputExchangeItem(0).Quantity,"LinkID");

				//add linear conversion data operation
				bool dataOperationWasFound = false;
				int dataOperationIndex = -9;
				for (int i = 0; i < riverModelLC.GetOutputExchangeItem(2).DataOperationCount; i++)
				{
					if (riverModelLC.GetOutputExchangeItem(2).GetDataOperation(i).ID == "Linear Conversion")
					{
						dataOperationWasFound = true;
						dataOperationIndex = i;
					}
				}
				Assert.AreEqual(true,dataOperationWasFound);
				IDataOperation linearConvertionDataOperation = riverModelLC.GetOutputExchangeItem(2).GetDataOperation(dataOperationIndex);
				bool key_A_WasFound = false;
				bool key_B_WasFound = false;
				bool key_Type_WasFound = false;

				for (int i = 0; i < linearConvertionDataOperation.ArgumentCount; i++)
				{
					if ( linearConvertionDataOperation.GetArgument(i).Key == "A")
					{
						linearConvertionDataOperation.GetArgument(i).Value = "2.5";
						key_A_WasFound = true;
						Assert.AreEqual(false,linearConvertionDataOperation.GetArgument(i).ReadOnly);
					}
					if ( linearConvertionDataOperation.GetArgument(i).Key == "B")
					{
						linearConvertionDataOperation.GetArgument(i).Value = "3.5";
						key_B_WasFound = true;
						Assert.AreEqual(false,linearConvertionDataOperation.GetArgument(i).ReadOnly);
					}

					if ( linearConvertionDataOperation.GetArgument(i).Key == "Type")
					{
						key_Type_WasFound = true;
						Assert.AreEqual(true,linearConvertionDataOperation.GetArgument(i).ReadOnly);
					}
				}

				Assert.AreEqual(true,key_A_WasFound);
				Assert.AreEqual(true,key_B_WasFound);
				Assert.AreEqual(true,key_Type_WasFound);
				Assert.AreEqual("Linear Conversion",linearConvertionDataOperation.ID);

				link.AddDataOperation(linearConvertionDataOperation);

				riverModelLC.AddLink(link);
				trigger.AddLink(link);

				riverModelLC.Prepare();
				
				double firstTriggerGetValuesTime = riverModelLC.TimeHorizon.Start.ModifiedJulianDay;
				TimeStamp[] triggerTimes = new TimeStamp[2];
				triggerTimes[0] = new TimeStamp(firstTriggerGetValuesTime + 2);
				triggerTimes[1] = new TimeStamp(firstTriggerGetValuesTime + 4.3);
	
				trigger.Run(triggerTimes);
				double x1 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(0);
				Assert.AreEqual(2.5*(35.0/4.0) + 3.5, x1);

				double x2 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(1)).GetScalar(0);
				Assert.AreEqual(2.5 * (35.0/4.0) + 3.5, x2);

				riverModelLC.Finish();
				riverModelLC.Dispose();
				
			}
			catch (System.Exception e)
			{
				ExceptionHandler.WriteException(e);
				throw (e);
			}
		}
コード例 #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;
        }
コード例 #6
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;
		}
コード例 #7
0
		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");
		}