public async Task <data.Counter> Update(data.InvoiceContext db, CounterUpdate update) { try { var counterToUpdate = await db.Counters.FirstOrDefaultAsync(w => w.Name == update.Name); counterToUpdate.Name = update.Name; counterToUpdate.Value = update.Value; return(counterToUpdate); } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
// Update Transaction Code public async Task <CounterView> Update(CounterUpdate update) { try { using (var db = new data.InvoiceContext()) { var result = await Update(db, update); await db.SaveChangesAsync(); return((CounterView)result); } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
public async Task <CounterView> CounterUpdate(CounterUpdate update) { try { string json = ""; var client = new HttpClient(); using (var ms = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(CounterUpdate), new DataContractJsonSerializerSettings() { DateTimeFormat = new DateTimeFormat("yyyy-MM-dd'T'HH:mm:ss") }); serializer.WriteObject(ms, update); ms.Position = 0; StreamReader sr = new StreamReader(ms); json = sr.ReadToEnd(); } var stream = await client.PutAsync($"http://localhost:44443/api/counter/{update.Name}", new StringContent(json, Encoding.UTF8, "application/json")); using (var ms = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(CounterView)); await stream.Content.CopyToAsync(ms); ms.Position = 0; var view = serializer.ReadObject(ms) as CounterView; return(view); } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
private void OnMeanCounter(string name, string displayName, IDictionary <string, object> kvPairs) { var value = double.Parse(kvPairs["Mean"].ToString()); CounterUpdate?.Invoke(new CounterEventArgs(name, displayName, CounterType.Mean, value)); }