public CSharpAppFactory(HomeGenieService hg)
 {
     homegenie = hg;
     masterControlProgram = homegenie.ProgramEngine;
     //AppDomain currentDomain = AppDomain.CurrentDomain;
     //currentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyLookup);
 }
 public void RestoreFactorySettings()
 {
     string archiveName = "homegenie_factory_config.zip";
     //
     try
     {
         masterControlProgram.Enabled = false;
         masterControlProgram.StopEngine();
         // delete old programs assemblies
         foreach (var program in masterControlProgram.Programs)
         {
             program.AppAssembly = null;
         }
         masterControlProgram = null;
     }
     catch
     {
     }
     //
     Utility.UncompressZip(archiveName, AppDomain.CurrentDomain.BaseDirectory);
     //
     Reload();
     //
     // regenerate encrypted files
     UpdateModulesDatabase();
     SystemConfiguration.Update();
 }
 public void LoadConfiguration()
 {
     LoadSystemConfig();
     //
     // load modules data
     //
     LoadModules();
     //
     // load last saved groups data into controlGroups list
     try
     {
         var serializer = new XmlSerializer(typeof(List<Group>));
         using (var reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "groups.xml")))
             controlGroups = (List<Group>)serializer.Deserialize(reader);
     }
     catch
     {
         //TODO: log error
     }
     //
     // load last saved automation groups data into automationGroups list
     try
     {
         var serializer = new XmlSerializer(typeof(List<Group>));
         using (var reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "automationgroups.xml")))
             automationGroups = (List<Group>)serializer.Deserialize(reader);
     }
     catch
     {
         //TODO: log error
     }
     //
     // load last saved programs data into masterControlProgram.Programs list
     //
     if (masterControlProgram != null)
     {
         masterControlProgram.Enabled = false;
         masterControlProgram.StopEngine();
         masterControlProgram = null;
     }
     masterControlProgram = new ProgramEngine(this);
     try
     {
         var serializer = new XmlSerializer(typeof(List<ProgramBlock>));
         using (var reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "programs.xml")))
         {
             var programs = (List<ProgramBlock>)serializer.Deserialize(reader);
             foreach (var program in programs)
             {
                 program.IsRunning = false;
                 // backward compatibility with hg < 0.91
                 if (program.Address == 0)
                 {
                     // assign an id to program if unassigned
                     program.Address = masterControlProgram.GeneratePid();
                 }
                 masterControlProgram.ProgramAdd(program);
             }
         }
     }
     catch (Exception ex)
     {
         LogError(
             Domains.HomeAutomation_HomeGenie,
             "LoadConfiguration()",
             ex.Message,
             "Exception.StackTrace",
             ex.StackTrace
         );
     }
     //
     // load last saved scheduler items data into masterControlProgram.SchedulerService.Items list
     //
     try
     {
         var serializer = new XmlSerializer(typeof(List<SchedulerItem>));
         using (var reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "scheduler.xml")))
         {
             var schedulerItems = (List<SchedulerItem>)serializer.Deserialize(reader);
             masterControlProgram.SchedulerService.Items.AddRange(schedulerItems);
         }
     }
     catch
     {
         //TODO: log error
     }
     // force re-generation of Modules list
     modules_RefreshAll();
     //
     // enable automation programs engine
     //
     masterControlProgram.Enabled = true;
 }
Exemple #4
0
 public MacroRecorder(ProgramEngine mcp)
 {
     masterControlProgram = mcp;
 }
 public void LoadConfiguration()
 {
     LoadSystemConfig();
     //
     // load modules data
     //
     LoadModules();
     //
     // load last saved groups data into controlGroups list
     try
     {
         var serializer = new XmlSerializer(typeof(List<Group>));
         var reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "groups.xml"));
         controlGroups = (List<Group>)serializer.Deserialize(reader);
         reader.Close();
     }
     catch
     {
         //TODO: log error
     }
     //
     // load last saved automation groups data into automationGroups list
     try
     {
         var serializer = new XmlSerializer(typeof(List<Group>));
         var reader = new StreamReader(Path.Combine(
                          AppDomain.CurrentDomain.BaseDirectory,
                          "automationgroups.xml"
                      ));
         automationGroups = (List<Group>)serializer.Deserialize(reader);
         reader.Close();
     }
     catch
     {
         //TODO: log error
     }
     //
     // load last saved programs data into masterControlProgram.Programs list
     //
     if (masterControlProgram != null)
     {
         masterControlProgram.Enabled = false;
         masterControlProgram.StopEngine();
         masterControlProgram = null;
     }
     masterControlProgram = new ProgramEngine(this);
     try
     {
         var serializer = new XmlSerializer(typeof(List<ProgramBlock>));
         var reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "programs.xml"));
         var programs = (List<ProgramBlock>)serializer.Deserialize(reader);
         foreach (var program in programs)
         {
             program.IsRunning = false;
             //program.IsEvaluatingConditionBlock = false;
             //program.ScriptErrors = "";
             // backward compatibility with hg < 0.91
             if (program.Address == 0)
             {
                 // assign an id to program if unassigned
                 program.Address = masterControlProgram.GeneratePid();
             }
             // in case of c# script preload assembly from generated .dll
             if (program.Type.ToLower() == "csharp" && !program.AssemblyLoad())
             {
                 program.ScriptErrors = "Program update is required.";
             }
             //else
             //{
             //    program.ScriptErrors = "";
             //}
             masterControlProgram.ProgramAdd(program);
         }
         reader.Close();
     }
     catch (Exception ex)
     {
         //TODO: log error
         HomeGenieService.LogEvent(
             Domains.HomeAutomation_HomeGenie,
             "LoadConfiguration()",
             ex.Message,
             "Exception.StackTrace",
             ex.StackTrace
         );
     }
     //
     // load last saved scheduler items data into masterControlProgram.SchedulerService.Items list
     //
     try
     {
         var serializer = new XmlSerializer(typeof(List<SchedulerItem>));
         var reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "scheduler.xml"));
         var schedulerItems = (List<SchedulerItem>)serializer.Deserialize(reader);
         masterControlProgram.SchedulerService.Items.AddRange(schedulerItems);
         reader.Close();
     }
     catch
     {
         //TODO: log error
     }
     //
     // start MIG Interfaces
     //
     try
     {
         migService.StartInterfaces();
     }
     catch
     {
         //TODO: log error
     }
     // force re-generation of Modules list
     //_jsonSerializedModules(false);
     modules_RefreshAll();
     //
     // enable automation programs engine
     //
     masterControlProgram.Enabled = true;
 }
Exemple #6
0
 public MacroRecorder(ProgramEngine mcp)
 {
     masterControlProgram = mcp;
 }
Exemple #7
0
 public MacroRecorder(ProgramEngine mcp)
 {
     _mastercontrolprogram = mcp;
 }