public void CanWriteToolData() { DateTime period = DateTime.Parse("2017-07-01"); int clientId = 1296; using (var conn = NewConnection()) { conn.Open(); var proc = new WriteToolDataProcess(new WriteToolDataConfig { Connection = conn, Context = "LNF.Tests.WriteToolDataManagerTests.CanWriteToolData", Period = period, ClientID = clientId, ResourceID = 0 }); //var dtExtract = proc.Extract(); //var dtTransform = proc.Transform(dtExtract); //var rows = dtTransform.Select($"ReservationID = {757744}"); //Assert.AreEqual(1, rows.Length); //var ot = rows[0].Field<double>("OverTime"); //Assert.AreEqual(0.083333, ot); proc.Start(); conn.Close(); } }
public void CanComputeCorrectTransferDuration() { DateTime period = DateTime.Parse("2018-05-01"); int clientId = 1759; int resourceId = 14021; int reservationId = 833138; using (var conn = NewConnection()) { var costs = Provider.Data.Cost.GetToolCosts(period, resourceId); WriteToolDataProcess proc = new WriteToolDataProcess(WriteToolDataConfig.Create(conn, "LNF.Tests.WriteToolDataProcessTests.CanComputeCorrectTransferDuration", period, clientId, resourceId, costs)); var dtToolDataClean = proc.Extract(); var transformer = proc.GetTransformer(); transformer.ProcessCleanData(dtToolDataClean); transformer.CalculateTransferTime(dtToolDataClean); var rows = dtToolDataClean.Select($"ReservationID = {reservationId}"); var actual = rows.Sum(dr => dr.Field <double>("TransferredDuration")); Assert.AreEqual(0, actual); } }
public BillingResult Post([FromBody] BillingModel model) { HttpContext.Current.Server.ScriptTimeout = 1800; if (model == null) { throw new ArgumentNullException("model"); } DateTime start = DateTime.Now; int clientId = (model.ClientID == 0) ? -1 : model.ClientID; bool success = true; int count; string message = string.Empty; string subject = "Data.Controllers.ApiBillingController.Post"; LogMessageLevel level = LogMessageLevel.Info; ProcessResult result; string context = "Data.Controllers.ApiBillingController.Post"; if (model.StartPeriod != DateTime.MinValue) { if (model.EndPeriod == DateTime.MinValue) { model.EndPeriod = model.StartPeriod.AddMonths(1); } using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnSselData"].ConnectionString)) { conn.Open(); BillingDataProcessStep1 step1 = new BillingDataProcessStep1(new Step1Config { Connection = conn, ClientID = clientId, IsTemp = model.IsTemp, Period = model.StartPeriod, Now = DateTime.Now, Context = context }); BillingDataProcessStep2 step2; BillingDataProcessStep3 step3; BillingDataProcessStep4Subsidy step4; switch (model.Command) { case "tool-data-clean": result = new WriteToolDataCleanProcess(new WriteToolDataCleanConfig { Connection = conn, StartDate = model.StartPeriod, EndDate = model.EndPeriod, ClientID = clientId, Context = context }).Start(); message += result.LogText; break; case "room-data-clean": result = new WriteRoomDataCleanProcess(new WriteRoomDataCleanConfig { Connection = conn, StartDate = model.StartPeriod, EndDate = model.EndPeriod, ClientID = clientId, RoomID = model.RoomID, Context = context }).Start(); message += result.LogText; break; case "store-data-clean": result = new WriteStoreDataCleanProcess(new WriteStoreDataCleanConfig { Connection = conn, StartDate = model.StartPeriod, EndDate = model.EndPeriod, ClientID = clientId, Context = context }).Start(); message += result.LogText; break; case "tool-data": result = new WriteToolDataProcess(new WriteToolDataConfig { Connection = conn, Period = model.StartPeriod, ClientID = clientId, ResourceID = model.ResourceID, Context = context }).Start(); message += result.LogText; break; case "room-data": result = new WriteRoomDataProcess(new WriteRoomDataConfig { Connection = conn, Period = model.StartPeriod, ClientID = clientId, RoomID = model.RoomID, Context = context }).Start(); message += result.LogText; break; case "store-data": result = new WriteStoreDataProcess(new WriteStoreDataConfig { Connection = conn, Period = model.StartPeriod, ClientID = clientId, ItemID = model.ItemID, Context = context }).Start(); message += result.LogText; break; case "tool-billing-step1": result = step1.PopulateToolBilling(); message += result.LogText; break; case "room-billing-step1": result = step1.PopulateRoomBilling(); message += result.LogText; break; case "store-billing-step1": result = step1.PopulateStoreBilling(); message += result.LogText; break; case "tool-billing-step2": step2 = new BillingDataProcessStep2(conn); count = step2.PopulateToolBillingByAccount(model.StartPeriod, clientId); message += $"Tool Step2 By Account: count = {count}"; count = step2.PopulateToolBillingByToolOrg(model.StartPeriod, clientId); message += $"{Environment.NewLine}Tool Step2 By Tool Org: count = {count}"; break; case "room-billing-step2": step2 = new BillingDataProcessStep2(conn); count = step2.PopulateRoomBillingByAccount(model.StartPeriod, clientId); message += $"Room Step2 By Account: count = {count}"; count = step2.PopulateRoomBillingByRoomOrg(model.StartPeriod, clientId); message += $"{Environment.NewLine}Room Step2 By Room Org: count = {count}"; break; case "store-billing-step2": step2 = new BillingDataProcessStep2(conn); count = step2.PopulateStoreBillingByAccount(model.StartPeriod, clientId); message += $"Store Step2 By Account: count = {count}"; count = step2.PopulateStoreBillingByItemOrg(model.StartPeriod, clientId); message += $"{Environment.NewLine}Store Step2 By Item Org: count = {count}"; break; case "tool-billing-step3": step3 = new BillingDataProcessStep3(conn); count = step3.PopulateToolBillingByOrg(model.StartPeriod, clientId); message += $"Tool Step3 By Org: count = {count}"; break; case "room-billing-step3": step3 = new BillingDataProcessStep3(conn); count = step3.PopulateRoomBillingByOrg(model.StartPeriod, clientId); message += $"Room Step3 By Org: count = {count}"; break; case "store-billing-step3": step3 = new BillingDataProcessStep3(conn); count = step3.PopulateStoreBillingByOrg(model.StartPeriod); message += $"Store Step3 By Org: count = {count}"; break; case "subsidy-billing-step4": step4 = new BillingDataProcessStep4Subsidy(new Step4Config { Connection = conn, Period = model.StartPeriod, ClientID = clientId, Context = context }); result = step4.PopulateSubsidyBilling(); message += result.LogText; break; case "subsidy-distribution": step4 = new BillingDataProcessStep4Subsidy(new Step4Config { Connection = conn, Period = model.StartPeriod, ClientID = clientId, Context = context }); step4.DistributeSubsidyMoneyEvenly(); message += "Subsidy distribution: complete"; break; case "finalize-data-tables": result = DataTableManager.Create(Provider).Finalize(model.StartPeriod); message += result.LogText; break; default: success = false; message += $"Unknown command: {model.Command}"; level = LogMessageLevel.Error; break; } } } else { success = false; message += $"Missing parameter: StartPeriod [{model.StartPeriod:yyyy-MM-dd HH:mm:ss}]"; level = LogMessageLevel.Error; } Log.Write(level, subject, message, null); DateTime end = DateTime.Now; return(new BillingResult() { Success = success, Command = model.Command, Description = subject, StartDate = start, EndDate = end, TimeTaken = (end - start).TotalSeconds, LogText = message }); }
public static ScriptHost.Result BillingTask(string task, QueryParameters queryParams) { ScriptHost.Result result = new ScriptHost.Result(); DateTime sd; DateTime ed; DateTime period; void getDates(bool startRequired, bool endRequired, bool periodRequired) { if (startRequired && !queryParams.ContainsParameter("StartDate")) { throw new Exception("Missing parameter: StartDate"); } if (endRequired && !queryParams.ContainsParameter("EndDate")) { throw new Exception("Missing parameter: EndDate"); } if (periodRequired && !queryParams.ContainsParameter("Period")) { throw new Exception("Missing parameter: Period"); } sd = queryParams.GetValue("StartDate", DateTime.Now); ed = queryParams.GetValue("EndDate", DateTime.Now); period = queryParams.GetValue("Period", DateTime.Now); } var context = "Data.Models.CommandLine.CommandLineUtility.BillingTask"; var clientId = queryParams.GetValue("ClientID", 0); using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnSselData"].ConnectionString)) { conn.Open(); switch (task) { case "ToolDataClean": getDates(true, true, false); var writeToolDataCleanResult = new WriteToolDataCleanProcess(new WriteToolDataCleanConfig { Connection = conn, StartDate = sd, EndDate = ed, ClientID = clientId, Context = context }).Start(); result.Success = true; result.Message = null; result.Data = writeToolDataCleanResult.LogText; break; case "ToolData": getDates(true, true, false); var writeToolDataResult = new WriteToolDataProcess(new WriteToolDataConfig { Connection = conn, Period = sd, ClientID = clientId, ResourceID = queryParams.GetValue("ResourceID", 0), Context = context }).Start(); result.Success = true; result.Message = null; result.Data = writeToolDataResult.LogText; break; case "RoomDataClean": getDates(true, true, false); var writeRoomDataCleanResult = new WriteRoomDataCleanProcess(new WriteRoomDataCleanConfig { Connection = conn, StartDate = sd, EndDate = ed, ClientID = clientId, Context = context }).Start(); result.Success = true; result.Message = null; result.Data = writeRoomDataCleanResult.LogText; break; case "RoomData": getDates(true, true, false); var writeRoomDataResult = new WriteRoomDataProcess(new WriteRoomDataConfig { Connection = conn, Period = sd, ClientID = clientId, RoomID = queryParams.GetValue("RoomID", 0), Context = context }).Start(); result.Success = true; result.Message = null; result.Data = writeRoomDataResult.LogText; break; case "StoreDataClean": getDates(true, true, false); var writeStoreDataCleanResult = new WriteStoreDataCleanProcess(new WriteStoreDataCleanConfig { Connection = conn, StartDate = sd, EndDate = ed, ClientID = clientId, Context = context }).Start(); result.Success = true; result.Message = null; result.Data = writeStoreDataCleanResult.LogText; break; case "StoreData": getDates(true, true, false); var writeStoreDataResult = new WriteStoreDataProcess(new WriteStoreDataConfig { Connection = conn, Period = sd, ClientID = clientId, ItemID = queryParams.GetValue("ItemID", 0), Context = context }).Start(); result.Success = true; result.Message = null; result.Data = writeStoreDataResult.LogText; break; case "ToolBillingStep1": getDates(false, false, true); var step1 = new BillingDataProcessStep1(new Step1Config { Connection = conn, Period = period, ClientID = clientId, IsTemp = queryParams.GetValue("IsTemp", false), Now = DateTime.Now, Context = context }); var step1Result = step1.PopulateToolBilling(); result.Success = true; result.Message = null; result.Data = step1Result.LogText; break; default: result.Success = false; result.Message = "Unknown task: " + task; break; } conn.Close(); } return(result); }