/// <summary> /// Provide work with remote console <paramref name="remoteConsole"/> /// </summary> /// <param name="remoteConsole">Remote console</param> private static void DoWork(IRemoteConsole remoteConsole) { while (true) { Console.Write("{0}> ", remoteConsole.GetUserPosition()); string command = Console.ReadLine(); if (command.ToUpper().Equals("QUITE")) { remoteConsole.Quite(); break; } string serverResponse = String.Empty; try { serverResponse = remoteConsole.SendCommand(command); } catch (CommunicationObjectFaultedException ex) { Console.WriteLine("Соединение с сервером потеряно"); break; } catch (ProtocolException ex) { Console.WriteLine("Соединение с сервером потеряно"); break; } if (serverResponse == null || serverResponse.Trim() == String.Empty) { continue; } Console.WriteLine(serverResponse); } }
internal static void Main(string[] args) { IWindsorContainer container = new WindsorContainer(new XmlInterpreter("../../ServerConfig.xml")); //Testing the component IRemoteConsole remoteConsole = (IRemoteConsole)container["remote.console"]; remoteConsole.WriteLine("Server started....press a key to stop."); Console.ReadLine(); }
static void Main(String[] args) { IWindsorContainer container = new WindsorContainer(new XmlInterpreter("../../ClientConfig.xml")); // The component doesn't exists here, so it's a remoteComponent IRemoteConsole remoteConsole = (IRemoteConsole)container["remote.console"]; remoteConsole.WriteLine("Writing this text from Client into Server."); Console.WriteLine("....press a key to stop"); Console.ReadLine(); }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); InstanceContext context = new InstanceContext(new ConsoleCallback()); _factory = new DuplexChannelFactory <IRemoteConsole>(context, _endpointName); while (true) { IRemoteConsole remoteConsole = connectToServer(); if (remoteConsole == null) { return; } DoWork(remoteConsole); } }
/// <summary> /// Provide create connection to server /// </summary> /// <returns>Remote console to work with server</returns> private static IRemoteConsole connectToServer() { IRemoteConsole returnValue = null; while (returnValue == null) { Console.Write("> "); string command = Console.ReadLine(); ConnectionData connectionData = null; try { connectionData = ConnectionData.Parse(command); } catch (FormatException ex) { Console.WriteLine("Пожалуйста введите 'connect <server address/server name> <user name>'"); continue; } returnValue = tryConnectToServer(connectionData); } return(returnValue); }
/// <summary> /// try to connect to the server by connection information <paramref name="connectionData"/> /// </summary> /// <param name="connectionData">data to connect to a server</param> /// <returns>Remote console from server. <c>null</c> - if connection was fail</returns> private static IRemoteConsole tryConnectToServer(ConnectionData connectionData) { IRemoteConsole remoteConsole = _factory.CreateChannel(connectionData.Endpoint); try { AuthenticationResult authenticateSuccess = remoteConsole.Authenticate(connectionData.UserName); if (authenticateSuccess.IsSuccess) { Console.WriteLine("Количесто уже подключенных пользователей: {0}", authenticateSuccess.CountAuthenticatedUsers); return(remoteConsole); } else { Console.WriteLine("Ошибка при аутентификации"); } } catch (EndpointNotFoundException ex) { Console.WriteLine("Сервер с данным адресом не был найден"); } return(null); }
/// <summary> /// Creates the actual VNC or RDP client control. /// </summary> private void initSubControl() { Program.AssertOnEventThread(); //When switch to RDP from VNC, if RDP IP is empty, do not try to switch. if (String.IsNullOrEmpty(rdpIP) && !UseVNC && RemoteConsole != null) { return; } bool wasFocused = false; this.Controls.Clear(); Size oldSize = new Size(1024, 768); // Kill the old client. if (RemoteConsole != null) { oldSize = RemoteConsole.DesktopSize; wasFocused = RemoteConsole.ConsoleControl != null && RemoteConsole.ConsoleControl.Focused; RemoteConsole.DisconnectAndDispose(); RemoteConsole = null; this.vncPassword = null; } // Reset haveTriedLoginWithoutPassword = false; if (UseVNC || String.IsNullOrEmpty(rdpIP)) { this.AutoScroll = false; this.AutoScrollMinSize = new Size(0, 0); vncClient = new VNCGraphicsClient(this); vncClient.UseSource = UseSource; vncClient.DesktopResized += ResizeHandler; vncClient.Resize += ResizeHandler; vncClient.ErrorOccurred += ErrorHandler; vncClient.ConnectionSuccess += ConnectionSuccess; vncClient.Dock = DockStyle.Fill; } else { if (rdpClient == null) { if (this.ParentForm is FullScreenForm) { oldSize = ((FullScreenForm)ParentForm).contentPanel.Size; } this.AutoScroll = true; this.AutoScrollMinSize = oldSize; rdpClient = new RdpClient(this, oldSize, ResizeHandler); rdpClient.OnDisconnected += new EventHandler(parentVNCTabView.RdpDisconnectedHandler); } } if (RemoteConsole != null && RemoteConsole.ConsoleControl != null) { RemoteConsole.KeyHandler = this.KeyHandler; RemoteConsole.SendScanCodes = !this.sourceIsPV; RemoteConsole.Scaling = Scaling; RemoteConsole.DisplayBorder = this.displayFocusRectangle; SetKeyboardAndMouseCapture(autoCaptureKeyboardAndMouse); if (wasPaused) { RemoteConsole.Pause(); } else { RemoteConsole.Unpause(); } ConnectToRemoteConsole(); if (wasFocused) { RemoteConsole.Activate(); } } parentVNCTabView.ShowGpuWarningIfRequired(); }