public void ShouldCalcTheCorrectTotals( int quantity, decimal powerConsumption, AUSchedule aUSchedule, decimal expTotalPowerConsumption, decimal expTotalOnSolarEnergyConsumption, decimal expTotalOffSolarEnergyConsumption, decimal expTotalEnergyConsumption) { var builder = new ApplianceUsageBuilder(); var applianceUsage = new ApplianceUsage( builder.TestConsumptionCalculator, builder.TestAppliance, quantity, powerConsumption, builder.TestEnabled); applianceUsage.ApplianceUsageSchedule.ClearUsageIntervals(); foreach (var u in aUSchedule.UsageIntervals) { var ti = u.TimeInterval; int startHr = ti.Start.Hours, startMin = ti.Start.Minutes; int endHr = ti.End.Hours, endMin = ti.End.Minutes; applianceUsage.ApplianceUsageSchedule.AddUsageInterval( startHr, startMin, endHr, endMin, u.UsageKind ); } var applianceUsageTotal = new ApplianceUsageTotal(applianceUsage); Assert.Equal(expTotalPowerConsumption, applianceUsageTotal.TotalPowerConsumption); Assert.Equal(expTotalOnSolarEnergyConsumption, applianceUsageTotal.TotalOnSolarEnergyConsumption); Assert.Equal(expTotalOffSolarEnergyConsumption, applianceUsageTotal.TotalOffSolarEnergyConsumption); Assert.Equal(expTotalEnergyConsumption, applianceUsageTotal.TotalEnergyConsumption); }
protected override bool startPendingProcess(List <Table> items) { AUSchedule schedule = PX.Common.PXContext.GetSlot <AUSchedule>(); if (schedule == null) { return(base.startPendingProcess(items)); } PXCache cache = _OuterView.Cache; cache.IsDirty = false; List <Table> list = new List <Table>(); foreach (Table item in items) { object sel = cache.GetValue(item, _SelectedField); if (sel != null && Convert.ToBoolean(sel)) { PXEntryStatus status = cache.GetStatus(item); if (status == PXEntryStatus.Inserted || status == PXEntryStatus.Updated) { list.Add(item); } } } PX.Common.PXContext.SetSlot <AUSchedule>(null); AUSchedule scheduleparam = schedule; if (_IsInstance) { ProcessSyncCC(_ProcessDelegate, list, scheduleparam); } else { PXLongOperation.StartOperation(_Graph, delegate() { ProcessSyncCC(_ProcessDelegate, list, scheduleparam); }); } schedule = null; return(true); }
protected void ProcessSyncCC(ProcessListDelegate processor, List <Table> list, AUSchedule schedule) { beforeScheduleProcessAll?.Invoke(); PXLongOperation.SetCustomInfo(new List <SyncCCProcessingInfoEntry>(), ProcessingInfo.processingKey); list.Clear(); _InProc = new PXResultset <Table>(); base._ProcessScheduled(processor, list, schedule); var histCache = _Graph.Caches[typeof(AUScheduleHistory)]; List <SyncCCProcessingInfoEntry> infoList = PXLongOperation.GetCustomInfoForCurrentThread(ProcessingInfo.processingKey) as List <SyncCCProcessingInfoEntry>; if (infoList != null) { foreach (SyncCCProcessingInfoEntry infoEntry in infoList) { AUScheduleHistory hist = new PX.SM.AUScheduleHistory(); hist.ExecutionResult = infoEntry.ProcessingMessage.Message; hist.ErrorLevel = (short)infoEntry.ProcessingMessage.ErrorLevel; hist.ScheduleID = schedule.ScheduleID; hist.ScreenID = schedule.ScreenID; var timeZone = PXTimeZoneInfo.FindSystemTimeZoneById(schedule.TimeZoneID); DateTime startUtc = PXTimeZoneInfo.UtcNow; DateTime start = PXTimeZoneInfo.ConvertTimeFromUtc(startUtc, timeZone); hist.ExecutionDate = start; hist.RefNoteID = infoEntry.NoteId; histCache.Insert(hist); } } histCache.Persist(PXDBOperation.Insert); }