Example #1
0
 public MIGService()
 {
     Interfaces = new Dictionary<string, MIGInterface>();
     //
     //tcpGateway = new TcpSocketGateway();
     //tcpGateway.ProcessRequest += tcpGateway_ProcessRequest;
     //
     webGateway = new WebServiceGateway();
     webGateway.ProcessRequest += webGateway_ProcessRequest;
     webServiceConfig = new WebServiceGatewayConfiguration()
     {
         Port = 80,
         HomePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "html"),
         BaseUrl = "hg/html",
         Password = ""
     };
 }
Example #2
0
        /// <summary>
        /// Reload system configuration and restart services and interfaces.
        /// </summary>
        public void Reload()
        {
            migService.StopService();

            LoadConfiguration();

            webGateway = (WebServiceGateway)migService.GetGateway("WebServiceGateway");
            if (webGateway == null)
            {
                RaiseEvent(
                    Domains.HomeGenie_System,
                    Domains.HomeAutomation_HomeGenie,
                    SourceModule.Master,
                    "Configuration entry not found",
                    "Gateways",
                    "WebServiceGateway"
                );
                Program.Quit(false);
            }
            int webPort = int.Parse(webGateway.GetOption("Port").Value);

            bool started = migService.StartService();
            while (!started)
            {
                RaiseEvent(
                    Domains.HomeGenie_System,
                    Domains.HomeAutomation_HomeGenie,
                    SourceModule.Master,
                    "HTTP binding failed.",
                    Properties.SystemInfoHttpAddress,
                    webGateway.GetOption("Host").Value + ":" + webGateway.GetOption("Port").Value
                );
                // Try auto-binding to another port >= 8080 (up to 8090)
                if (webPort < 8080)
                    webPort = 8080;
                else
                    webPort++;
                if (webPort <= 8090)
                {
                    webGateway.SetOption("Port", webPort.ToString());
                    started = webGateway.Start();
                }
            }

            if (started)
            {
                RaiseEvent(
                    Domains.HomeGenie_System,
                    Domains.HomeAutomation_HomeGenie,
                    SourceModule.Master,
                    "HomeGenie service ready",
                    Properties.SystemInfoHttpAddress,
                    webGateway.GetOption("Host").Value + ":" + webGateway.GetOption("Port").Value
                );
            }
            else
            {
                Program.Quit(false);
            }
        }
Example #3
0
 // try to bind httpport, launch WebGateway threads, and listen to Interfaces' changes
 public bool StartService()
 {
     bool success = false;
     try
     {
         // TODO: collects gateways to a List<MIGGateway> and expose it by public member Gateways
         //
         webGateway.Configure(webServiceConfig);
         webGateway.ProcessRequest += webGateway_ProcessRequest;
         webGateway.Start();
         //
         tcpGateway.Configure(new TcpSocketGatewayConfiguration()
         {
             Port = tcpGatewayPort
         });
         tcpGateway.ProcessRequest += tcpGateway_ProcessRequest;
         tcpGateway.Start();
         //
         success = true;
     }
     catch (Exception ex)
     {
         webGateway = new WebServiceGateway();
         tcpGateway = new TcpSocketGateway();
         // TODO: add error logging
     }
     return success;
 }