public ConnectionsViewModel() { _controllerPipeClient = new ControllerPipeClient(); _controllerPipeClient.ConnectionInfo += OnConnectInfo; _controllerPipeClient.RequestPassword += OnRequestPassword; _controllerPipeClient.Message += OnMessage; _controllerPipeClient.Initialized += OnInitialized; }
private static void ListConnections(ControllerPipeClient pPipeClient) { throw new NotImplementedException(); }
private static void Main(string[] pArgs) { if (pArgs.Length == 0 || pArgs[0] == "--help" || pArgs[0] == "-h") { PrintHelp(); return; } switch (pArgs[0]) { case "--makefile": var output = pArgs[1]; var config = pArgs[2]; var ca = pArgs[3]; var name = pArgs[4]; var connectionFile = new ConnectionDefinitionFile { ConfigurationData = File.ReadAllText(config), AuthorityCertData = File.ReadAllBytes(ca), ConnectionName = name }; connectionFile.SaveFile(output + ".connection"); return; } ControllerPipeClient pipeClient; try { pipeClient = new ControllerPipeClient(); } catch (Exception exception) { Console.WriteLine("An error has occured connecting to the OpenVPN UI Host service."); Console.WriteLine("Exception: " + exception.Message); return; } pipeClient.Initialized += pMessage => { switch (pArgs[0]) { case "--list": ListConnections(pipeClient); return; //case "--start": // var con = 0; // if(pArgs.Length!=2 || !Int32.TryParse(pArgs[1],out con)) // { // Console.WriteLine("SYNTAX: --start {connection number}"); // return; // } // if(con < pipeClient.ConnectionCount) // { // if(pipeClient[con].ConnectionStatus==ConnectionStatus.Disconnected) // { // } else // { // Console.WriteLine("{0} is already {1}.", pipeClient[con].Name, pipeClient[i].ConnectionStatus.ToString().ToLower()); // } // } // else // Console.WriteLine("ERROR: Invalid connection number."); // break; case "--stop": if (pArgs.Length != 2 || !int.TryParse(pArgs[1], out var _)) { Console.WriteLine("SYNTAX: --start {connection number}"); return; } if (0 < pipeClient.ConnectionCount) { if (pipeClient[0].ConnectionStatus == ConnectionStatus.Disconnected) { } else { Console.WriteLine("{0} is already {1}.", pipeClient[0].Name, pipeClient[0].ConnectionStatus.ToString().ToLower()); } } else { Console.WriteLine("ERROR: Invalid connection number."); } break; } }; }
public ConnectionViewModel(ConnectionsViewModel pConnections, ControllerPipeClient pPipeClient, BaseMessage <ConfigurationInfo> pInfo) { _timer = new Timer(1000); _timer.Elapsed += OnTimer; _connections = pConnections; _pipeClient = pPipeClient; Error = pInfo.Data.Error; Index = pInfo.Connection; InterfaceID = pInfo.Data.Interface; LoginCommand = new BasicCommand(OnLogin, () => !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)); ClearLogCommand = new BasicCommand(OnClearLog); CopyLogCommand = new BasicCommand(OnCopyLog); Status = pInfo.Data.ConnectionStatus; if (Status != ConnectionStatus.Disconnected) { _pipeClient.GetFullInfo(Index); } Name = pInfo.Data.Name; ConnectCommand = new BasicCommand( pObj => { if (Status != ConnectionStatus.Disconnected) { switch (Status) { case ConnectionStatus.Authenticating: IsAuthenticatingCanceled = true; break; case ConnectionStatus.Connecting: IsConnectingCanceled = true; _pipeClient.Disconnect(Index); break; case ConnectionStatus.Connected: Status = ConnectionStatus.Disconnecting; break; } ShowLog = false; } else { if (!ShowLog && _connections.AnyShowLog) { ShowLog = true; } if (pInfo.Data.RequiresUsername) { Status = ConnectionStatus.Authenticating; } else { Status = ConnectionStatus.Connecting; _pipeClient.Connect(Index); } _ignoreConnecting = true; } var thread = new Thread( () => { Thread.Sleep(300); if (Status == ConnectionStatus.Connecting && _ignoreConnecting) { } else { _pipeClient.Disconnect(pInfo.Connection); } }); thread.Priority = ThreadPriority.Lowest; thread.Start(); }, pObj => true); }