Exemplo n.º 1
0
 /// <summary>
 /// Occurs when the user connects a new object to the port.
 /// </summary>
 /// <remarks><para>Raising an event invokes the event handler through a delegate.</para>
 /// <para>The <c>OnPortConencted</c> method also allows derived classes to handle the event without attaching a delegate. This is the preferred
 /// technique for handling the event in a derived class.</para>
 /// <para>Notes to Inheritors: </para>
 /// <para>When overriding <c>OnPortConencted</c> in a derived class, be sure to call the base class's <c>OnPortConnected</c> method so that registered
 /// delegates receive the event.</para>
 /// </remarks>
 /// <param name = "args">A <see cref = "PortConnectedEventArgs">PortConnectedEventArgs</see> that contains information about the event.</param>
 protected void OnPortConnected(PortConnectedEventArgs args)
 {
     if (PortConnected != null)
     {
         PortConnected(this, args);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        ///	Connects an object to the port. For a material port it must
        /// be an object implementing the ICapeThermoMaterialObject interface,
        /// for Energy and Information ports it must be an object implementing
        /// the ICapeParameter interface.
        /// </summary>
        /// <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>
        virtual public void Connect(Object objectToConnect)
        {
            this.Disconnect(true);
            PortConnectedEventArgs args = new PortConnectedEventArgs(this.ComponentName);

            if (objectToConnect.GetType().IsCOMObject)
            {
                //If the port is a material port
                if (m_Type == CapePortType.CAPE_MATERIAL || m_Type == CapePortType.CAPE_ANY)
                {
                    // does the material object support both thermo 1.0 and 1.1?
                    if (objectToConnect is ICapeThermoMaterialObjectCOM && objectToConnect is ICapeThermoMaterialCOM)
                    {
                        //use the material wrapper that exposes both interfaces.
                        m_ConnectedNonSerializableObject = new MaterialObjectWrapper(objectToConnect);
                        m_ConnectedObject           = null;
                        isConnectObjectSerializable = false;
                        OnPortConnected(args);
                        NotifyPropertyChanged("connectedObject");
                        return;
                    }
                    // Does the material only support thermo 1.1?
                    else if (objectToConnect is ICapeThermoMaterialCOM)
                    {
                        //then only use the material wrapper that exposes thermo 1.1
                        m_ConnectedNonSerializableObject = new MaterialObjectWrapper11(objectToConnect);
                        m_ConnectedObject           = null;
                        isConnectObjectSerializable = false;
                        OnPortConnected(args);
                        NotifyPropertyChanged("connectedObject");
                        return;
                    }
                    //Does the thermo only support thermo 1.0?
                    else if (objectToConnect is ICapeThermoMaterialObjectCOM)
                    {
                        // then use the wrapper that supports thermo 1.0.
                        m_ConnectedNonSerializableObject = new MaterialObjectWrapper1(objectToConnect);
                        m_ConnectedObject           = null;
                        isConnectObjectSerializable = false;
                        OnPortConnected(args);
                        NotifyPropertyChanged("connectedObject");
                        return;
                    }
                    //If we get here, the object to connect is not a material.
                    //The object will be connected as-is.
                    m_ConnectedNonSerializableObject = objectToConnect;
                    m_ConnectedObject           = null;
                    isConnectObjectSerializable = false;
                    OnPortConnected(args);
                    NotifyPropertyChanged("connectedObject");
                    return;
                }
            }
            if (objectToConnect.GetType().IsSerializable)
            {
                m_ConnectedObject                = objectToConnect;
                isConnectObjectSerializable      = true;
                m_ConnectedNonSerializableObject = null;
                OnPortConnected(args);
                NotifyPropertyChanged("connectedObject");
                return;
            }
            m_ConnectedNonSerializableObject = objectToConnect;
            m_ConnectedObject           = null;
            isConnectObjectSerializable = false;
            OnPortConnected(args);
            NotifyPropertyChanged("connectedObject");
        }