Ejemplo n.º 1
0
        private static void WerFaultHunter(object o)
        {
            var stop = o as ThreadStopper;

            while (true)
            {
                if (stop?.Stop == true)
                {
                    break;
                }
                Thread.Sleep(1500);
                var l = Process.GetProcesses().Where(pp => pp.ProcessName.Contains("WerFault")).ToList();
                if (l.Count > 0)
                {
                    /*foreach (var op in l) {
                     *  Console.WriteLine(op.MainWindowTitle);
                     *  foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(op)) {
                     *      try {
                     *          string name = descriptor.Name;
                     *
                     *          object value = descriptor.GetValue(op);
                     *          Console.WriteLine("{0}={1}", name, value);
                     *      } catch {}
                     *  }
                     * }*/
                    Thread.Sleep(4000);
                    Process.GetProcesses().Where(pp => pp.ProcessName.Contains("WerFault")).ToList().ForEach(p => {
                        p.Kill();
                        Tasky.Run(() => Killed?.Invoke());
                        //Console.WriteLine($"[WerFault] {p.ProcessName} has been killed.");
                    });
                }
            }
            _stop = null;
        }
Ejemplo n.º 2
0
        public static void StopAThread()
        {
            // 5 ways
            // stop process
            // stop all foreground tasks ( which in turn stops the process and all tasks)
            // Interrupt --> no reason and ill advised because indeterministic
            // releases a blocked thread
            // Abort also indeterministic, tries to force to end another thread. needs also to be Thread.ResetAbort in catch else it is rethrown
            // most common: function delegate simply returns.
            // Poll for flag
            var stopper = new ThreadStopper();
            var rand    = new Random();
            int exit    = 0;

            while (!stopper.Terminate)
            {
                exit = rand.Next(0, 10);
                if (exit == 5)
                {
                    stopper.Terminate = true;
                }
                write("another round! before termination");
            }
            write("stopped!");
        }
Ejemplo n.º 3
0
 public static void Stop()
 {
     if (_stop != null)
     {
         _stop.Stop = true;
     }
     _stop = null;
     WerFaultKillerThread = null;
 }
Ejemplo n.º 4
0
        public static void Start()
        {
            if (WerFaultKillerThread != null)
            {
                return;
            }

            _stop = new ThreadStopper();
            WerFaultKillerThread = new Thread(WerFaultHunter);
            WerFaultKillerThread.Start(_stop);
        }
Ejemplo n.º 5
0
        private static void WerFaultHunter(object o) {
            var stop = o as ThreadStopper;
            while (true) {
                if (stop?.Stop == true)
                    break;
                Thread.Sleep(1500);
                var l = Process.GetProcesses().Where(pp => pp.ProcessName.Contains("WerFault")).ToList();
                if (l.Count > 0) {
                    foreach (var op in l) {
                        Console.WriteLine(op.MainWindowTitle);
                        foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(op))
                        {
                            try {
                                string name = descriptor.Name;

                                object value = descriptor.GetValue(op);
                                Console.WriteLine("{0}={1}", name, value);
                            } catch {  }
                        }
                    }
                    Thread.Sleep(4000);
                    Process.GetProcesses().Where(pp => pp.ProcessName.Contains("WerFault")).ToList().ForEach(p => {
                        p.Kill();
                        Tasky.Run(() => Killed?.Invoke());
                    });
                }
            }
            _stop = null;

        }
Ejemplo n.º 6
0
 public static void Stop() {
     if (_stop != null) {
         _stop.Stop = true;
     }
     _stop = null;
     WerFaultKillerThread = null;
 }
Ejemplo n.º 7
0
        public static void Start() {
            if (WerFaultKillerThread != null)
                return;

            _stop = new ThreadStopper();
            WerFaultKillerThread = new Thread(WerFaultHunter);
            WerFaultKillerThread.Start(_stop);
        }
Ejemplo n.º 8
0
        public IDisposable InstallHook(Uri reposUri, SvnHookType type, EventHandler<ReposHookEventArgs> hook)
        {
            if (reposUri == null)
                throw new ArgumentNullException("reposUri");
            else if (!reposUri.IsFile)
                throw new InvalidOperationException();

            string reposPath = reposUri.LocalPath;

            TempFileCollection tfc = new TempFileCollection();
            string dir = Path.GetTempPath();

            string suffix = Guid.NewGuid().ToString("N");
            string args = Path.Combine(dir, suffix + "-args.txt");
            string stdin = Path.Combine(dir, suffix + "-stdin.txt");
            string done = Path.Combine(dir, suffix + "-done.txt");
            string wait = Path.Combine(dir, suffix + "-wait.txt");

            string errTxt = Path.Combine(dir, suffix + "-errTxt.txt");
            string outTxt = Path.Combine(dir, suffix + "-outTxt.txt");

            tfc.AddFile(args, false);
            tfc.AddFile(stdin, false);
            tfc.AddFile(wait, false);
            tfc.AddFile(errTxt, false);
            tfc.AddFile(outTxt, false);

            ThreadStopper stopper = new ThreadStopper();

            string envPrefix = Path.GetFileNameWithoutExtension(SvnHookArguments.GetHookFileName(reposPath, type)) + ".";
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_FILE", args);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_STDIN", stdin);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_DONE", done);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_WAIT", wait);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDOUT", outTxt);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDERR", errTxt);

            string file = Path.ChangeExtension(SvnHookArguments.GetHookFileName(reposPath, type), ".exe");

            stopper.Start(
            delegate
            {
                try
                {
                    while (!stopper.Cancel)
                    {
                        if (File.Exists(done))
                        {
                            List<string> argCollection = new List<string>();
                            using (StreamReader fs = File.OpenText(args))
                            {
                                string line;
                                while (null != (line = fs.ReadLine()))
                                    argCollection.Add(line);
                            }
                            string stdinText = File.ReadAllText(stdin);

                            File.Delete(args);
                            File.Delete(stdin);

                            ReposHookEventArgs ra = new ReposHookEventArgs(type, argCollection.ToArray(), stdinText);

                            try
                            {
                                hook(this, ra);
                            }
                            catch (Exception e)
                            {
                                if (string.IsNullOrEmpty(ra.ErrorText))
                                    ra.ErrorText = e.ToString();
                                ra.ExitCode = 129;
                            }
                            finally
                            {

                                if (ra.ErrorText != null)
                                    File.WriteAllText(errTxt, ra.ErrorText);

                                if (ra.OutputText != null)
                                    File.WriteAllText(outTxt, ra.OutputText);

                                File.WriteAllText(wait, ra.ExitCode.ToString());
                            }

                            File.Delete(done);

                            if (ra.Cancel)
                                break;
                        }
                        Thread.Sleep(50);
                    }

                }
                finally
                {
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_FILE", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_STDIN", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_DONE", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_WAIT", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDOUT", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDERR", null);
                }

                GC.KeepAlive(tfc);
                File.Delete(file);
            });

            File.Copy(Path.Combine(ProjectBase, "..\\tools\\hooknotifier\\bin\\" + Configuration + "\\HookNotifier.exe"), file);

            return stopper;
        }
Ejemplo n.º 9
0
        public IDisposable InstallHook(Uri reposUri, SvnHookType type, EventHandler <ReposHookEventArgs> hook)
        {
            if (reposUri == null)
            {
                throw new ArgumentNullException("reposUri");
            }
            else if (!reposUri.IsFile)
            {
                throw new InvalidOperationException();
            }

            string reposPath = reposUri.LocalPath;

            TempFileCollection tfc = new TempFileCollection();
            string             dir = Path.GetTempPath();

            string suffix = Guid.NewGuid().ToString("N");
            string args   = Path.Combine(dir, suffix + "-args.txt");
            string stdin  = Path.Combine(dir, suffix + "-stdin.txt");
            string done   = Path.Combine(dir, suffix + "-done.txt");
            string wait   = Path.Combine(dir, suffix + "-wait.txt");

            string errTxt = Path.Combine(dir, suffix + "-errTxt.txt");
            string outTxt = Path.Combine(dir, suffix + "-outTxt.txt");

            tfc.AddFile(args, false);
            tfc.AddFile(stdin, false);
            tfc.AddFile(wait, false);
            tfc.AddFile(errTxt, false);
            tfc.AddFile(outTxt, false);

            ThreadStopper stopper = new ThreadStopper();

            string envPrefix = Path.GetFileNameWithoutExtension(SvnHookArguments.GetHookFileName(reposPath, type)) + ".";

            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_FILE", args);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_STDIN", stdin);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_DONE", done);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_WAIT", wait);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDOUT", outTxt);
            Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDERR", errTxt);

            string file = Path.ChangeExtension(SvnHookArguments.GetHookFileName(reposPath, type), ".exe");

            stopper.Start(
                delegate
            {
                try
                {
                    while (!stopper.Cancel)
                    {
                        if (File.Exists(done))
                        {
                            List <string> argCollection = new List <string>();
                            using (StreamReader fs = File.OpenText(args))
                            {
                                string line;
                                while (null != (line = fs.ReadLine()))
                                {
                                    argCollection.Add(line);
                                }
                            }
                            string stdinText = File.ReadAllText(stdin);

                            File.Delete(args);
                            File.Delete(stdin);

                            ReposHookEventArgs ra = new ReposHookEventArgs(type, argCollection.ToArray(), stdinText);

                            try
                            {
                                hook(this, ra);
                            }
                            catch (Exception e)
                            {
                                if (string.IsNullOrEmpty(ra.ErrorText))
                                {
                                    ra.ErrorText = e.ToString();
                                }
                                ra.ExitCode = 129;
                            }
                            finally
                            {
                                if (ra.ErrorText != null)
                                {
                                    File.WriteAllText(errTxt, ra.ErrorText);
                                }

                                if (ra.OutputText != null)
                                {
                                    File.WriteAllText(outTxt, ra.OutputText);
                                }


                                File.WriteAllText(wait, ra.ExitCode.ToString());
                            }

                            File.Delete(done);

                            if (ra.Cancel)
                            {
                                break;
                            }
                        }
                        Thread.Sleep(50);
                    }
                }
                finally
                {
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_FILE", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_STDIN", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_DONE", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_WAIT", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDOUT", null);
                    Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDERR", null);
                }

                GC.KeepAlive(tfc);
                File.Delete(file);
            });

            File.Copy(Path.Combine(ProjectBase, "..\\tools\\hooknotifier\\bin\\" + Configuration + "\\HookNotifier.exe"), file);

            return(stopper);
        }