Beispiel #1
0
        /// <summary>
        /// Shuts down the tor application process and releases the associated components of the class.
        /// </summary>
        /// <param name="exited">A value indicating whether the shutdown is being performed after the process has exited.</param>
        private void Stop(bool exited)
        {
            if (disposed && !exited)
            {
                return;
            }

            lock (synchronize)
            {
                if (!IsRemote && process != null)
                {
                    if (exited)
                    {
                        process.Dispose();
                        process = null;
                    }
                    else
                    {
                        SignalHaltCommand command  = new SignalHaltCommand();
                        Response          response = command.Dispatch(this);

                        if (response.Success)
                        {
                            return;
                        }

                        process.Kill();
                        process.Dispose();
                        process = null;
                    }
                }

                if (proxy != null)
                {
                    proxy.Dispose();
                    proxy = null;
                }

                if (events != null)
                {
                    events.Dispose();
                    events = null;
                }

                configuration = null;
                controller    = null;
                logging       = null;
                status        = null;

                if (Shutdown != null)
                {
                    Shutdown(this, EventArgs.Empty);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Starts the tor application executable using the provided creation parameters.
        /// </summary>
        private void Start()
        {
            if (createParams != null)
            {
                createParams.ValidateParameters();
            }
            else
            {
                remoteParams.ValidateParameters();
            }

            if (createParams != null)
            {
                lock (synchronize)
                {
                    ProcessStartInfo psi;

                    if (process != null && !process.HasExited)
                    {
                        return;
                    }

                    psi                  = new ProcessStartInfo(createParams.Path);
                    psi.Arguments        = createParams.ToString();
                    psi.CreateNoWindow   = true;
                    psi.UseShellExecute  = false;
                    psi.WindowStyle      = ProcessWindowStyle.Hidden;
                    psi.WorkingDirectory = Path.GetDirectoryName(createParams.Path);

                    try
                    {
                        process = new Process();
                        process.EnableRaisingEvents = true;
                        process.Exited   += new EventHandler(OnHandleProcessExited);
                        process.StartInfo = psi;

                        if (!process.Start())
                        {
                            process.Dispose();
                            process = null;

                            throw new TorException("The tor application process failed to launch");
                        }
                    }
                    catch (Exception exception)
                    {
                        throw new TorException("The tor application process failed to launch", exception);
                    }
                }
            }

            Thread.Sleep(500);

            lock (synchronize)
            {
                configuration = new Configuration(this);
                controller    = new Control(this);
                logging       = new Logging.Logging(this);
                proxy         = new Proxy.Proxy(this);
                status        = new Status.Status(this);

                events = new Events.Events(this);
                events.Start((Action) delegate
                {
                    configuration.Start();
                    status.Start();

                    GetClientConfigurations();
                });
            }
        }