Ejemplo n.º 1
0
        void IDriverPresenter.OnRegisterDriver()
        {
            try
            {
                DriverClient listener = new DriverClient(this);
                _scsClient = ScsServiceClientBuilder.CreateClient <IDriverServer>(
                    new ScsTcpEndPoint(defaultIP, defaultPort), listener);
                _scsClient.Connect();

                _server = _scsClient.ServiceProxy;

                _driverId = _view.GetDriverId();

                if (_driverId != INVALID_DRIVER_ID)
                {
                    _server.RegisterDriver(_driverId, 0);
                    _view.OnConnected();
                }
                else
                {
                    _scsClient = null;
                    _view.OnDisconnected();
                }
            }

            catch (Exception)
            {
                _scsClient = null;
                _view.OnDisconnected();
            }
        }
Ejemplo n.º 2
0
        private void Connect(object sender, RoutedEventArgs e)
        {
            if (ScsClient != null)
                ScsClient.Disconnect();

            ScsClient = ScsServiceClientBuilder.CreateClient<IInformerService>(
                new ScsTcpEndPoint(ServerIp.Text, 23232), Client);

            ScsClient.Timeout = 1000;
            ScsClient.ConnectTimeout = 2000;

            ScsClient.Connected += OnScsConnnected;
            ScsClient.Disconnected += OnScsDisconnected;

            Log("Try connect...");

            ThreadPool.QueueUserWorkItem(
                o =>
                    {
                        try
                        {
                            ScsClient.Connect();
                        }
                        catch
                        {
                            Log("Can't connect to server.");
                        }
                    });
        }
Ejemplo n.º 3
0
        void IDriverPresenter.RegisterDriver(int driverID)
        {
            try
            {
                _driverId = driverID;

                DriverClient listener = new DriverClient(this);
                _scsClient = ScsServiceClientBuilder.CreateClient <IDriverServer>(
                    new ScsTcpEndPoint(defaultIP, defaultPort), listener);
                _scsClient.Connect();

                _server = _scsClient.ServiceProxy;

                if (_driverId != INVALID_DRIVER_ID && _server.RegisterDriver(_driverId, 0) == 0)
                {
                    NotifyConnected();
                }
                else
                {
                    _scsClient = null;
                    NotifyDisconnected();
                }
            }

            catch (Exception)
            {
                _scsClient = null;
                NotifyDisconnected();
            }
        }
Ejemplo n.º 4
0
        private void Connect(object sender, RoutedEventArgs e)
        {
            if (ScsClient != null)
            {
                ScsClient.Disconnect();
            }

            ScsClient = ScsServiceClientBuilder.CreateClient <IInformerService>(
                new ScsTcpEndPoint(ServerIp.Text, 23232), Client);

            ScsClient.Timeout        = 1000;
            ScsClient.ConnectTimeout = 2000;

            ScsClient.Connected    += OnScsConnnected;
            ScsClient.Disconnected += OnScsDisconnected;

            Log("Try connect...");

            ThreadPool.QueueUserWorkItem(
                o =>
            {
                try
                {
                    ScsClient.Connect();
                }
                catch
                {
                    Log("Can't connect to server.");
                }
            });
        }
Ejemplo n.º 5
0
        public void ConnectionTest()
        {
            //Disconnect if currently connected

            //Create a ChatClient to handle remote method invocations by server
            //_chatClient = this;

            //Create a SCS client to connect to SCS server
            //The 2nd parameter is EXTREMELY important to note and must be non-null if you want to have Server -> Client callbacks.
            _scsClient = ScsServiceClientBuilder.CreateClient<IChatService>(
                new ScsTcpEndPoint("127.0.0.1", 10048), this );

            //Register events of SCS client
            _scsClient.Connected += ScsClient_Connected;
            _scsClient.Disconnected += ScsClient_Disconnected;

            //Connect to the server
            _scsClient.Connect();

            Thread.Sleep(5000);

            _scsClient.ServiceProxy.SendMessageToRoom(new ChatMessage("Hi Everyone"));

            Console.ReadKey();
        }
Ejemplo n.º 6
0
 public void Connect()
 {
     _client = ScsServiceClientBuilder.CreateClient<INDistManagementService>(ScsEndPoint.CreateEndPoint(Address), _serverListener);
     _client.Connected += Client_Connected;
     _client.Disconnected += Client_Disconnected;
     _client.Connect();
 }
Ejemplo n.º 7
0
 public void Connect()
 {
     _client               = ScsServiceClientBuilder.CreateClient <INDistManagementService>(ScsEndPoint.CreateEndPoint(Address), _serverListener);
     _client.Connected    += Client_Connected;
     _client.Disconnected += Client_Disconnected;
     _client.Connect();
 }
Ejemplo n.º 8
0
 public bool Connect(string IP, int Port)
 {
     clientService = ScsServiceClientBuilder.CreateClient <ITaxiService>(new ScsTcpEndPoint(IP, Port));
     try
     {
         clientService.Connect();
     }
     catch
     {
         clientService.Dispose();
         return(false);
     }
     return(true);
 }
Ejemplo n.º 9
0
        public void GetExamCopy()
        {
            //  try
            {
                HighSecurity = highSecChkBox.Checked;
                //Create a client to connecto to phone book service on local server and
                //10048 TCP port.
                client = ScsServiceClientBuilder.CreateClient <INetworkExamService>(
                    new ScsTcpEndPoint(ipTxtBox.Text, int.Parse(portTxtBox.Text)));

                // client.Timeout = 3;
                aLogger.LogMessage($"Trying to connect to the server (timeout {client.Timeout} Seconds)", LogMsgType.Verbose);
                //Connect to the server
                client.Connect();

                aLogger.LogMessage("Connected to server", LogMsgType.Verbose);


                RequiredDetails requiredDetails = new RequiredDetails(studentNameTxtBox.Text, studentIDTxtBox.Text, examKeyTxtBox.Text, (HighSecurity? sharedKeyISTxtBox.Text:"Low Security Settings Selected"));
                //Add some persons
                var copy = client.ServiceProxy.GetExamCopyEncryptedZipped(requiredDetails);
                requiredDetails.DecryptDetails(examKeyTxtBox.Text);
                if (!ExamHelper.ValidateExamCopy(copy, examKeyTxtBox.Text, aLogger, sharedKeyISTxtBox.Text,
                                                 (highSecChkBox.Checked ? Security.FilterationSecurityLevel.High : Security.FilterationSecurityLevel.Moderate), requiredDetails.SequenceNumber))
                {
                    return;
                }

                aLogger.LogMessage("Received Exam Copy", LogMsgType.Verbose);

                aLogger.LogMessage("Checking Exam Copy...", LogMsgType.Verbose);

                var exam = Quizez.ExamHelper.GetExamFromByteArray(copy, examKeyTxtBox.Text, sharedKeyISTxtBox.Text,
                                                                  (highSecChkBox.Checked?Security.FilterationSecurityLevel.High:Security.FilterationSecurityLevel.Moderate));

                aLogger.LogMessage("Exam Checked Correcly ...", LogMsgType.Verbose);

                //Disconnect from server
                //   client.Disconnect();

                //  aLogger.LogMessage("Disconnected from server", LogMsgType.Verbose);

                anExam = exam;
            }
            // catch (Exception ex)
            {
                //  aLogger.LogMessage(ex.Message, LogMsgType.Error);
            }
        }
Ejemplo n.º 10
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}"));
        }
Ejemplo n.º 11
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 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);
            }
        }
Ejemplo n.º 12
0
 private void loginButton_Click(object sender, EventArgs e)
 {
     client = ScsServiceClientBuilder.CreateClient <IBugTrackerService>(new ScsTcpEndPoint("127.0.0.1", 10048));
     client.Connect();
     userInfo          = new UserInfo();
     userInfo.Username = usernameField.Text;
     userInfo.Password = passwordField.Text;
     if (client.ServiceProxy.Login(userInfo))
     {
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     else
     {
         MessageBox.Show("Wrong username or password");
     }
 }
Ejemplo n.º 13
0
        static void Main()
        {
            ServerOpt so = new ServerOpt();

            Client = new InformerClient();

            Client.OnMessage += Console.WriteLine;

            Client.OnAuthed += () =>
            {
                Console.WriteLine("Authed...");
                new Thread(SendOnlineUpdates).Start();
            };

            ScsClient = ScsServiceClientBuilder.CreateClient <IInformerService>
                            (new ScsTcpEndPoint(so.serverip, so.informerPort), Client);

            ScsClient.Timeout = ScsClient.ConnectTimeout = 2500;

            ScsClient.Connected += (sender, args) =>
            {
                Console.WriteLine("Connected...");
                ScsClient.ServiceProxy.Auth(so.sercurityKey);
            };

            while (true)
            {
                try
                {
                    if (ScsClient.CommunicationState == CommunicationStates.Disconnected)
                    {
                        ScsClient.Connect();
                    }

                    while (ScsClient.CommunicationState == CommunicationStates.Connected)
                    {
                        Thread.Sleep(1000);
                    }
                }
                catch
                {
                }

                SendUpdate(); //Offline
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Connects to the server.
        /// It automatically Logins to server if connection success.
        /// </summary>
        public void Connect()
        {
            //Disconnect if currently connected
            Disconnect();

            //Create a ChatClient to handle remote method invocations by server
            _bugTrackerClient = new BugTrackerClient(BugProcess);

            //Create a SCS client to connect to SCS server
            _scsClient = ScsServiceClientBuilder.CreateClient <IBugTrackerService>(new ScsTcpEndPoint("localhost", 10048), _bugTrackerClient);

            //Register events of SCS client
            _scsClient.Connected    += ScsClient_Connected;
            _scsClient.Disconnected += ScsClient_Disconnected;

            //Connect to the server
            _scsClient.Connect();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Connects to the server.
        /// It automatically Logins to server if connection success.
        /// </summary>
        public void Connect()
        {
            //Disconnect if currently connected
            Disconnect();

            //Create a ChatClient to handle remote method invocations by server
            _chatClient = new ChatClient(ChatRoom);

            //Create a SCS client to connect to SCS server
            _scsClient = ScsServiceClientBuilder.CreateClient <IChatService>(new ScsTcpEndPoint(LoginForm.ServerIpAddress, LoginForm.ServerTcpPort), _chatClient);

            //Register events of SCS client
            _scsClient.Connected    += ScsClient_Connected;
            _scsClient.Disconnected += ScsClient_Disconnected;

            //Connect to the server
            _scsClient.Connect();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Connects to the server.
        /// It automatically Logins to server if connection success.
        /// </summary>
        public void Connect()
        {
            //Disconnect if currently connected
            Disconnect();

            //Create a ChatClient to handle remote method invocations by server
            _chatClient = new ChatClient(ChatRoom);

            //Create a SCS client to connect to SCS server
            _scsClient = ScsServiceClientBuilder.CreateClient<IChatService>(new ScsTcpEndPoint(LoginForm.ServerIpAddress, LoginForm.ServerTcpPort), _chatClient);

            //Register events of SCS client
            _scsClient.Connected += ScsClient_Connected;
            _scsClient.Disconnected += ScsClient_Disconnected;

            //Connect to the server
            _scsClient.Connect();
        }
Ejemplo n.º 17
0
        private void Connect(int attempts)
        {
            try {
                _client.Connect();
                SpeechHost = _client.ServiceProxy;
                //make sure the interface is supported
                try {
                    var speakHostVersion = SpeechHost.version();
                    if (speakHostVersion != SPEAKER_INTERFACE_VERSION)
                    {
                        Console.WriteLine("Speaker API version mismatch");
                        DisconnectNow();
                        return;
                    }
                }
                catch (Exception exception) {
                    Console.WriteLine($"Error attempting to connect to server, please check your connection options: {exception.Message}");
                    DisconnectNow();
                    return;
                }

                var response = SpeechHost.Connect(HostName, ClientName, IpAddress, _username, _password);

                if (string.IsNullOrEmpty(response))
                {
                    return;
                }

                Console.WriteLine($"Error, Unable to connect speaker client interface: {response}");
                DisconnectNow();
            }
            catch (Exception exception) {
                Console.WriteLine($"Cannot connect speaker client attempt {attempts.ToString()}");
                if (exception.Message.ToLower().Contains("timeout occurred.") && attempts < 6)
                {
                    Connect(attempts + 1);
                }
                else
                {
                    DisconnectNow();
                    Console.WriteLine($"Error, Unable to connect speaker client interface: {exception.Message}");
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Connects to the server.
        /// It automatically Logins to server if connection success.
        /// </summary>
        public void Connect()
        {
            //Disconnect if currently connected
            Disconnect();

            //Create a ChatClient to handle remote method invocations by server
            _chatClient = new ChatClient(FormView);

            //Create a SCS client to connect to SCS server
            _scsClient = ScsServiceClientBuilder.CreateClient <IMsgService>(new ScsTcpEndPoint("127.0.0.1", 9000), _chatClient);


            //Register events of SCS client
            _scsClient.Connected    += ScsClient_Connected;
            _scsClient.Disconnected += ScsClient_Disconnected;

            //Connect to the server
            _scsClient.Connect();
        }
Ejemplo n.º 19
0
        static void Main()
        {
            ServerOpt so = new ServerOpt();

            Client = new InformerClient();

            Client.OnMessage += Console.WriteLine;

            Client.OnAuthed += () =>
                {
                    Console.WriteLine("Authed...");
                    new Thread(SendOnlineUpdates).Start();
                };

            ScsClient = ScsServiceClientBuilder.CreateClient<IInformerService>
                (new ScsTcpEndPoint(so.serverip, so.informerPort), Client);

            ScsClient.Timeout = ScsClient.ConnectTimeout = 2500;

            ScsClient.Connected += (sender, args) =>
                {
                    Console.WriteLine("Connected...");
                    ScsClient.ServiceProxy.Auth(so.sercurityKey);
                };

            while (true)
            {
                try
                {
                    if (ScsClient.CommunicationState == CommunicationStates.Disconnected)
                        ScsClient.Connect();

                    while (ScsClient.CommunicationState == CommunicationStates.Connected)
                        Thread.Sleep(1000);
                }
                catch
                {
                }

                SendUpdate(); //Offline
            }
        }
Ejemplo n.º 20
0
        public AuthentificationServiceClient()
        {
            string ip   = ConfigurationManager.AppSettings["MasterIP"];
            int    port = Convert.ToInt32(ConfigurationManager.AppSettings["MasterPort"]);

            _client = ScsServiceClientBuilder.CreateClient <IAuthentificationService>(new ScsTcpEndPoint(ip, port));
            System.Threading.Thread.Sleep(1000);
            while (_client.CommunicationState != CommunicationStates.Connected)
            {
                try
                {
                    _client.Connect();
                }
                catch (Exception)
                {
                    Logger.Error(Language.Instance.GetMessageFromKey("RETRY_CONNECTION"), memberName: nameof(AuthentificationServiceClient));
                    System.Threading.Thread.Sleep(1000);
                }
            }
        }
        public CommunicationServiceClient()
        {
            string ip   = ConfigurationManager.AppSettings["MasterIP"];
            int    port = Convert.ToInt32(ConfigurationManager.AppSettings["MasterPort"]);

            _commClient = new CommunicationClient();
            _client     = ScsServiceClientBuilder.CreateClient <ICommunicationService>(new ScsTcpEndPoint(ip, port), _commClient);
            while (_client.CommunicationState != CommunicationStates.Connected)
            {
                try
                {
                    _client.Connect();
                }
                catch
                {
                    Logger.Log.Error(Language.Instance.GetMessageFromKey("RETRY_CONNECTION"));
                    System.Threading.Thread.Sleep(5000);
                }
            }
        }
Ejemplo n.º 22
0
        public void Connect(string serverAddress, int serverPort)
        {
            hsClient = ScsServiceClientBuilder.CreateClient <IHSApplication>(
                new ScsTcpEndPoint(serverAddress, serverPort), this);
            hsClient.Connect();

            hs = hsClient.ServiceProxy;
            Program.HsClient = hs;
            // make sure we're connected successfully
            double apiVersion = hs.APIVersion;

            callbackClient =
                ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(serverAddress, serverPort),
                                                                       this);
            callbackClient.Connect();
            callbacks  = callbackClient.ServiceProxy;
            apiVersion = callbacks.APIVersion;

            hs.Connect(this.Name, this.InstanceFriendlyName());
        }
        public AuthentificationServiceClient()
        {
            string ip   = ConfigurationManager.AppSettings["MasterIP"];
            int    port = Convert.ToInt32(ConfigurationManager.AppSettings["MasterPort"]);

            _client = ScsServiceClientBuilder.CreateClient <IAuthentificationService>(new ScsTcpEndPoint(ip, port));
            System.Threading.Thread.Sleep(1000);
            while (_client.CommunicationState != CommunicationStates.Connected)
            {
                try
                {
                    _client.Connect();
                }
                catch (Exception)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("[Info] Connection will be established");
                    System.Threading.Thread.Sleep(1000);
                }
            }
        }
Ejemplo n.º 24
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Connects to Homeseer at the specified server address and port.
        /// This is called by the console wrapper.
        /// </summary>
        /// <param name="serverAddress">The server address.</param>
        /// <param name="serverPort">The server port.</param>
        /// <exception cref="Exception"> Error connecting homeseer SCS client </exception>
        /// <exception cref="Exception"> Error connecting callback SCS client </exception>
        /// <exception cref="Exception"> Error connecting homeseer to our plugin </exception>
        public virtual void Connect(string serverAddress, int serverPort)
        {
            // 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;
                double 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;
                double 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(IFACE_NAME, INSTANCE_NAME);
            }
            catch (Exception ex)
            {
                throw new Exception("Error connecting homeseer to our plugin: " + ex.Message, ex);
            }
        }
Ejemplo n.º 25
0
        private void TryToConnect()
        {
            while (LoginBridge.CommunicationState != CommunicationStates.Connected && _autoConnect)
            {
                Log.Info("Try to connect to Login Server at {0}:{1}", _loginIp, _loginPort);
                try
                {
                    LoginBridge.Connect();
                    Log.Info("Connected to Login Server at {0}:{1}", _loginIp, _loginPort);
                }
                catch
                {
                    if (LoginBridge == null)
                    {
                        return;
                    }

                    Log.Info("Connection failed, reconnect...");
                    ConnectToLogin();
                }
            }
        }
Ejemplo n.º 26
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (LoginBox.Text == "" || PasswordBox.Password == "")
            {
                MessageBox.Show("Incorrect login or password");
                return;
            }
            try
            {
                LauncherService =
                    ScsServiceClientBuilder.CreateClient <ILauncherContract>(
                        new ScsTcpEndPoint("127.0.0.1", 6667));

                LauncherService.ConnectTimeout = 3000;
                LauncherService.Timeout        = 1000;

                LauncherService.Connect();

                StartingSequence(LauncherService.ServiceProxy.RegisterClientToken(LoginBox.Text, PasswordBox.Password));


                if (RememberBox.IsChecked != null && RememberBox.IsChecked.Value)
                {
                    using (StreamWriter sw = new StreamWriter(".\\cfg.ini"))
                    {
                        sw.WriteLine("{0}@{1}", LoginBox.Text, PasswordBox.Password);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Close();
            }
        }
Ejemplo n.º 27
0
        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!!!");
        }
Ejemplo n.º 28
0
        private void LoginToServer(string username, string password, string host)
        {
            _pingTimer.Enabled = false;
            _client = new DataClientClass(username);
            _logClient = new DataNetLogService();

            _serverHost = host;
            _logClientService = ScsServiceClientBuilder.CreateClient<IDataNetLogService>(new ScsTcpEndPoint(host, 443), _logClient);
            _clientService = ScsServiceClientBuilder.CreateClient<IDataAdminService>(new ScsTcpEndPoint(host, 443), _client);

            _clientService.Connected += ScsClient_Connected;

            try
            {
                _clientService.Connect();
                _logClientService.Connect();
                _client.login += LoggedIn;
                _client.block += BlockedByAdmin;
                _client.loginFailed += LoginFailed;
                _client.changePrivilages += ChangedPrivileges;
                _client.logout += DeletedClient;
                _client.symblolListRecieved += GroupSymbolChange;
                _client.symbolListChanged += RefreshSymbols;
                _client.groupChanged += RefreshGroups;
                _client.logoutServer += ServerStatusChanged;
                _client.busySymbolListReceived += BusySymbolChanged;
                _client.symbolPermissionChanged += RefreshSymbols;
                _clientService.Disconnected += OnServerCrashed;

                var logmsg = new DataAdminMessageFactory.LogMessage { Symbol = username, LogType = DataAdminMessageFactory.LogMessage.Log.Login, Group = "" };

                _logClientService.ServiceProxy.SendSimpleLog(logmsg);
                Settings.Default.connectionHost = _startControl.ui_textBox_ip.Text;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (_startControl != null)
                    _startControl.Invoke((Action)(() =>
                    {
                        ToastNotification.Show(_startControl, "Can't connect. IP is incorrect");
                        _startControl.ui_buttonX_logon.Enabled = true;
                    }
                        ));

                return;
            }
            var loginMsg = new DataAdminMessageFactory.LoginMessage(username, password, 't');
            try
            {
                _clientService.ServiceProxy.Login(loginMsg);

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 29
0
        private bool LoginToNormalizer(string host)
        {
            var serverStatus = true;
            var succesLogin = true;

            var tcpClient = new TcpClient();
            try
            {
                tcpClient.Connect(host, 442);
            }
            catch (Exception ex)
            {
                ToastNotification.Show(this, "The DataNormalizer is not available.");
                Console.Write(ex.Message);
                serverStatus = false;

            }
            if (serverStatus)
            {

                _dataNormalizatorClient = new DataNormalizatorClient();
                _dnormClientService =
                   ScsServiceClientBuilder.CreateClient<IDataNormalizatorService>(new ScsTcpEndPoint(host, 442),
                                                                                  _dataNormalizatorClient);

                try
                {
                    _dnormClientService.Connect();
                    _dnormClientService.ServiceProxy.Login(new DataNormalizatorMessageFactory.LoginMessage()
                                                            {
                                                                Username = _client.UserName,
                                                                IsLoginedToDa = true,
                                                                ServerMessage = ""
                                                            });
                    _normalizerStatus = true;
                }
                catch (Exception)
                {
                    succesLogin = false;
                    _normalizerStatus = false;
                }

                if (succesLogin)
                {
                    _dnormClientService.Disconnected += OnDNormCrashed;
                    _dataNormalizatorClient.OnActivation += CollectActivated;
                    _dataNormalizatorClient.OnDeactivation += CollectDeactivated;
                }
            }
            else succesLogin = false;

            return succesLogin;
        }
Ejemplo n.º 30
0
        private void OnGetAllIdsButtonClick(Object sender
                                            , EventArgs e)
        {
            if (m_RemoteAccessClient == null)
            {
                m_RemoteAccessClient = ScsServiceClientBuilder.CreateClient <IDVDProfilerRemoteAccess>(new ScsTcpEndPoint(IPAddressTextBox.Text, 10083));

                m_RemoteAccessClient.Connect();
            }

            ProfileIdListView.Items.Clear();

            TransactionObject transactionObject = m_RemoteAccessClient.ServiceProxy.BeginTransaction();

            if (m_ChangeNotificationObject == null)
            {
                AccessResult <ChangeNotificationObject> result = m_RemoteAccessClient.ServiceProxy.RegisterForProfileChanges(transactionObject, false);

                m_ChangeNotificationObject = result.Result;

                Timer.Interval = 5000;
                Timer.Tick    += new EventHandler(OnTimer1Tick);
            }

            Timer.Stop();

            try
            {
                AccessResult <List <String> > result = m_RemoteAccessClient.ServiceProxy.GetAllProfileIds(transactionObject, false);

                if (result.Success)
                {
                    if (result.Result != null)
                    {
                        foreach (String profileId in result.Result)
                        {
                            ListViewItem item = new ListViewItem();

                            GetTitle(transactionObject, profileId, item);

                            ProfileIdListView.Items.Add(item);
                        }
                    }

                    m_RemoteAccessClient.ServiceProxy.CommitTransaction(transactionObject);
                }
                else
                {
                    m_RemoteAccessClient.ServiceProxy.AbortTransaction(transactionObject);

                    MessageBox.Show("An error occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Timer.Start();
            }
            catch (Exception ex)
            {
                try
                {
                    m_RemoteAccessClient.ServiceProxy.AbortTransaction(transactionObject);
                }
                catch { }

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 31
0
        public static void Main(string[] args)
        {
            string serverIp = "127.0.0.1";

            string serverCmd = null;

            foreach (string serverCmd_loopVariable in args)
            {
                serverCmd = serverCmd_loopVariable;
                string[] ch = new string[1];
                ch[0] = "=";
                string[] parts = serverCmd.Split(ch, StringSplitOptions.None);
                switch (parts[0].ToLower())
                {
                case "server":
                    serverIp = parts[1];
                    break;

                case "instance":
                    try
                    {
                        Util.Instance = parts[1];
                    }
                    catch (Exception)
                    {
                        Util.Instance = "";
                    }
                    break;
                }
            }
Reconnect:
            Console.WriteLine("Plugin: " + Util.IFACE_NAME + " Instance: " + Util.Instance + " starting...");
            Console.WriteLine("Connecting to server at " + serverIp + "...");
            client         = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverIp, 10400), plugin);
            clientCallback = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(serverIp, 10400), plugin);
            int Attempts = 1;

TryAgain:

            try
            {
                client.Connect();
                clientCallback.Connect();

                double APIVersion = 0;

                try
                {
                    host       = client.ServiceProxy;
                    APIVersion = host.APIVersion;
                    // will cause an error if not really connected
                    Console.WriteLine("Host API Version: " + APIVersion.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error getting API version from host object: " + ex.Message + "->" + ex.StackTrace);
                    //Return
                }

                try
                {
                    callback   = clientCallback.ServiceProxy;
                    APIVersion = callback.APIVersion;
                    // will cause an error if not really connected
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error getting API version from callback object: " + ex.Message + "->" + ex.StackTrace);
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot connect attempt " + Attempts.ToString() + ": " + ex.Message);
                if (ex.Message.ToLower().Contains("timeout occurred."))
                {
                    Attempts += 1;
                    if (Attempts < 6)
                    {
                        goto TryAgain;
                    }
                }

                if (client != null)
                {
                    client.Dispose();
                    client = null;
                }
                if (clientCallback != null)
                {
                    clientCallback.Dispose();
                    clientCallback = null;
                }
                wait(4);
                return;
            }

            try
            {
                connectionJunction();
                if (reset)
                {
                    HSPI.armReset();
                    goto Reconnect;
                }
                else
                {
                    System.Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot connect(2): " + ex.Message);
                wait(2);
                System.Environment.Exit(0);
                return;
            }
        }
Ejemplo n.º 32
0
        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!!!");
        }
Ejemplo n.º 33
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (LoginBox.Text == "" || PasswordBox.Password == "")
            {
                MessageBox.Show("Incorrect login or password");
                return;
            }
            try
            {

                LauncherService =
                    ScsServiceClientBuilder.CreateClient<ILauncherContract>(
                        new ScsTcpEndPoint("127.0.0.1", 6667));

                LauncherService.ConnectTimeout = 3000;
                LauncherService.Timeout = 1000;

                LauncherService.Connect();

                StartingSequence(LauncherService.ServiceProxy.RegisterClientToken(LoginBox.Text, PasswordBox.Password));

                if (RememberBox.IsChecked != null && RememberBox.IsChecked.Value)
                {
                    using (StreamWriter sw = new StreamWriter(".\\cfg.ini"))
                    {
                        sw.WriteLine("{0}@{1}", LoginBox.Text, PasswordBox.Password);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Close();
            }
        }
Ejemplo n.º 34
0
        private void LoginToServer(string username, string password, string host, bool isMaster)
        {
            _logonThread = new Thread(
                () =>
                {
                    _pingTimer.Enabled = false;
                    _client = new DataClientClass(username);
                    _logClient = new DataNetLogService();
                    _logClientService =
                        ScsServiceClientBuilder.CreateClient<IDataNetLogService>(new ScsTcpEndPoint(host, 443),
                            _logClient);
                    _clientService =
                        ScsServiceClientBuilder.CreateClient<IDataAdminService>(new ScsTcpEndPoint(host, 443), _client);
                    _clientService.Connected += ScsClient_Connected;

                    try
                    {
                        _clientService.Connect();
                        _logClientService.Connect();

                        _client.login += LoggedIn;
                        _client.block += BlockedByAdmin;
                        _client.loginFailed += LoginFailed;
                        _client.changePrivilages += ChangedPrivileges;
                        _client.logout += DeletedClient;
                        _client.symblolListRecieved += GroupSymbolChange;
                        _client.symbolListChanged += RefreshSymbols;
                        _client.groupChanged += RefreshGroups;
                        //_client.logoutServer += ServerStatusChanged;
                        _client.busySymbolListReceived += BusySymbolChanged;
                        _client.symbolPermissionChanged += RefreshSymbols;
                        _clientService.Disconnected += OnServerCrashed;

                        var logmsg = new DataAdminMessageFactory.LogMessage
                        {
                            Symbol = username,
                            LogType = DataAdminMessageFactory.LogMessage.Log.Login,
                            Group = ""
                        };

                        _logClientService.ServiceProxy.SendSimpleLog(logmsg);
                        Settings.Default.scHost = _startControl.ui_textBox_ip.Text;
                        Settings.Default.scHostSlave = _startControl.ui_textBox_ip_slave.Text;
                        Invoke((Action) (() =>
                        {
                            labelItem_server.Text = isMaster ? "Master" : "Slave";
                            styleManager1.MetroColorParameters = new MetroColorGeneratorParameters(Color.White,
                                isMaster ? Color.Green : Color.YellowGreen);

                            metroStatusBar1.Refresh();
                        }));

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        if (_startControl != null)
                            _startControl.Invoke((Action) (() =>
                            {
                                if (isMaster)
                                {
                                    ToastNotification.Show(_startControl, "Can't connect. IP is incorrect");
                                    _startControl.ui_buttonX_logon.Enabled = true;
                                }
                                else
                                {
                                    Logout();
                                }
                            }
                                ));

                        return;
                    }
                    var loginMsg = new DataAdminMessageFactory.LoginMessage(username, password, 'd');
                    try
                    {
                        _clientService.ServiceProxy.Login(loginMsg);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        MessageBox.Show(ex.Message);
                    }
                }) {Name = "LogonThread", IsBackground = true};

            _logonThread.Start();
        }
Ejemplo n.º 35
0
        public static void Main(string[] args)
        {
            string serverIp = "127.0.0.1";

            string serverCmd = null;

            foreach (string serverCmd_loopVariable in args)
            {
                serverCmd = serverCmd_loopVariable;
                string[] ch = new string[1];
                ch[0] = "=";
                string[] parts = serverCmd.Split(ch, StringSplitOptions.None);
                switch (parts[0].ToLower())
                {
                case "server":
                    serverIp = parts[1];
                    break;

                case "instance":
                    try
                    {
                        Util.Instance = parts[1];
                    }
                    catch (Exception)
                    {
                        Util.Instance = "";
                    }
                    break;
                }
            }

            Console.WriteLine("Plugin: " + Util.IFACE_NAME + " Instance: " + Util.Instance + " starting...");
            Console.WriteLine("Connecting to server at " + serverIp + "...");
            client         = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverIp, 10400), plugin);
            clientCallback = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(serverIp, 10400), plugin);
            int Attempts = 1;

TryAgain:

            try
            {
                client.Connect();
                clientCallback.Connect();

                double APIVersion = 0;

                try
                {
                    host       = client.ServiceProxy;
                    APIVersion = host.APIVersion;
                    // will cause an error if not really connected
                    Console.WriteLine("Host API Version: " + APIVersion.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error getting API version from host object: " + ex.Message + "->" + ex.StackTrace);
                    //Return
                }

                try
                {
                    callback   = clientCallback.ServiceProxy;
                    APIVersion = callback.APIVersion;
                    // will cause an error if not really connected
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error getting API version from callback object: " + ex.Message + "->" + ex.StackTrace);
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot connect attempt " + Attempts.ToString() + ": " + ex.Message);
                if (ex.Message.ToLower().Contains("timeout occurred."))
                {
                    Attempts += 1;
                    if (Attempts < 6)
                    {
                        goto TryAgain;
                    }
                }

                if (client != null)
                {
                    client.Dispose();
                    client = null;
                }
                if (clientCallback != null)
                {
                    clientCallback.Dispose();
                    clientCallback = null;
                }
                wait(4);
                return;
            }

            try
            {
                // create the user object that is the real plugin, accessed from the pluginAPI wrapper
                Util.callback = callback;
                Util.hs       = host;
                plugin.OurInstanceFriendlyName = Util.Instance;
                // connect to HS so it can register a callback to us
                host.Connect(Util.IFACE_NAME, Util.Instance);
                Console.WriteLine("Connected, waiting to be initialized...");
                do
                {
                    System.Threading.Thread.Sleep(10);
                } while (client.CommunicationState == HSCF.Communication.Scs.Communication.CommunicationStates.Connected & !HSPI.bShutDown);
                Console.WriteLine("Connection lost, exiting");
                // disconnect from server for good here
                client.Disconnect();
                clientCallback.Disconnect();
                wait(2);
                System.Environment.Exit(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot connect(2): " + ex.Message);
                wait(2);
                System.Environment.Exit(0);
                return;
            }
        }
Ejemplo n.º 36
0
        public bool Connect(string username, string password)
        {
            lock (objlock)
            {
                string ipAddress = "127.0.0.1";

                Logger.LogInfo("Connecting speaker client {0} to HomeSeer IP {1}", _clientName, ipAddress);

                try
                {
                    _client = ScsServiceClientBuilder.CreateClient <ISpeechAPI>(new ScsTcpEndPoint(ipAddress, 10401), this);
                    _client.Disconnected += new EventHandler(ClientDisconnected);
                    _client.Connected    += new EventHandler(ClientConnected);
                }
                catch (Exception e)
                {
                    Logger.LogError(e.ToString());
                    return(false);
                }

                try
                {
                    _client.Connect();
                    _speakHost = _client.ServiceProxy;
                    //make sure the interface is supported
                    int v;
                    try
                    {
                        v = _speakHost.version();
                    }
                    catch (Exception e)
                    {
                        Logger.LogError("Error attempting to connect to server, please check your connection options: {0}", e.Message);
                        return(false);
                    }

                    if (v != SPEAKER_INTERFACE_VERSION)
                    {
                        Logger.LogError("Speaker API version mismatch");
                        return(false);
                    }

                    //string localIp = Util.GetLocalIp();
                    string rval = _speakHost.Connect("Sample Plugin", _clientName, "127.0.0.1", username, password);

                    if (!string.IsNullOrEmpty(rval))
                    {
                        Logger.LogError("Error, Unable to connect speaker client interface: {0}", rval);
                        DisconnectNow();
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError("Error while connecting speaker client: {0}", e.ToString());
                    return(false);
                }
            }

            return(true);
        }