Exemplo n.º 1
0
 public static TransHistory ReadFromJObject(JObject o)
 {
     return new TransHistory
     {
         List =
             o.OfType<KeyValuePair<string, JToken>>()
                 .ToDictionary(a => int.Parse(a.Key), a => Transaction.ReadFromJObject(a.Value as JObject))
     };
 }
Exemplo n.º 2
0
		public static OrderList ReadFromJObject(JObject o)
		{
		    var orderList = new OrderList() {List = new Dictionary<int, Order>()};
		    var res = o.Properties().ToList();
		    foreach (JProperty property in res)
		    {
		        orderList.List.Add(int.Parse(property.Name), Order.ReadFromJObject(property.Value as JObject));
		    }

		    return orderList;

			return new OrderList() {
                List = o.OfType<KeyValuePair<string, JToken>>().ToDictionary(item => int.Parse(item.Key), item => Order.ReadFromJObject(item.Value as JObject))
			};
		}
Exemplo n.º 3
0
        private IEnumerable<StatEntry> Stat(JObject hitTable)
        {
            var table = hitTable
                .OfType<JProperty>()
                .Select(x => new
                {
                    Database = x.Name,
                    Hashes = ((JObject)x.Value).OfType<JProperty>()
                        .Select(y => new
                        {
                            Hash = GetStateHash(y.Name),
                            LastHitTime = new DateTime((long)y.Value)
                        })
                }).SelectMany(x => x.Hashes, (d, h) => new
                {
                    d.Database,
                    h.Hash,
                    h.LastHitTime
                });
            var root = GetCachesDir(false);
            var dirs = root.Exists ? root.EnumerateDirectories() : Enumerable.Empty<DirectoryInfo>();
            var files = dirs
                .Select(x => new
                {
                    Database = x.Name,
                    Files = x.EnumerateFiles()
                }).SelectMany(x => x.Files, (d, f) => new
                {
                    d.Database,
                    Hash = GetStateHash(f.Name),
                    FilePath = f.FullName
                });

            var lookTable = table.ToLookup(x => new { x.Database, x.Hash });
            var lookFiles = files.ToLookup(x => new { x.Database, x.Hash });

            var keys = lookTable.ToHashSet(x => x.Key);
            keys.UnionWith(lookFiles.Select(x => x.Key));

            return
                from key in keys
                let tLook = lookTable[key]
                let fLook = lookFiles[key]
                from t in tLook.DefaultIfEmpty()
                from f in fLook.DefaultIfEmpty()
                select new StatEntry(key.Database, key.Hash, f == null ? null : f.FilePath, t == null ? (DateTime?)null : t.LastHitTime);
        }
Exemplo n.º 4
0
		public static TradeHistory ReadFromJObject(JObject o) {
			return new TradeHistory() {
				List = o.OfType<KeyValuePair<string, JToken>>().ToDictionary(item => int.Parse(item.Key), item => Trade.ReadFromJObject(item.Value as JObject))
			};
		}
Exemplo n.º 5
0
		public static OrderList ReadFromJObject(JObject o) {
			return new OrderList() {
				List = o.OfType<KeyValuePair<string, JToken>>().ToDictionary(item => int.Parse(item.Key), item => Order.ReadFromJObject(item.Value as JObject))
			};
		}