示例#1
0
        public void AddRawData(Business.RawData raw)
        {
            foreach (KeyValuePair <string, DAO.CalculType> kv in Type)
            {
                if (!ResultCalculType.ContainsKey(raw.MacAddress))
                {
                    ResultCalculType.Add(raw.MacAddress, new Dictionary <string, double>());
                }
                if (!ResultCalculType[raw.MacAddress].ContainsKey(kv.Value.Period))
                {
                    ResultCalculType[raw.MacAddress].Add(kv.Value.Period, 0);
                }
                double temp = ResultCalculType[raw.MacAddress][kv.Value.Period];

                if (!Cache.ContainsKey(raw.MacAddress))
                {
                    Cache.Add(raw.MacAddress, new Dictionary <string, List <RawData> >());
                }
                if (!Cache[raw.MacAddress].ContainsKey(kv.Value.Period))
                {
                    Cache[raw.MacAddress].Add(kv.Value.Period, new List <RawData>());
                }
                Cache[raw.MacAddress][kv.Value.Period].Add(raw);

                temp = temp + raw.MetricValue;

                if (Cache[raw.MacAddress][kv.Value.Period].Count - 1 >= kv.Value.PeriodSecondCount)
                {
                    temp = temp - Cache[raw.MacAddress][kv.Value.Period][0].MetricValue;
                    Cache[raw.MacAddress][kv.Value.Period].RemoveAt(0);
                }
                ResultCalculType[raw.MacAddress][kv.Value.Period] = temp;
            }
        }
 public void AssignRawDataToCache(string raw)
 {
     Business.RawData temp = Mapper.MapperRawData.DAOToBusiness(new DAO.RawData(raw));
     if (temp != null)
     {
         if (Cache.ContainsKey(temp.Name))
         {
             Cache[temp.Name].AddRawData(temp);
         }
     }
 }
示例#3
0
        private void Client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
        {
            string mess = Encoding.UTF8.GetString(e.Message);

            Business.RawData temp = Mapper.MapperRawData.DAOToBusiness(new DAO.RawData(mess));

            if (temp != null)
            {
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(temp);
                Console.WriteLine(json);
                StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");

                try { HTTPClient.PostAsync(RawDataDetination, stringContent); } catch { }
                try { HTTPClient.PostAsync(CalculationEngine, stringContent); } catch { }
            }
        }