Beispiel #1
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);
            }
        }
Beispiel #2
0
        public void Connect(string serverAddress, int serverPort)
        {
            Trace.WriteLine(Invariant($"Connecting to {serverAddress}"));
            try
            {
                HsClient = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverAddress, serverPort), this);
                HsClient.Connect();
                HS = HsClient.ServiceProxy;

#pragma warning disable S1481                   // Unused local variables should be removed
                var apiVersion = HS.APIVersion; // just to make sure our connection is valid
#pragma warning restore S1481                   // Unused local variables should be removed

                hsTraceListener = new HSTraceListener(this as ILogger);
                Debug.Listeners.Add(hsTraceListener);
            }
            catch (Exception ex)
            {
                throw new HspiConnectionException(Invariant($"Error connecting homeseer SCS client: {ex.GetFullMessage()}"), ex);
            }

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

#pragma warning disable S1481                         // Unused local variables should be removed
                var apiVersion = Callback.APIVersion; // just to make sure our connection is valid
#pragma warning restore S1481                         // Unused local variables should be removed
            }
            catch (Exception ex)
            {
                throw new HspiConnectionException(Invariant($"Error connecting callback SCS client: {ex.GetFullMessage()}"), ex);
            }

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

            HsClient.Disconnected += HsClient_Disconnected;
            Trace.WriteLine(Invariant($"Connected to {serverAddress}"));
        }