예제 #1
0
        public void WriteData(ObjectEncoding objectEncoding, object data)
        {
            if (data == null)
            {
                WriteNull();

                return;
            }

            Type type = data.GetType();

            if (amf0ObjectReferences.ContainsKey(data))
            {
                WriteReference(data);

                return;
            }

            IAMFWriter amfWriter = null;

            if (AmfWriterTable[0].ContainsKey(type))
            {
                amfWriter = AmfWriterTable[0][type] as IAMFWriter;
            }

            if (amfWriter == null)
            {
                if (type.BaseType != null)
                {
                    if (AmfWriterTable[0].ContainsKey(type.BaseType))
                    {
                        amfWriter = AmfWriterTable[0][type.BaseType] as IAMFWriter;
                    }
                }
            }

            if (amfWriter == null)
            {
                amfWriter = new AMF0ObjectWriter();
            }

            if (objectEncoding == ObjectEncoding.AMF0)
            {
                amfWriter.WriteData(this, data);
            }
            else
            {
                if (amfWriter.IsPrimitive)
                {
                    amfWriter.WriteData(this, data);
                }
                else
                {
                    WriteByte(AMF0TypeCode.AMF3Tag);

                    WriteAMF3Data(data);
                }
            }
        }
예제 #2
0
 public void WriteAMF3Data(object data)
 {
     if (data == null)
     {
         this.WriteAMF3Null();
     }
     else if (data is DBNull)
     {
         this.WriteAMF3Null();
     }
     else
     {
         if (FluorineConfiguration.Instance.AcceptNullValueTypes && (FluorineConfiguration.Instance.NullableValues != null))
         {
             Type type = data.GetType();
             if (FluorineConfiguration.Instance.NullableValues.ContainsKey(type) && data.Equals(FluorineConfiguration.Instance.NullableValues[type]))
             {
                 this.WriteAMF3Null();
                 return;
             }
         }
         IAMFWriter writer = null;
         if (AmfWriterTable[3].ContainsKey(data.GetType()))
         {
             writer = AmfWriterTable[3][data.GetType()];
         }
         if ((writer == null) && AmfWriterTable[3].ContainsKey(data.GetType().BaseType))
         {
             writer = AmfWriterTable[3][data.GetType().BaseType];
         }
         if (writer == null)
         {
             lock (AmfWriterTable)
             {
                 if (!AmfWriterTable[3].ContainsKey(data.GetType()))
                 {
                     writer = new AMF3ObjectWriter();
                     AmfWriterTable[3].Add(data.GetType(), writer);
                 }
                 else
                 {
                     writer = AmfWriterTable[3][data.GetType()];
                 }
             }
         }
         if (writer == null)
         {
             throw new FluorineException(string.Format("Could not find serializer for type {0}", data.GetType().FullName));
         }
         writer.WriteData(this, data);
     }
 }
예제 #3
0
        public void WriteAMF3Data(object data)
        {
            if (data == null)
            {
                WriteAMF3Null();
                return;
            }
            Type type = data.GetType();

            IAMFWriter amfWriter = null;

            if (amfWriterTable.ContainsKey(type))
            {
                amfWriter = amfWriterTable[type] as IAMFWriter;
            }
            else if (ReflectionUtils.IsSubClass(type, ReflectionUtils.GenericIListType))
            {
                amfWriterTable.Add(type, new AMF3ArrayWriter());
            }
            //Second try with basetype (Enums for example)
            if (amfWriter == null && type.BaseType != null && amfWriterTable.ContainsKey(type.BaseType))
            {
                amfWriter = amfWriterTable[type.BaseType] as IAMFWriter;
            }

            if (amfWriter == null)
            {
                if (!amfWriterTable.ContainsKey(type))
                {
                    amfWriter = new AMF3ObjectWriter();
                    amfWriterTable.Add(type, amfWriter);
                }
                else
                {
                    amfWriter = amfWriterTable[type] as IAMFWriter;
                }
            }

            if (amfWriter != null)
            {
                amfWriter.WriteData(this, data);
            }
            else
            {
                throw new NotImplementedException(type.FullName + "not has amf3writer!");
            }
        }
예제 #4
0
        public void WriteAMF3Data(object data)
        {
            if (data == null)
            {
                WriteAMF3Null();

                return;
            }

            if (data is DBNull)
            {
                WriteAMF3Null();

                return;
            }

            Type type = data.GetType();

            IAMFWriter amfWriter = null;

            if (AmfWriterTable[3].ContainsKey(type))
            {
                amfWriter = AmfWriterTable[3][type] as IAMFWriter;
            }

            if (amfWriter == null)
            {
                if (type.BaseType != null)
                {
                    if (AmfWriterTable[3].ContainsKey(type.BaseType))
                    {
                        amfWriter = AmfWriterTable[3][type.BaseType] as IAMFWriter;
                    }
                }
            }

            if (amfWriter == null)
            {
                amfWriter = new AMF3ObjectWriter();
            }

            amfWriter.WriteData(this, data);
        }
예제 #5
0
 public void WriteData(ObjectEncoding objectEncoding, object data)
 {
     if (data == null)
     {
         this.WriteNull();
     }
     else
     {
         Type type = data.GetType();
         if ((FluorineConfiguration.Instance.AcceptNullValueTypes && (FluorineConfiguration.Instance.NullableValues != null)) && (FluorineConfiguration.Instance.NullableValues.ContainsKey(type) && data.Equals(FluorineConfiguration.Instance.NullableValues[type])))
         {
             this.WriteNull();
         }
         else if (this._amf0ObjectReferences.ContainsKey(data))
         {
             this.WriteReference(data);
         }
         else
         {
             IAMFWriter writer = null;
             if (AmfWriterTable[0].ContainsKey(type))
             {
                 writer = AmfWriterTable[0][type];
             }
             if ((writer == null) && AmfWriterTable[0].ContainsKey(type.BaseType))
             {
                 writer = AmfWriterTable[0][type.BaseType];
             }
             if (writer == null)
             {
                 lock (AmfWriterTable)
                 {
                     if (!AmfWriterTable[0].ContainsKey(type))
                     {
                         writer = new AMF0ObjectWriter();
                         AmfWriterTable[0].Add(type, writer);
                     }
                     else
                     {
                         writer = AmfWriterTable[0][type];
                     }
                 }
             }
             if (writer == null)
             {
                 throw new FluorineException(__Res.GetString("TypeSerializer_NotFound", new object[] { type.FullName }));
             }
             if (objectEncoding == ObjectEncoding.AMF0)
             {
                 writer.WriteData(this, data);
             }
             else if (writer.IsPrimitive)
             {
                 writer.WriteData(this, data);
             }
             else
             {
                 this.WriteByte(0x11);
                 this.WriteAMF3Data(data);
             }
         }
     }
 }