Exemple #1
0
 // turn the device off
 public void TurnOff(SmartSwitchDbContext context)
 {
     using (ILifetimeScope scope = Program.Container.BeginLifetimeScope())
     {
         if (scope.Resolve <IWebsocketsServer>().TurnOff(Mac))
         {
             IsOn = false;
             context.Entry(this).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
 }
Exemple #2
0
 public static void ExecuteAndScheduleNextExecution(Operations operation, string mac, int repeatEvery, int taskId)
 {
     using (ILifetimeScope scope = Program.Container.BeginLifetimeScope())
     {
         SmartSwitchDbContext context = scope.Resolve <SmartSwitchDbContext>();
         var tasks = context.Tasks;
         var task  = tasks.Find(taskId);
         if (task == null)
         {
             throw new Exception("task is null");
         }
         task.JobId = BackgroundJob.Schedule(() => ExecuteAndScheduleNextExecution(operation, mac, repeatEvery, taskId), TimeSpan.FromMinutes(repeatEvery));
         context.SaveChanges();
         Execute(operation, context.Plugs.Find(mac), context);
     }
 }
Exemple #3
0
 public void AddTask(Task task, SmartSwitchDbContext context)
 {
     Tasks.Add(task);
     context.SaveChanges();
     task.Schedule();
 }