Ejemplo n.º 1
0
        protected override void RunCore(RunArgs args)
        {
            int  gen        = 2;
            bool compact    = true;
            bool compactLoh = true;

            if (args.TryGetFirst(out string mode))
            {
                switch (mode)
                {
                case "s":
                    compactLoh = false;
                    break;

                case "g":
                    compact    = false;
                    compactLoh = false;
                    break;
                }
            }
            if (compactLoh)
            {
                GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
            }
            GC.Collect(gen, GCCollectionMode.Forced, blocking: true, compact);
            GC.WaitForPendingFinalizers();
            GC.Collect(gen, GCCollectionMode.Forced, blocking: true, compact);
            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.Default;
        }
Ejemplo n.º 2
0
        protected override void RunCore(RunArgs args)
        {
            if (args.TryGetFirst(out var type))
            {
                if (!args.TryGetSecondAsInt(out int count))
                {
                    count = 100;
                }
                switch (type)
                {
                case "m":
                    Task.Run((() =>
                    {
                        LoggerManager.Log($"ManagedLeak Work On {Thread.CurrentThread.ManagedThreadId} Begin");
                        try
                        {
                            for (int i = 0; i < count; i++)
                            {
                                ManagedLeak();
                            }
                        } catch (Exception e)
                        {
                            LoggerManager.Error(e);
                        }
                        LoggerManager.Log($"ManagedLeak Work On {Thread.CurrentThread.ManagedThreadId} End");
                    }));
                    break;

                case "n":
                    Task.Run((() =>
                    {
                        LoggerManager.Log($"NativeLeak Work On {Thread.CurrentThread.ManagedThreadId} Begin");

                        try
                        {
                            for (int i = 0; i < count; i++)
                            {
                                NativeLeak($"Prod_{count}");
                            }
                        } catch (Exception e)
                        {
                            LoggerManager.Error(e);
                        }

                        LoggerManager.Log($"NativeLeak Work On {Thread.CurrentThread.ManagedThreadId} End");
                    }));
                    break;
                }
            }
        }
Ejemplo n.º 3
0
 protected override void RunCore(RunArgs args)
 {
     if (args.TryGetFirst(out var action))
     {
         switch (action)
         {
         case "a":
             if (args.TryGetSecondAsInt(out var count) && args.TryGetInt(2, out var size))
             {
                 AddString(count, size);
             }
             else
             {
                 LoggerManager.Warn("Lack Arguments...");
             }
             break;
Ejemplo n.º 4
0
        protected override void RunCore(RunArgs args)
        {
            try
            {
                ThrowException();
            } catch (Exception e)
            {
                if (args.TryGetFirst(out string arg))
                {
                    switch (arg)
                    {
                    case "c":
                        throw new CrashException(e, false);

                    case "f":

                        // ReSharper disable once UnusedVariable
                        var objectWhichFinalizerThrowsException = new ObjectWhichFinalizerThrowsException();
                        break;

                    case "fn":
                        using (new ObjectWhichFinalizerThrowsException()) { }
                        break;

                    case "t":
                        new Thread(() =>
                        {
                            LoggerManager.Log("throw new CrashException();");
                            throw new CrashException();
                        }).Start();
                        break;

                    case "s":
                        new Thread(() =>
                        {
                            LoggerManager.Log("LogException(new CrashException());");
                            LogException(new CrashException());
                        }).Start();
                        break;
                    }
                }
                else
                {
                    throw new CrashException(e);
                }
            }
        }
Ejemplo n.º 5
0
            protected override void BeginProcessing()
            {
                base.BeginProcessing();
                try
                {
                    Exception reason = null;

                    // post the job as task
                    var task = Tasks.Job(() =>
                    {
                        if (Self.Confirm)
                        {
                            if (!Self.ShowConfirm("ps:", $"{Path.GetFileName(Script.File)}\r\n{Script}"))
                            {
                                throw new PipelineStoppedException();
                            }
                        }

                        var args = new RunArgs(_codeJob)
                        {
                            Writer        = new ConsoleOutputWriter(),
                            NoOutReason   = true,
                            UseLocalScope = true,
                            Arguments     = new object[] { Script, Self._data, Arguments }
                        };
                        A.Psf.Run(args);
                        reason = args.Reason;
                    });

                    // await
                    task.Wait();
                    FarNet.Works.Far2.Api.WaitSteps().Wait();
                    if (reason != null)
                    {
                        throw reason;
                    }
                }
                catch (Exception exn)
                {
                    throw FarNet.Works.Kit.UnwrapAggregateException(exn);
                }
            }
Ejemplo n.º 6
0
 protected override void RunCore(RunArgs args)
 {
     if (!args.TryGetFirstAsInt(out int threadCount))
     {
         threadCount = 5;
     }
     if (!args.TryGetSecondAsInt(out int loop))
     {
         loop = 1000000;
     }
     for (int i = 0; i < threadCount; i++)
     {
         Task.Run(() =>
         {
             LoggerManager.Log($"Work On {Thread.CurrentThread.ManagedThreadId} Begin");
             CreateBigData(loop);
             LoggerManager.Log($"Work On {Thread.CurrentThread.ManagedThreadId} End");
         });
     }
 }
Ejemplo n.º 7
0
        void MnuRunClick(object sender, EventArgs e)
        {
            if (currentDSN == null)
            {
                MessageBox.Show("Select a data source", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var args = new RunArgs
            {
                DSN        = currentDSN.GetDSNName(),
                UserName   = txtUserName.Text,
                Password   = txtPassword.Text,
                SQL        = textEditorControl1.Text,
                OutputPath = txtOutputPath.Text
            };

            if (string.IsNullOrEmpty(txtOutputPath.Text))
            {
                args.OutputPath = Path.Combine(Program.CurrentDirectory, Path.GetFileNameWithoutExtension(tabControl1.SelectedTab.Text) + ".csv");
            }


            if (Program.worker == null)
            {
                Program.worker = new System.ComponentModel.BackgroundWorker();
                Program.worker.WorkerReportsProgress      = true;
                Program.worker.WorkerSupportsCancellation = true;
                Program.worker.DoWork             += new DoWorkEventHandler(RunWorker_DoWork);
                Program.worker.ProgressChanged    += new ProgressChangedEventHandler(RunWorker_ProgressChanged);
                Program.worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorker_RunWorkerCompleted);
            }

            mnuRun.Enabled = false;
            Program.worker.RunWorkerAsync(args);
            frm.Start(CancelHandler);
            frm.ShowDialog();
        }
Ejemplo n.º 8
0
        protected override void RunCore(RunArgs args)
        {
            object lockObject = new object();

            if (!args.TryGetFirstAsInt(out var threadCount))
            {
                threadCount = 3;
            }
            for (int i = 0; i < threadCount; i++)
            {
                var thread = new Thread(() =>
                {
                    System.DateTime start = System.DateTime.Now;
                    lock (lockObject)
                    {
                        var hash = lockObject.GetHashCode();
                        if (args.TryGetSecondAsInt(out int seconds))
                        {
                            Thread.Sleep(seconds * 1000);
                        }
                        else
                        {
                            Thread.Sleep(5 * 1000);
                        }
                    }

                    System.DateTime end = System.DateTime.Now;
                    LoggerManager.Warn(
                        $"{Thread.CurrentThread.Name} Hung for {end.Subtract(start).Seconds}.{end.Subtract(start).Milliseconds}");
                })
                {
                    Name = $"Thread_{i}"
                };
                thread.Start();
            }
        }
    }
Ejemplo n.º 9
0
        public object Execute(RunArgs args)
        {
            Console.WriteLine("Resgrid Email Processor");
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("Starting Up");

            var _running = true;
            var model    = new RunViewModel();

            var config = _configService.LoadSettingsFromFile();

            _fileService.SetupDirectories();

            TelemetryConfiguration configuration   = null;
            TelemetryClient        telemetryClient = null;

            if (!String.IsNullOrWhiteSpace(config.DebugKey))
            {
                try
                {
                    configuration = TelemetryConfiguration.Active;
                    configuration.InstrumentationKey = config.DebugKey;
                    configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
                    configuration.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());
                    telemetryClient = new TelemetryClient();

                    System.Console.WriteLine("Application Insights Debug Key Detected and AppInsights Initialized");
                }
                catch { }
            }

            Logger log;

            if (config.Debug)
            {
                log = new LoggerConfiguration()
                      .MinimumLevel.Debug()
                      .WriteTo.Console()
                      .CreateLogger();
            }
            else
            {
                log = new LoggerConfiguration()
                      .MinimumLevel.Error()
                      .WriteTo.Console()
                      .CreateLogger();
            }

            using (InitializeDependencyTracking(configuration))
            {
                // Define the cancellation token.
                CancellationTokenSource source = new CancellationTokenSource();
                CancellationToken       token  = source.Token;

                Thread dataThread = new Thread(() => _dataService.Run(token, log, config));
                dataThread.Name = $"Data Service Thread";
                dataThread.Start();

                Thread emailThread = new Thread(() => _emailService.Run(token, log));
                emailThread.Name = $"Email Service Thread";
                emailThread.Start();

                Thread importThread = new Thread(() => _montiorService.Run(token, log));
                importThread.Name = $"Import Service Thread";
                importThread.Start();

                System.Console.WriteLine("Email Processor is Running...");
                System.Console.WriteLine("Press any key to stop");

                var line = Console.ReadLine();
                source.Cancel();
                System.Console.WriteLine("Shutting down, please wait...");
                Task.Delay(2000).Wait();

                _running = false;
            }

            if (telemetryClient != null)
            {
                telemetryClient.Flush();
                Task.Delay(5000).Wait();
            }

            return(View("Run", model));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// RunCore
 /// </summary>
 /// <param name="args">argument</param>
 protected override void RunCore(RunArgs args)
 {
     LoggerManager.Warn("Going To Exit...");
     Environment.Exit(0);
 }
Ejemplo n.º 11
0
 /// <summary>
 ///  Do Nothing
 /// </summary>
 /// <param name="args"></param>
 protected override void RunCore(RunArgs args)
 {
     LoggerManager.Log(string.Join(" ", args.Arguments));
 }
Ejemplo n.º 12
0
        void RunWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            RunArgs args = (RunArgs)e.Argument;

            Program.Export(true, args.DSN, args.UserName, args.Password, args.SQL, args.OutputPath, settings.Delimiter, e);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Run Crasher Core
 /// </summary>
 /// <param name="args">arguments</param>
 protected abstract void RunCore(RunArgs args);
Ejemplo n.º 14
0
 /// <summary>
 /// Run Crasher
 /// </summary>
 /// <param name="args">arguments</param>
 public void Run(RunArgs args = null)
 {
     RunCore(args);
 }
Ejemplo n.º 15
0
        public string Execute(RunArgs args)
        {
            CreateAudioDirectory();

            System.Console.WriteLine("Resgrid Audio");
            System.Console.WriteLine("-----------------------------------------");

            System.Console.WriteLine("Loading Settings");
            Config config = LoadSettingsFromFile();

            Logger log;

            if (config.Debug)
            {
                log = new LoggerConfiguration()
                      .MinimumLevel.Debug()
                      .WriteTo.Console()
                      .CreateLogger();
            }
            else
            {
                log = new LoggerConfiguration()
                      .MinimumLevel.Error()
                      .WriteTo.Console()
                      .CreateLogger();
            }

            TelemetryConfiguration configuration   = null;
            TelemetryClient        telemetryClient = null;

            if (!String.IsNullOrWhiteSpace(config.DebugKey))
            {
                try
                {
                    configuration = TelemetryConfiguration.Active;
                    configuration.InstrumentationKey = config.DebugKey;
                    configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
                    configuration.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());
                    telemetryClient = new TelemetryClient();

                    System.Console.WriteLine("Application Insights Debug Key Detected and AppInsights Initialized");
                }
                catch { }
            }

            using (InitializeDependencyTracking(configuration))
            {
                while (true)
                {
                    try
                    {
                        if (Run(config, log))
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Fatal(ex.ToString());
                        System.Console.WriteLine($"Restarting listener due to an error, if this keeps occurring consider checking for updates or logging an issue.");
                    }
                }
            }

            if (telemetryClient != null)
            {
                telemetryClient.Flush();
                Task.Delay(5000).Wait();
            }

            return("");
        }
Ejemplo n.º 16
0
        private void Run(RunArgs args)
        {
            _logger.Information(string.Format("Beginning test run of {0}...", args.Suite.RunTarget));
            GTestRunOutputParser parser = new GTestRunOutputParser(args.Suite, _logger);
            DataReceivedEventHandler handler = (sender, eventArgs) => parser.ParseLine(eventArgs.Data);
            parser.TestFinished += OnTestCompleted;

            foreach (var testCase in args.Suite.TestCases)
            {
                foreach (var test in testCase.Tests)
                {
                    if(test.Name.StartsWith("DISABLED_"))
                    {
                        TestResult result = new TestResult() {Outcome = TestStatus.Ignored};
                        test.Completed(result);
                        OnTestCompleted(test, result);
                    }
                }
            }

            ProcessStartInfo gtestProcInfo = new ProcessStartInfo(args.Suite.RunTarget)
                {
                    RedirectStandardOutput = true,
                    CreateNoWindow = true,
                    UseShellExecute = false
                };
            if (!string.IsNullOrEmpty(args.Filter))
            {
                gtestProcInfo.Arguments = string.Format("--gtest_filter={0}", args.Filter);
            }
            else
            {
                List<string> caseNames = new List<string>();
                foreach (var testCase in args.Suite.TestCases)
                {
                    foreach (var test in testCase.Tests)
                    {
                        caseNames.Add(test.FullyQualifiedName);
                    }
                }
                if (caseNames.Count > 0)
                {
                    gtestProcInfo.Arguments = string.Format("--gtest_filter={0}", string.Join(":", caseNames.ToArray()));
                }
            }

            Process gtestProc = new Process();
            gtestProc.StartInfo = gtestProcInfo;
            gtestProc.OutputDataReceived += handler;

            gtestProc.Start();
            gtestProc.BeginOutputReadLine();

            while (!gtestProc.HasExited)
            {
                gtestProc.WaitForExit(0);
                if (_worker.CancellationPending)
                {
                    gtestProc.Close();
                    break;
                }
            }

            gtestProc.WaitForExit();

            gtestProc.OutputDataReceived -= handler;
        }