Ejemplo n.º 1
0
        private static void HandleValue(string key, ComponentConfiguration config, Dictionary<string, object> data)
        {
            HandleTotalValue(key, config, data);
            foreach (var dataItem in data)
            {
                var itemKey = dataItem.Key;
                if (config.ComponentItems.ContainsKey(itemKey))
                {
                    var configItem = config.ComponentItems[itemKey];
                    var db = server.GetDatabase(key);
                    var collection = db.GetCollection(itemKey);
                    var doc = new BsonDocument().Add("V", BsonValue.Create(dataItem.Value));
                    doc.SetDocumentId(DateTime.Now.ToUniversalTime());
                    if (configItem.ItemValueType == ItemValueType.TextValue)
                    {
                        collection.RemoveAll();
                        collection.Insert(doc);
                    }
                    else if (configItem.ItemValueType == ItemValueType.ExpressionValue)
                    {

                    }
                    else
                    {
                        collection.Insert(doc);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private static void HandleTotalValue(string key, ComponentConfiguration config, Dictionary<string, object> rawData)
 {
     if (!dataCache.ContainsKey(key))
     {
         var cache = new Dictionary<string, long>();
         foreach (var k in new List<string>(rawData.Keys))
         {
             if (config.ComponentItems.ContainsKey(k))
             {
                 var configItem = config.ComponentItems[k];
                 if (configItem.ItemValueType == ItemValueType.TotalValue)
                 {
                     var current = Convert.ToInt64(rawData[k]);
                     cache.Add(k, current);
                     rawData[k] = 0;
                 }
             }
         }
         dataCache.Add(key, cache);
     }
     else
     {
         var cache = dataCache[key];
         foreach (var k in new List<string>(rawData.Keys))
         {   
             if (config.ComponentItems.ContainsKey(k))
             {
                 var configItem = config.ComponentItems[k];
                 if (configItem.ItemValueType == ItemValueType.TotalValue)
                 {
                     var current = Convert.ToInt64(rawData[k]);
                     if (cache.ContainsKey(k))
                     {
                         rawData[k] = Math.Max(current - cache[k], 0);
                         cache[k] = current;
                     }
                     else
                     {
                         cache.Add(k, current);
                         rawData[k] = 0;
                     }
                 }
             }
         }
     }
 }