Beispiel #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);
        }
Beispiel #2
0
        public void OneActiveOnePassiveInputDeterminesOneBufferedPassiveOutputTest()
        {
            PortManagementFacade pmf = Setup(out in0, out in1, out out0, out out1, out facadeIn0, out facadeIn1, out facadeOut0, out facadeOut1, out entryPoint0, out entryPoint1);

            // Active input. Writes to this port cause a value to be pushed out the output.
            facadeIn0.WriteAction           = InputPortManager.DataWriteAction.StoreAndInvalidate;
            facadeIn0.ReadSource            = InputPortManager.DataReadSource.BufferOrPull;
            facadeIn0.DataBufferPersistence = PortManager.BufferPersistence.UntilRead;
            facadeIn0.SetDependents(facadeOut0);

            // Passive input. We pull a value if none is present, and store it in a buffer that remains valid until overwritten.
            facadeIn1.WriteAction           = InputPortManager.DataWriteAction.StoreAndInvalidate;
            facadeIn1.ReadSource            = InputPortManager.DataReadSource.BufferOrPull;
            facadeIn1.DataBufferPersistence = PortManager.BufferPersistence.UntilWrite;
            facadeIn1.SetDependents(facadeOut0);

            // Pulls from the output cause the buffer value to be reused.
            facadeOut0.ComputeFunction       = new Action(() => { facadeOut0.Buffer = ((string)facadeIn0.Value) + ((string)facadeIn1.Value); });
            facadeOut0.DataBufferPersistence = PortManager.BufferPersistence.UntilWrite;

            entryPoint0.OwnerPut("PushData0");
            Console.WriteLine("With data0 not yet provided, and data1 not yet provided, " + out0.Take(null) + " taken.");
            Console.WriteLine("With data0 provided, and data1 not not yet provided, " + out0.Take(null) + " taken.");
            entryPoint0.OwnerPut("PushData1");
            entryPoint0.OwnerPut("PushData2");
            entryPoint1.OwnerPut("EntryPoint1(2)");
            Console.WriteLine(out0.Take(null) + " taken.");
        }
Beispiel #3
0
        public OnePullValue(IModel model, string name, string description, Guid guid)
        {
            m_output = new SimpleOutputPort(null, "Output", Guid.NewGuid(), this, null, null);

            PortManagementFacade pmf = new PortManagementFacade(this);

            m_opm = pmf.ManagerFor(m_output);

            m_opm.DataBufferPersistence = PortManager.BufferPersistence.UntilWrite; // Output value is reusable. We never use the compute function.
        }
Beispiel #4
0
        public void DoAbbreviatedFacadeTest()
        {
            PortManagementFacade pmf = Setup(out in0, out in1, out out0, out out1, out facadeIn0, out facadeIn1, out facadeOut0, out facadeOut1, out entryPoint0, out entryPoint1);

            facadeOut0.ComputeFunction = new Action(() => { facadeOut0.Buffer = facadeIn0.Value.ToString() + " " + facadeIn1.Value.ToString(); });
            facadeOut1.ComputeFunction = new Action(() => { facadeOut1.Buffer = facadeIn1.Value.ToString() + " " + facadeIn0.Value.ToString(); });

            Console.WriteLine(out0.Take(null) + " taken.");
            Console.WriteLine(out0.Take(null) + " taken.");
            Console.WriteLine(out1.Take(null) + " taken.");
            Console.WriteLine(out1.Take(null) + " taken.");
        }
Beispiel #5
0
        public void DoAbbreviatedSimplePullTest()
        {
            PortManagementFacade pmf = Setup(out in0, out in1, out out0, out out1, out facadeIn0, out facadeIn1, out facadeOut0, out facadeOut1, out entryPoint0, out entryPoint1);

            facadeIn0.WriteAction           = InputPortManager.DataWriteAction.StoreAndInvalidate;
            facadeIn0.ReadSource            = InputPortManager.DataReadSource.BufferOrPull;
            facadeIn0.DataBufferPersistence = PortManager.BufferPersistence.UntilRead;
            facadeIn0.SetDependents(facadeOut0);

            facadeOut0.ComputeFunction       = new Action(() => { facadeOut0.Buffer = facadeIn0.Value; });
            facadeOut0.DataBufferPersistence = PortManager.BufferPersistence.UntilRead;

            Console.WriteLine(out0.Take(null) + " taken.");
            Console.WriteLine(out0.Take(null) + " taken.");
        }
Beispiel #6
0
        public void DoAbbreviatedSimplePushTest()
        {
            PortManagementFacade pmf = Setup(out in0, out in1, out out0, out out1, out facadeIn0, out facadeIn1, out facadeOut0, out facadeOut1, out entryPoint0, out entryPoint1);

            facadeIn0.WriteAction = InputPortManager.DataWriteAction.Push;
            facadeIn0.ReadSource  = InputPortManager.DataReadSource.BufferOrPull;

            facadeOut0.ComputeFunction = new Action(() => { facadeOut0.Buffer = facadeIn0.Value; });
            facadeIn0.SetDependents(facadeOut0);

            entryPoint0.OwnerPut("Data0");
            entryPoint0.OwnerPut("Data1");
            //Console.WriteLine(out0.Take(null) + " taken.");
            //Console.WriteLine(out0.Take(null) + " taken.");
            //Console.WriteLine(out1.Take(null) + " taken.");
            //Console.WriteLine(out1.Take(null) + " taken.");
        }
Beispiel #7
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.
        }
Beispiel #8
0
        public void DoAbbreviatedOutputSideBufferedPullTest()
        {
            // Put a value into the input. Read the output several times. Replace the input, read the output twice more.

            PortManagementFacade pmf = Setup(out in0, out in1, out out0, out out1, out facadeIn0, out facadeIn1, out facadeOut0, out facadeOut1, out entryPoint0, out entryPoint1);

            facadeIn0.WriteAction           = InputPortManager.DataWriteAction.StoreAndInvalidate;
            facadeIn0.ReadSource            = InputPortManager.DataReadSource.Buffer;
            facadeIn0.DataBufferPersistence = PortManager.BufferPersistence.None;
            facadeIn0.SetDependents(facadeOut0);

            facadeOut0.ComputeFunction       = new Action(() => { facadeOut0.Buffer = facadeIn0.Value; });
            facadeOut0.DataBufferPersistence = PortManager.BufferPersistence.UntilWrite;

            entryPoint0.OwnerPut("PushData0");
            Console.WriteLine(out0.Take(null) + " taken.");
            Console.WriteLine(out0.Take(null) + " taken.");
            entryPoint0.OwnerPut("PushData1");
            Console.WriteLine(out0.Take(null) + " taken.");
            //Console.WriteLine(out1.Take(null) + " taken.");
            //Console.WriteLine(out1.Take(null) + " taken.");
        }