Esempio n. 1
0
        public async Task StartAsync(string type, IToIni obj)
        {
            if (frpProcess != null)
            {
                throw new Exception("存在仍在运行的Frp实例");
            }
            this.type = type;
            this.obj  = obj;
            Process[] existProcess = null;
            await Task.Run(() =>
            {
                string ini = $"./frp/frp{type}.ini";
                File.WriteAllText(ini, obj.ToIni());
                existProcess = Process.GetProcessesByName($"frp{type}");
            });

            if (existProcess.Length > 0)
            {
                foreach (var p in existProcess)
                {
                    p.Kill(true);
                }
                await Task.Delay(500);
            }
            frpProcess           = new Process();
            frpProcess.StartInfo = new ProcessStartInfo()
            {
                FileName               = $"./frp/frp{type}.exe",
                Arguments              = $"-c frp{type}.ini",
                WorkingDirectory       = "./frp",
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true
            };
            frpProcess.EnableRaisingEvents = true;
            frpProcess.OutputDataReceived += P_OutputDataReceived;
            frpProcess.ErrorDataReceived  += P_OutputDataReceived;
            frpProcess.Start();
            frpProcess.BeginOutputReadLine();
            frpProcess.BeginErrorReadLine();
            frpProcess.Exited += FrpProcess_Exited;
        }
Esempio n. 2
0
        public void Start(string type, IToIni obj)
        {
            (App.Current.MainWindow as MainWindow).AddLogOnMainThread("正在启动" + type, "I");

            if (frpProcess != null)
            {
                frpProcess.Kill();
            }
            this.type = type;
            this.obj  = obj;
            string tempDir = Path.Combine(FzLib.Program.App.ProgramDirectoryPath, "temp");

            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }
            string ini = Path.Combine(tempDir, Guid.NewGuid().ToString() + ".ini");

            File.WriteAllText(ini, obj.ToIni());
            frpProcess           = new Process();
            frpProcess.StartInfo = new ProcessStartInfo()
            {
                FileName               = $"./frp/frp{type}.exe",
                Arguments              = $"-c \"{ini}\"",
                WorkingDirectory       = "./frp",
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
            };
            frpProcess.EnableRaisingEvents = true;
            frpProcess.OutputDataReceived += P_OutputDataReceived;
            frpProcess.ErrorDataReceived  += P_OutputDataReceived;
            frpProcess.Start();
            frpProcess.BeginOutputReadLine();
            frpProcess.BeginErrorReadLine();
            frpProcess.Exited += FrpProcess_Exited;
            IsRunning          = true;
            Started?.Invoke(this, new EventArgs());
        }
Esempio n. 3
0
 public void StartClient(IToIni obj)
 {
     Start("c", obj);
 }
Esempio n. 4
0
 public void StartServer(IToIni obj)
 {
     Start("s", obj);
 }