public List <ConsumptionLog> ListConsumptionLog(string customerId) { Database db = new SqlDatabase(SmartEmConnectionString); List <ConsumptionLog> consumptionLogs = new List <ConsumptionLog>(); using (DbConnection conn = db.CreateConnection()) { conn.Open(); using (DbCommand cmd = conn.CreateCommand()) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "ConsumptionLogGetById"; cmd.Parameters.Add(new SqlParameter("@CustomerId", customerId) { SqlDbType = SqlDbType.NVarChar }); using (var reader = db.ExecuteReader(cmd)) { while (reader.Read()) { ConsumptionLog tempConsumptionLog = new ConsumptionLog(); tempConsumptionLog.Id = Convert.ToInt32((reader["Id"])); tempConsumptionLog.CustomerId = reader["CustomerId"].ToString(); tempConsumptionLog.SmartEnergyMeterId = reader["SmartEnergyMeterId"].ToString(); tempConsumptionLog.Unit = Convert.ToDecimal(reader["Unit"]); tempConsumptionLog.CreatedDateTime = Convert.ToDateTime(reader["CreatedDateTime"]); consumptionLogs.Add(tempConsumptionLog); } } return(consumptionLogs); } } }
public LogParseResult(ConsumptionLog log, int validEntriesCount, int invalidEntriesCount, int emptyEntriesCount) { Log = log; ValidEntriesCount = validEntriesCount; InvalidEntriesCount = invalidEntriesCount; EmptyEntriesCount = emptyEntriesCount; }
public void it_should_insert_the_consumption_logs_into_the_store() { deleteConsumptionLogTable(); var subject = new TableEventStore(CloudStorageAccount.DevelopmentStorageAccount, "test"); var expectedEvent = new RaisedEvent( Guid.NewGuid(), new DummyEvent {Prop = "Property"}, new DateTimeOffset(2013, 01, 17, 12, 06, 39, 967, TimeZoneInfo.Utc.BaseUtcOffset), "txid"); var expectedConsumptionLog = new ConsumptionLog( expectedEvent, expectedEvent.RaisedTimestamp.AddSeconds(1), new AggregateInfo(typeof (DummyAggregate), 123)); subject.LogConsumption(expectedEvent, expectedConsumptionLog); var actual = storedConsumptionLogEntity(expectedConsumptionLog); actual.ShouldNotBeNull(); actual.ConsumedTimestamp.ShouldEqual(expectedConsumptionLog.ConsumedTimestamp); actual.ConsumptionException.ShouldEqual(expectedConsumptionLog.ConsumptionException); actual.Event.ShouldEqual(JsonEvent.ConvertToJson(expectedEvent)); actual.EventThumbprint.ShouldEqual(expectedConsumptionLog.EventThumbprint); }
public async Task <List <ConsumptionLog> > ConsumptionLogGetById(string customerId) { List <ConsumptionLog> consumptionLogList = new List <ConsumptionLog>(); HttpResponseMessage response = await client.GetAsync(url + "customer/log/" + customerId); if (response.IsSuccessStatusCode) { var data = await response.Content.ReadAsStringAsync(); var customerData = Newtonsoft.Json.JsonConvert.DeserializeObject <List <ConsumptionLog> >(data); if (customerData != null) { foreach (ConsumptionLog consumptionLog in customerData) { ConsumptionLog tempConsumptionLog = new ConsumptionLog(); tempConsumptionLog.Id = consumptionLog.Id; tempConsumptionLog.CustomerId = consumptionLog.CustomerId; tempConsumptionLog.SmartEnergyMeterId = consumptionLog.SmartEnergyMeterId; tempConsumptionLog.Unit = consumptionLog.Unit; tempConsumptionLog.CreatedDateTime = consumptionLog.CreatedDateTime; consumptionLogList.Add(tempConsumptionLog); } } } return(consumptionLogList); }
public ConsumptionLogEntity(ConsumptionLog consumptionLog, RaisedEvent raisedEvent) { PartitionKey = consumptionLog.AffectedAggregate.Type.FullName + "@" + consumptionLog.AffectedAggregate.Key; RowKey = consumptionLog.ConsumedTimestamp.Ticks.ToString(longPad); EventThumbprint = raisedEvent.Thumbprint; ConsumedTimestamp = consumptionLog.ConsumedTimestamp; ExecutionTime = consumptionLog.ExecutionTime; ConsumptionException = consumptionLog.ConsumptionException; Event = JsonEvent.ConvertToJson(raisedEvent); }
private void consumeEventOnAggregate(RaisedEvent raisedEvent, AggregateInfo aggregateInfo, ConsumptionLog consumptionLog) { //If it's not tracked, then select it from the domain. if (aggregateInfo.Lifestate == AggregateLifestate.Untracked) selectAggregate(aggregateInfo); using (var scope = new TransactionScope()) { try { try { //If we haven't found it in the domain, then create it, otherwise consume the event. if (aggregateInfo.Lifestate == AggregateLifestate.Untracked) AggregateFactory.Create(aggregateInfo, raisedEvent.Event); else aggregateInfo.Instance.AsDynamic().Receive(raisedEvent); } catch (ApplicationException e) { if (e.Source == "ReflectionMagic") throw new MissingMethodException( aggregateInfo.Type.FullName, string.Format( "{0}({1})", aggregateInfo.Lifestate == AggregateLifestate.Untracked ? "_ctor" : "Receive", raisedEvent.GetType())); throw; } } catch (Exception e) { consumptionLog.RecordExceptionForConsumer(e); } consumptionLog.RecordConsumptionComplete(); Store.LogConsumption(raisedEvent, consumptionLog); scope.Complete(); } }
private ConsumptionLogEntity storedConsumptionLogEntity(ConsumptionLog consumptionLog) { var cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount; var cloudTableClient = cloudStorageAccount.CreateCloudTableClient(); var table = cloudTableClient.GetTableReference("testConsumptionLog"); var retrieve = TableOperation.Retrieve<ConsumptionLogEntity>( consumptionLog.AffectedAggregate.Type.FullName + "@" + consumptionLog.AffectedAggregate.Key, consumptionLog.ConsumedTimestamp.Ticks.ToString("0000000000000000000")); var result = table.Execute(retrieve); return result.Result as ConsumptionLogEntity; }
public void LogConsumption(RaisedEvent raisedEvent, ConsumptionLog consumptionLog) { var logEntity = new ConsumptionLogEntity(consumptionLog, raisedEvent); var insert = TableOperation.Insert(logEntity); logTable.Execute(insert); }