Example #1
0
        public void WriteObject(string className, IDictionary objectFields, IProtocolFormatter writer)
        {
            if (objectFields.Contains("serializeAsArrayMap"))
            {
                objectFields.Remove("serializeAsArrayMap");
                WriteObjectMap(objectFields, writer);
                return;
            }

            if (className != null)
            {
                writer.BeginWriteNamedObject(className, objectFields.Count);
            }
            else
            {
                //writer.BeginWriteObjectMap( objectFields.Count );
                writer.BeginWriteObject(objectFields.Count);
            }

            IEnumerator en = objectFields.Keys.GetEnumerator();

            while (en.MoveNext())
            {
                object fieldName = en.Current;

                if (Log.isLogging(LoggingConstants.SERIALIZATION))
                {
                    Log.log(LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName);
                }

                writer.WriteFieldName(fieldName.ToString());
                writer.BeginWriteFieldValue();

                try
                {
                    MessageWriter.writeObject(objectFields[fieldName], writer);
                }
                catch (Exception exception)
                {
                    if (Log.isLogging(LoggingConstants.ERROR))
                    {
                        Log.log(LoggingConstants.ERROR, "unable to serialize object's field " + fieldName, exception);
                    }
                }
                finally
                {
                    writer.EndWriteFieldValue();
                }
            }

            if (className != null)
            {
                writer.EndWriteNamedObject();
            }
            else
            {
                //writer.EndWriteObjectMap();
                writer.EndWriteObject();
            }
        }
Example #2
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            Enum enumeration = (Enum)obj;
            Type undertype   = Enum.GetUnderlyingType(enumeration.GetType());

            MessageWriter.writeObject(Enum.GetName(obj.GetType(), Convert.ChangeType(enumeration, undertype, CultureInfo.InvariantCulture)), writer);;
        }
Example #3
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            Header header = (Header)obj;

            writer.DirectWriteString(header.headerName);
            writer.DirectWriteBoolean(header.mustUnderstand);
            writer.DirectWriteInt(-1);
            MessageWriter.writeObject(header.headerValue, writer);
        }
Example #4
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            Enum   enumeration     = (Enum)obj;
            Type   undertype       = Enum.GetUnderlyingType(enumeration.GetType());
            Type   enumType        = obj.GetType();
            Object convertedToType = Convert.ChangeType(enumeration, undertype, CultureInfo.InvariantCulture);
            String enumName        = Enum.GetName(enumType, convertedToType);

            MessageWriter.writeObject(enumName, writer);
        }
Example #5
0
        private void WriteObjectMap(IDictionary objectFields, IProtocolFormatter writer)
        {
            int maxInt = -1;

            for (int i = 0; i < objectFields.Count; i++)
            {
                if (!objectFields.Contains(i))
                {
                    break;
                }

                maxInt = i;
            }

            writer.BeginWriteObjectMap(maxInt + 1);

            IEnumerator en = objectFields.Keys.GetEnumerator();

            while (en.MoveNext())
            {
                object fieldName = en.Current;

                if (fieldName.Equals("length"))
                {
                    continue;
                }

                if (Log.isLogging(LoggingConstants.SERIALIZATION))
                {
                    Log.log(LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName);
                }

                writer.WriteFieldName(fieldName.ToString());
                writer.BeginWriteFieldValue();

                MessageWriter.writeObject(objectFields[fieldName], writer);

                writer.EndWriteFieldValue();
            }

            if (maxInt >= 0)
            {
                writer.WriteFieldName("length");
                MessageWriter.writeObject(maxInt + 1, writer);
            }

            writer.EndWriteObjectMap();
        }
Example #6
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            IDictionary propertyBag = ((AnonymousObject)obj).Properties;

            writer.BeginWriteObject(propertyBag.Count);

            foreach (object key in propertyBag.Keys)
            {
                writer.WriteFieldName(key.ToString());
                writer.BeginWriteFieldValue();
                MessageWriter.writeObject(propertyBag[key], writer);
                writer.EndWriteFieldValue();
            }

            writer.EndWriteObject();
        }
Example #7
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            Request message = (Request)obj;

            writer.BeginWriteMessage(message);
            writer.WriteMessageVersion((int)message.getVersion());

            Header[] headers = message.getResponseHeaders();
            Body[]   bodies  = message.getResponseBodies();

            writer.DirectWriteShort(headers.Length);

            if (Log.isLogging(LoggingConstants.DEBUG))
            {
                Log.log(LoggingConstants.DEBUG, "got headers " + headers.Length);
                Log.log(LoggingConstants.DEBUG, "got bodies " + bodies.Length);
                Log.log(LoggingConstants.DEBUG, "AMFMessageWriter.write - message version: " + message.getVersion() + " header length: " + headers.Length);
            }

            for (int i = 0; i < headers.Length; i++)
            {
                MessageWriter.writeObject(headers[i], writer);
            }

            writer.DirectWriteShort(bodies.Length);

#if FULL_BUILD
            bool isAMF3 = ThreadContext.currentHttpContext() != null && ThreadContext.currentHttpContext().Items.Contains("v3_request");
#endif

            for (int i = 0; i < bodies.Length; i++)
            {
                // if message is amf0 then body of the message is invocation result and if should be
                // processed via cache managment
#if FULL_BUILD
                if (!isAMF3)
                {
                    Cache.WriteAndSave(bodies[i], writer);
                }
                else
#endif
                MessageWriter.writeObject(bodies[i], writer);
            }

            writer.EndWriteMessage();
        }
Example #8
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            //Log.log( ORBConstants.INFO, "AMFBodyWriter.write.begin: " + writer.BaseStream.Length );
            Body body = (Body)obj;

            if (Log.isLogging(LoggingConstants.DEBUG))
            {
                Log.log(LoggingConstants.DEBUG, "AMFBodyWriter:write body.responseURI: " + body.responseURI + " body.serviceURI: " + body.serviceURI);
            }

            writer.DirectWriteString(body.ResponseUri == null ? "null" : body.ResponseUri);
            writer.DirectWriteString(body.ServiceUri == null ? "null" : body.ServiceUri);
            writer.DirectWriteInt(-1);
            //((FlashorbBinaryWriter)writer).WriteInt( i );
            //Log.log( ORBConstants.INFO, "AMFBodyWriter.write.before writing response object: " + writer.BaseStream.Length );
            writer.ResetReferenceCache();
            writer.BeginWriteBodyContent();
            MessageWriter.writeObject(body.responseDataObject, writer);
            writer.EndWriteBodyContent();
            //Log.log( ORBConstants.INFO, "AMFBodyWriter.write.end: " + writer.BaseStream.Length );
        }
Example #9
0
        private void serialize(int[] coord, int dim, Array array, IProtocolFormatter writer)
        {
            int dimLength = array.GetLength(dim);

            writer.BeginWriteArray(dimLength);

            for (int i = 0; i < dimLength; i++)
            {
                coord[dim] = i;

                if (dim == (array.Rank - 1))
                {
                    MessageWriter.writeObject(array.GetValue(coord), writer);
                }
                else
                {
                    serialize(coord, dim + 1, array, writer);
                }
            }

            writer.EndWriteArray();
        }
Example #10
0
 public override void write(object obj, IProtocolFormatter formatter)
 {
     MessageWriter.writeObject(((Guid)obj).ToString(), formatter);
 }
Example #11
0
        public override void write(object obj, IProtocolFormatter formatter)
        {
            TimeSpan ts = (TimeSpan)obj;

            MessageWriter.writeObject(ts.TotalMilliseconds, formatter);
        }
Example #12
0
        public override void write(object obj, IProtocolFormatter formatter)
        {
            Type type = (Type)obj;

            MessageWriter.writeObject(type.FullName, formatter);
        }