コード例 #1
0
ファイル: MarketUploader.cs プロジェクト: warlof/EveHQ
        private static UnifiedDataFormat NormalizeFormat(
            KeyValuePair <object,
                          object> result,
            IEnumerable <IMarketDataReceiver> receivers)
        {
            if (result.Key == null)
            {
                return(null);
            }

            UnifiedDataFormat data;

            // the key of the KVP is actually a set of data types
            var objectTuple = result.Key as Tuple <object>;

            if (objectTuple == null)
            {
                return(null);
            }

            var hashedObjects = objectTuple.Item1 as List <object>;

            if (hashedObjects == null || hashedObjects.Count < 4)
            {
                return(null);
            }

            // convert it to an array so that indexer access is possible.
            object[] dataKeys = hashedObjects.ToArray();

            // check that this result contains market information
            if (dataKeys[0].ToString() != "marketProxy")
            {
                return(null);
            }

            // these offsets are assumed to be fixed
            long regionId = dataKeys[2].ToInt64();
            long typeId   = dataKeys[3].ToInt64();

            // the value half of the KVP is a dictionary of various data types.
            var valueBag = result.Value as Dictionary <object, object>;

            if (valueBag == null)
            {
                return(null);
            }

            // Columns and Rows info
            var values = valueBag["lret"] as List <object>;

            if (values == null)
            {
                return(null);
            }

            // time stamp collection... one is a windows 64bit timestamp.. the other, no idea.
            var versionInfo = valueBag["version"] as List <object>;

            if (versionInfo == null)
            {
                return(null);
            }

            DateTimeOffset fileGenerationTime = DateTimeOffset.FromFileTime(versionInfo[0].ToInt64()).ToUniversalTime();

            // create the UDF appropriate object based on the method name used for the cache file.
            switch (dataKeys[1].ToString())
            {
            // GetXXXPriceHistory gets the historical data for a given item.
            case "GetNewPriceHistory":
            case "GetOldPriceHistory":

                var historyData = new UnifiedDataFormat <HistoryRowset> {
                    Columns = HistoryRowset.ColumnNames
                };
                var historyRows = new HistoryRowset
                {
                    GeneratedAt = fileGenerationTime.ToString(Iso8601Format, CultureInfo.InvariantCulture),
                    RegionID    = regionId.ToInvariantString(),
                    TypeID      = typeId.ToInvariantString()
                };
                historyRows.Rows.AddRange(
                    values.Cast <Dictionary <object, object> >()
                    .Select(
                        record =>
                        new HistoryRow
                {
                    Average = record["avgPrice"].ToDouble(),
                    Date    =
                        DateTimeOffset.FromFileTime(record["historyDate"].ToInt64())
                        .ToUniversalTime()
                        .ToString(Iso8601Format, CultureInfo.InvariantCulture),
                    High     = record["highPrice"].ToDouble(),
                    Low      = record["lowPrice"].ToDouble(),
                    Orders   = record["orders"].ToInt64(),
                    Quantity = record["volume"].ToInt64(),
                }));
                historyData.Rowsets.Add(historyRows);
                historyData.ResultType = ResultType.History;

                data = historyData;
                break;

            // GetOrders is for the current active order list for an item.
            case "GetOrders":
                var orderData = new UnifiedDataFormat <OrderRowset> {
                    Columns = OrderRowset.ColumnNames
                };
                var orderRowset = new OrderRowset
                {
                    GeneratedAt = fileGenerationTime.ToString(Iso8601Format, CultureInfo.InvariantCulture),
                    RegionID    = regionId.ToInvariantString(),
                    TypeID      = typeId.ToInvariantString()
                };
                orderRowset.Rows.AddRange(
                    values.Cast <List <object> >()
                    .SelectMany(
                        obj => obj.Cast <Dictionary <object, object> >(),
                        (obj, order) =>
                        new OrderRow
                {
                    Bid       = order["bid"].ToBoolean(),
                    Duration  = order["duration"].ToInt64(),
                    IssueDate =
                        DateTimeOffset.FromFileTime(order["issueDate"].ToInt64())
                        .ToUniversalTime()
                        .ToString(Iso8601Format, CultureInfo.InvariantCulture),
                    MinVolume     = order["minVolume"].ToInt64(),
                    OrderId       = order["orderID"].ToInt64(),
                    Price         = order["price"].ToDouble(),
                    Range         = order["range"].ToInt64(),
                    SolarSystemId = order["solarSystemID"].ToInt64(),
                    StationId     = order["stationID"].ToInt64(),
                    VolEntered    = order["volEntered"].ToInt64(),
                    VolRemaining  = order["volRemaining"].ToInt64()
                }));
                orderData.Rowsets.Add(orderRowset);
                orderData.ResultType = ResultType.Orders;

                data = orderData;
                break;

            // any other value we encounter means this isn't a file we should be processing.
            default:
                return(null);
            }

            // add in the upload keys
            data.UploadKeys = new List <UploadKey>();
            data.UploadKeys.AddRange(receivers.Select(target => target.UnifiedUploadKey));

            return(data);
        }
コード例 #2
0
ファイル: MarketUploader.cs プロジェクト: itguy327/EveHQ
        private static UnifiedDataFormat NormalizeFormat(
            KeyValuePair<object, 
                object> result,
            IEnumerable<IMarketDataReceiver> receivers)
        {
            if (result.Key == null)
            {
                return null;
            }

            UnifiedDataFormat data;

            // the key of the KVP is actually a set of data types
            var objectTuple = result.Key as Tuple<object>;
            if (objectTuple == null)
            {
                return null;
            }

            var hashedObjects = objectTuple.Item1 as List<object>;
            if (hashedObjects == null || hashedObjects.Count < 4)
            {
                return null;
            }

            // convert it to an array so that indexer access is possible.
            object[] dataKeys = hashedObjects.ToArray();

            // check that this result contains market information
            if (dataKeys[0].ToString() != "marketProxy")
            {
                return null;
            }

            // these offsets are assumed to be fixed
            long regionId = dataKeys[2].ToInt64();
            long typeId = dataKeys[3].ToInt64();

            // the value half of the KVP is a dictionary of various data types.
            var valueBag = result.Value as Dictionary<object, object>;
            if (valueBag == null)
            {
                return null;
            }

            // Columns and Rows info
            var values = valueBag["lret"] as List<object>;
            if (values == null)
            {
                return null;
            }

            // time stamp collection... one is a windows 64bit timestamp.. the other, no idea.
            var versionInfo = valueBag["version"] as List<object>;
            if (versionInfo == null)
            {
                return null;
            }

            DateTimeOffset fileGenerationTime = DateTimeOffset.FromFileTime(versionInfo[0].ToInt64()).ToUniversalTime();

            // create the UDF appropriate object based on the method name used for the cache file.
            switch (dataKeys[1].ToString())
            {
                    // GetXXXPriceHistory gets the historical data for a given item.
                case "GetNewPriceHistory":
                case "GetOldPriceHistory":

                    var historyData = new UnifiedDataFormat<HistoryRowset> { Columns = HistoryRowset.ColumnNames };
                    var historyRows = new HistoryRowset
                    {
                        GeneratedAt = fileGenerationTime.ToString(Iso8601Format, CultureInfo.InvariantCulture),
                        RegionID = regionId.ToInvariantString(),
                        TypeID = typeId.ToInvariantString()
                    };
                    historyRows.Rows.AddRange(
                        values.Cast<Dictionary<object, object>>()
                            .Select(
                                record =>
                                    new HistoryRow
                                    {
                                        Average = record["avgPrice"].ToDouble(),
                                        Date =
                                            DateTimeOffset.FromFileTime(record["historyDate"].ToInt64())
                                                .ToUniversalTime()
                                                .ToString(Iso8601Format, CultureInfo.InvariantCulture),
                                        High = record["highPrice"].ToDouble(),
                                        Low = record["lowPrice"].ToDouble(),
                                        Orders = record["orders"].ToInt64(),
                                        Quantity = record["volume"].ToInt64(),
                                    }));
                    historyData.Rowsets.Add(historyRows);
                    historyData.ResultType = ResultType.History;

                    data = historyData;
                    break;

                    // GetOrders is for the current active order list for an item.
                case "GetOrders":
                    var orderData = new UnifiedDataFormat<OrderRowset> { Columns = OrderRowset.ColumnNames };
                    var orderRowset = new OrderRowset
                    {
                        GeneratedAt = fileGenerationTime.ToString(Iso8601Format, CultureInfo.InvariantCulture),
                        RegionID = regionId.ToInvariantString(),
                        TypeID = typeId.ToInvariantString()
                    };
                    orderRowset.Rows.AddRange(
                        values.Cast<List<object>>()
                            .SelectMany(
                                obj => obj.Cast<Dictionary<object, object>>(),
                                (obj, order) =>
                                    new OrderRow
                                    {
                                        Bid = order["bid"].ToBoolean(),
                                        Duration = order["duration"].ToInt64(),
                                        IssueDate =
                                            DateTimeOffset.FromFileTime(order["issueDate"].ToInt64())
                                                .ToUniversalTime()
                                                .ToString(Iso8601Format, CultureInfo.InvariantCulture),
                                        MinVolume = order["minVolume"].ToInt64(),
                                        OrderId = order["orderID"].ToInt64(),
                                        Price = order["price"].ToDouble(),
                                        Range = order["range"].ToInt64(),
                                        SolarSystemId = order["solarSystemID"].ToInt64(),
                                        StationId = order["stationID"].ToInt64(),
                                        VolEntered = order["volEntered"].ToInt64(),
                                        VolRemaining = order["volRemaining"].ToInt64()
                                    }));
                    orderData.Rowsets.Add(orderRowset);
                    orderData.ResultType = ResultType.Orders;

                    data = orderData;
                    break;

                    // any other value we encounter means this isn't a file we should be processing.
                default:
                    return null;
            }

            // add in the upload keys
            data.UploadKeys = new List<UploadKey>();
            data.UploadKeys.AddRange(receivers.Select(target => target.UnifiedUploadKey));

            return data;
        }