Esempio n. 1
0
 public async Task <object> Get([FromQuery] string name, string cache)
 {
     return(await Task.Run(async() => {
         try
         {
             var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no";
             if (isCache == "no")
             {
                 await CacheMemory.Remove(name);
             }
             var jsonResults = await CacheMemory.Get <IList <Form> >(name);
             if (jsonResults != null)
             {
                 return jsonResults;
             }
             var form = await Form.Get(name);
             await CacheMemory.SetAndExpiresDays(name, form, 1);
             return form;
         }
         catch (Exception ex)
         {
             Trace.TraceError(ex.ToString());
             return null;
         }
     }));
 }
Esempio n. 2
0
 public async Task <object> Get([FromQuery] string name, string lang, string cache)
 {
     return(await Task.Run(async() => {
         try
         {
             var keyword = name;
             var language = (string.IsNullOrWhiteSpace(lang)) ? "eng" : lang;
             var cacheKey = $"label:{name}:{language}";
             await AddCorOptions();
             var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no";
             if (isCache == "no")
             {
                 await CacheMemory.Remove(cacheKey);
             }
             var jsonResults = await CacheMemory.Get <List <DictionaryItem> >(cacheKey);
             if (jsonResults != null)
             {
                 return jsonResults;
             }
             List <DictionaryItem> labels = await Labels.Get(keyword, language);
             await CacheMemory.SetAndExpiresDays(cacheKey, labels, 1);
             return labels;
         }
         catch (Exception ex)
         {
             await Tracer.Exception("LabelController:Get", ex);
             return null;
         }
     }));
 }
Esempio n. 3
0
 public async Task <object> Get([FromQuery] string name, string cache)
 {
     return(await Task.Run(async() => {
         try
         {
             await AddCorOptions();
             var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no";
             if (isCache == "no")
             {
                 await CacheMemory.Remove(name);
             }
             var jsonResults = await CacheMemory.Get <object>(name);
             if (jsonResults != null)
             {
                 return jsonResults;
             }
             var datasource = await DataSource.Get(name);
             await CacheMemory.SetAndExpiresDays(name, datasource, 1);
             return datasource;
         }
         catch (Exception ex)
         {
             Trace.TraceError(ex.ToString());
             return Json(new object());
         }
     }));
 }
Esempio n. 4
0
        public async Task <object> Get([FromQuery] string name, string cache)
        {
            return(await Task.Run(async() => {
                try
                {
                    await AddCorOptions();
                    var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no";
                    if (isCache == "no")
                    {
                        await CacheMemory.Remove(name);
                    }

                    var jsonResults = await CacheMemory.Get <List <Media> >(name);
                    if (jsonResults != null)
                    {
                        return jsonResults;
                    }
                    var media = await Medias.Get(name);
                    await CacheMemory.SetAndExpiresDays(name, media, 1);
                    return media;
                }
                catch (Exception ex)
                {
                    Trace.TraceError((ex.ToString()));
                    return null;
                }
            }));
        }
Esempio n. 5
0
        public async Task <object> Get([FromQuery] string cache)
        {
            return(await Task.Run(async() =>
            {
                try
                {
                    await AddCorOptions();
                    var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no";
                    if (isCache == "no")
                    {
                        await CacheMemory.Remove("menu");
                    }

                    var jsonResults = await CacheMemory.Get <IList <Menu> >("menu");
                    if (jsonResults != null)
                    {
                        return jsonResults;
                    }
                    var menu = await Menu.Get();
                    await CacheMemory.SetAndExpiresDays("menu", menu, 1);
                    return menu;
                }
                catch (Exception ex)
                {
                    await Tracer.Exception("MenuController:Get", ex);
                    return null;
                }
            }));
        }
Esempio n. 6
0
        private static async Task GetKelvinHistogram(string kelvinQueueKey, COREALL sensor)
        {
            var kelvkinQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(kelvinQueueKey) ??
                                   new FixedQueue <decimal>();

            kelvkinQueueTemp.Enqueue(sensor.Kelvin);
            await CacheMemory.SetAndExpiresDays(kelvinQueueKey, kelvkinQueueTemp, 1);

            sensor.KelvinHistogram = kelvkinQueueTemp;
        }
Esempio n. 7
0
        private static async Task GetCelciusHistogram(string celciusQueueKey, COREALL sensor)
        {
            var celciusQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(celciusQueueKey) ??
                                   new FixedQueue <decimal>();

            celciusQueueTemp.Enqueue(sensor.Celcius);
            await CacheMemory.SetAndExpiresDays(celciusQueueKey, celciusQueueTemp, 1);

            sensor.CelciusHistogram = celciusQueueTemp;
        }
Esempio n. 8
0
        private static async Task GetFehrenheitHistogram(string fehrenheitQueueKey, COREALL sensor)
        {
            var fehrenheitQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(fehrenheitQueueKey) ??
                                      new FixedQueue <decimal>();

            fehrenheitQueueTemp.Enqueue(sensor.Fahrenheit);
            await CacheMemory.SetAndExpiresDays(fehrenheitQueueKey, fehrenheitQueueTemp, 1);

            sensor.FahrenheitHistogram = fehrenheitQueueTemp;
        }
Esempio n. 9
0
        private static async Task GetPpmHistogram(string ppmQueueKey, COREALL sensor)
        {
            var ppmQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(ppmQueueKey) ??
                               new FixedQueue <decimal>();

            ppmQueueTemp.Enqueue(sensor.PPM.Measurement);
            await CacheMemory.SetAndExpiresDays(ppmQueueKey, ppmQueueTemp, 1);

            sensor.PPM.Histogram = ppmQueueTemp;
        }
Esempio n. 10
0
        private static async Task GetHumidityHistogram(string humidityQueueKey, COREALL sensor)
        {
            var humidityQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(humidityQueueKey) ??
                                    new FixedQueue <decimal>();

            humidityQueueTemp.Enqueue(sensor.Humidity);
            await CacheMemory.SetAndExpiresDays(humidityQueueKey, humidityQueueTemp, 1);

            sensor.HumidityHistogram = humidityQueueTemp;
        }
Esempio n. 11
0
        public async Task <object> Get([FromQuery] string name,
                                       string serial,
                                       string version,
                                       string lic,
                                       string author,
                                       string value,
                                       string cache)
        {
            return(await Task.Run(async() => {
                try
                {
                    var cacheKey = $"sensor:{serial}:ENS210";
                    var fehrenheitQueueKey = $"fehrenheitListKey:{serial}:ENS210";
                    var celciusQueueKey = $"celciusListKey:{serial}:ENS210";
                    var kelvinQueueKey = $"kelvinListKey:{serial}:ENS210";
                    var humidityQueueKey = $"humidityListKey:{serial}:ENS210";
                    var ppmQueueKey = $"ppmListKey:{serial}:ENS210";

                    await AddCorOptions();
                    var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no";
                    if (isCache == "no")
                    {
                        await CacheMemory.Remove(cacheKey);
                    }
                    var jsonResults = await CacheMemory.Get <COREALL>(cacheKey);
                    if (jsonResults != null)
                    {
                        return jsonResults;
                    }
                    var sensor = await ICoreall.Get(serial, value);
                    sensor.LastRecord = DateTime.Now.ToString(CultureInfo.CurrentCulture);
                    sensor.Version = version ?? string.Empty;
                    sensor.Lic = lic ?? string.Empty;
                    sensor.Author = author ?? string.Empty;
                    sensor.Name = name ?? string.Empty;
                    await GetFehrenheitHistogram(fehrenheitQueueKey, sensor);
                    await GetCelciusHistogram(celciusQueueKey, sensor);
                    await GetKelvinHistogram(kelvinQueueKey, sensor);
                    await GetHumidityHistogram(humidityQueueKey, sensor);
                    await GetPpmHistogram(ppmQueueKey, sensor);

                    await CacheMemory.SetAndExpiresDays(cacheKey, sensor, 1);
                    return sensor;
                }
                catch (Exception ex)
                {
                    await Tracer.Exception("COREALLController:Get", ex);
                    return null;
                }
            }));
        }