public void Init()
 {
     events = new List <LinkableComponentStatusChangeEventArgs>();
     Argument[] arguments = { new Argument("Path", @"..\..\Data\", true, "description") };
     riverModelLC = new RiverModelLinkableComponent();
     riverModelLC.StatusChanged += riverModelLC_StatusChanged;
     riverModelLC.Initialize(arguments);
 }
Exemple #2
0
        public void Init()
        {
            gwModelLC = new Oatc.OpenMI.Examples.ModelComponents.SpatialModels.GroundWaterModel.GWModelLC();

            Oatc.OpenMI.Sdk.Backbone.Argument[] arguments = new Argument[10];
            arguments[0] = new Oatc.OpenMI.Sdk.Backbone.Argument("simulationStart", "1990,1,2,0,0,0", true, " year, month, day, hour, minute, second for simulation start");
            arguments[1] = new Oatc.OpenMI.Sdk.Backbone.Argument("simulationEnd", "1990,2,1,0,0,0", true, " year, month, day, hour, minute, second for simulation start");
            arguments[2] = new Oatc.OpenMI.Sdk.Backbone.Argument("nx", "2", true, "Number of grid cells in x-direction");
            arguments[3] = new Oatc.OpenMI.Sdk.Backbone.Argument("ny", "2", true, "Number of grid cells in y-direction");
            arguments[4] = new Oatc.OpenMI.Sdk.Backbone.Argument("ox", "1000", true, "origo X");
            arguments[5] = new Oatc.OpenMI.Sdk.Backbone.Argument("oy", "2000", true, "origo Y");
            arguments[6] = new Oatc.OpenMI.Sdk.Backbone.Argument("cellSize", "900", true, "cell size");
            arguments[7] = new Oatc.OpenMI.Sdk.Backbone.Argument("groundWaterLevel", "1.0", true, "Ground Wagter Level");
            arguments[8] = new Oatc.OpenMI.Sdk.Backbone.Argument("modelID", "GWModelEngineModelID", true, "model ID");
            arguments[9] = new Oatc.OpenMI.Sdk.Backbone.Argument("gridAngle", "0", true, "rotation angle for the grid");

            gwModelLC.Initialize(arguments);
        }
Exemple #3
0
        /// <summary>
        /// Sets this model according to OMI file.
        /// </summary>
        /// <param name="filename">Relative or absolute path to OMI file describing the model.</param>
        /// <param name="relativeDirectory">Directory <c>filename</c> is relative to, or <c>null</c> if <c>filename</c> is absolute or relative to current directory.</param>
        /// <remarks>See <see cref="Utils.GetFileInfo">Utils.GetFileInfo</see> for more info about how
        /// specified file is searched.</remarks>
        public void ReadOMIFile(string relativeDirectory, string filename)
        {
            // Open OMI file as xmlDocument
            FileInfo omiFileInfo = Utils.GetFileInfo(relativeDirectory, filename);

            if (!omiFileInfo.Exists)
            {
                throw(new Exception("Omi file not found (CurrentDirectory='" + Directory.GetCurrentDirectory() + "', File='" + filename + "')"));
            }

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(omiFileInfo.FullName);

            // get 1st LinkableComponent element
            XmlElement xmlLinkableComponent = null;

            foreach (XmlNode node in xmlDocument.ChildNodes)
            {
                if (node.Name == "LinkableComponent")
                {
                    xmlLinkableComponent = (XmlElement)node;
                    break;
                }
            }

            // load assembly if present (from relative location of the OMI file)
            if (xmlLinkableComponent == null)
            {
                throw new Exception("No linkable components found in composition file " + omiFileInfo);
            }
            else
            {
                string assemblyFilename = xmlLinkableComponent.GetAttribute("Assembly");
                if (assemblyFilename != null)
                {
                    AssemblySupport.LoadAssembly(omiFileInfo.DirectoryName, assemblyFilename);
                }
            }

            // read arguments
            ArrayList linkableComponentArguments = new ArrayList();

            foreach (XmlElement xmlArguments in xmlLinkableComponent.ChildNodes)
            {
                if (xmlArguments.Name == "Arguments")
                {
                    foreach (XmlElement xmlArgument in xmlArguments.ChildNodes)
                    {
                        linkableComponentArguments.Add(new Argument(xmlArgument.GetAttribute("Key"), xmlArgument.GetAttribute("Value"), true, "No description"));
                    }
                }
            }

            // get new instance of ILinkableComponent type
            // for this moment set current directory to omi file's directory
            string oldDirectory = Directory.GetCurrentDirectory();

            try
            {
                Directory.SetCurrentDirectory(omiFileInfo.DirectoryName);

                string classTypeName = xmlLinkableComponent.GetAttribute("Type");
                object obj           = AssemblySupport.GetNewInstance(classTypeName);
                if (!(obj is ILinkableComponent))
                {
                    throw new Exception("\n\nThe class type " + classTypeName + " in\n" +
                                        filename +
                                        "\nis not an OpenMI.Standard.ILinkableComponent (OpenMI.Standard.dll version 1.4.0.0)." +
                                        "\nYou may have specified a wrong class name, " +
                                        "\nor the class implements the ILinkableComponent interface of a previous version of the OpenMI Standard.\n");
                }
                _linkableComponent = (ILinkableComponent)obj;
                _linkableComponent.Initialize((IArgument[])linkableComponentArguments.ToArray(typeof(IArgument)));
            }
            finally
            {
                Directory.SetCurrentDirectory(oldDirectory);
            }

            _omiFilename = omiFileInfo.FullName;

            _modelID = _linkableComponent.ModelID;

            // remote components have rectangle style
            string componentDescription = _linkableComponent.ComponentDescription;

            if (componentDescription != null)
            {
                if (componentDescription.IndexOf("OpenMI.Distributed") >= 0)
                {
                    _rectanglePen.DashStyle = DashStyle.Dash;
                }
            }
        }
Exemple #4
0
		/// <summary>
		/// Sets this model according to OMI file.
		/// </summary>
		/// <param name="filename">Relative or absolute path to OMI file describing the model.</param>
		/// <param name="relativeDirectory">Directory <c>filename</c> is relative to, or <c>null</c> if <c>filename</c> is absolute or relative to current directory.</param>
		/// <remarks>See <see cref="Utils.GetFileInfo">Utils.GetFileInfo</see> for more info about how
		/// specified file is searched.</remarks>	
		public void ReadOMIFile( string relativeDirectory, string filename )
		{
			// Open OMI file as xmlDocument
			FileInfo omiFileInfo = Utils.GetFileInfo( relativeDirectory, filename );
			if( !omiFileInfo.Exists )
				throw( new Exception("Omi file not found (CurrentDirectory='"+Directory.GetCurrentDirectory()+"', File='"+filename+"')") );

			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load( omiFileInfo.FullName );

			// get 1st LinkableComponent element
			XmlElement xmlLinkableComponent = null;
			foreach( XmlNode node in xmlDocument.ChildNodes )
				if( node.Name=="LinkableComponent" )
				{
					xmlLinkableComponent = (XmlElement)node;
					break;
				}

			// load assembly if present (from relative location of the OMI file)
			if (xmlLinkableComponent == null)
			{
				throw new Exception("No linkable components found in composition file " + omiFileInfo);
			}
			else
			{
				string assemblyFilename = xmlLinkableComponent.GetAttribute("Assembly");
				if (assemblyFilename != null)
					AssemblySupport.LoadAssembly(omiFileInfo.DirectoryName, assemblyFilename);
			}

			// read arguments
			ArrayList linkableComponentArguments = new ArrayList();

			foreach( XmlElement xmlArguments in xmlLinkableComponent.ChildNodes )
				if( xmlArguments.Name == "Arguments" )
					foreach( XmlElement xmlArgument in xmlArguments.ChildNodes )
						linkableComponentArguments.Add( new Argument(xmlArgument.GetAttribute("Key"), xmlArgument.GetAttribute("Value"), true, "No description"));

			// get new instance of ILinkableComponent type
			// for this moment set current directory to omi file's directory
			string oldDirectory = Directory.GetCurrentDirectory(); 
			try 
			{
				Directory.SetCurrentDirectory( omiFileInfo.DirectoryName );

				string classTypeName = xmlLinkableComponent.GetAttribute("Type");
				object obj = AssemblySupport.GetNewInstance( classTypeName );
				if ( ! ( obj is ILinkableComponent ) )
				{
					throw new Exception("\n\nThe class type " + classTypeName + " in\n" +
						filename +
						"\nis not an OpenMI.Standard.ILinkableComponent (OpenMI.Standard.dll version 1.4.0.0)." +
						"\nYou may have specified a wrong class name, " +
						"\nor the class implements the ILinkableComponent interface of a previous version of the OpenMI Standard.\n");
				}
				_linkableComponent = (ILinkableComponent)obj;
				_linkableComponent.Initialize( (IArgument[])linkableComponentArguments.ToArray(typeof(IArgument)) );
			}
			finally
			{
				Directory.SetCurrentDirectory( oldDirectory );
			}

			_omiFilename = omiFileInfo.FullName;
			
			_modelID = _linkableComponent.ModelID;

			// remote components have rectangle style
			string componentDescription = _linkableComponent.ComponentDescription;
			if( componentDescription != null )
				if( componentDescription.IndexOf( "OpenMI.Distributed" ) >= 0 )				
					_rectanglePen.DashStyle = DashStyle.Dash;
		}