Esempio n. 1
0
        public override object ReadJson(JsonReader Reader, Type ObjectType, object ExistingValue, JsonSerializer Serializer)
        {
            JObject Json = JObject.Load(Reader);

            if (JsonHelper.GetJsonNumber(Json, "type", out int Type))
            {
                StreamEntry Entry = StreamEntryFactory.CreateStreamEntryByType(Type);
                Entry.Load(Json);
                return(Entry);
            }

            return(null);
        }
        protected sealed override void Load(LogicJSONObject jsonObject)
        {
            LogicJSONArray ownerIdArray = jsonObject.GetJSONArray(StreamDocument.JSON_ATTRIBUTE_OWNER_ID);

            this.OwnerId    = new LogicLong(ownerIdArray.GetJSONNumber(0).GetIntValue(), ownerIdArray.GetJSONNumber(1).GetIntValue());
            this.CreateTime = DateTime.Parse(jsonObject.GetJSONString(StreamDocument.JSON_ATTRIBUTE_CREATE_TIME).GetStringValue());
            this.Type       = (StreamType)jsonObject.GetJSONNumber(StreamDocument.JSON_ATTRIBUTE_TYPE).GetIntValue();

            switch (this.Type)
            {
            case StreamType.ALLIANCE:
            {
                StreamEntry entry = StreamEntryFactory.CreateStreamEntryByType((StreamEntryType)jsonObject.GetJSONNumber(StreamDocument.JSON_ATTRIBUTE_ENTRY_TYPE).GetIntValue());
                entry.Load(jsonObject.GetJSONObject(StreamDocument.JSON_ATTRIBUTE_ENTRY));
                entry.SetId(this.Id);
                this.Entry = entry;
                break;
            }

            case StreamType.AVATAR:
            {
                AvatarStreamEntry entry =
                    AvatarStreamEntryFactory.CreateStreamEntryByType((AvatarStreamEntryType)jsonObject.GetJSONNumber(StreamDocument.JSON_ATTRIBUTE_ENTRY_TYPE).GetIntValue());
                entry.Load(jsonObject.GetJSONObject(StreamDocument.JSON_ATTRIBUTE_ENTRY));
                entry.SetId(this.Id);
                this.Entry = entry;
                break;
            }

            case StreamType.REPLAY:
            {
                ReplayStreamEntry entry = new ReplayStreamEntry();
                entry.Load(jsonObject.GetJSONObject(StreamDocument.JSON_ATTRIBUTE_ENTRY));
                this.Entry = entry;
                break;
            }
            }
        }