コード例 #1
0
        /// <summary>
        /// Tells the AMFProcessor to immediately begin processing the AMF request on the input
        /// stream and to format the response on the output stream.  During this method execution, the
        /// AMFProcessor will raise the Command event and give your code a chance to set the Response
        /// property for the request(s).  If you do not send the outputStream to this call, you can
        /// have the results rendered later by calling RenderResponse.
        ///
        /// If you are using the AMFProcessor for Http processing, you should call ProcessHttpRequest
        /// instead of this method and let the processor take care of the stream handling for you.
        /// </summary>
        /// <param name="inputStream"></param>
        /// <param name="outputStream"></param>
        public void ProcessRequest(Stream inputStream, Stream outputStream)
        {
            //read the incoming
            AMFReader reader = new AMFReader(inputStream);

            _envelope = reader.ReadRequest();

            //for each body that we have, prepare a response
            for (int i = 0; i < _envelope.Bodies.Count; i++)
            {
                AMFBody          body        = _envelope.Bodies[i];
                AMFClientRequest flexRequest = new AMFClientRequest();
                flexRequest.Command    = body.Target;
                flexRequest.Id         = body.ResponseId;
                flexRequest.Parameters = body.Value;
                flexRequest.Headers    = _envelope.Headers;

                if (Command != null)
                {
                    Command(flexRequest);
                }

                _clientRequests.Add(flexRequest);
            }

            //now render the result
            if (outputStream != null)
            {
                RenderResponse(outputStream);
            }
        }
コード例 #2
0
        private void ProcessBodies(ushort bodyCount)
        {
            for (int i = 0; i < bodyCount; i++)
            {
                _references = new Dictionary <int, AMFData>();
                AMFBody body = new AMFBody();
                body.Target     = ReadUTF();
                body.ResponseId = ReadUTF();

                uint bodyLength = ReadUInt32();

                body.Value = ReadAMFData();

                _envelope.Bodies.Add(body);
            }
        }
コード例 #3
0
        /// <summary>
        /// Call this method to tell the AMFProcessor you are done processing the
        /// client requests and ready for it to write the results to the output
        /// stream.  Only call this method if you did not send an output stream
        /// to the ProcessRequest method (normally used in an asynchronous situation)
        /// </summary>
        /// <param name="outputStream"></param>
        public void RenderResponse(Stream outputStream)
        {
            for (int i = 0; i < _envelope.Bodies.Count; i++)
            {
                AMFClientRequest flexRequest = _clientRequests[i];
                AMFBody          body        = _envelope.Bodies[i];

                //set the responses
                if (flexRequest.Response != null)
                {
                    body.ReturnValue = flexRequest.Response;
                }
            }

            AMFWriter writer = new AMFWriter(outputStream, _envelope);

            writer.WriteResponse();
        }