Пример #1
0
 /// <summary>
 /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="amfMessage"></param>
 public void WriteMessage(AMFMessage amfMessage)
 {
     try {
         WriteShort(amfMessage.Version);
         var headerCount = amfMessage.HeaderCount;
         WriteShort(headerCount);
         for (var i = 0; i < headerCount; i++)
         {
             WriteHeader(amfMessage.GetHeaderAt(i), ObjectEncoding.AMF0);
         }
         var bodyCount = amfMessage.BodyCount;
         WriteShort(bodyCount);
         for (var i = 0; i < bodyCount; i++)
         {
             var responseBody = amfMessage.GetBodyAt(i) as ResponseBody;
             if (responseBody != null && !responseBody.IgnoreResults)
             {
                 responseBody.WriteBody(amfMessage.ObjectEncoding, this);
             }
             else
             {
                 var amfBody = amfMessage.GetBodyAt(i);
                 ValidationUtils.ObjectNotNull(amfBody, "amfBody");
                 amfBody.WriteBody(amfMessage.ObjectEncoding, this);
             }
         }
     } catch (Exception exception) {
         if (Log.IsFatalEnabled)
         {
             Log.Fatal(String.Format(Resources.Amf_SerializationFail), exception);
         }
         throw;
     }
 }
Пример #2
0
        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);
                                //this.BaseStream.Position = position;

#if !SILVERLIGHT
                                if (log.IsFatalEnabled)
                                {
                                    log.Fatal(__Res.GetString(__Res.Amf_SerializationFail), exception);
                                }
#endif

                                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);
                                }
#if !SILVERLIGHT
                                catch (Exception exception2)
                                {
                                    if (log.IsFatalEnabled)
                                    {
                                        log.Fatal(__Res.GetString(__Res.Amf_ResponseFail), exception2);
                                    }
                                    throw;
                                }
#else
                                catch (Exception)
                                {
                                    throw;
                                }
#endif
                            }
                        }
                        else
                        {
                            responseBody.WriteBody(amfMessage.ObjectEncoding, this);
                        }
                    }
                    else
                    {
                        AMFBody amfBody = amfMessage.GetBodyAt(i);
                        FluorineFx.Util.ValidationUtils.ObjectNotNull(amfBody, "amfBody");
                        amfBody.WriteBody(amfMessage.ObjectEncoding, this);
                    }
                }
            }
#if !SILVERLIGHT
            catch (Exception exception)
            {
                if (log.IsFatalEnabled)
                {
                    log.Fatal(__Res.GetString(__Res.Amf_SerializationFail), exception);
                }
                throw;
            }
#else
            catch (Exception)
            {
                throw;
            }
#endif
        }
Пример #3
0
        public void WriteMessage(AMFMessage amfMessage)
        {
            Exception exception;

            try
            {
                int num2;
                base.WriteShort(amfMessage.Version);
                int headerCount = amfMessage.HeaderCount;
                base.WriteShort(headerCount);
                for (num2 = 0; num2 < headerCount; num2++)
                {
                    this.WriteHeader(amfMessage.GetHeaderAt(num2), ObjectEncoding.AMF0);
                }
                int bodyCount = amfMessage.BodyCount;
                base.WriteShort(bodyCount);
                for (num2 = 0; num2 < bodyCount; num2++)
                {
                    ResponseBody bodyAt = amfMessage.GetBodyAt(num2) as ResponseBody;
                    if ((bodyAt != null) && !bodyAt.IgnoreResults)
                    {
                        if (this.BaseStream.CanSeek)
                        {
                            long position = this.BaseStream.Position;
                            try
                            {
                                bodyAt.WriteBody(amfMessage.ObjectEncoding, this);
                            }
                            catch (Exception exception1)
                            {
                                ErrorResponseBody body2;
                                exception = exception1;
                                this.BaseStream.Seek(position, SeekOrigin.Begin);
                                if (log.get_IsFatalEnabled())
                                {
                                    log.Fatal(__Res.GetString("Amf_SerializationFail"), exception);
                                }
                                if (bodyAt.RequestBody.IsEmptyTarget)
                                {
                                    object content = bodyAt.RequestBody.Content;
                                    if (content is IList)
                                    {
                                        content = (content as IList)[0];
                                    }
                                    IMessage         message    = content as IMessage;
                                    MessageException exception2 = new MessageException(exception)
                                    {
                                        FaultCode = __Res.GetString("Amf_SerializationFail")
                                    };
                                    body2 = new ErrorResponseBody(bodyAt.RequestBody, message, exception2);
                                }
                                else
                                {
                                    body2 = new ErrorResponseBody(bodyAt.RequestBody, exception);
                                }
                                try
                                {
                                    body2.WriteBody(amfMessage.ObjectEncoding, this);
                                }
                                catch (Exception exception3)
                                {
                                    if (log.get_IsFatalEnabled())
                                    {
                                        log.Fatal(__Res.GetString("Amf_ResponseFail"), exception3);
                                    }
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            bodyAt.WriteBody(amfMessage.ObjectEncoding, this);
                        }
                    }
                    else
                    {
                        AMFBody body3 = amfMessage.GetBodyAt(num2);
                        ValidationUtils.ObjectNotNull(body3, "amfBody");
                        body3.WriteBody(amfMessage.ObjectEncoding, this);
                    }
                }
            }
            catch (Exception exception5)
            {
                exception = exception5;
                if (log.get_IsFatalEnabled())
                {
                    log.Fatal(__Res.GetString("Amf_SerializationFail"), exception);
                }
                throw;
            }
        }