예제 #1
0
        public void ProgramRemove(ProgramBlock program)
        {
            program.IsEnabled = false;
            program.Stop();
            automationPrograms.Remove(program);
            // delete program files
            string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "programs");

            // remove csharp assembly
            try
            {
                File.Delete(Path.Combine(file, program.Address + ".dll"));
            }
            catch
            {
            }
            // remove arduino folder files
            try
            {
                Directory.Delete(Path.Combine(file, "arduino", program.Address.ToString()), true);
            }
            catch
            {
            }
        }
예제 #2
0
 public void ProgramRemove(ProgramBlock pb)
 {
     pb.Stop();
     pb.IsEnabled = false;
     lock (_programblocks)
     {
         _programblocks.Remove(pb);
     }
 }
예제 #3
0
 public void Run(ProgramBlock program, string options)
 {
     if (program.IsRunning)
     {
         return;
     }
     //
     if (program.ProgramThread != null)
     {
         program.Stop();
         program.IsRunning = false;
     }
     //
     program.IsRunning = true;
     RaiseProgramModuleEvent(program, Properties.PROGRAM_STATUS, "Running");
     //
     program.TriggerTime   = DateTime.UtcNow;
     program.ProgramThread = new Thread(() =>
     {
         MethodRunResult result = null;
         try
         {
             result = program.Run(options);
         }
         catch (Exception ex)
         {
             result           = new MethodRunResult();
             result.Exception = ex;
         }
         //
         if (result != null && result.Exception != null)
         {
             // runtime error occurred, script is being disabled
             // so user can notice and fix it
             List <ProgramError> error = new List <ProgramError>()
             {
                 program.GetFormattedError(result.Exception, false)
             };
             program.ScriptErrors = JsonConvert.SerializeObject(error);
             program.IsEnabled    = false;
             RaiseProgramModuleEvent(program, Properties.RUNTIME_ERROR, "CR: " + result.Exception.Message.Replace('\n', ' ').Replace('\r', ' '));
         }
         program.IsRunning     = false;
         program.ProgramThread = null;
         RaiseProgramModuleEvent(program, Properties.PROGRAM_STATUS, "Idle");
     });
     //
     if (program.ConditionType == ConditionType.Once)
     {
         program.IsEnabled = false;
     }
     //
     try
     {
         program.ProgramThread.Start();
     }
     catch
     {
         program.Stop();
         program.IsRunning = false;
         RaiseProgramModuleEvent(program, Properties.PROGRAM_STATUS, "Idle");
     }
     //
     //Thread.Sleep(100);
 }
예제 #4
0
 public void ProgramRemove(ProgramBlock program)
 {
     program.IsEnabled = false;
     program.Stop();
     automationPrograms.Remove(program);
 }
예제 #5
0
 public void Run(ProgramBlock program, string options)
 {
     if (program.IsRunning)
     {
         return;
     }
     //
     if (program.ProgramThread != null)
     {
         program.Stop();
         program.IsRunning = false;
     }
     //
     program.IsRunning = true;
     RaiseProgramModuleEvent(program, "Program.Status", "Running");
     //
     if (program.Type.ToLower() != "wizard")
     {
         if (program.Type.ToLower() == "csharp" && program.AppAssembly == null)
         {
             program.IsRunning = false;
         }
         else
         {
             program.TriggerTime   = DateTime.UtcNow;
             program.ProgramThread = new Thread(() =>
             {
                 MethodRunResult result = null;
                 try
                 {
                     result = program.Run(options);
                 } catch (Exception ex) {
                     result           = new MethodRunResult();
                     result.Exception = ex;
                 }
                 //
                 if (result != null && result.Exception != null)
                 {
                     // runtime error occurred, script is being disabled
                     // so user can notice and fix it
                     List <ProgramError> error = new List <ProgramError>()
                     {
                         new ProgramError()
                         {
                             CodeBlock    = "CR",
                             Column       = 0,
                             Line         = 0,
                             ErrorNumber  = "-1",
                             ErrorMessage = result.Exception.Message
                         }
                     };
                     program.ScriptErrors = JsonConvert.SerializeObject(error);
                     program.IsEnabled    = false;
                     RaiseProgramModuleEvent(
                         program,
                         "Runtime.Error",
                         "CR: " + result.Exception.Message.Replace(
                             '\n',
                             ' '
                             )
                         );
                 }
                 program.IsRunning     = false;
                 program.ProgramThread = null;
                 RaiseProgramModuleEvent(program, "Program.Status", "Idle");
             });
             //
             try
             {
                 program.ProgramThread.Start();
             }
             catch
             {
                 program.Stop();
                 program.IsRunning = false;
                 RaiseProgramModuleEvent(program, "Program.Status", "Idle");
             }
         }
     }
     else
     {
         program.TriggerTime = DateTime.UtcNow;
         if (program.ConditionType == ConditionType.Once)
         {
             program.IsEnabled = false;
         }
         //
         program.ProgramThread = new Thread(() =>
         {
             try
             {
                 ExecuteWizardScript(program);
             }
             catch (ThreadAbortException)
             {
                 program.IsRunning = false;
             }
             finally
             {
                 program.IsRunning = false;
             }
             RaiseProgramModuleEvent(program, "Program.Status", "Idle");
         });
         //
         program.ProgramThread.Start();
     }
     //
     Thread.Sleep(100);
 }
예제 #6
0
 public void ProgramRemove(ProgramBlock program)
 {
     program.IsEnabled = false;
     program.Stop();
     automationPrograms.Remove(program);
     // delete program files
     string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "programs");
     // remove csharp assembly
     try { File.Delete(Path.Combine(file, program.Address + ".dll")); } catch { }
     // remove arduino folder files 
     try { Directory.Delete(Path.Combine(file, "arduino", program.Address.ToString()), true); } catch { }
 }
예제 #7
0
 public void Run(ProgramBlock program, string options)
 {
     if (program.IsRunning) return;
     //
     if (program.ProgramThread != null)
     {
         program.Stop();
         program.IsRunning = false;
     }
     //
     program.IsRunning = true;
     RaiseProgramModuleEvent(program, "Program.Status", "Running");
     //
     if (program.Type.ToLower() != "wizard")
     {
         if (program.Type.ToLower() == "csharp" && program.AppAssembly == null)
         {
             program.IsRunning = false;
         }
         else
         {
             program.TriggerTime = DateTime.UtcNow;
             program.ProgramThread = new Thread(() =>
             {
                 MethodRunResult result = null;
                 try
                 {
                     result = program.Run(options);
                 } catch (Exception ex) {
                     result = new MethodRunResult();
                     result.Exception = ex;
                 }
                 //
                 if (result != null && result.Exception != null)
                 {
                     // runtime error occurred, script is being disabled
                     // so user can notice and fix it
                     List<ProgramError> error = new List<ProgramError>() { new ProgramError() {
                             CodeBlock = "CR",
                             Column = 0,
                             Line = 0,
                             ErrorNumber = "-1",
                             ErrorMessage = result.Exception.Message
                         }
                     };
                     program.ScriptErrors = JsonConvert.SerializeObject(error);
                     program.IsEnabled = false;
                     RaiseProgramModuleEvent(
                         program,
                         "Runtime.Error",
                         "CR: " + result.Exception.Message.Replace(
                             '\n',
                             ' '
                         )
                     );
                 }
                 program.IsRunning = false;
                 program.ProgramThread = null;
                 RaiseProgramModuleEvent(program, "Program.Status", "Idle");
             });
             //
             try
             {
                 program.ProgramThread.Start();
             }
             catch
             {
                 program.Stop();
                 program.IsRunning = false;
                 RaiseProgramModuleEvent(program, "Program.Status", "Idle");
             }
         }
     }
     else
     {
         program.TriggerTime = DateTime.UtcNow;
         if (program.ConditionType == ConditionType.Once)
         {
             program.IsEnabled = false;
         }
         //
         program.ProgramThread = new Thread(() =>
         {
             try
             {
                 ExecuteWizardScript(program);
             }
             catch (ThreadAbortException)
             {
                 program.IsRunning = false;
             }
             finally
             {
                 program.IsRunning = false;
             }
             RaiseProgramModuleEvent(program, "Program.Status", "Idle");
         });
         //
         program.ProgramThread.Start();
     }
     //
     Thread.Sleep(100);
 }
예제 #8
0
 public void Run(ProgramBlock pb, string options)
 {
     if (pb.IsRunning)
     {
         return;
     }
     //
     if (pb.ProgramThread != null)
     {
         pb.Stop();
         pb.IsRunning = false;
     }
     //
     lock (_lock)
     {
         pb.IsRunning = true;
         //
         if (pb.Type.ToLower() == "csharp")
         {
             if (pb.ScriptAssembly != null)
             {
                 pb.TriggerTime   = DateTime.UtcNow;
                 pb.ProgramThread = new Thread(new ThreadStart(delegate()
                 {
                     MethodRunResult res = pb.RunScript(_homegenie, options);
                     if (res != null && res.Exception != null)
                     {
                         // runtime error occurred, script is being disabled
                         // so user can notice and fix it
                         pb.ScriptErrors = res.Exception.Message + "\n" + res.Exception.StackTrace;
                         pb.IsEnabled    = false;
                     }
                     pb.IsRunning = false;
                 }));
                 pb.ProgramThread.Priority = ThreadPriority.BelowNormal;
                 try
                 {
                     pb.ProgramThread.Start();
                 }
                 catch
                 {
                     pb.Stop();
                     pb.IsRunning = false;
                 }
             }
             else
             {
                 pb.IsRunning = false;
             }
         }
         else
         {
             pb.TriggerTime = DateTime.UtcNow;
             if (pb.ConditionType == ConditionType.Once)
             {
                 pb.IsEnabled = false;
             }
             //
             pb.ProgramThread = new Thread(new ThreadStart(delegate()
             {
                 try
                 {
                     ExecuteWizardScript(pb);
                 }
                 catch (ThreadAbortException)
                 {
                     pb.IsRunning = false;
                 }
                 finally
                 {
                     pb.IsRunning = false;
                 }
             }));
             pb.ProgramThread.Priority = ThreadPriority.Lowest;
             pb.ProgramThread.Start();
         }
         //
         Thread.Sleep(100);
     }
 }
예제 #9
0
 public void Run(ProgramBlock program, string options)
 {
     if (program.IsRunning)
         return;
     //
     if (program.ProgramThread != null)
     {
         program.Stop();
         program.IsRunning = false;
     }
     //
     program.IsRunning = true;
     RaiseProgramModuleEvent(program, Properties.PROGRAM_STATUS, "Running");
     //
     program.TriggerTime = DateTime.UtcNow;
     program.ProgramThread = new Thread(() =>
     {
         MethodRunResult result = null;
         try
         {
             result = program.Run(options);
         }
         catch (Exception ex)
         {
             result = new MethodRunResult();
             result.Exception = ex;
         }
         //
         if (result != null && result.Exception != null && !result.Exception.GetType().Equals(typeof(System.Reflection.TargetException)))
         {
             // runtime error occurred, script is being disabled
             // so user can notice and fix it
             List<ProgramError> error = new List<ProgramError>() { program.GetFormattedError(result.Exception, false) };
             program.ScriptErrors = JsonConvert.SerializeObject(error);
             program.IsEnabled = false;
             RaiseProgramModuleEvent(program, Properties.RUNTIME_ERROR, "CR: " + result.Exception.Message.Replace('\n', ' ').Replace('\r', ' '));
         }
         program.IsRunning = false;
         program.ProgramThread = null;
         RaiseProgramModuleEvent(program, Properties.PROGRAM_STATUS, "Idle");
     });
     //
     if (program.ConditionType == ConditionType.Once)
     {
         program.IsEnabled = false;
     }
     //
     try
     {
         program.ProgramThread.Start();
     }
     catch
     {
         program.Stop();
         program.IsRunning = false;
         RaiseProgramModuleEvent(program, Properties.PROGRAM_STATUS, "Idle");
     }
     //
     //Thread.Sleep(100);
 }
예제 #10
0
 public void ProgramRemove(ProgramBlock program)
 {
     program.IsEnabled = false;
     program.Stop();
     automationPrograms.Remove(program);
 }