public void Connect(string serverAddress, int serverPort)
        {
            try
            {
                HsClient = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverAddress, serverPort), this);
                HsClient.Connect();
                HS = HsClient.ServiceProxy;

                var apiVersion = HS.APIVersion; // just to make sure our connection is valid

                hsTraceListener = new HSTraceListener(this as IDebugLogger);
                Debug.Listeners.Add(hsTraceListener);
                this.Log.HS = HS;
            }
            catch (Exception ex)
            {
                throw new HspiConnectionException(
                          String.Format(CultureInfo.InvariantCulture, "Error connecting homeseer SCS client: {0}", ex.GetFullMessage()),
                          ex
                          );
            }

            try
            {
                CallbackClient = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(serverAddress, serverPort), this);
                CallbackClient.Connect();
                Callback = CallbackClient.ServiceProxy;

                var apiVersion = Callback.APIVersion; // just to make sure our connection is valid
            }
            catch (Exception ex)
            {
                throw new HspiConnectionException(
                          String.Format(CultureInfo.InvariantCulture, "Error connecting callback SCS client: {0}", ex.GetFullMessage()),
                          ex
                          );
            }

            // Establish the reverse connection from homeseer back to our plugin
            try
            {
                HS.Connect(Name, InstanceFriendlyName());
            }
            catch (Exception ex)
            {
                throw new HspiConnectionException(
                          String.Format(CultureInfo.InvariantCulture, "Error connecting homeseer to our plugin: {0}", ex.GetFullMessage()),
                          ex
                          );
            }

            HsClient.Disconnected += HsClient_Disconnected;
        }
Beispiel #2
0
        public void Connect(string serverAddress, int serverPort)
        {
            // This method is called by our console wrapper at launch time

            // Create our main connection to the HomeSeer TCP communication framework
            // part 1 - hs object Proxy
            try
            {
                HsClient =
                    ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverAddress, serverPort),
                                                                          this);
                HsClient.Connect();
                HS = HsClient.ServiceProxy;

                // ReSharper disable once UnusedVariable
                var apiVersion = HS.APIVersion; // just to make sure our connection is valid
            }
            catch (Exception ex)
            {
                throw new HspiConnectionException($"Error connecting HomeSeer SCS client: {ex.Message}", ex);
            }

            // part 2 - callback object Proxy
            try
            {
                CallbackClient =
                    ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(
                        new ScsTcpEndPoint(serverAddress, serverPort), this);
                CallbackClient.Connect();
                Callback = CallbackClient.ServiceProxy;

                // ReSharper disable once UnusedVariable
                var apiVersion = Callback.APIVersion; // just to make sure our connection is valid
            }
            catch (Exception ex)
            {
                throw new HspiConnectionException($"Error connecting callback SCS client: {ex.Message}", ex);
            }

            // Establish the reverse connection from HomeSeer back to our plugin
            try
            {
                HS.Connect(Name, InstanceFriendlyName());
            }
            catch (Exception ex)
            {
                throw new HspiConnectionException($"Error connecting HomeSeer to our plugin: {ex.Message}", ex);
            }
        }
        public bool Connect(string serverAddress = null, int serverPort = -1)
        {
            if (Shutdown)
            {
                return(true);
            }

            if (serverAddress != null)
            {
                // If passed address/port - store it
                // So later may try to reconnect using stored values
                this.serverAddress = serverAddress;
                this.serverPort    = serverPort;
            }

            // Set HS to HsClient.ServiceProxy only when succsessfully finished connecting
            HS = null;

            // Create our main connection to the HomeSeer TCP communication framework
            // part 1 - hs object Proxy
            try
            {
                HsClient = ScsServiceClientBuilder.CreateClient <IHSApplication>(
                    new ScsTcpEndPoint(this.serverAddress, this.serverPort), this);
                HsClient.Disconnected += HsClient_Disconnected;
                HsClient.Connect();
                // Set HS to HsClient.ServiceProxy only when succsessfully finished connecting
                //HS = HsClient.ServiceProxy;

                // just to make sure our connection is valid
                Console.WriteLine("Host ApiVersion : {0}", HsClient.ServiceProxy.APIVersion);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error connecting HomeSeer SCS client: {ex.Message}");
                return(false);
            }

            // part 2 - callback object Proxy
            try
            {
                CallbackClient = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(
                    new ScsTcpEndPoint(this.serverAddress, this.serverPort), this);
                CallbackClient.Connect();
                Callback = CallbackClient.ServiceProxy;

                // just to make sure our connection is valid
                Console.WriteLine("Host CB ApiVersion : {0}", Callback.APIVersion);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error connecting callback SCS client: {ex.Message}");
                return(false);
            }

            // part 3 - Establish the reverse connection from HomeSeer back to our plugin
            try
            {
                HsClient.ServiceProxy.Connect(Name, InstanceFriendlyName());
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error connecting HomeSeer to our plugin: {ex.Message}");
                return(false);
            }

            // All good, call virtual Connected() to inform plugin
            HS = HsClient.ServiceProxy;
            Connected(true);
            return(true);
        }