Ejemplo n.º 1
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.
        }
Ejemplo n.º 2
0
        public void TestOneInOneOutPushPullTransform()
        {
            DLog dlog = new DLog(null, null, null, Guid.NewGuid());

            double i1 = 0.1;

            entryPoint1 = new SimpleOutputPort(null, "", Guid.NewGuid(), null, delegate(IOutputPort iop, object selector) { return(i1++); }, null);
            ConnectorFactory.Connect(entryPoint1, dlog.Ports.Inputs[0]);

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


            Console.WriteLine(String.Format("Pushing {0}", i1)); entryPoint1.OwnerPut(i1++);
            Console.WriteLine(String.Format("Pushing {0}", i1)); entryPoint1.OwnerPut(i1++);


            Console.WriteLine(dlog.Ports.Outputs[0].Take(null));
            Console.WriteLine(dlog.Ports.Outputs[0].Take(null));
            Console.WriteLine(dlog.Ports.Outputs[0].Take(null));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ItemSource"/> 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="objectSource">The object source.</param>
        /// <param name="pulseSource">The pulse source.</param>
        /// <param name="persistentOutput">If true, then the most recent output value will be returned on any peek or pull.</param>
        public ItemSource(IModel model, string name, Guid guid, ObjectSource objectSource, IPulseSource pulseSource, bool persistentOutput = false)
        {
            InitializeIdentity(model, name, null, guid);

            if (persistentOutput)
            {
                m_output = new SimpleOutputPort(model, "Source", Guid.NewGuid(), this, new DataProvisionHandler(PersistentOutput), new DataProvisionHandler(PersistentOutput));
            }
            else
            {
                m_output = new SimpleOutputPort(model, "Source", Guid.NewGuid(), this, new DataProvisionHandler(VolatileOutput), new DataProvisionHandler(VolatileOutput));
            }
            // m_ports.AddPort(m_output); <-- Done in port's ctor.
            m_objectSource          = objectSource;
            m_pulseSource           = pulseSource;
            pulseSource.PulseEvent += new PulseEvent(OnPulse);

            IMOHelper.RegisterWithModel(this);

            model.Starting += new ModelEvent(delegate(IModel theModel) { m_latestEmission = null; });
        }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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);
        }