Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the ErrorResponseBody class.
 /// </summary>
 /// <param name="requestBody"></param>
 /// <param name="message"></param>
 /// <param name="errorMessage"></param>
 public ErrorResponseBody(AMFBody requestBody, IMessage message, ErrorMessage errorMessage) : base(requestBody)
 {
     this.Content       = errorMessage;
     this.Target        = requestBody.Response + AMFBody.OnStatus;
     this.IgnoreResults = requestBody.IgnoreResults;
     this.Response      = "";
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the ErrorResponseBody class.
 /// </summary>
 /// <param name="requestBody"></param>
 /// <param name="error"></param>
 public ErrorResponseBody(AMFBody requestBody, string error) : base(requestBody)
 {
     this.IgnoreResults = requestBody.IgnoreResults;
     this.Target        = requestBody.Response + AMFBody.OnStatus;
     this.Response      = null;
     this.Content       = error;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the ErrorResponseBody class.
        /// </summary>
        /// <param name="requestBody"></param>
        /// <param name="message"></param>
        /// <param name="exception"></param>
        public ErrorResponseBody(AMFBody requestBody, IMessage message, Exception exception) : base(requestBody)
        {
            ErrorMessage errorMessage = ErrorMessage.GetErrorMessage(message, exception);

            this.Content       = errorMessage;
            this.Target        = requestBody.Response + AMFBody.OnStatus;
            this.IgnoreResults = requestBody.IgnoreResults;
            this.Response      = "";
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the ErrorResponseBody class.
 /// </summary>
 /// <param name="requestBody"></param>
 /// <param name="exception"></param>
 public ErrorResponseBody(AMFBody requestBody, Exception exception) : base(requestBody)
 {
     this.Content = exception;
     if (requestBody.IsEmptyTarget)
     {
         object content = requestBody.Content;
         if (content is IList)
         {
             content = (content as IList)[0];
         }
         IMessage message = content as IMessage;
         //Check for Flex2 messages and handle
         if (message != null)
         {
             ErrorMessage errorMessage = ErrorMessage.GetErrorMessage(message, exception);
             this.Content = errorMessage;
         }
     }
     this.IgnoreResults = requestBody.IgnoreResults;
     this.Target        = requestBody.Response + AMFBody.OnStatus;
     this.Response      = null;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Adds a body to the AMF packet.
 /// </summary>
 /// <param name="body">The body object to add.</param>
 public void AddBody(AMFBody body)
 {
     this._bodies.Add(body);
 }
Exemplo n.º 6
0
        private AMFBody ReadBody()
        {
            this.Reset();
            string target = base.ReadString();

            // Response that the client understands.
            string response = base.ReadString();
            int    length   = base.ReadInt32();

            if (base.BaseStream.CanSeek)
            {
                long position = base.BaseStream.Position;
                // Read content.
                try
                {
                    object    content   = base.ReadData();
                    AMFBody   amfBody   = new AMFBody(target, response, content);
                    Exception exception = this.LastError;
                    if (exception != null)
                    {
                        ErrorResponseBody errorResponseBody = GetErrorBody(amfBody, exception);
                        _failedAMFBodies.Add(errorResponseBody);
                        return(null);
                    }
                    return(amfBody);
                }
                catch (Exception exception)
                {
                    base.BaseStream.Position = position + length;
                    //Try to build a valid response from partialy deserialized amf body
                    AMFBody           amfBody           = new AMFBody(target, response, null);
                    ErrorResponseBody errorResponseBody = GetErrorBody(amfBody, exception);
                    _failedAMFBodies.Add(errorResponseBody);
                    return(null);
                }
            }
            else
            {
                try
                {
                    object    content   = base.ReadData();
                    AMFBody   amfBody   = new AMFBody(target, response, content);
                    Exception exception = this.LastError;
                    if (exception != null)
                    {
                        ErrorResponseBody errorResponseBody = GetErrorBody(amfBody, exception);
                        _failedAMFBodies.Add(errorResponseBody);
                        return(null);
                    }
                    return(amfBody);
                }
                catch (Exception exception)
                {
                    //Try to build a valid response from partialy deserialized amf body
                    AMFBody           amfBody           = new AMFBody(target, response, null);
                    ErrorResponseBody errorResponseBody = GetErrorBody(amfBody, exception);
                    _failedAMFBodies.Add(errorResponseBody);
                    throw;
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the ResponseBody class.
 /// </summary>
 /// <param name="requestBody"></param>
 public ResponseBody(AMFBody requestBody)
 {
     _requestBody = requestBody;
 }
Exemplo n.º 8
0
        /// <summary>
        /// This method supports the AMFCore infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="amfMessage"></param>

        public void WriteMessage(AMFMessage amfMessage)
        {
            try
            {
                base.WriteShort(amfMessage.Version);
                int headerCount = amfMessage.HeaderCount;
                base.WriteShort(headerCount);
                for (int i = 0; i < headerCount; i++)
                {
                    this.WriteHeader(amfMessage.GetHeaderAt(i), ObjectEncoding.AMF0);
                }
                int bodyCount = amfMessage.BodyCount;
                base.WriteShort(bodyCount);
                for (int i = 0; i < bodyCount; i++)
                {
                    ResponseBody responseBody = amfMessage.GetBodyAt(i) as ResponseBody;
                    if (responseBody != null && !responseBody.IgnoreResults)
                    {
                        //Try to catch serialization errors
                        if (this.BaseStream.CanSeek)
                        {
                            long position = this.BaseStream.Position;

                            try
                            {
                                responseBody.WriteBody(amfMessage.ObjectEncoding, this);
                            }
                            catch (Exception exception)
                            {
                                this.BaseStream.Seek(position, SeekOrigin.Begin);

                                ErrorResponseBody errorResponseBody;
                                if (responseBody.RequestBody.IsEmptyTarget)
                                {
                                    object content = responseBody.RequestBody.Content;
                                    if (content is IList)
                                    {
                                        content = (content as IList)[0];
                                    }
                                    IMessage         message          = content as IMessage;
                                    MessageException messageException = new MessageException(exception);
                                    messageException.FaultCode = __Res.GetString(__Res.Amf_SerializationFail);
                                    errorResponseBody          = new ErrorResponseBody(responseBody.RequestBody, message, messageException);
                                }
                                else
                                {
                                    errorResponseBody = new ErrorResponseBody(responseBody.RequestBody, exception);
                                }

                                try
                                {
                                    errorResponseBody.WriteBody(amfMessage.ObjectEncoding, this);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            responseBody.WriteBody(amfMessage.ObjectEncoding, this);
                        }
                    }
                    else
                    {
                        AMFBody amfBody = amfMessage.GetBodyAt(i);
                        SolidSoft.AMFCore.Util.ValidationUtils.ObjectNotNull(amfBody, "amfBody");
                        amfBody.WriteBody(amfMessage.ObjectEncoding, this);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }