Skip to content

Commit

Permalink
2998 Schedule commands
Browse files Browse the repository at this point in the history
  • Loading branch information
E068097 authored and judramos committed Dec 3, 2024
1 parent 46bbaed commit d223fe4
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 345 deletions.

This file was deleted.

36 changes: 25 additions & 11 deletions src/IoTHub.Portal.Infrastructure/Jobs/SendPlanningCommandJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void UpdateDatabase()
{
foreach (var device in this.devices.Data)
{
if (device.LayerId != null) AddNewDevice(device);
if (!string.IsNullOrWhiteSpace(device.LayerId)) AddNewDevice(device);
}
}

Expand Down Expand Up @@ -169,29 +169,43 @@ public void AddCommand(PlanningCommand planningCommand)
{
var planningData = plannings.FirstOrDefault(planning => planning.Id == planningCommand.planningId);

// Connect off days command to the planning
addPlanningSchedule(planningData, planningCommand);
// If planning is active
if (planningData != null && IsPlanningActive(planningData))
{
// Connect off days command to the planning
addPlanningSchedule(planningData, planningCommand);


foreach (var schedule in schedules)
{
// Add schedules to the planning
if (schedule.PlanningId == planningCommand.planningId) addSchedule(schedule, planningCommand);
foreach (var schedule in schedules)
{
// Add schedules to the planning
if (schedule.PlanningId == planningCommand.planningId) addSchedule(schedule, planningCommand);
}
}
}

private bool IsPlanningActive(PlanningDto planning)
{
var startDay = DateTime.ParseExact(planning.Start, "yyyy-MM-dd", CultureInfo.InvariantCulture);
var endDay = DateTime.ParseExact(planning.End, "yyyy-MM-dd", CultureInfo.InvariantCulture);

return DateTime.Now >= startDay && DateTime.Now <= endDay;
}

// Include Planning Commands used for off days in the command dictionary.
// "Sa" represents Saturday and serves as a dictionary key.
// planning.commands[Sa] contains a list of PayloadCommand Values.
public void addPlanningSchedule(PlanningDto planningData, PlanningCommand planning)
{
foreach (var key in planning.commands.Keys)
if (planningData != null)
{
if ((planningData.DayOff & key) == planningData.DayOff)
foreach (var key in planning.commands.Keys)
{
var newPayload = new PayloadCommand(getTimeSpan("0:00"), getTimeSpan("24:00"), planningData.CommandId);
planning.commands[key].Add(newPayload);
if ((planningData.DayOff & key) == planningData.DayOff)
{
var newPayload = new PayloadCommand(getTimeSpan("0:00"), getTimeSpan("24:00"), planningData.CommandId);
planning.commands[key].Add(newPayload);
}
}
}
}
Expand Down
325 changes: 0 additions & 325 deletions src/IoTHub.Portal.Server/Services/SendPlanningCommandService.cs

This file was deleted.

Loading

0 comments on commit d223fe4

Please sign in to comment.