示例#1
0
        protected override void OnMobileDeserializeState(ISerializationContext context)
        {
            this.Value = context.GetState<object>("v");
            this.TypeName = context.GetState<string>("t");

            base.OnMobileDeserializeState(context);
        }
示例#2
0
        internal ServerInfo(ISerializationContext context, IValueReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException ("reader");

            Deserialize (context, reader);
        }
示例#3
0
        protected override void OnMobileSerializeState(ISerializationContext context)
        {
            base.OnMobileSerializeState(context);

            context.AddState("v", this.Value);
            context.AddState("t", this.TypeName);
        }
        /// <summary>
        /// Serializes the member.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="memberValue">The member value.</param>
        public override void SerializeMember(ISerializationContext context, MemberValue memberValue)
        {
            base.SerializeMember(context, memberValue);

            var value = memberValue.Value;
            if (value != null)
            {
                var valueType = value.GetType();
                if (valueType.IsGenericTypeEx())
                {
                    if (valueType.GetGenericTypeDefinitionEx() == typeof(KeyValuePair<,>))
                    {
                        var keyProperty = valueType.GetPropertyEx("Key");
                        var valueProperty = valueType.GetPropertyEx("Value");

                        var kvpKey = keyProperty.GetValue(value, null);
                        var kvpValue = valueProperty.GetValue(value, null);

                        var finalValue = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}", Prefix, Splitter,
                            keyProperty.PropertyType, valueProperty.PropertyType,
                            ObjectToStringHelper.ToString(kvpKey), ObjectToStringHelper.ToString(kvpValue));

                        memberValue.Value = finalValue;
                    }
                }
            }
        }
        /// <summary>
        /// Deserializes the member.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="memberValue">The member value.</param>
        public override void DeserializeMember(ISerializationContext context, MemberValue memberValue)
        {
            var valueAsString = memberValue.Value as string;
            if (!string.IsNullOrEmpty(valueAsString))
            {
                if (valueAsString.StartsWith(Prefix))
                {
                    var splittedValues = valueAsString.Split(new[] { Splitter }, StringSplitOptions.None);

                    var keyValuePairType = typeof(KeyValuePair<,>);
                    var keyType = TypeCache.GetTypeWithoutAssembly(splittedValues[1]);
                    var valueType = TypeCache.GetTypeWithoutAssembly(splittedValues[2]);
                    var keyValue = splittedValues[3];
                    var valueValue = splittedValues[4];

                    // TODO: consider caching
                    var keyValuePairGenericType = keyValuePairType.MakeGenericType(keyType, valueType);

                    var key = StringToObjectHelper.ToRightType(keyType, keyValue);
                    var value = StringToObjectHelper.ToRightType(valueType, valueValue);

                    var keyValuePair = Activator.CreateInstance(keyValuePairGenericType, new [] { key, value });

                    memberValue.Value = keyValuePair;
                }
            }

            base.DeserializeMember(context, memberValue);
        }
示例#6
0
        public ChannelChangeInfo(ISerializationContext context, IValueReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            Deserialize (context, reader);
        }
        private NetworkEntity ReadEntity(ISerializationContext context, IValueReader reader)
        {
            var entity = new NetworkEntity (reader.ReadString (), EntityType.Client);

            entity.NetworkID = reader.ReadUInt16 ();
            UInt16 fieldCount = reader.ReadUInt16 ();

            for (int f = 0; f < fieldCount; f++)
            {
                string name = reader.ReadString ();
                ushort typeID = reader.ReadUInt16 ();

                Type type;
                context.TypeMap.TryGetType (typeID, out type);

                object value;

                if (type == typeof (Vector2))
                    value = reader.Read (context, Vector2Serializer.Instance);
                else if (type == typeof (Vector3))
                    value = reader.Read (context, Vector3Serializer.Instance);
                else
                    value = reader.Read (context, type);

                entity.Fields.Add (name, new PropertyGroup (value, type));
            }

            return entity;
        }
示例#8
0
        public override void ReadPayload(ISerializationContext context, IValueReader reader)
        {
            int[] sourceIds = new int[reader.ReadInt32()];
            for (int i = 0; i < sourceIds.Length; ++i)
                sourceIds[i] = reader.ReadInt32();

            this.SourceIds = sourceIds;
        }
示例#9
0
		public override void WritePayload (ISerializationContext context, IValueWriter writer)
		{
			if (writer.WriteBool (SenderId != null))
				writer.WriteString (SenderId);

			writer.WriteInt32 (GroupId);
			writer.WriteString (Text);
		}
示例#10
0
        public override void ReadPayload(ISerializationContext context, IValueReader reader)
        {
            AudioSource[] sourceInfos = new AudioSource[reader.ReadInt32()];
            for (int i = 0; i < sourceInfos.Length; ++i)
                sourceInfos[i] = new AudioSource (context, reader);

            this.Sources = sourceInfos;
        }
示例#11
0
        public static TextReader Normalize(TextReader tr, ISerializationContext ctx)
        {
            string s = tr.ReadToEnd();
            TextReader reader = Normalize(s, ctx);
            tr.Close();

            return reader;
        }
 public override void SetObjectData(ISerializationData dataHolder, ISerializationContext context)
 {
     base.SetObjectData(dataHolder, context);
     if (dataHolder.ContainsField("Priority"))
         Priority = dataHolder.GetValue<float>("Priority");
     else
         Priority = context.Context as float? ?? DEFAULT_ACTION_PRIORITY;
 }
示例#13
0
		public override void ReadPayload (ISerializationContext context, IValueReader reader)
		{
			if (reader.ReadBool())
				SenderId = reader.ReadString();

			GroupId = reader.ReadInt32();
			Text = reader.ReadString();
		}
 public override void WritePayload(ISerializationContext context, IValueWriter writer)
 {
     using (var ms = new MemoryStream())
     {
         ScreenFrame.Save(ms, ImageFormat.Png);
         writer.WriteBytes(ms.GetBuffer());
     }
 }
示例#15
0
        public override void ReadPayload(ISerializationContext context, IValueReader reader)
        {
            int numUsers = reader.ReadInt32();
            IUser[] users = new IUser[numUsers];
            for (int i = 0; i < users.Length; ++i)
                users[i] = new User (reader.ReadInt32(), reader.ReadString());

            Users = users;
        }
示例#16
0
 public virtual void RegisterId(string id, object value, ISerializationContext context)
 {
     if (value != null)
     {
         var type = Serializer.GetSerializationInfo(value.GetType(), true);
         InsertIntoIdStore(id, value, type);
         context.Register(value, new Uri(id, UriKind.Relative), this);
     }
 }
示例#17
0
        public override void WritePayload(ISerializationContext context, IValueWriter writer)
        {
            writer.WriteInt32 (Entities.Count);

            foreach (SnapshotEntity sentity in Entities)
            {
                WriteEntity (sentity.Entity, context, writer);
            }
        }
        public override void DeserializeMember(ISerializationContext context, MemberValue memberValue)
        {
            if (string.Equals(memberValue.Name, "ProjectTypes"))
            {
                // TODO: Match the list with WP8 => WP80 somehow?
            }

            base.DeserializeMember(context, memberValue);
        }
示例#19
0
 public ItemValueSerializerNode(object value,
                                TypeSpec expectedBaseType,
                                string expandPath,
                                ISerializationContext context,
                                ISerializerNode parentNode,
                                bool isRemoved = false)
     : base(expectedBaseType, expandPath, context, parentNode, isRemoved)
 {
     Value = value;
 }
 public PropertyValueSerializerNode(
     ISerializerNode parentNode, PropertySpec property)
 {
     if (parentNode == null)
         throw new ArgumentNullException("parentNode");
     if (property == null)
         throw new ArgumentNullException("propertyMapping");
     this.parentNode = parentNode;
     this.property = property;
     context = parentNode.Context;
 }
示例#21
0
        /// <summary>
        /// Normalizes line endings, converting "\r" into "\r\n" and "\n" into "\r\n".        
        /// </summary>
        public static TextReader Normalize(string s, ISerializationContext ctx)
        {
            // Replace \r and \n with \r\n.
            s = Regex.Replace(s, @"((\r(?=[^\n]))|((?<=[^\r])\n))", "\r\n");

            ISerializationSettings settings = ctx.GetService(typeof(ISerializationSettings)) as ISerializationSettings;
            if (settings == null || !settings.EnsureAccurateLineNumbers)
                s = RemoveEmptyLines(UnwrapLines(s));

            return new StringReader(s);
        }
示例#22
0
 public virtual void GetObjectData(ISerializationData dataHolder, ISerializationContext context)
 {
     dataHolder.SetValue("Id", Id);
     dataHolder.SetValue("Type", Type);
     dataHolder.SetValue("Subject", Subject);
     dataHolder.SetValue("Timestamp", Timestamp);
     if (m_linkedEmotions.Count > 0)
     {
         dataHolder.SetValue("LinkedEmotions", m_linkedEmotions.ToArray());
     }
 }
示例#23
0
        /// <summary>
        /// Serializes the provided object asynchronously.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="textWriter">The <see cref="TextWriter"/> used to write the object content.</param>
        /// <param name="context">The context.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A Task promising the serialized object as a string.
        /// </returns>
        public Task SerializeAsync(
            object obj,
            TextWriter textWriter,
            ISerializationContext context = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Contract.Requires(textWriter != null);
            Contract.Ensures(Contract.Result<Task>() != null);

            return Contract.Result<Task>();
        }
示例#24
0
 public ItemValueSerializerNode(
     object value, TypeSpec expectedBaseType, string expandPath, ISerializationContext context,
     ISerializerNode parentNode, bool isRemoved = false)
 {
     this.value = value;
     this.expectedBaseType = expectedBaseType;
     this.expandPath = expandPath;
     this.context = context;
     this.parentNode = parentNode;
     this.isRemoved = isRemoved;
 }
示例#25
0
 protected SerializerNode(TypeSpec expectedBaseType,
                          string expandPath,
                          ISerializationContext context,
                          ISerializerNode parentNode,
                          bool isRemoved = false)
 {
     ExpectedBaseType = expectedBaseType;
     ExpandPath = expandPath;
     Context = context;
     ParentNode = parentNode;
     IsRemoved = isRemoved;
 }
示例#26
0
        public override void ReadPayload(ISerializationContext context, IValueReader reader)
        {
            int entityCount = reader.ReadInt32 ();
            Entities = new List<SnapshotEntity>(entityCount);

            // Read in the entities
            for (int i = 0; i < entityCount; i++)
            {
                NetworkEntity entity = ReadEntity(context, reader);
                Entities.Add (new SnapshotEntity (entity, true));
            }
        }
示例#27
0
        /// <summary>
        /// Gets a serializer for the provided context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        /// The serializer.
        /// </returns>
        public ISerializer GetSerializer(ISerializationContext context = null)
        {
            context = context ?? new SerializationContext(typeof(JsonFormat));
            var formatType = context.FormatType ?? typeof(JsonFormat);

            var serializer = this.serializerFactories.TryGetValue(formatType);
            if (serializer == null)
            {
                throw new KeyNotFoundException(string.Format(Strings.DefaultSerializationService_SerializerNotFound_Exception, formatType));
            }

            return serializer.CreateExport().Value;
        }
示例#28
0
        /// <summary>
        /// Serializes a tag structure into a context.
        /// </summary>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStructure">The tag structure.</param>
        public void Serialize(ISerializationContext context, object tagStructure, uint? offset = null)
        {
            // Serialize the structure to a data block
            var info = new TagStructureInfo(tagStructure.GetType(), _version);
            context.BeginSerialize(info);
            var tagStream = new MemoryStream();
            var structBlock = context.CreateBlock();
            SerializeStruct(context, tagStream, structBlock, info, tagStructure);

            // Finalize the block and write all of the tag data out
            var mainStructOffset = offset.HasValue ? offset.Value : structBlock.Finalize(tagStream);
            var data = tagStream.ToArray();
            context.EndSerialize(info, data, mainStructOffset);
        }
        /// <summary>
        /// Returns a serializer that can be used to serialize and object
        /// of type <paramref name="objectType"/>.
        /// <note>
        ///     TODO: Add support for caching.
        /// </note>
        /// </summary>
        /// <param name="objectType">The type of object to be serialized.</param>
        /// <param name="ctx">The serialization context.</param>
        virtual public ISerializer Build(Type objectType, ISerializationContext ctx)
        {
            if (objectType != null)
            {
                ISerializer s = null;

                if (typeof(IAttachment).IsAssignableFrom(objectType))
                    s = new AttachmentSerializer();
                else if (typeof(IAttendee).IsAssignableFrom(objectType))
                    s = new AttendeeSerializer();
                else if (typeof(IDateTime).IsAssignableFrom(objectType))
                    s = new DateTimeSerializer();
                else if (typeof(IFreeBusyEntry).IsAssignableFrom(objectType))
                    s = new FreeBusyEntrySerializer();
                else if (typeof(IGeographicLocation).IsAssignableFrom(objectType))
                    s = new GeographicLocationSerializer();
                else if (typeof(IOrganizer).IsAssignableFrom(objectType))
                    s = new OrganizerSerializer();
                else if (typeof(IPeriod).IsAssignableFrom(objectType))
                    s = new PeriodSerializer();
                else if (typeof(IPeriodList).IsAssignableFrom(objectType))
                    s = new PeriodListSerializer();
                else if (typeof(IRecurrencePattern).IsAssignableFrom(objectType))
                    s = new RecurrencePatternSerializer();
                else if (typeof(IRequestStatus).IsAssignableFrom(objectType))
                    s = new RequestStatusSerializer();
                else if (typeof(IStatusCode).IsAssignableFrom(objectType))
                    s = new StatusCodeSerializer();
                else if (typeof(ITrigger).IsAssignableFrom(objectType))
                    s = new TriggerSerializer();
                else if (typeof(IUTCOffset).IsAssignableFrom(objectType))
                    s = new UTCOffsetSerializer();
                else if (typeof(IWeekDay).IsAssignableFrom(objectType))
                    s = new WeekDaySerializer();
                // Default to a string serializer, which simply calls
                // ToString() on the value to serialize it.
                else
                    s = new StringSerializer();
                
                // Set the serialization context
                if (s != null)
                    s.SerializationContext = ctx;

                return s;
            }
            return null;
        }
示例#30
0
        /// <summary>
        /// Returns a serializer that can be used to serialize and object
        /// of type <paramref name="objectType"/>.
        /// <note>
        ///     TODO: Add support for caching.
        /// </note>
        /// </summary>
        /// <param name="objectType">The type of object to be serialized.</param>
        /// <param name="ctx">The serialization context.</param>
        virtual public ISerializer Build(Type objectType, ISerializationContext ctx)
        {
            if (objectType != null)
            {
                ISerializer s = null;

                if (typeof(IICalendar).IsAssignableFrom(objectType))
                    s = new iCalendarSerializer();
                else if (typeof(ICalendarComponent).IsAssignableFrom(objectType))
                {
                    if (typeof(IEvent).IsAssignableFrom(objectType))
                        s = new EventSerializer();
                    else
                        s = new ComponentSerializer();
                }
                else if (typeof(ICalendarProperty).IsAssignableFrom(objectType))
                    s = new PropertySerializer();
                else if (typeof(ICalendarParameter).IsAssignableFrom(objectType))
                    s = new ParameterSerializer();
                else if (typeof(string).IsAssignableFrom(objectType))
                    s = new StringSerializer();
                // FIXME: remove?
                //else if (objectType.IsGenericType && typeof(IList<>).IsAssignableFrom(objectType.GetGenericTypeDefinition()))
                //    s = new GenericListSerializer(objectType);
                else if (objectType.IsEnum)
                    s = new EnumSerializer(objectType);
                else if (typeof(TimeSpan).IsAssignableFrom(objectType))
                    s = new TimeSpanSerializer();
                else if (typeof(int).IsAssignableFrom(objectType))
                    s = new IntegerSerializer();
                else if (typeof(Uri).IsAssignableFrom(objectType))
                    s = new UriSerializer();
                else if (typeof(ICalendarDataType).IsAssignableFrom(objectType))
                    s = m_DataTypeSerializerFactory.Build(objectType, ctx);
                // Default to a string serializer, which simply calls
                // ToString() on the value to serialize it.
                else
                    s = new StringSerializer();
                
                // Set the serialization context
                if (s != null)
                    s.SerializationContext = ctx;

                return s;
            }
            return null;
        }
 /// <summary>
 /// Serializes the member.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="memberValue">The member value.</param>
 /// <returns>The deserialized member value.</returns>
 protected abstract void SerializeMember(ISerializationContext <TSerializationContext> context, MemberValue memberValue);
示例#32
0
 /// <summary>
 /// Deserializes the member.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="memberValue">The member value.</param>
 /// <returns>The <see cref="SerializationObject" /> representing the deserialized value or result.</returns>
 protected abstract SerializationObject DeserializeMember(ISerializationContext <TSerializationContext> context, MemberValue memberValue);
示例#33
0
 /// <summary>
 /// Called before the serializer starts deserializing an object.
 /// </summary>
 /// <param name="context">The context.</param>
 protected virtual void BeforeDeserialization(ISerializationContext <TSerializationContext> context)
 {
 }
示例#34
0
 public override void ReadPayload(ISerializationContext context, IValueReader reader)
 {
     ConnectionId = reader.ReadInt32();
 }
示例#35
0
 public ImageContent(SerializationContext context)
 {
     Context = context;
 }
示例#36
0
 TCollection IFactory <TCollection> .Create(ISerializationContext context) => Initialize(default, context);
示例#37
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutPascalString(CallId.ToString());
 }
示例#38
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     Mode     = input.GetEnum <MatchmakerNotifyType>();
     LotID    = input.GetUInt32();
     AvatarID = input.GetUInt32();
 }
 /// <summary>
 /// Called before the serializer starts serializing a specific member.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="memberValue">The member value.</param>
 protected virtual void BeforeSerializeMember(ISerializationContext <TSerializationContext> context, MemberValue memberValue)
 {
 }
 protected SerializerBase(ISerializationContext ctx)
 {
     _mSerializationContext = ctx;
 }
 protected SerializerBase()
 {
     _mSerializationContext = Serialization.SerializationContext.Default;
 }
示例#42
0
 public abstract void Deserialize(IoBuffer input, ISerializationContext context);
示例#43
0
 /// <summary>
 /// Creates a new instance of the <see cref="NestedSerializationContext"/> class.
 /// </summary>
 /// <param name="parent">The parent context.</param>
 /// <param name="offset">The absolute offset at which this stream begins.</param>
 /// <param name="writer">The writer.</param>
 public NestedSerializationContext(ISerializationContext parent, int offset, BinaryTokenStreamWriter writer)
 {
     this.parentContext = parent;
     this.initialOffset = offset;
     this.StreamWriter  = writer;
 }
 public OrganizerSerializer(ISerializationContext ctx) : base(ctx)
 {
 }
示例#45
0
 public override void ReadPayload(ISerializationContext context, IValueReader reader)
 {
     this.channel = new ChannelInfo(context, reader);
     Delete       = reader.ReadBool();
     MakeDefault  = reader.ReadBool();
 }
示例#46
0
 /// <summary>
 /// Called after the serializer has deserialized a specific member.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="memberValue">The member value.</param>
 protected virtual void AfterDeserializeMember(ISerializationContext <TSerializationContext> context, MemberValue memberValue)
 {
 }
示例#47
0
 public void GetObjectData(ISerializationData dataHolder, ISerializationContext context)
 {
     dataHolder.SetValue("SocialExchanges", m_SocialExchanges.ToArray());
 }
示例#48
0
 public void ReadBinary(ISerializationContext context)
 {
 }
示例#49
0
 public static T Deserialize <T>(JsonString jsonString, ISerializationContext context)
 {
     return((T)Deserialize(typeof(T), jsonString, context));
 }
 public EventSerializer(ISerializationContext ctx) : base(ctx)
 {
 }
示例#51
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     CallId = Guid.Parse(input.GetPascalString());
 }
示例#52
0
            public static void Serializer(object untypedInput, ISerializationContext context, Type expected)
            {
                TestTypeA input = (TestTypeA)untypedInput;

                SerializationManager.SerializeInner(input.Collection, context, typeof(ICollection <TestTypeA>));
            }
示例#53
0
 public void WriteBinary(ISerializationContext context)
 {
 }
示例#54
0
 public override void WritePayload(ISerializationContext context, IValueWriter writer)
 {
     writer.WriteInt32(ConnectionId);
 }
示例#55
0
 public abstract void Serialize(IoBuffer output, ISerializationContext context);
示例#56
0
 public CalendarSerializer(ISerializationContext ctx) : base(ctx)
 {
 }
示例#57
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutEnum(Mode);
     output.PutUInt32(LotID);
     output.PutUInt32(AvatarID);
 }
示例#58
0
 public static void RecordObject(this ISerializationContext context, object original)
 {
     context.RecordObject(original, context.CurrentOffset);
 }
示例#59
0
 public override void WritePayload(ISerializationContext context, IValueWriter writer)
 {
     this.channel.Serialize(context, writer);
     writer.WriteBool(Delete);
     writer.WriteBool(MakeDefault);
 }
示例#60
0
 /// <summary>
 /// Called after the serializer has deserialized an object.
 /// </summary>
 /// <param name="context">The context.</param>
 protected virtual void AfterDeserialization(ISerializationContext <TSerializationContext> context)
 {
 }