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; } })); }
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()); } })); }
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; } })); }
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; } })); }
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; } })); }
public async Task <object> Get([FromQuery] string emailto, string emailfrom, string emailsubject, string emailtext, string emailattachment, string emailtype, string cache) { return(await Task.Run(async() => { try { if (emailto == null) { return new[] { "status", "need emailto" } } ; if (emailfrom == null) { return new[] { "status", "need emailfrom" } } ; if (emailsubject == null) { return new[] { "status", "need emailsubject" } } ; if (emailtext == null) { return new[] { "status", "need emailtext" } } ; var cacheKey = $"email:{emailfrom}:{emailsubject.Trim().Replace(" ", "").ToLower()}"; if (cache != null) { if (cache == "no") { await CacheMemory.Remove(cacheKey); } } var jsonResults = await CacheMemory.Get <object>(cacheKey); if (jsonResults != null) { return new[] { "status", "No eamil not sent. Waiting for cache to expired" } } ; await AddCorOptions(); await Email.Send(emailto, emailfrom, emailsubject, emailtext); var results = new [] { "status", "OK" }; await CacheMemory.SetAndExpiresSeconds(cacheKey, results, 10); return results; } catch (Exception ex) { await Tracer.Exception("SendEmailController:Get", ex); return null; } })); }
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; } })); }
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}:IAQCORE"; await AddCorOptions(); var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no"; if (isCache == "no") { await CacheMemory.Remove(cacheKey); } var jsonResults = await CacheMemory.Get <IAQCORE>(cacheKey); if (jsonResults != null) { return jsonResults; } var sensor = await IiAQCOREs.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 CacheMemory.SetAndExpiresSeconds(cacheKey, sensor, 30); return sensor; } catch (Exception ex) { await Tracer.Exception("IAQCOREController:Get", ex); return null; } })); }