Example #1
0
        public static void SaveData(string realmSlug, DataPoint dataPoint, List<DataPointToAuction> snapshots, List<Auction> auctions, List<Upgrade> upgrades, List<Modifier> modifiers)
        {
            var dir = $"data/{realmSlug}";
            var auctionIds = GetAuctionIds(realmSlug);

            if (!Directory.Exists("data")) Directory.CreateDirectory("data");
            if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);

            using (var stream = new FileStream(dir + DataPointsPath, FileMode.Append))
                dataPoint.Serialize(stream);

            using (var stream = new FileStream(dir + SnapshotsPath, FileMode.Append))
                foreach (var snapshot in snapshots)
                    snapshot.Serialize(stream);

            using (var stream = new FileStream(dir + AuctionsPath, FileMode.Append))
            {
                using (var idsStream = new FileStream(dir + AuctionIdsPath, FileMode.Append))
                {
                    foreach (var auction in auctions.Where(auction => !auctionIds.Contains(auction.Id)))
                    {
                        auction.Serialize(stream);
                        idsStream.Write(BitConverter.GetBytes(auction.Id), 0, 8);
                    }
                }
            }

            using (var stream = new FileStream(dir + UpgradesPath, FileMode.Append))
                foreach (var upgrade in upgrades.Where(upgrade => !auctionIds.Contains(upgrade.Auction)))
                    upgrade.Serialize(stream);

            using (var stream = new FileStream(dir + ModifiersPath, FileMode.Append))
                foreach (var modifier in modifiers.Where(a => !auctionIds.Contains(a.Auction)))
                    modifier.Serialize(stream);
        }
Example #2
0
        public static DataPoint Deserialize(Stream stream)
        {
            var reader = new BinaryReader(stream);
            var dataPoint = new DataPoint();
            dataPoint.RealmName = reader.ReadString();
            dataPoint.RealmSlug = reader.ReadString();
            dataPoint.TimeStamp = reader.ReadDouble();

            return dataPoint;
        }