Beispiel #1
0
        public static async Task Handle(Packet p, Presence pr)
        {
            var match = pr.CurrentMatch;

            if (match is null)
            {
                return;
            }

            var reader    = new SerializationReader(new MemoryStream(p.Data));
            var slotIndex = reader.ReadInt32();

            if (match.InProgress || slotIndex > Match.MAX_PLAYERS || slotIndex < 0)
            {
                return;
            }

            var slot = match.Slots[slotIndex];

            if ((slot.Status & SlotStatus.HasPlayer) > 0 || slot.Status == SlotStatus.Locked)
            {
                return;
            }

            var currentSlot = match.Slots.FirstOrDefault(x => x.Presence == pr);

            slot.CopyFrom(currentSlot);
            currentSlot.Clear();

            foreach (var presence in match.Presences)
            {
                await presence.MatchUpdate(match);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Parses presence.db file.
        /// </summary>
        /// <param name="stream">Stream containing presence.db data.</param>
        /// <returns>A usable <see cref="PresenceDatabase"/>.</returns>
        public static PresenceDatabase DecodePresence(Stream stream)
        {
            PresenceDatabase db = new PresenceDatabase();

            using (var r = new SerializationReader(stream))
            {
                db.OsuVersion = r.ReadInt32();
                int playersCount = r.ReadInt32();

                for (int i = 0; i < playersCount; i++)
                {
                    Player player = new Player();
                    player.UserId      = r.ReadInt32();
                    player.Username    = r.ReadString();
                    player.Timezone    = r.ReadByte() - 24;
                    player.CountryCode = r.ReadByte();
                    byte b = r.ReadByte();
                    player.Permissions    = (Permissions)(b & ~0xe0);
                    player.Ruleset        = (Ruleset)Math.Max(0, Math.Min(3, ((b & 0xe0) >> 5)));
                    player.Longitude      = r.ReadSingle();
                    player.Latitude       = r.ReadSingle();
                    player.Rank           = r.ReadInt32();
                    player.LastUpdateTime = r.ReadDateTime();
                    db.Players.Add(player);
                }
            }

            return(db);
        }
Beispiel #3
0
        internal Score(SerializationInfo info, StreamingContext ctxt)
        {
            SerializationReader sr = SerializationReader.GetReader(info);

            pass = true;

            fileChecksum = sr.ReadString();
            playerName   = sr.ReadString();
            string scoreChecksumCheck = sr.ReadString();

            count300            = sr.ReadUInt16();
            count100            = sr.ReadUInt16();
            count50             = sr.ReadUInt16();
            countGeki           = sr.ReadUInt16();
            countKatu           = sr.ReadUInt16();
            countMiss           = sr.ReadUInt16();
            totalScore          = sr.ReadInt32();
            maxCombo            = sr.ReadUInt16();
            perfect             = sr.ReadBoolean();
            enabledMods         = (Mods)sr.ReadInt32();
            rawGraph            = sr.ReadString();
            rawReplayCompressed = sr.ReadByteArray();
            date = sr.ReadDateTime();

            if (scoreChecksumCheck != offlineScoreChecksum)
            {
                throw new Exception("f****d score");
            }
        }
        public void Load(SerializationReader reader, Fallen8 fallen8)
        {
            if (WriteResource())
            {
                reader.ReadInt32();//parameter

                var keyCount = reader.ReadInt32();

                _idx = new Dictionary <IComparable, AGraphElement>(keyCount);

                for (var i = 0; i < keyCount; i++)
                {
                    var           key            = reader.ReadObject();
                    var           graphElementId = reader.ReadInt32();
                    AGraphElement graphElement;
                    if (fallen8.TryGetGraphElement(out graphElement, graphElementId))
                    {
                        _idx.Add((IComparable)key, graphElement);
                    }
                    else
                    {
                        Logger.LogError(String.Format("[SingleValueIndex] Error while deserializing the index. Could not find the graph element \"{0}\"", graphElementId));
                    }
                }

                FinishWriteResource();

                return;
            }

            throw new CollisionException(this);
        }
Beispiel #5
0
        /// <summary>
        /// Parses collection.db file.
        /// </summary>
        /// <param name="stream">Stream containing collection.db data.</param>
        /// <returns>A usable <see cref="CollectionDatabase"/>.</returns>
        public static CollectionDatabase DecodeCollection(Stream stream)
        {
            CollectionDatabase db = new CollectionDatabase();

            using (var r = new SerializationReader(stream))
            {
                db.OsuVersion = r.ReadInt32();
                int collectionsCount = r.ReadInt32();
                db.CollectionCount = collectionsCount;

                for (int i = 0; i < collectionsCount; i++)
                {
                    Collection collection = new Collection();

                    collection.Name = r.ReadString();
                    int count = r.ReadInt32();
                    collection.Count = count;

                    for (int j = 0; j < count; j++)
                    {
                        collection.MD5Hashes.Add(r.ReadString());
                    }

                    db.Collections.Add(collection);
                }
            }

            return(db);
        }
Beispiel #6
0
        public static async Task Handle(Packet p, Presence pr)
        {
            var ms = new MemoryStream(p.Data);

            using var reader = new SerializationReader(ms);

            pr.Status = new ()
            {
                Status          = (ActionStatuses)reader.ReadByte(),
                StatusText      = reader.ReadString(),
                BeatmapChecksum = reader.ReadString(),
                CurrentMods     = (Mods)reader.ReadUInt32(),
                CurrentPlayMode = (PlayMode)reader.ReadByte(),
                BeatmapId       = reader.ReadInt32()
            };

            var lbMode = pr.Status.CurrentMods switch
            {
                var mod when(mod& Mods.Relax) > 0 => LeaderboardMode.Relax,
                _ => LeaderboardMode.Vanilla,
            };

            // We just want to update our stats from cache, so we don't
            // use context here
            await pr.GetOrUpdateUserStats(null, lbMode, false);

            await pr.UserStats();
        }
    }
Beispiel #7
0
 public void ReadFromStream(SerializationReader r)
 {
     Sender   = r.ReadString();
     Message  = r.ReadString();
     Channel  = r.ReadString();
     SenderId = r.ReadInt32();
 }
Beispiel #8
0
 /// <exclude/>
 public FilterColumn(SerializationInfo serializationInfo, StreamingContext streamingContext)
 {
     if (SerializerHelper.UseFastSerialization)
     {
         using (SerializationReader reader = new SerializationReader((byte[])serializationInfo.GetValue("d", typeof(byte[]))))
         {
             _alias           = reader.ReadString();
             _columnId        = reader.ReadString();
             _compareOperator = reader.ReadString();
             _logicalOperator = reader.ReadString();
         }
     }
     else
     {
         if (SerializerHelper.FileVersionCurrent <= SerializerHelper.FileVersionLatest)
         {
             _alias           = serializationInfo.GetString("Alias");
             _column          = (Column)serializationInfo.GetValue("Column", ModelTypes.Column);
             _compareOperator = serializationInfo.GetString("CompareOperator");
             _logicalOperator = serializationInfo.GetString("LogicalOperator");
         }
         else
         {
             throw new NotImplementedException(string.Format("FilterColumn deserialize does not handle version {0} yet.", SerializerHelper.FileVersionCurrent));
         }
     }
 }
Beispiel #9
0
        public virtual void Load(SerializationReader SR)
        {
            SR.ReadStartElement();
            int version = SR.ReadVersion();

            switch (version)
            {
            case 0:
            {
                Author  = SR.ReadString();
                Create  = SR.ReadString();
                Message = SR.ReadString();

                SR.ReadStartElement();
                int length = SR.ReadInt();
                for (int i = 0; i < length; i++)
                {
                    ForumMessage baseforum = SR.ReadType() as ForumMessage;
                    if (baseforum != null)
                    {
                        baseforum.Load(SR);
                        Add(baseforum);
                    }
                }
                SR.ReadEndElement();
                break;
            }
            }
            SR.ReadEndElement();
        }
Beispiel #10
0
        // Load data is called when loading the save game, we also need to override this
        public override void LoadData(SerializationReader Reader)
        {
            // Load our normal data
            base.LoadData(Reader);


            this.Recipes = new List <acegiak_PaintingRecipe>();


            if (Reader == null)
            {
                throw new Exception("The Reader is null!");
            }
            if (Recipes == null)
            {
                throw new Exception("The recipes list is null!");
            }

            if (this == null)
            {
                throw new Exception("This is null!");
            }


            // Read the number we wrote earlier telling us how many items there were
            int arraySize = Reader.ReadInt32();

            for (int i = 0; i < arraySize; i++)
            {
                acegiak_PaintingRecipe.Read(Reader, this);
                // Similar to above, if we had a basic type in our list, we would instead use the Reader.Read function specific to our object type.
            }
        }
Beispiel #11
0
        protected override void SetObjectData(SerializationReader sr)
        {
            base.SetObjectData(sr);

            sr.ReadInt32();
            _Url = sr.ReadString();
        }
Beispiel #12
0
        public static PlayerPresence ReadFromReader(SerializationReader r)
        {
            var p = new PlayerPresence();

            p.ReadFromStream(r);
            return(p);
        }
 public override void Load(SerializationReader Reader)
 {
     base.Load(Reader);
     this.Stat   = Reader.ReadString();
     this.Amount = Reader.ReadSingle();
     this.Needs  = Reader.ReadInt32();
 }
Beispiel #14
0
        private List <BeatmapCollection> readCollections(Stream stream, ProgressNotification notification = null)
        {
            if (notification != null)
            {
                notification.Text     = "Reading collections...";
                notification.Progress = 0;
            }

            var result = new List <BeatmapCollection>();

            try
            {
                using (var sr = new SerializationReader(stream))
                {
                    sr.ReadInt32(); // Version

                    int collectionCount = sr.ReadInt32();
                    result.Capacity = collectionCount;

                    for (int i = 0; i < collectionCount; i++)
                    {
                        if (notification?.CancellationToken.IsCancellationRequested == true)
                        {
                            return(result);
                        }

                        var collection = new BeatmapCollection {
                            Name = { Value = sr.ReadString() }
                        };
                        int mapCount = sr.ReadInt32();

                        for (int j = 0; j < mapCount; j++)
                        {
                            if (notification?.CancellationToken.IsCancellationRequested == true)
                            {
                                return(result);
                            }

                            string checksum = sr.ReadString();

                            collection.BeatmapHashes.Add(checksum);
                        }

                        if (notification != null)
                        {
                            notification.Text     = $"Imported {i + 1} of {collectionCount} collections";
                            notification.Progress = (float)(i + 1) / collectionCount;
                        }

                        result.Add(collection);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e, "Failed to read collection database.");
            }

            return(result);
        }
Beispiel #15
0
 public Association(SerializationInfo serializationInfo, StreamingContext streamingContext)
 {
     if (SerializerHelper.UseFastSerialization)
     {
         using (SerializationReader reader = new SerializationReader((byte[])serializationInfo.GetValue("d", typeof(byte[]))))
         {
             _UniqueId = reader.ReadString();
             _AssociatedObjectId = reader.ReadString();
             _AssociationKind = reader.ReadString();
             _Mappings = (List<Mapping>)reader.ReadObject();
             _Name = reader.ReadString();
             _Enabled = reader.ReadBoolean();
         }
     }
     else
     {
         if (SerializationVersionExists)
         {
             try
             {
             }
             catch (SerializationException)
             {
                 // ignore
                 SerializationVersionExists = false;
             }
         }
         _AssociatedObject = (ScriptObject)serializationInfo.GetValue("AssociatedObject", ModelTypes.ScriptObject);
         _PrimaryObject = (ScriptObject)serializationInfo.GetValue("PrimaryObject", ModelTypes.ScriptObject);
         _AssociationKind = serializationInfo.GetString("AssociationKind");
         _Mappings = (List<Mapping>)serializationInfo.GetValue("Mappings", typeof(List<Mapping>));
         _Name = serializationInfo.GetString("Name");
         _Enabled = serializationInfo.GetBoolean("Enabled");
     }
 }
Beispiel #16
0
        public static async Task Handle(Packet p, Presence pr)
        {
            var match = pr.CurrentMatch;

            if (match is null)
            {
                return;
            }

            var reader = new SerializationReader(new MemoryStream(p.Data));

            var newMatch = await reader.ReadMatch();

            if (string.IsNullOrEmpty(newMatch.GamePassword))
            {
                match.GamePassword = null;
            }

            match.GamePassword = newMatch.GamePassword;

            foreach (var presence in match.Presences)
            {
                await presence.MatchUpdate(match);
            }
        }
		public void CreateWriter()
		{
			writer = new SerializationWriter();
			reader = null;
			writerPosition = 0;
			writerLength = -1;
		}
Beispiel #18
0
        public static Unit DeserializeUnit(SerializationReader reader)
        {
            BitVector32 state = reader.ReadOptimizedBitVector32();

            int unitType = state[UnitType];

            if (unitType == 0)
            {
                return(System.Web.UI.WebControls.Unit.Empty);
            }
            else if (state[UnitIsDoubleValue])
            {
                return(new Unit(reader.ReadDouble(), (UnitType)unitType));
            }
            else if (state[UnitIsZeroValue] == 1)
            {
                return(new Unit(0, (UnitType)unitType));
            }
            else
            {
                int integerValue = state[UnitIsOptimizedValue] == 1 ? reader.ReadOptimizedInt32() : reader.ReadInt16();
                if (state[UnitIsNegativeValue] == 1)
                {
                    integerValue = -integerValue - 1;
                }
                return(new Unit(integerValue, (UnitType)unitType));
            }
        }
Beispiel #19
0
        public static StateBag DeserializeStateBag(SerializationReader reader)
        {
            BitVector32 flags    = reader.ReadOptimizedBitVector32();
            StateBag    stateBag = new StateBag(flags[StateBagIsIgnoreCase]);

            if (flags[StateBagHasDirtyEntries])
            {
                int count = reader.ReadOptimizedInt32();
                for (int i = 0; i < count; i++)
                {
                    string key   = reader.ReadOptimizedString();
                    object value = reader.ReadObject();
                    stateBag.Add(key, value).IsDirty = true;
                }
            }

            if (flags[StateBagHasCleanEntries])
            {
                int count = reader.ReadOptimizedInt32();
                for (int i = 0; i < count; i++)
                {
                    string key   = reader.ReadOptimizedString();
                    object value = reader.ReadObject();
                    stateBag.Add(key, value);
                }
            }
            return(stateBag);
        }
 public void Deserialize(byte[] mySerializedBytes)
 {
     var _SerializationReader    = new SerializationReader(mySerializedBytes);
     FailedCopy                  = _SerializationReader.ReadInt32();
     MaxNumberOfCopies           = _SerializationReader.ReadInt32();
     SerializedObjectStream      = _SerializationReader.ReadByteArray();
 }
            public void Deserialize(byte[] mySerializedBytes)
            {
                var _SerializationReader = new SerializationReader(mySerializedBytes);

                ObjectLocation = _SerializationReader.ReadString();
                NewDefaultRule = _SerializationReader.ReadOptimizedByte();
            }
        public void TestOutOfRange()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationReader sr = new SerializationReader(ms))
            {
                sr.Read<bool>();
                sr.Read<byte>();
                sr.Read<char>();
                sr.Read<short>();
                sr.Read<int>();
                sr.Read<long>();
                sr.Read<float>();
                sr.Read<double>();
                sr.Read<decimal>();
                sr.Read<DateTime>();
                sr.Read<string>();
                sr.Read<TestEnum>();

                sr.Read<string[]>();
                sr.Read<List<string>>();
                sr.Read<Dictionary<int, string>>();

                sr.Read<TestSerializable>();
            }
        }
        public static Color DeserializeColor(SerializationReader reader)
        {
            BitVector32 flags = reader.ReadOptimizedBitVector32();

            if (flags[ColorIsKnown])
            {
                return(Color.FromKnownColor((KnownColor)reader.ReadOptimizedInt32()));
            }
            else if (flags[ColorHasName])
            {
                return(Color.FromName(reader.ReadOptimizedString()));
            }
            else if (!flags[ColorHasValue])
            {
                return(Color.Empty);
            }
            else
            {
                byte red   = flags[ColorHasRed] ? reader.ReadByte() : (byte)0;
                byte green = flags[ColorHasGreen] ? reader.ReadByte() : (byte)0;
                byte blue  = flags[ColorHasBlue] ? reader.ReadByte() : (byte)0;
                byte alpha = flags[ColorHasAlpha] ? reader.ReadByte() : (byte)0;
                return(Color.FromArgb(alpha, red, green, blue));
            }
        }
Beispiel #24
0
        public bScoreFrame(SerializationReader sr)
        {
            //checksum = sr.ReadString();
            time         = sr.ReadInt32();
            id           = sr.ReadByte();
            count300     = sr.ReadUInt16();
            count100     = sr.ReadUInt16();
            count50      = sr.ReadUInt16();
            countGeki    = sr.ReadUInt16();
            countKatu    = sr.ReadUInt16();
            countMiss    = sr.ReadUInt16();
            totalScore   = sr.ReadInt32();
            maxCombo     = sr.ReadUInt16();
            currentCombo = sr.ReadUInt16();
            perfect      = sr.ReadBoolean();
            currentHp    = sr.ReadByte();
            tagByte      = sr.ReadByte();
            usingScoreV2 = sr.ReadBoolean();
            comboPortion = usingScoreV2 ? sr.ReadDouble() : 0;
            bonusPortion = usingScoreV2 ? sr.ReadDouble() : 0;

            if (currentHp == 254)
            {
                currentHp = 0;
                pass      = false;
            }
            else
            {
                pass = true;
            }
        }
Beispiel #25
0
        //public string checksum;

        public bScoreFrame(Stream s)
        {
            SerializationReader sr = new SerializationReader(s);

            //checksum = sr.ReadString();
            time         = sr.ReadInt32();
            id           = sr.ReadByte();
            count300     = sr.ReadUInt16();
            count100     = sr.ReadUInt16();
            count50      = sr.ReadUInt16();
            countGeki    = sr.ReadUInt16();
            countKatu    = sr.ReadUInt16();
            countMiss    = sr.ReadUInt16();
            totalScore   = sr.ReadInt32();
            maxCombo     = sr.ReadUInt16();
            currentCombo = sr.ReadUInt16();
            perfect      = sr.ReadBoolean();
            currentHp    = sr.ReadByte();
            if (currentHp == 254)
            {
                currentHp = 0;
                pass      = false;
            }
            else
            {
                pass = true;
            }
        }
Beispiel #26
0
        public bUserStats(Stream s, bool forceFull)
        {
            SerializationReader sr = new SerializationReader(s);

            userId = sr.ReadInt32();

            Completeness comp = (Completeness)sr.ReadByte();

            completeness = forceFull ? Completeness.Full : comp;

            status = new bStatusUpdate(s);

            if (completeness > Completeness.StatusOnly)
            {
                rankedScore = sr.ReadInt64();
                accuracy    = sr.ReadSingle();
                playcount   = sr.ReadInt32();
                totalScore  = sr.ReadInt64();
                rank        = sr.ReadUInt16();
            }
            if (completeness == Completeness.Full)
            {
                username       = sr.ReadString();
                avatarFilename = sr.ReadString();
                timezone       = sr.ReadByte() - 24;
                location       = sr.ReadString();
            }
        }
Beispiel #27
0
        public static TimingPoint ReadFromReader(SerializationReader r)
        {
            var t = new TimingPoint();

            t.ReadFromStream(r);
            return(t);
        }
Beispiel #28
0
        /// <summary>
        ///   Opens and deserializes an index
        /// </summary>
        /// <param name="indexName"> The index name </param>
        /// <param name="indexPluginName"> The index plugin name </param>
        /// <param name="reader"> Serialization reader </param>
        /// <param name="fallen8"> Fallen-8 </param>
        internal void OpenIndex(string indexName, string indexPluginName, SerializationReader reader, Fallen8 fallen8)
        {
            IIndex index;

            if (PluginFactory.TryFindPlugin(out index, indexPluginName))
            {
                index.Load(reader, fallen8);

                if (WriteResource())
                {
                    try
                    {
                        Indices.Add(indexName, index);

                        return;
                    }
                    finally
                    {
                        FinishWriteResource();
                    }
                }

                throw new CollisionException();
            }

            Logger.LogError(String.Format("Could not find index plugin with name \"{0}\".", indexPluginName));
        }
Beispiel #29
0
        private List <MarketOrder> GetAccountHistoryOrders(FarmAccount account)
        {
            var context = account.GetContext();

            byte[] buffer;
            context.GetHistoryOrdersCompressed(account.AccountId, startDate, out buffer);
            if (buffer == null || buffer.Length == 0)
            {
                return(null);
            }

            try
            {
                using (var reader = new SerializationReader(buffer))
                {
                    var array = reader.ReadObjectArray(typeof(MarketOrder));
                    if (array != null && array.Length > 0)
                    {
                        return(array.Cast <MarketOrder>().ToList());
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetHistoryOrdersUncompressed() - serialization error", ex);
                return(null);
            }
        }
Beispiel #30
0
        public static async Task Handle(Packet p, Presence pr)
        {
            var ms = new MemoryStream(p.Data);

            using var reader = new SerializationReader(ms);

            var presenceIds = new List <int>();
            int length      = reader.ReadInt16();

            for (var i = 0; i < length; i++)
            {
                presenceIds.Add(reader.ReadInt32());
            }

            foreach (var prId in presenceIds)
            {
                var otherPresence = PresenceManager.GetPresenceById(prId);
                if (otherPresence is not null)
                {
                    await pr.UserPresence(otherPresence);
                }
                else
                {
                    await pr.UserLogout(prId);
                }
            }
        }
Beispiel #31
0
        /// <summary>
        /// Opens a serialized service
        /// </summary>
        /// <param name="serviceName">Service name</param>
        /// <param name="servicePluginName">Service plugin name</param>
        /// <param name="reader">Serialization reader</param>
        /// <param name="fallen8">Fallen-8</param>
        /// <param name="startService">Start the service?</param>
        internal void OpenService(string serviceName, string servicePluginName, SerializationReader reader, Fallen8 fallen8, Boolean startService)
        {
            IService service;

            if (PluginFactory.TryFindPlugin(out service, servicePluginName))
            {
                if (WriteResource())
                {
                    try
                    {
                        if (Services.ContainsKey(serviceName))
                        {
                            Logger.LogError(String.Format("A service with the same name \"{0}\" already exists.", serviceName));
                        }

                        service.Load(reader, fallen8);

                        if (service.TryStart())
                        {
                            Services.Add(serviceName, service);
                        }
                    }
                    finally
                    {
                        FinishWriteResource();
                    }

                    return;
                }

                throw new CollisionException();
            }

            Logger.LogError(String.Format("Could not find service plugin with name \"{0}\".", servicePluginName));
        }
        public RequestStatus GetHistoryOrdersUncompressed(int? accountId, DateTime? startDate, out List<MarketOrder> orders)
        {
            orders = null;

            byte[] buffer;
            var retVal = proxy.GetHistoryOrdersCompressed(accountId, startDate, out buffer);
            if (buffer == null || buffer.Length == 0) return retVal;

            try
            {
                using (var reader = new SerializationReader(buffer))
                {
                    var array = reader.ReadObjectArray(typeof (MarketOrder));
                    if (array != null && array.Length > 0)
                        orders = array.Cast<MarketOrder>().ToList();
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetHistoryOrdersUncompressed() - serialization error", ex);
                return RequestStatus.SerializationError;
            }

            return retVal;
        }
Beispiel #33
0
        void IFastSerializable.Deserialize(SerializationReader reader)
        {
            base.Deserialize(reader);
            string name = reader.ReadString();

            part = SpeechPart.GetPart(name);
        }
        public static StateBag DeserializeStateBag(SerializationReader reader)
        {
            var flags = reader.ReadOptimizedBitVector32();
            var stateBag = new StateBag(flags[StateBagIsIgnoreCase]);

            if (flags[StateBagHasDirtyEntries])
            {
                var count = reader.ReadOptimizedInt32();

                for(var i = 0; i < count; i++)
                {
                    var key = reader.ReadOptimizedString();
                    var value = reader.ReadObject();

            // ReSharper disable PossibleNullReferenceException
                    stateBag.Add(key, value).IsDirty = true;
            // ReSharper restore PossibleNullReferenceException
                }
            }

            if (flags[StateBagHasCleanEntries])
            {
                var count = reader.ReadOptimizedInt32();

                for(var i = 0; i < count; i++)
                {
                    var key = reader.ReadOptimizedString();
                    var value = reader.ReadObject();

                    stateBag.Add(key, value);
                }
            }
            return stateBag;
        }
        public ForecastItem(SerializationInfo info, StreamingContext context)
        {
            var reader = SerializationReader.GetReader(info);

            AccountId    = reader.ReadString();
            Amount       = reader.ReadInt64();
            CategoryId   = reader.ReadString();
            CategoryName = reader.ReadString();
            Date         = reader.ReadDateTime();
            if (reader.ReadBoolean())
            {
                FlagColor = (FlagColor)reader.ReadByte();
            }
            ForecastItemType          = (ForecastItemType)reader.ReadByte();
            Funded                    = reader.ReadInt64();
            IsSplit                   = reader.ReadBoolean();
            Memo                      = reader.ReadString();
            PayeeId                   = reader.ReadString();
            PayeeName                 = reader.ReadString();
            ScheduledSubTransactionId = reader.ReadString();
            ScheduledTransactionId    = reader.ReadString();
            SubTransactionId          = reader.ReadString();
            TransactionId             = reader.ReadString();
            TransferAccountId         = reader.ReadString();
        }
Beispiel #36
0
        public override void Load(SerializationReader Reader)
        {
            this.village = HistoricEntity.Load(Reader, XRLCore.Core.Game.sultanHistory).GetCurrentSnapshot();
            this.amount  = Reader.ReadSingle();
            this.faction = Factions.get(Reader.ReadString());

            int countTales = Reader.ReadInt32();

            this.historytales = new List <JournalVillageNote>();
            List <JournalVillageNote> allnotes = JournalAPI.GetNotesForVillage(village.entity.id);

            for (int i = 0; i < countTales; i++)
            {
                string             thissecretid = Reader.ReadString();
                JournalVillageNote note         = allnotes.FirstOrDefault(c => c.secretid == thissecretid);
                if (note != null)
                {
                    this.historytales.Add(note);
                }
            }
            int counttales = Reader.ReadInt32();

            this.tales = new List <string>();
            for (int i = 0; i < counttales; i++)
            {
                this.tales.Add(Reader.ReadString());
            }
        }
            public void Deserialize(byte[] mySerializedBytes)
            {
                var reader = new SerializationReader(mySerializedBytes);

                ObjectLocation = reader.ReadString();
                RightUUID       = new UUID(reader.ReadByteArray());
                EntitiyUUID     = new UUID(reader.ReadByteArray());
            }
Beispiel #38
0
        /// <summary>
        /// Implementing the ISerializable to provide a faster, more optimized
        /// serialization for the class.
        /// </summary>
        public EnvelopeStamp(SerializationInfo info, StreamingContext context)
        {
            // Get from the info.
            SerializationReader reader = new SerializationReader((byte[])info.GetValue("data", typeof(byte[])));

            _stampId = reader.ReadInt64();
            _receiverId = (ClientId)reader.ReadObject();
            _senderId = (ClientId)reader.ReadObject();
        }
Beispiel #39
0
        /// <exclude/>
        public Index(SerializationInfo serializationInfo, StreamingContext streamingContext)
        {
            if (SerializerHelper.UseFastSerialization)
            {
                _columns = null;

                using (SerializationReader reader = new SerializationReader((byte[])serializationInfo.GetValue("d", typeof(byte[]))))
                {
                    UniqueId = reader.ReadString();
                    Lookups.Add(UniqueId, this);
                    _alias = reader.ReadString();
                    _columnIds = reader.ReadStringArray();
                    _enabled = reader.ReadBoolean();
                    _isUserDefined = reader.ReadBoolean();
                    _name = reader.ReadString();
                    // TODO: Parent
                    _type = reader.ReadString();
                    _userOptions = (List<IUserOption>)reader.ReadObject();
                }
            }
            else
            {
                int version = 0;

                if (SerializationVersionExists)
                {
                    try
                    {
                        version = serializationInfo.GetInt32("SerializationVersion");
                    }
                    catch (SerializationException)
                    {
                        // ignore
                        SerializationVersionExists = false;
                    }
                }
                _alias = serializationInfo.GetString("Alias");
                _columns = (List<Column>)serializationInfo.GetValue("Columns", ModelTypes.ColumnList);
                _enabled = serializationInfo.GetBoolean("Enabled");
                //this._exposedUserOptions = serializationInfo.GetValue("ExposedUserOptions", ModelTypes.Object);
                _isUserDefined = serializationInfo.GetBoolean("IsUserDefined");
                _name = serializationInfo.GetString("Name");
                _parent = (ScriptObject)serializationInfo.GetValue("Parent", ModelTypes.ScriptObject);
                _type = serializationInfo.GetString("Type");
                _userOptions = (List<IUserOption>)serializationInfo.GetValue("UserOptions", ModelTypes.UserOptionList);

                for (int i = 0; i < _userOptions.Count; i++)
                {
                    _userOptions[i].Owner = this;
                }
                if (version >= 8)
                {
                    _description = serializationInfo.GetString("Description");
                }
            }
        }
Beispiel #40
0
        public void Deserialize(byte[] Data)
        {
            SerializationReader reader = new SerializationReader(Data);
            
			AccountName = (String)reader.ReadObject();
            DeviceID = (String)reader.ReadObject();
			Timestamp = (String)reader.ReadObject();
			Latitude = (String)reader.ReadObject();
			Longitude = (String)reader.ReadObject();
			AccuracyInMeters = (String)reader.ReadObject();
        }
Beispiel #41
0
            public void Deserialize(byte[] mySerializedBytes)
            {
                SerializationReader reader = new SerializationReader(mySerializedBytes);

                ServiceGlobalUniqueName         = reader.ReadString();
                String _ServiceUri              = reader.ReadString();
                ServiceType                     = (DiscoverableServiceType)reader.ReadOptimizedByte();

                if (!Uri.TryCreate(_ServiceUri,UriKind.Absolute,out ServiceUri))
                    throw new NotificationException_InvalidNotificationPayload("IP not parseable. Notification Packet invalid!");
            }
Beispiel #42
0
        /// <summary>
        /// Implementing the ISerializable to provide a faster, more optimized
        /// serialization for the class using the fast serialization elements.
        /// </summary>
        public Envelope(SerializationInfo info, StreamingContext context)
        {
            // Get from the info.
            SerializationReader reader = new SerializationReader((byte[])info.GetValue("data", typeof(byte[])));

            _duplicationMode = (DuplicationModeEnum)reader.ReadInt32();
            _executionModel = (ExecutionModelEnum)reader.ReadInt32();
            _message = reader.ReadObject();
            _transportHistory = (EnvelopeTransportation)reader.ReadObject();
            _transportTargetAddress = (EnvelopeTransportation)reader.ReadObject();
        }
        public static MarketOrder DeserializeOrder(SerializationReader reader)
        {
            var deal = new MarketOrder
            {
                ID = reader.ReadInt32(),
                AccountID = reader.ReadInt32(),
                Comment = reader.ReadString(),
                ExitReason = (PositionExitReason)reader.ReadInt16(),
                ExpertComment = reader.ReadString(),
                PriceEnter = reader.ReadSingle(),
                ResultDepo = reader.ReadSingle(),
                ResultPoints = reader.ReadSingle(),
                Side = reader.ReadSByte(),
                State = (PositionState) reader.ReadInt16(),
                Symbol = reader.ReadString(),
                TimeEnter = reader.ReadDateTime(),
                Trailing = reader.ReadString(),
                Volume = reader.ReadInt32(),
                VolumeInDepoCurrency = reader.ReadSingle()
            };

            // nullable values
            var flags = reader.ReadOptimizedBitVector32();

            if (flags[magicIsValued])
                deal.Magic = reader.ReadInt32();

            if (flags[pendingOrderIdIsValued])
                deal.PendingOrderID = reader.ReadInt32();

            if (flags[priceBestIsValued])
                deal.PriceBest = reader.ReadSingle();

            if (flags[priceExitIsValued])
                deal.PriceExit = reader.ReadSingle();

            if (flags[priceWorstIsValued])
                deal.PriceWorst = reader.ReadSingle();

            if (flags[stopLossIsValued])
                deal.StopLoss = reader.ReadSingle();

            if (flags[swapIsValued])
                deal.Swap = reader.ReadSingle();

            if (flags[takeProfitIsValued])
                deal.TakeProfit = reader.ReadSingle();

            if (flags[timeExitIsValued])
                deal.TimeExit = reader.ReadDateTime();

            return deal;
        }
		public object Deserialize(SerializationReader reader, Type type)
		{
			if (type == typeof(Color))
			{
				return DeserializeColor(reader);
			}

			else
			{
				throw new InvalidOperationException(string.Format("{0} does not support Type: {1}", GetType(), type));
			}
		}
            public void Deserialize(byte[] mySerializedBytes)
            {
                var _SerializationReader = new SerializationReader(mySerializedBytes);

                StorageURIs = new List<String>();
                UInt32 numberOfStorageURIs = _SerializationReader.ReadUInt32();

                for(UInt32 i=0; i<numberOfStorageURIs; i++)
                    StorageURIs.Add(_SerializationReader.ReadString());

                StorageType = _SerializationReader.ReadString();
                StorageSize = _SerializationReader.ReadUInt64();
            }
        internal static readonly BitVector32.Section UnitType = BitVector32.CreateSection(9); // 4 bits

        #endregion Fields

        #region Methods

        // Note this is a simplistic version as it assumes defaults for comparer, hashcodeprovider, loadfactor etc.
        public static Hashtable DeserializeHashtable(SerializationReader reader)
        {
            var keys = reader.ReadOptimizedObjectArray();
            var values = reader.ReadOptimizedObjectArray();
            var result = new Hashtable(keys.Length);

            for(var i = 0; i < keys.Length; i++)
            {
                result[keys[i]] = values[i];
            }

            return result;
        }
        public void Deserialize(byte[] Data)
        {
            SerializationReader reader = new SerializationReader(Data);
            
			AccountName = (String)reader.ReadObject();
			LatitudeID = (String)reader.ReadObject();
			Timecode = (Int64)reader.ReadObject();
			reverseGeocode = (String)reader.ReadObject();
			Latitude = (Double)reader.ReadObject();
			Longitude = (Double)reader.ReadObject();
			AccuracyInMeters = (Int32)reader.ReadObject();

        }
Beispiel #48
0
        public void Deserialize(ref SerializationReader mySerializationReader)
        {
            Features = new List<FeatureIDs>();
            UInt32 cnt = mySerializationReader.ReadUInt32();

            for (int i = 0; i < cnt; i++)
            {
                byte entry = mySerializationReader.ReadOptimizedByte();
                Features.Add((FeatureIDs)entry);
            }

            NumberOfLicensedCPUs = mySerializationReader.ReadInt32();
            NumberOfLicensedRAM  = mySerializationReader.ReadInt32();
        }
Beispiel #49
0
        /// <summary>
        /// Implementing the ISerializable to provide a faster, more optimized
        /// serialization for the class.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        public SuperPoolCall(SerializationInfo info, StreamingContext context)
        {
            // Get from the info.
            SerializationReader reader = new SerializationReader((byte[])info.GetValue("data", typeof(byte[])));

            Id = reader.ReadInt64();
            State = (StateEnum)reader.ReadInt32();
            RequestResponse = reader.ReadBoolean();
            Parameters = reader.ReadObjectArray();
            string methodInfoName = reader.ReadString();

            _methodInfoName = methodInfoName;
            MethodInfoLocal = SerializationHelper.DeserializeMethodBaseFromString(_methodInfoName, true);
        }
        public void TestNull()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                sw.Write<object>(null);

                sw.Write<int[]>(null);
                sw.Write<List<int>>(null);
                sw.Write<Dictionary<int, string>>(null);

                sw.Write<TestSerializable>(null);
            }
        }
        /// <summary>
        /// Implementing the ISerializable to provide a faster, more optimized
        /// serialization for the class.
        /// </summary>
        public EnvelopeTransportation(SerializationInfo info, StreamingContext context)
        {
            // Get from the info.
            SerializationReader reader = new SerializationReader((byte[])info.GetValue("data", typeof(byte[])));

            object[] stamps = reader.ReadObjectArray();
            if (stamps.Length == 0)
            {
                _stamps = new Deque<EnvelopeStamp>();
            }
            else
            {
                _stamps = new Deque<EnvelopeStamp>((EnvelopeStamp[])stamps);
            }
        }
		public static Color DeserializeColor(SerializationReader reader)
		{
			var flags = reader.ReadOptimizedBitVector32();

			if (flags[ColorIsKnown]) return Color.FromKnownColor((KnownColor) reader.ReadOptimizedInt32());
			if (flags[ColorHasName]) return Color.FromName(reader.ReadOptimizedString());
			if (!flags[ColorHasValue]) return Color.Empty;

			var red = flags[ColorHasRed] ? reader.ReadByte() : (byte) 0;
			var green = flags[ColorHasGreen] ? reader.ReadByte() : (byte) 0;
			var blue = flags[ColorHasBlue] ? reader.ReadByte() : (byte) 0;
			var alpha = flags[ColorHasAlpha] ? reader.ReadByte() : (byte) 0;

			return Color.FromArgb(alpha, red, green, blue);
		}
        public void TestUTF16Chars()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms, new UnicodeEncoding()))
            using (SerializationReader sr = new SerializationReader(ms, new UnicodeEncoding()))
            {
                for (int i = 0; i < 55296; i++)
                    sw.Write((char)i);

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < 55296; i++)
                    Assert.AreEqual((char)i, sr.Read<char>());
            }
        }
        public void TestUTF16String()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms, new UnicodeEncoding()))
            using (SerializationReader sr = new SerializationReader(ms, new UnicodeEncoding()))
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < 55296; i++)
                    sb.Append((char)i);
                string res = sb.ToString();
                sw.Write(res);

                sw.Flush();
                ms.Position = 0;

                Assert.AreEqual(res, sr.Read<string>());
            }
        }
Beispiel #55
0
		/// <exclude/>
		public UserOption(SerializationInfo serializationInfo, StreamingContext streamingContext)
			: base()
		{
			try
			{
				using (Slyce.Common.SerializationReader reader = new SerializationReader((byte[])serializationInfo.GetValue("d", typeof(byte[]))))
				{
					_name = reader.ReadString();
					_dataType = (Type)reader.ReadObject();
					_value = reader.ReadObject();
				}
			}
			catch
			{
				this._name = serializationInfo.GetString("_name");
				this._dataType = (Type)serializationInfo.GetValue("_dataType", typeof(Type));
				this._value = serializationInfo.GetValue("_value", typeof(object));
			}
		}
        public void TestBytes()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                byte[] values = new byte[Config.MULTI_TEST_COUNT];
                rand.NextBytes(values);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    sw.Write(values[i]);

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    Assert.AreEqual(values[i], sr.Read<byte>());
            }
        }
        public void TestBasicDictionary()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                Dictionary<int, float> dict = new Dictionary<int, float>(Config.MULTI_TEST_COUNT);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    dict[rand.Next(int.MinValue, int.MaxValue)] = (float)rand.NextDouble();
                sw.Write(dict);

                sw.Flush();
                ms.Position = 0;

                Dictionary<int, float> ret = sr.Read<Dictionary<int, float>>();
                foreach (KeyValuePair<int, float> kvp in dict)
                    Assert.AreEqual(kvp.Value, ret[kvp.Key]);
            }
        }
        public void TestBasicArray()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                int[] array = new int[Config.MULTI_TEST_COUNT];
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    array[i] = rand.Next(int.MinValue, int.MaxValue);
                sw.Write(array);

                sw.Flush();
                ms.Position = 0;

                int[] ret = sr.Read<int[]>();
                for (int i = 0; i < ret.Length; i++)
                    Assert.AreEqual(array[i], ret[i]);
            }
        }
        public void TestBasicList()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                List<int> list = new List<int>(Config.MULTI_TEST_COUNT);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    list.Add(rand.Next(int.MinValue, int.MaxValue));
                sw.Write(list);

                sw.Flush();
                ms.Position = 0;

                List<int> ret = sr.Read<List<int>>();
                for (int i = 0; i < list.Count; i++)
                    Assert.AreEqual(list[i], ret[i]);
            }
        }
		public object Deserialize(SerializationReader reader, Type type)
		{
			if (type == typeof(Pair))
				return DeserializePair(reader);

			else if (type == typeof(Triplet))
				return DeserializeTriplet(reader);

			else if (type == typeof(StateBag))
				return DeserializeStateBag(reader);

			else if (type == typeof(Unit))
				return DeserializeUnit(reader);

			else if (type == typeof(Hashtable))
				return DeserializeHashtable(reader);

			else
			{
				throw new InvalidOperationException(string.Format("{0} does not support Type: {1}", GetType(), type));
			}
		}