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}: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; } })); }