Ejemplo n.º 1
0
 /// Constructor
 public CtrlCInterceptor()
 {
     _ctl = new ConsoleCtrl();
     _ctl.ControlEvent += ctrlEvent;
     ThreadToAbort = Thread.CurrentThread;
     AbortDelay = TimeSpan.FromSeconds(5);
     ExitDelay = TimeSpan.FromSeconds(10);
     Output = Console.Error;
 }
Ejemplo n.º 2
0
        private static int createRemotingScriptContext(string[] args)
        {
            progress("remoteClient: createRemotingScriptContext");
            for (int i = 0; i < args.Length;++i )
                progress("remoteClient: arg"+i+": ["+args[i]+"]");
            try
            {
                progress("remoteClient: Setting up ipc client");
                Random r=new Random();
                registerChannel(args[1], args[1] + ":"+r.Next(9000,15000));
                if (!string.IsNullOrEmpty(args[2]))
                    BaseDirectory = args[2];
                RemotingCallback callback = (RemotingCallback)Activator.GetObject(typeof(RemotingCallback), "ipc://" + args[1] + "/RemotingCallback");

                progress("remoteClient: attaching console");
                uint pid = uint.Parse(args[3]);
                if (pid != 0)
                {
                    FreeConsole();
                    bool b=AttachConsole(pid);
                    if (b)
                        progress("remoteClient: attaching console was successful");
                    else
                        progress("remoteClient: attaching console failed");
                }
                progress("remoteClient: ipc setup. About to instantiate context");
                XS.ScriptContext sc = new XS.ScriptContext(ResourceAssembly);
                if (sc.IsAdministrator)
                {
                    progress(sc.GetType().FullName + " instantiated");

                    using (XS.ConsoleCtrl ctrl = new XS.ConsoleCtrl())
                    {
                        // Ignore Ctrl+C
                        ctrl.ControlEvent += delegate(object sender, XS.ConsoleCtrlEventArgs e)
                            {
                                progress("remoteClient: Ctrl+C received");
                                try
                                {
                                    sc.Abort();
                                }
                                catch
                                {

                                }
                            };
                        return callback.OnContextReady(sc);
                    }
                }
                progress("remoteClient: Administrator privileges required!");
            }
            catch (Exception e)
            {
                progress("remoteClient: " + e);
                throw;
            }

            return -1;
        }
Ejemplo n.º 3
0
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 protected virtual void Dispose(bool dispose)
 {
     if (dispose)
     {
         KillAbortTimer();
         if (_ctl!=null)
             _ctl.Dispose();
     }
     _ctl = null;
 }
Ejemplo n.º 4
0
        private static int createRemotingScriptContext(string[] args)
        {
            progress("remoteClient: createRemotingScriptContext");
            for (int i = 0; i < args.Length; ++i)
            {
                progress("remoteClient: arg" + i + ": [" + args[i] + "]");
            }
            try
            {
                progress("remoteClient: Setting up ipc client");
                Random r = new Random();
                registerChannel(args[1], args[1] + ":" + r.Next(9000, 15000));
                if (!string.IsNullOrEmpty(args[2]))
                {
                    BaseDirectory = args[2];
                }
                RemotingCallback callback = (RemotingCallback)Activator.GetObject(typeof(RemotingCallback), "ipc://" + args[1] + "/RemotingCallback");

                progress("remoteClient: attaching console");
                uint pid = uint.Parse(args[3]);
                if (pid != 0)
                {
                    FreeConsole();
                    bool b = AttachConsole(pid);
                    if (b)
                    {
                        progress("remoteClient: attaching console was successful");
                    }
                    else
                    {
                        progress("remoteClient: attaching console failed");
                    }
                }
                progress("remoteClient: ipc setup. About to instantiate context");
                XS.ScriptContext sc = new XS.ScriptContext(ResourceAssembly);
                if (sc.IsAdministrator)
                {
                    progress(sc.GetType().FullName + " instantiated");

                    using (XS.ConsoleCtrl ctrl = new XS.ConsoleCtrl())
                    {
                        // Ignore Ctrl+C
                        ctrl.ControlEvent += delegate(object sender, XS.ConsoleCtrlEventArgs e)
                        {
                            progress("remoteClient: Ctrl+C received");
                            try
                            {
                                sc.Abort();
                            }
                            catch
                            {
                            }
                        };
                        return(callback.OnContextReady(sc));
                    }
                }
                progress("remoteClient: Administrator privileges required!");
            }
            catch (Exception e)
            {
                progress("remoteClient: " + e);
                throw;
            }

            return(-1);
        }