public void ProcessModules(object objState)
        {
            //A loop is carried out where messages are de-queued one by one
            //and is submitted first to serializer component.
            //Serializer component converts the message into raw bytes and
            //it is made available as part of return argument of Process.
            //The returned information then becomes part of contextual information
            //and is assigned to Data property which is then passed to Transport
            //component.Also after processing all messages inside the store the state
            //of store is reset to idle state.
            IMessageStore store = objState as IMessageStore;

            if (store.Count > 0)
            {
                Console.WriteLine("Dispatching Store : " + store.Name);
            }
            while (store.Count > 0)
            {
                PipeContext pipeCtx = new PipeContext(store);
                pipeCtx.Message = store.DeQueue();
                for (int ctr = 0; ctr < moduleChain.Count; ctr++)
                {
                    IModule module  = moduleChain[ctr] as IModule;
                    object  ctxData = module.Process(pipeCtx);
                    pipeCtx.Data = ctxData;
                }
            }
            store.State = StoreState.Idle;
        }
        public object Process(PipeContext pipeCtx)
        {
            //data is broad-casted after it is received
            //from serializer module
            DataSerializerContext szCtx = pipeCtx.Data as DataSerializerContext;

            serverSocket.BeginSendTo(szCtx.Data, 0, szCtx.Data.Length, SocketFlags.None, mcastEP,
                                     new AsyncCallback(SendData), null);
            return(null);
        }
Esempio n. 3
0
        public object Process(PipeContext pipeCtx)
        {
            //Receive the strongly typed broadcast message
            IBCastMessage msg = pipeCtx.Message;
            //Calculate the object size
            int objectSize = Marshal.SizeOf(msg);

            //Assign the lenght of message
            msg.MessageLength = objectSize;
            //convert the managed object into array of bytes
            IntPtr memBuffer = Marshal.AllocHGlobal(objectSize);

            Marshal.StructureToPtr(msg, memBuffer, false);
            byte[] byteArray = new byte[objectSize];
            Marshal.Copy(memBuffer, byteArray, 0, objectSize);
            Marshal.FreeHGlobal(memBuffer);
            //Return the byte array that will then be
            //used by transport module to deliver to its destination
            return(new DataSerializerContext(byteArray));
        }