コード例 #1
0
        /// <summary>
        /// Populates a SerializationInfo with the data needed to serialize the <see craf = "UnitOperationWrapper"/>.
        /// </summary>
        /// <remarks>This method restores serializable .NET-based port connections. COM-bassed stream objects may need to
        /// be connected manually to the ports.</remarks>
        /// <param name="info">The SerializationInfo to populate the <see craf = "UnitOperationWrapper"/> with data.</param>
        /// <param name="context">The destination <see craf = "StreamingContext"/> for this serialization.</param>
        void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            bool isCOM = p_Unit.GetType().IsCOMObject;

            info.AddValue("isCOM", isCOM, typeof(bool));
            if (isCOM)
            {
                info.AddValue("CLSID", m_CLSID.ToString(), typeof(string));
            }
            else
            {
                info.AddValue("Unit Type", p_Unit.GetType(), typeof(Type));
                info.AddValue("Unit Assembly", p_Unit.GetType().Assembly, typeof(System.Reflection.Assembly));
            }

            ICapeIdentification p_Id = (ICapeIdentification)p_Unit;

            info.AddValue("Unit Name", p_Id.ComponentName, typeof(string));
            info.AddValue("Unit Description", p_Id.ComponentDescription, typeof(string));
            // ICapeUtilities p_Util = (ICapeUtilities)p_Unit;
            //if (this.SimulationContext != null)
            //{
            //    if (this.SimulationContext.GetType().IsSerializable)
            //    {
            //        info.AddValue("Simulation Context", this.SimulationContext, typeof(object));
            //    }
            //    else
            //    {
            //        info.AddValue("Simulation Context", null, typeof(object));
            //    }
            //}
            // else info.AddValue("Simulation Context", null, typeof(object));
            object[]        paramValues = new object[this.Parameters.Count];
            CapeParamMode[] paramModes  = new CapeParamMode[this.Parameters.Count];
            int             i           = 0;

            foreach (ICapeParameter parameter in this.Parameters)
            {
                paramValues[i] = parameter.value;
                paramModes[i]  = parameter.Mode;
                i++;
            }
            info.AddValue("Parameter Values", paramValues, typeof(object[]));
            info.AddValue("Parameter Modes", paramModes, typeof(CapeParamMode[]));
            object[] portConnections = new object[this.Ports.Count];
            i = 0;
            foreach (ICapeUnitPort port in this.Ports)
            {
                portConnections[i] = port.connectedObject;
                if (portConnections[i] != null)
                {
                    if (!portConnections[i].GetType().IsSerializable)
                    {
                        portConnections[i] = null;
                    }
                }
                i++;
            }
            info.AddValue("PortConnections", portConnections, typeof(object[]));
        }
コード例 #2
0
 public CapeCollectionPair(string key, ICapeIdentification value)
 {
     if (key == null)
     {
         throw new ECapeUnknownException(
                   "key in CapeCollectionPair cannot be null.");
     }
     Key   = key;
     Value = value;
 }
コード例 #3
0
        /// <summary>
        /// Remove the same item, should be reference equal
        /// </summary>
        public bool Remove(ICapeIdentification item)
        {
            string key = (from p in _items
                          where p.Value.Equals(item)
                          select p.Key).SingleOrDefault();

            if (key == null)
            {
                return(false);
            }
            _items.Remove(key);
            return(true);
        }
コード例 #4
0
        override public void Initialize()
        {
            ICapeUtilitiesCOM p_Util = ((ICapeUtilitiesCOM)this.p_Unit);

            p_Util.Initialize();

            ICapeIdentification p_Id = (ICapeIdentification)p_Unit;

            //wrap ports...
            ICapeCollection portColl  = (ICapeCollection)((ICapeUnitCOM)(p_Unit)).ports;
            int             portCount = portColl.Count();

            object[] portConnections = new object[portCount];
            for (int i = 0; i < portCount; i++)
            {
                ICapeUnitPortCOM port = (ICapeUnitPortCOM)portColl.Item(i + 1);
                this.Ports.Add(new UnitPortWrapper(port));
            }

            //wrap parameters...
            ICapeCollection paramColl  = (ICapeCollection)((ICapeUtilitiesCOM)(p_Unit)).parameters;
            int             paramCount = paramColl.Count();

            for (int i = 0; i < paramCount; i++)
            {
                ICapeParameter param     = (ICapeParameter)paramColl.Item(i + 1);
                CapeParamType  paramType = ((ICapeParameterSpecCOM)param.Specification).Type;
                if (((ICapeParameterSpecCOM)param.Specification).Type == CapeParamType.CAPE_REAL)
                {
                    this.Parameters.Add(new RealParameterWrapper(param));
                }
                if (((ICapeParameterSpecCOM)param.Specification).Type == CapeParamType.CAPE_INT)
                {
                    this.Parameters.Add(new IntegerParameterWrapper(param));
                }
                if (((ICapeParameterSpecCOM)param.Specification).Type == CapeParamType.CAPE_OPTION)
                {
                    this.Parameters.Add(new OptionParameterWrapper(param));
                }
                if (((ICapeParameterSpecCOM)param.Specification).Type == CapeParamType.CAPE_BOOLEAN)
                {
                    this.Parameters.Add(new BooleanParameterWrapper(param));
                }
                if (((ICapeParameterSpecCOM)param.Specification).Type == CapeParamType.CAPE_ARRAY)
                {
                    this.Parameters.Add(new ArrayParameterWrapper(param));
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Add an item with a key
 /// </summary>
 public void Add(string key, ICapeIdentification item)
 {
     if (constraint != null && !constraint(item))
     {
         throw new ECapeUnknownException(this,
                                         $"<{key}> is not a valid item in collection <{ComponentName}>. Due to <{constraint.ToString()}>");
     }
     if (_items.ContainsValue(item))
     {
         throw new ECapeUnknownException(this,
                                         $"This Collection already has the same item: <{item.ComponentName}>.");
     }
     if (_items.ContainsKey(key))
     {
         throw new ECapeUnknownException(this,
                                         $"This collection already has an item with the same key: <{key}>.");
     }
     _items.Add(key, item);
 }
コード例 #6
0
        /// <summary>
        /// Creates an instance of the UnitOperationWrapper unit operation wrapping the unit operation.
        /// </summary>
        /// <remarks>
        /// This constructor creates a new instance of a <see craf = "UnitOperationWrapper"/> from a serialized
        /// instance.
        /// </remarks>
        /// <param name="info">The serialization data for the object.</param>
        /// <param name="context">The serialization context of the serialized stream.</param>
        public UnitOperationWrapper(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            bool isCom = info.GetBoolean("isCOM");

            if (isCom)
            {
                m_CLSID     = new System.Guid(info.GetString("CLSID"));
                this.p_Unit = Activator.CreateInstance(Type.GetTypeFromCLSID(m_CLSID));
            }
            else
            {
                Type type = (Type)info.GetValue("Unit Type", typeof(Type));
            }
            this.Initialize();
            ICapeIdentification p_Id = (ICapeIdentification)p_Unit;

            p_Id.ComponentName = info.GetString("Unit Name");
            p_Id.ComponentName = info.GetString("Unit Description");
            //this.SimulationContext = (ICapeSimulationContext)info.GetValue("Simulation Context", typeof(object));
            object[]        m_ParameterValues = (object[])info.GetValue("Parameter Values", typeof(object[]));
            CapeParamMode[] m_ParameterModes  = (CapeParamMode[])info.GetValue("Parameter Modes", typeof(CapeParamMode[]));
            int             i = 0;

            foreach (ICapeParameter parameter in this.Parameters)
            {
                parameter.value = m_ParameterValues[i];
                parameter.Mode  = m_ParameterModes[i];
                i++;
            }
            object[] portConnections = (object[])info.GetValue("PortConnections", typeof(object[]));
            i = 0;
            foreach (ICapeUnitPort port in this.Ports)
            {
                if (portConnections[i] != null)
                {
                    this.Ports[i].Connect(portConnections[i]);
                }
                i++;
            }
        }
コード例 #7
0
        /// <summary>
        ///	Gets the specific item stored within the collection, identified by its
        /// ICapeIdentification.ComponentName or 1-based index passed as an argument
        /// to the method.
        /// </summary>
        /// <remarks>
        /// Return an element from the collection. The requested element can be
        /// identified by its actual name (e.g. type CapeString) or by its position
        /// in the collection (e.g. type CapeLong). The name of an element is the
        /// value returned by the ComponentName() method of its ICapeIdentification
        /// interface. The advantage of retrieving an item by name rather than by
        /// position is that it is much more efficient. This is because it is faster
        /// to check all names from the server part than checking then from the
        /// client, where a lot of COM/CORBA calls would be required.
        /// </remarks>
        /// <param name = "index">
        /// <para>Identifier for the requested item:</para>
        /// <para>name of item (the variant contains a string)</para>
        /// <para>position in collection (it contains a long)</para>
        /// </param>
        /// <returns>
        /// System.Object containing the requested collection item.
        /// </returns>
        /// <exception cref ="ECapeUnknown">The error to be raised when other error(s),  specified for this operation, are not suitable.</exception>
        /// <exception cref = "ECapeInvalidArgument">To be used when an invalid argument value is passed, for example, an unrecognised Compound identifier or UNDEFINED for the props argument.</exception>
        /// <exception cref = "ECapeFailedInitialisation">ECapeFailedInitialisation</exception>
        /// <exception cref = "ECapeOutOfBounds">ECapeOutOfBounds</exception>
        Object ICapeCollection.Item(Object index)
        {
            Type indexType = index.GetType();

            if ((indexType == typeof(System.Int16)) || (indexType == typeof(System.Int32)) || (indexType == typeof(System.Int64)))
            {
                int i = Convert.ToInt32(index);
                return(this.Items[i - 1]);
            }
            if ((indexType == typeof(String)))
            {
                String name = index.ToString();
                for (int i = 0; i < this.Items.Count; i++)
                {
                    ICapeIdentification p_Id = (ICapeIdentification)(this.Items[i]);
                    if (p_Id.ComponentName == name)
                    {
                        return(this.Items[i]);
                    }
                }
            }
            throw new CapeInvalidArgumentException("Item " + index.ToString() + " not found.", 0);
        }
コード例 #8
0
 /// <summary>
 /// whether CapeCollection contains this item
 /// </summary>
 public bool Contains(ICapeIdentification item)
 => _items.ContainsValue(item);
コード例 #9
0
ファイル: UnitSelector.cs プロジェクト: Chukanof/CapeOpen
        private void AddType(Type type, TreeNode node)
        {
            if (!type.IsAbstract)
            {
                if (typeof(CapeOpen.ICapeUnit).IsAssignableFrom(type))
                {
                    if (type.FullName != "CapeOpen.UnitOperationManager")
                    {
                        System.Reflection.Assembly assembly = type.Assembly;
                        String versionNumber           = (new System.Reflection.AssemblyName(assembly.FullName)).Version.ToString();
                        Object p_Unit                  = Activator.CreateInstance(type);
                        ICapeIdentification p_Id       = (ICapeIdentification)p_Unit;
                        System.Object[]     attributes = type.GetCustomAttributes(false);
                        String nameInfoString          = type.FullName;
                        String descriptionInfoString   = "";
                        String versionInfoString       = "";
                        String companyURLInfoString    = "";
                        String helpURLInfoString       = "";
                        String aboutInfoString         = "";
                        bool   consumesThermo          = false;
                        bool   thermo10                = false;
                        bool   thermo11                = false;
                        for (int i = 0; i < attributes.Length; i++)
                        {
                            if (attributes[i] is CapeConsumesThermoAttribute)
                            {
                                consumesThermo = true;
                            }
                            if (attributes[i] is CapeSupportsThermodynamics10Attribute)
                            {
                                thermo10 = true;
                            }
                            if (attributes[i] is CapeSupportsThermodynamics11Attribute)
                            {
                                thermo11 = true;
                            }
                            if (attributes[i] is CapeNameAttribute)
                            {
                                nameInfoString = ((CapeNameAttribute)attributes[i]).Name;
                            }
                            if (attributes[i] is CapeDescriptionAttribute)
                            {
                                descriptionInfoString = ((CapeDescriptionAttribute)attributes[i]).Description;
                            }
                            if (attributes[i] is CapeVersionAttribute)
                            {
                                versionInfoString = ((CapeVersionAttribute)attributes[i]).Version;
                            }
                            if (attributes[i] is CapeVendorURLAttribute)
                            {
                                companyURLInfoString = ((CapeVendorURLAttribute)attributes[i]).VendorURL;
                            }
                            if (attributes[i] is CapeHelpURLAttribute)
                            {
                                helpURLInfoString = ((CapeHelpURLAttribute)attributes[i]).HelpURL;
                            }
                            if (attributes[i] is CapeAboutAttribute)
                            {
                                aboutInfoString = ((CapeAboutAttribute)attributes[i]).About;
                            }
                        }

                        TreeNode newNode = new TreeNode(nameInfoString);
                        node.Nodes.Add(newNode);
                        newNode.Tag = type;
                        newNode.Nodes.Add(String.Concat("Description: ", descriptionInfoString));
                        newNode.Nodes.Add(String.Concat("CapeVersion: ", versionInfoString));
                        newNode.Nodes.Add(String.Concat("ComponentVersion: ", versionNumber));
                        newNode.Nodes.Add(String.Concat("VendorURL: ", companyURLInfoString));
                        newNode.Nodes.Add(String.Concat("HelpURL: ", helpURLInfoString));
                        newNode.Nodes.Add(String.Concat("About: ", aboutInfoString));
                        if (consumesThermo)
                        {
                            TreeNode thermoNode = new TreeNode("Supported Thermo Versions");
                            newNode.Nodes.Add(thermoNode);
                            if (thermo10)
                            {
                                thermoNode.Nodes.Add("Supports Thermo 1.0");
                            }
                            if (thermo11)
                            {
                                thermoNode.Nodes.Add("Supports Thermo 1.1");
                            }
                        }
                    }
                }
            }
        }