示例#1
0
    public static int Main(string[] args)
    {
        string     tmpFile = null;
        TextReader input   = null;

        try {
            // The first parameter is the task id
            // The second parameter is the temp file that contains the data
            // If not provided, data is read from the standard input

            if (args.Length > 1)
            {
                tmpFile = args [1];
                input   = new StreamReader(tmpFile);
            }
            else
            {
                input = Console.In;
            }

            string sref       = input.ReadLine();
            string pidToWatch = input.ReadLine();

            if (tmpFile != null)
            {
                try {
                    input.Close();
                    File.Delete(tmpFile);
                } catch {
                }
            }

            WatchParentProcess(int.Parse(pidToWatch));

            string unixPath = RegisterRemotingChannel();

            byte[]                 data = Convert.FromBase64String(sref);
            MemoryStream           ms   = new MemoryStream(data);
            BinaryFormatter        bf   = new BinaryFormatter();
            IProcessHostController pc   = (IProcessHostController)bf.Deserialize(ms);

            LoggingService.AddLogger(new LocalLogger(pc.GetLogger(), args[0]));

            ProcessHost rp = new ProcessHost(pc);
            pc.RegisterHost(rp);
            try {
                pc.WaitForExit();
            } catch {
            }

            try {
                rp.Dispose();
            } catch {
            }

            if (unixPath != null)
            {
                File.Delete(unixPath);
            }
        } catch (Exception ex) {
            Console.WriteLine(ex);
        }

        return(0);
    }