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; }
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 Exception("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 Exception("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 Exception("Error connecting homeseer to our plugin: " + ex.Message, ex); } }
public void run() { string[] cmdArgs = Environment.GetCommandLineArgs(); Console.WriteLine("Manager::run() - arguments are {0}", Environment.CommandLine); String paramServer = "127.0.0.1"; String paramInstance = ""; foreach (string arg in cmdArgs) { Console.WriteLine(" - arg: {0}", arg); if (arg.Contains("=")) { String[] ArgS = arg.Split('='); Console.WriteLine(" -- {0}=>{1}", ArgS[0], ArgS[1]); switch (ArgS[0]) { case "server": paramServer = ArgS[1]; break; case "instance": paramInstance = ArgS[1]; break; default: Console.WriteLine("Unhandled param: {0}", ArgS[0]); break; } } } pluginInst = new HSPI(paramInstance); //Environment.CommandLine. client = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); clientCB = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); try { client.Connect(); clientCB.Connect(); hsHost = client.ServiceProxy; double ApiVer = hsHost.APIVersion; Console.WriteLine("Host ApiVersion : {0}", ApiVer); hsHostCB = clientCB.ServiceProxy; ApiVer = hsHostCB.APIVersion; Console.WriteLine("Host CB ApiVersion : {0}", ApiVer); } catch (Exception e) { Console.WriteLine("Cannot start instance because of : {0}", e.Message); return; } Console.WriteLine("Connection to HS succeeded!"); try { pluginInst.hsHost = hsHost; pluginInst.hsHostCB = hsHostCB; hsHost.Connect(pluginInst.Name, ""); Console.WriteLine("Connected, waiting to be initialized..."); do { Thread.Sleep(500); } while (client.CommunicationState == CommunicationStates.Connected && pluginInst.Running); Console.WriteLine("Connection lost, exiting"); pluginInst.Running = false; client.Disconnect(); clientCB.Disconnect(); } catch (Exception e) { Console.WriteLine("Failed to host connect: {0}", e.Message); return; } Console.WriteLine("Exiting!!!"); }
public void run() { string[] cmdArgs = Environment.GetCommandLineArgs(); Console.WriteLine("Manager::run() - arguments are {0}", Environment.CommandLine); String paramServer = "127.0.0.1"; String paramInstance = ""; foreach (string arg in cmdArgs) { Console.WriteLine(" - arg: {0}", arg); if (arg.Contains("=")) { String[] ArgS = arg.Split('='); Console.WriteLine(" -- {0}=>{1}", ArgS[0], ArgS[1]); switch (ArgS[0]) { case "server": paramServer = ArgS[1]; break; case "instance": paramInstance = ArgS[1]; break; default: Console.WriteLine("Unhandled param: {0}", ArgS[0]); break; } } } pluginInst = new HSPI(paramInstance); //Environment.CommandLine. client = ScsServiceClientBuilder.CreateClient<IHSApplication>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); clientCB = ScsServiceClientBuilder.CreateClient<IAppCallbackAPI>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); try { client.Connect(); clientCB.Connect(); hsHost = client.ServiceProxy; double ApiVer = hsHost.APIVersion; Console.WriteLine("Host ApiVersion : {0}", ApiVer); hsHostCB = clientCB.ServiceProxy; ApiVer = hsHostCB.APIVersion; Console.WriteLine("Host CB ApiVersion : {0}", ApiVer); } catch (Exception e) { Console.WriteLine("Cannot start instance because of : {0}", e.Message); return; } Console.WriteLine("Connection to HS succeeded!"); try { pluginInst.hsHost = hsHost; pluginInst.hsHostCB = hsHostCB; hsHost.Connect(pluginInst.Name, ""); Console.WriteLine("Connected, waiting to be initialized..."); do { Thread.Sleep(500); } while (client.CommunicationState == CommunicationStates.Connected && pluginInst.Running); Console.WriteLine("Connection lost, exiting"); pluginInst.Running = false; client.Disconnect(); clientCB.Disconnect(); } catch (Exception e) { Console.WriteLine("Failed to host connect: {0}", e.Message); return; } Console.WriteLine("Exiting!!!"); }