public static void ChangeTunnelStatus(TunnelStatuses tunnelStatus, bool saveTunnelStatus = true)
        {
            TunnelHelper.CurrentTunnelStatus = tunnelStatus;
            ServiceSettings serviceSettings = SettingsHelper.GetSettings();

            if (saveTunnelStatus)
            {
                Settings settings = new Settings();
                settings.CurrentTunnelStatus = (int)tunnelStatus;
                settings.Save();
            }

            if (tunnelStatus == TunnelStatuses.Started)
            {
                WcfServerHelper.BroadcastRemoteCallback(x => x.EventToLog("Plink Starting", DateTime.Now), true);
                if (ProcessHelper.StartPlink())
                {
                    TunnelPingHelper.OpenTunnelPingListener();
                    WcfServerHelper.BroadcastRemoteCallback(x => x.EventToLog("Plink Started: " + ProcessHelper.GetPlinkArguments(serviceSettings), DateTime.Now), true);
                }
                else
                {
                    ChangeTunnelStatus(TunnelStatuses.Paused);
                }
            }
            else
            {
                WcfServerHelper.BroadcastRemoteCallback(x => x.EventToLog("Plink Stopping", DateTime.Now), true);
                TunnelPingHelper.CloseTunnelPingListener();
                ProcessHelper.StopPlink();
            }

            WcfServerHelper.BroadcastRemoteCallback(x => x.TunnelStatusChanged(tunnelStatus), true);
        }
示例#2
0
        public static void StopPlink()
        {
            if (TunnelHelper.CurrentTunnelStatus == TunnelStatuses.Paused)
            {
                TunnelPingHelper.CloseTunnelPingListener();
            }

            if (_process != null && !_process.HasExited)
            {
                _process.Kill();
            }

            PlinkRunning = false;

            ClientHelper.PingClient();
        }