예제 #1
0
        /// <summary>
        /// Adds the gateway.
        /// </summary>
        /// <returns>The gateway.</returns>
        /// <param name="className">Class name.</param>
        /// <param name="assemblyName">Assembly name.</param>
        public IMigGateway AddGateway(string className, string assemblyName = "")
        {
            IMigGateway migGateway = GetGateway(className);

            if (migGateway == null)
            {
                try
                {
                    var type = TypeLookup("MIG.Gateways." + className, assemblyName);
                    migGateway = (IMigGateway)Activator.CreateInstance(type);
                }
                catch (Exception e)
                {
                    MigService.Log.Error(e);
                }
                if (migGateway != null)
                {
                    Log.Debug("Adding Gateway {0}", migGateway.GetName());
                    Gateways.Add(migGateway);
                    migGateway.PreProcessRequest  += Gateway_PreProcessRequest;
                    migGateway.PostProcessRequest += Gateway_PostProcessRequest;
                }
            }
            // Try loading gateway settings from MIG configuration
            var config = configuration.GetGateway(migGateway.GetName());

            if (config == null)
            {
                config      = new Gateway();
                config.Name = migGateway.GetName();
                if (config.Options == null)
                {
                    config.Options = new List <Option>();
                }
                configuration.Gateways.Add(config);
            }
            if (migGateway != null)
            {
                Log.Debug("Setting Gateway options");
                migGateway.Options = config.Options;
                foreach (var opt in configuration.GetGateway(migGateway.GetName()).Options)
                {
                    migGateway.SetOption(opt.Name, opt.Value);
                }
            }
            return(migGateway);
        }
예제 #2
0
 private bool UpdateSystemConfig()
 {
     string configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "systemconfig.xml");
     string configText = File.ReadAllText(Path.Combine(tempFolderPath, "systemconfig.xml"));
     if (configText.IndexOf("<ServicePort>") > 0)
     {
         configText = configText.Replace("SystemConfiguration", "SystemConfiguration_1_0");
         configText = configText.Replace("HomeGenieConfiguration", "HomeGenieConfiguration_1_0");
         // This is old configuration file from HG < 1.1
         SystemConfiguration_1_0 oldConfig;
         SystemConfiguration newConfig = new SystemConfiguration();
         try
         {
             // Load old config
             var serializerOld = new XmlSerializer(typeof(SystemConfiguration_1_0));
             using (var reader = new StringReader(configText))
                 oldConfig = (SystemConfiguration_1_0)serializerOld.Deserialize(reader);
             // Copy setting to the new config format
             newConfig.HomeGenie.Settings = oldConfig.HomeGenie.Settings;
             newConfig.HomeGenie.SystemName = oldConfig.HomeGenie.SystemName;
             newConfig.HomeGenie.Location = oldConfig.HomeGenie.Location;
             newConfig.HomeGenie.GUID = oldConfig.HomeGenie.GUID;
             newConfig.HomeGenie.EnableLogFile = oldConfig.HomeGenie.EnableLogFile;
             newConfig.HomeGenie.Statistics = new HomeGenieConfiguration.StatisticsConfiguration();
             newConfig.HomeGenie.Statistics.MaxDatabaseSizeMBytes = oldConfig.HomeGenie.Statistics.MaxDatabaseSizeMBytes;
             newConfig.HomeGenie.Statistics.StatisticsTimeResolutionSeconds = oldConfig.HomeGenie.Statistics.StatisticsTimeResolutionSeconds;
             newConfig.HomeGenie.Statistics.StatisticsUIRefreshSeconds = oldConfig.HomeGenie.Statistics.StatisticsUIRefreshSeconds;
             var webGateway = new Gateway() { Name = "WebServiceGateway", IsEnabled = true };
             webGateway.Options = new List<Option>();
             webGateway.Options.Add(new Option("BaseUrl", "/hg/html"));
             webGateway.Options.Add(new Option("HomePath", "html"));
             webGateway.Options.Add(new Option("Host", oldConfig.HomeGenie.ServiceHost));
             webGateway.Options.Add(new Option("Port", oldConfig.HomeGenie.ServicePort.ToString()));
             webGateway.Options.Add(new Option("Username", "admin"));
             webGateway.Options.Add(new Option("Password", oldConfig.HomeGenie.UserPassword));
             webGateway.Options.Add(new Option("HttpCacheIgnore.1", "^.*\\/pages\\/control\\/widgets\\/.*\\.(js|html)$"));
             webGateway.Options.Add(new Option("HttpCacheIgnore.2", "^.*\\/html\\/index.html"));
             webGateway.Options.Add(new Option("UrlAlias.1", "api/HomeAutomation.HomeGenie/Logging/RealTime.EventStream:events"));
             webGateway.Options.Add(new Option("UrlAlias.2", "hg/html/pages/control/widgets/homegenie/generic/images/socket_on.png:hg/html/pages/control/widgets/homegenie/generic/images/switch_on.png"));
             webGateway.Options.Add(new Option("UrlAlias.3", "hg/html/pages/control/widgets/homegenie/generic/images/socket_off.png:hg/html/pages/control/widgets/homegenie/generic/images/switch_off.png"));
             webGateway.Options.Add(new Option("UrlAlias.4", "hg/html/pages/control/widgets/homegenie/generic/images/siren.png:hg/html/pages/control/widgets/homegenie/generic/images/siren_on.png"));
             // TODO: EnableFileCaching value should be read from oldConfig.MIGService.EnableWebCache
             webGateway.Options.Add(new Option("EnableFileCaching", "false"));
             newConfig.MigService.Gateways.Add(webGateway);
             newConfig.MigService.Interfaces = oldConfig.MIGService.Interfaces;
             foreach(var iface in newConfig.MigService.Interfaces)
             {
                 if (iface.Domain == "HomeAutomation.ZWave")
                     iface.AssemblyName = "MIG.HomeAutomation.dll";
                 if (iface.Domain == "HomeAutomation.Insteon")
                     iface.AssemblyName = "MIG.HomeAutomation.dll";
                 if (iface.Domain == "HomeAutomation.X10")
                     iface.AssemblyName = "MIG.HomeAutomation.dll";
                 if (iface.Domain == "HomeAutomation.W800RF")
                     iface.AssemblyName = "MIG.HomeAutomation.dll";
                 if (iface.Domain == "Controllers.LircRemote")
                     iface.AssemblyName = "MIG.Controllers.dll";
                 if (iface.Domain == "Media.CameraInput")
                     iface.AssemblyName = "MIG.Media.dll";
                 if (iface.Domain == "Protocols.UPnP")
                     iface.AssemblyName = "MIG.Protocols.dll";
             }
             // Check for lircconfig.xml
             if (File.Exists(Path.Combine(tempFolderPath, "lircconfig.xml")))
             {
                 File.Copy(Path.Combine(tempFolderPath, "lircconfig.xml"), Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "lib", "mig", "lircconfig.xml"), true);
             }
             // Update configuration file
             if (File.Exists(configFile))
             {
                 File.Delete(configFile);
             }
             System.Xml.XmlWriterSettings ws = new System.Xml.XmlWriterSettings();
             ws.Indent = true;
             System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(newConfig.GetType());
             System.Xml.XmlWriter wri = System.Xml.XmlWriter.Create(configFile, ws);
             x.Serialize(wri, newConfig);
             wri.Close();
         }
         catch (Exception e)
         {
             MigService.Log.Error(e);
             return false;
         }
     }
     else
     {
         // HG >= 1.1
         File.Copy(Path.Combine(tempFolderPath, "systemconfig.xml"), configFile, true);
     }
     return true;
 }
예제 #3
0
 /// <summary>
 /// Adds the gateway.
 /// </summary>
 /// <returns>The gateway.</returns>
 /// <param name="className">Class name.</param>
 /// <param name="assemblyName">Assembly name.</param>
 public IMigGateway AddGateway(string className, string assemblyName = "")
 {
     IMigGateway migGateway = GetGateway(className);
     if (migGateway == null)
     {
         try
         {
             var type = TypeLookup("MIG.Gateways." + className, assemblyName);
             migGateway = (IMigGateway)Activator.CreateInstance(type);
         }
         catch (Exception e)
         {
             MigService.Log.Error(e);
         }
         if (migGateway != null)
         {
             Log.Debug("Adding Gateway {0}", migGateway.GetName());
             Gateways.Add(migGateway);
             migGateway.PreProcessRequest += Gateway_PreProcessRequest;
             migGateway.PostProcessRequest += Gateway_PostProcessRequest;
         }
     }
     // Try loading gateway settings from MIG configuration
     var config = configuration.GetGateway(migGateway.GetName());
     if (config == null)
     {
         config = new Gateway();
         config.Name = migGateway.GetName();
         if (config.Options == null)
             config.Options = new List<Option>();
         configuration.Gateways.Add(config);
     }
     if (migGateway != null)
     {
         Log.Debug("Setting Gateway options");
         migGateway.Options = config.Options;
         foreach (var opt in configuration.GetGateway(migGateway.GetName()).Options)
         {
             migGateway.SetOption(opt.Name, opt.Value);
         }
     }
     return migGateway;
 }