示例#1
0
        public static void Open(string template, Process p, ClientSession session, CancellationToken cancel)
        {
            var codeBase   = Assembly.GetExecutingAssembly().CodeBase ?? Assembly.GetEntryAssembly().CodeBase;
            var dll        = new Uri(codeBase).LocalPath;
            var monoserver = Path.Combine(Path.GetDirectoryName(dll), "MonoToolsServer.exe");
            var mirror     = ConsoleMirror.StartTerminalServer(p, session, cancel);

            if (mirror != null)
            {
                Open(template, $"mono {monoserver} -mirror={mirror.Pipes}");
            }
        }
示例#2
0
        public static void CreatePipes(out ConsoleMirror server, out ConsoleMirror client)
        {
            var input  = UnixPipes.CreatePipes();
            var output = UnixPipes.CreatePipes();
            var err    = UnixPipes.CreatePipes();

            server = new ConsoleMirror {
                Input = input.Reading, Output = output.Writing, Error = err.Writing
            };
            client = new ConsoleMirror {
                Input = input.Writing, Output = output.Reading, Error = err.Reading
            };
        }
示例#3
0
        public Process Start(string exe, Action <StringBuilder> arguments = null, Action <ProcessStartInfo> infos = null)
        {
            var  args     = new StringBuilder();
            var  template = Server.TerminalTemplate;
            bool terminal = false;

            if (!Directory.Exists(Message.WorkingDirectory))
            {
                Directory.CreateDirectory(Message.WorkingDirectory);
            }

            if (Message.ApplicationType != ApplicationTypes.ConsoleApplication)
            {
                RedirectOutput = true;
            }

            var codeBase = Assembly.GetExecutingAssembly().CodeBase ?? Assembly.GetEntryAssembly().CodeBase;

            var server = new Uri(codeBase).LocalPath;

            CreateWindow = false;
            if (!OS.IsWindows && !string.IsNullOrEmpty(Server.TerminalTemplate))               // use TerminalTemplate to start process
            {
                terminal     = true;
                CreateWindow = true;
            }
            else if (OS.IsWindows && !RedirectOutput)
            {
                CreateWindow = true;
            }
            else if (!Server.IsLocal)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Clear();
            }

            arguments?.Invoke(args);

            ProcessStartInfo procInfo = GetProcessStartInfo(exe);

            procInfo.Arguments = template == null?args.ToString() : string.Format(template, args.ToString());

            infos?.Invoke(procInfo);

            process                     = new System.Diagnostics.Process();
            process.StartInfo           = procInfo;
            process.EnableRaisingEvents = false;

            process.Start();

            if (terminal)
            {
                Terminal.Open(Server.TerminalTemplate, process, Session, Cancel.Token);
            }
            else
            {
                ConsoleMirror.StartServer(process, Session, Cancel.Token);
            }

            RaiseProcessStarted();

            return(process);
        }