Пример #1
0
        private PortManagementFacade Setup(out IInputPort in0, out IInputPort in1, out IOutputPort out0, out IOutputPort out1, out InputPortManager facadeIn0, out InputPortManager facadeIn1, out OutputPortManager facadeOut0, out OutputPortManager facadeOut1, out SimpleOutputPort entryPoint0, out SimpleOutputPort entryPoint1)
        {
            ManagementFacadeBlock mfb = new ManagementFacadeBlock();

            out0 = new SimpleOutputPort(null, "Out0", Guid.NewGuid(), mfb, null, null);
            out1 = new SimpleOutputPort(null, "Out1", Guid.NewGuid(), mfb, null, null);
            in0  = new SimpleInputPort(null, "In0", Guid.NewGuid(), mfb, null);
            in1  = new SimpleInputPort(null, "In1", Guid.NewGuid(), mfb, null);

            int i0 = 0;

            entryPoint0 = new SimpleOutputPort(null, "", Guid.NewGuid(), null, delegate(IOutputPort iop, object selector) { return(string.Format("Src0 ({0})", i0++)); }, null);
            ConnectorFactory.Connect(entryPoint0, in0);

            int i1 = 0;

            entryPoint1 = new SimpleOutputPort(null, "", Guid.NewGuid(), null, delegate(IOutputPort iop, object selector) { return(string.Format("Src1 ({0})", i1++)); }, null);
            ConnectorFactory.Connect(entryPoint1, in1);

            out0.PortDataPresented += new PortDataEvent(delegate(object data, IPort where) { Console.WriteLine(string.Format("{0} presented at {1}.", data.ToString(), where.Name)); });
            out1.PortDataPresented += new PortDataEvent(delegate(object data, IPort where) { Console.WriteLine(string.Format("{0} presented at {1}.", data.ToString(), where.Name)); });

            PortManagementFacade pmf = new PortManagementFacade(mfb);

            facadeIn0  = pmf.ManagerFor(in0);
            facadeIn1  = pmf.ManagerFor(in1);
            facadeOut0 = pmf.ManagerFor(out0);
            facadeOut1 = pmf.ManagerFor(out1);

            return(pmf);
        }
Пример #2
0
        public ItemSink(IModel model, string name, Guid guid)
        {
            InitializeIdentity(model, name, null, guid);

            m_input = new SimpleInputPort(model, "Input", Guid.NewGuid(), this, new DataArrivalHandler(CanAcceptPushedData));
            m_ports.AddPort(m_input);
            Input = m_input;
            m_input.PortDataAccepted += new PortDataEvent(m_input_PortDataAccepted);

            IMOHelper.RegisterWithModel(this);
        }
Пример #3
0
 /// <summary>
 /// Creates a channel for which the transit rate is fixed, and which can hold a specified
 /// capacity of payload.
 /// </summary>
 /// <param name="model">The model in which this FixedRateChannel exists.</param>
 /// <param name="name">The name of this FixedRateChannel.</param>
 /// <param name="guid">The GUID of this FixedRateChannel.</param>
 /// <param name="exec">The executive that controls this channel.</param>
 /// <param name="transitPeriod">How long it takes an object to transit the channel.</param>
 /// <param name="capacity">How many objects the channel can hold.</param>
 public FixedRateChannel(IModel model, string name, Guid guid, IExecutive exec, TimeSpan transitPeriod, double capacity)
 {
     m_exec          = exec;
     m_transitPeriod = transitPeriod;
     m_capacity      = capacity;
     m_entryPeriod   = TimeSpan.FromTicks((long)((double)m_transitPeriod.Ticks / m_capacity));
     m_queue         = new Queue();
     m_entry         = new SimpleInputPort(model, "Entry", Guid.NewGuid(), this, new DataArrivalHandler(OnEntryAttempted));
     m_exit          = new SimpleOutputPort(model, "Exit", Guid.NewGuid(), this, new DataProvisionHandler(CantTakeFromChannel), new DataProvisionHandler(CantPeekFromChannel));
     //m_ports.AddPort(m_entry); <-- Done in port's ctor.
     //m_ports.AddPort(m_exit); <-- Done in port's ctor.
     m_dequeueEventHandler = new ExecEventReceiver(DequeueEventHandler);
 }
Пример #4
0
        public MultiQueueHead(IModel model, string name, Guid guid, ArrayList queues, ISelectionStrategy selStrategy)          // TODO: Want to add/remove queues eventually, and use an IQueueSelectionStrategy.
        {
            m_selStrategy          = selStrategy;
            selStrategy.Candidates = queues;

            m_input = new SimpleInputPort(model, name, guid, this, new DataArrivalHandler(OnDataPushIn));

            Outputs = new IOutputPort[queues.Count];
            for (int i = 0; i < Outputs.GetLength(0); i++)
            {
                string portName = name + "#" + i;
                Outputs[i] = new SimpleOutputPort(model, portName, Guid.NewGuid(), this, new DataProvisionHandler(OnDataPullOut), null);
                ConnectorFactory.Connect(Outputs[i], ((Queue)queues[i]).Input);
            }
        }
Пример #5
0
        public SimpleServer(IModel model, string name, Guid guid, IPeriodicity periodicity)
        {
            InitializeIdentity(model, name, null, guid);

            m_input  = new SimpleInputPort(model, "Input", Guid.NewGuid(), this, new DataArrivalHandler(AcceptServiceObject));
            m_output = new SimpleOutputPort(model, "Output", Guid.NewGuid(), this, null, null);
            // AddPort(m_input); <-- Done in port's ctor.
            // AddPort(m_output); <-- Done in port's ctor.
            m_periodicity          = periodicity;
            m_input.DataAvailable += new PortEvent(OnServiceObjectAvailable);
            string sso = m_model.ModelConfig.GetSimpleParameter("SupportsServerObjects");

            m_supportsServerObjects = (sso == null)?false:bool.Parse(sso);

            IMOHelper.RegisterWithModel(this);
        }
Пример #6
0
 public Splitter(IModel model, string name, Guid guid, int nOuts)
 {
     IMOHelper.Initialize(ref m_model, model, ref m_name, name, ref m_description, null, ref m_guid, guid);
     m_ports = new PortSet();
     m_input = new SimpleInputPort(model, "Input", Guid.NewGuid(), this, GetDataArrivalHandler());
     //AddPort(m_input); <-- Done in SIP's ctor.
     Input     = m_input;
     Outputs   = new IOutputPort[nOuts];
     m_outputs = new SimpleOutputPort[nOuts];
     for (int i = 0; i < nOuts; i++)
     {
         m_outputs[i] = new SimpleOutputPort(model, "Output" + i, Guid.NewGuid(), this, GetDataProvisionHandler(i), GetPeekHandler(i));
         Outputs[i]   = m_outputs[i];
         //AddPort(m_outputs[i]); <-- Done in SOP's ctor.
     }
     IMOHelper.RegisterWithModel(this);
 }
Пример #7
0
        private MultiChannelDelayServer(IModel model, string name, Guid guid)
        {
            InitializeIdentity(model, name, null, guid);

            m_entryPort = new SimpleInputPort(model, "Input", Guid.NewGuid(), this, new DataArrivalHandler(OnDataArrived));
            m_exitPort  = new SimpleOutputPort(model, "Output", Guid.NewGuid(), this, null, null); // No take, no peek.

            // AddPort(m_entryPort); <-- Done in port's ctor.
            // AddPort(m_exitPort); <-- Done in port's ctor.

            m_releaseObject = new ExecEventReceiver(ReleaseObject);

            m_inService = new ArrayList();
            m_pending   = 0;

            IMOHelper.RegisterWithModel(this);
        }
Пример #8
0
        /// <summary>
        /// First-round follow-on to the <see cref="Initialize"/> call.
        /// </summary>
        /// <param name="model">The model in which this queue exists.</param>
        /// <param name="p">The array of passed-in arguments.</param>
        public void _Initialize(IModel model, object[] p)
        {
            Guid inGuid  = Utility.GuidOps.Increment(Guid);
            Guid outGuid = Utility.GuidOps.Increment(inGuid);

            m_output = new SimpleOutputPort(model, "Output", outGuid, this, new DataProvisionHandler(ProvideData), new DataProvisionHandler(PeekData));
            m_output.PortDataAccepted += new PortDataEvent(OnOutputPortDataAccepted);
            m_input = new SimpleInputPort(model, "Input", inGuid, this, new DataArrivalHandler(OnDataArrived));

            //Ports.AddPort(m_output); <-- Done in port's ctor.
            //Ports.AddPort(m_input);  <-- Done in port's ctor.

            LevelChangedEvent += new QueueLevelChangeEvent(OnQueueLevelChanged);

            m_max   = (int)p[0];
            m_queue = new System.Collections.Queue(m_max);
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Queue"/> class.
        /// </summary>
        /// <param name="model">The model in which this queue exists.</param>
        /// <param name="name">The name of this queue.</param>
        /// <param name="guid">The GUID of this queue.</param>
        /// <param name="max">The maximum number of items that can be held in this queue.</param>
        public Queue(IModel model, string name, Guid guid, int max)
        {
            InitializeIdentity(model, name, "", guid);
            m_max = max;

            m_queue = new System.Collections.Queue();

            Guid inGuid  = Utility.GuidOps.Increment(guid);
            Guid outGuid = Utility.GuidOps.Increment(inGuid);

            m_output = new SimpleOutputPort(model, "Output", outGuid, this, new DataProvisionHandler(ProvideData), new DataProvisionHandler(PeekData));
            m_output.PortDataAccepted += new PortDataEvent(OnOutputPortDataAccepted);
            m_input = new SimpleInputPort(model, "Input", inGuid, this, new DataArrivalHandler(OnDataArrived));

            LevelChangedEvent += new QueueLevelChangeEvent(OnQueueLevelChanged);

            IMOHelper.RegisterWithModel(this);
        }
Пример #10
0
        public Joiner(IModel model, string name, Guid guid, int nIns)
        {
            InitializeIdentity(model, name, null, guid);

            m_ports = new PortSet();

            m_output = new SimpleOutputPort(model, "Output", Guid.NewGuid(), this, GetTakeHandler(), GetPeekHandler());
            // AddPort(m_output); <-- Done in SOP's ctor.

            m_inputs = new SimpleInputPort[nIns];
            for (int i = 0; i < nIns; i++)
            {
                m_inputs[i] = new SimpleInputPort(model, "Input" + i, Guid.NewGuid(), this, GetDataArrivalHandler(i));
                Inputs[i]   = m_inputs[i];
                // AddPort(m_inputs[i]); <-- Done in SOP's ctor.
            }

            IMOHelper.RegisterWithModel(this);
        }
Пример #11
0
            public TestClient(IModel model, MaterialService source, MaterialService sink, MaterialType getThis, double getHowMuch, MaterialType sendThat, double sendHowMuch)
            {
                m_portSet = new PortSet();

                m_input      = new SimpleInputPort(source.Model, "In", Guid.NewGuid(), this, null);
                Input        = m_input;
                m_source     = source;
                m_getThis    = getThis;
                m_getHowMuch = getHowMuch;

                m_output      = new SimpleOutputPort(source.Model, "Out", Guid.NewGuid(), this, null, null);
                Output        = m_output;
                m_sink        = sink;
                m_sendThat    = sendThat;
                m_sendHowMuch = sendHowMuch;

                m_model   = model;
                m_mixture = new Mixture(model, "Test client's mixture");
            }
Пример #12
0
        /// <summary>
        /// Creates a new instance of the <see cref="T:ServerPlus"/> class.
        /// </summary>
        /// <param name="model">The model in which this object runs.</param>
        /// <param name="name">The user-friendly name of this object. Typically not required to be unique in a pan-model context.</param>
        /// <param name="guid">The GUID of this object. Typically registered as this object's ModelObject key, and thus, required to be unique in a pan-model context.</param>
        /// <param name="periodicity">The periodicity.</param>
        public ServerPlus(IModel model, string name, Guid guid, IPeriodicity periodicity)
        {
            InitializeIdentity(model, name, null, guid);

            m_input  = new SimpleInputPort(model, "Input", Guid.NewGuid(), this, new DataArrivalHandler(AcceptServiceObject));
            m_output = new SimpleOutputPort(model, "Output", Guid.NewGuid(), this, null, null);

            m_periodicity = periodicity;

            string sso = m_model.ModelConfig.GetSimpleParameter("SupportsServerObjects");

            m_supportsServerObjects = (sso == null)?false:bool.Parse(sso);

            OnCanWeProcessServiceObject = new ServiceRequestEvent(CanWeProcessServiceObjectHandler);
            OnPreCommencementSetup      = new ServiceEvent(PreCommencementSetupHandler);
            OnPreCompletionTeardown     = new ServiceEvent(PreCompletionTeardownHandler);

            IMOHelper.RegisterWithModel(this);
        }
Пример #13
0
        public OneInOneOutPushPullTransform(IModel model, string name, string description, Guid guid)
        {
            m_output = new SimpleOutputPort(null, "Output", Guid.NewGuid(), this, null, null);
            m_input  = new SimpleInputPort(null, "Input", Guid.NewGuid(), this, null);

            m_input.PortDataPresented += new PortDataEvent(delegate(object data, IPort where) { Console.WriteLine(data.ToString() + " presented to " + where.Name); });

            PortManagementFacade pmf = new PortManagementFacade(this);

            m_ipm = pmf.ManagerFor(m_input);
            m_opm = pmf.ManagerFor(m_output);

            m_ipm.WriteAction           = InputPortManager.DataWriteAction.Push;   // When a value is written into the input buffer, we push the resultant transform out the output port.
            m_ipm.DataBufferPersistence = InputPortManager.BufferPersistence.None; // The input buffer is re-read with every pull.
            m_ipm.ReadSource            = InputPortManager.DataReadSource.Pull;    // We'll always pull a new value.
            m_ipm.SetDependents(m_opm);                                            // A new value written to ipm impacts opm.

            m_opm.ComputeFunction       = new Action(ComputeFuction);
            m_opm.DataBufferPersistence = PortManager.BufferPersistence.None; // Output value is always recomputed.
        }
Пример #14
0
        /// <summary>
        /// Connects the Nexus to the specified port If the specified port is an input port, creates an output port
        /// on the nexus and adds a connector to the specified port from that output port. The relationship does not
        /// allow taking or peeking from the nexus.
        /// </summary>
        /// <param name="port">The port.</param>
        public void Bind(IPort port)
        {
            IPort myNewPort = null;

            if (port is IInputPort)
            {
                myNewPort = new SimpleOutputPort(m_model, "Output" + (m_outCount++), Guid.NewGuid(), this, m_cantTakeOrPeekFromNexus, m_cantTakeOrPeekFromNexus);
            }
            else if (port is IOutputPort)
            {
                myNewPort = new SimpleInputPort(m_model, "Input" + (m_inCount++), Guid.NewGuid(), this, m_canAlwaysAcceptData);
                myNewPort.PortDataAccepted += new PortDataEvent(OnPortDataAccepted);
            }
            else
            {
                throw new ApplicationException("Unknown port type " + port.GetType().Name + " encountered.");
            }
            // m_ports.AddPort(myNewPort); <-- Done in port's ctor.
            ConnectorFactory.Connect(port, myNewPort);
        }
Пример #15
0
 public SimplePassThroughPortOwner(IModel model, string name, Guid guid)
 {
     m_name = name;
     m_in   = new SimpleInputPort(model, "In", Guid.NewGuid(), this, new DataArrivalHandler(OnDataArrived));
     m_out  = new SimpleOutputPort(model, "Out", Guid.NewGuid(), this, new DataProvisionHandler(OnDataRequested), null);
 }