Esempio n. 1
0
 public Task Start(CancellationToken token)
 {
     using (var pbar = new ProgressBar(100, "A console progress that integrates with IProgress<float>"))
     {
         ProcessFiles(pbar.AsProgress <float>());
     }
     return(Task.FromResult(1));
 }
Esempio n. 2
0
        public void Execute()
        {
            {
                var sw = Stopwatch.StartNew();
                while (!TLoader.AllTripNodes.IsEmpty)
                {
                    TLoader.AllTripNodes.TryPop(out var nodes);
                    if (nodes.Count < 5)
                    {
                        continue;
                    }
                    var e = new ManualResetEvent(false);
                    lock (Events)
                    {
                        Events.Add(e);
                    }
                    ThreadPool.QueueUserWorkItem(state => EvalTrip(nodes, e));
                }
            }
            int eCount = Events.Count;

            using (var p = new ProgressBar(eCount, "Trips", Options))
            {
                var progress = p.AsProgress <double>();
                while (Events.Count >= 64)
                {
                    System.Threading.Thread.Sleep(5000);
                    double _eCount = Events.Count;
                    progress.Report((eCount - _eCount) / eCount);

                    Console.WriteLine("\r{0}% ", ((eCount - _eCount) / (eCount)) * 100);
                }
            }

            try
            {
                lock (Events)
                {
                    WaitHandle.WaitAll(Events.ToArray());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Finished");
            }
            lock (Results)
            {
                using (var streamWriter = new StreamWriter($"/Experiments/evaluations.csv", false, Encoding.UTF8))
                {
                    using (CsvWriter csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture))
                    {
                        csvWriter.WriteRecords(Results);
                    }
                }
            }
        }
Esempio n. 3
0
        public Task Start(CancellationToken token)
        {
            var files = Enumerable.Range(1, 10).Select(e => new FileInfo($"Data{e:D2}.csv")).ToList();

            using (var pbar = new ProgressBar(files.Count, "A console progress that integrates with IProgress<T>"))
            {
                ProcessFiles(files, pbar.AsProgress <FileInfo>(e => $"Processed {e.Name}"));
            }
            return(Task.FromResult(1));
        }
Esempio n. 4
0
        public ScenarioRunResult BuildAndRun(CancellationToken ct, ProgressBar pbar)
        {
            var tasks = new List <Task <ScenarioRunResult> >();

            Func <object, ScenarioRunResult> action = (object index) =>
            {
                var resultList   = new List <ScenarioRunResult>();
                var childOptions = new ProgressBarOptions
                {
                    ForegroundColor   = ConsoleColor.Green,
                    BackgroundColor   = ConsoleColor.DarkGreen,
                    ProgressCharacter = '─'
                };
                var pbarChild = pbar?.Spawn(ScenarioToRun.Repeat * ScenarioToRun.Steps.Count, $"concurent run ({index})", childOptions);
                var progress  = pbarChild?.AsProgress <int>();
                for (int ind = (int)index, i = 0; i < ScenarioToRun.Repeat; i++, ind++)
                {
                    if (ct.IsCancellationRequested)
                    {
                        break;
                    }

                    resultList.Add(Scenario.Run(ind, ScenarioToRun, ct, progress, i));
                }
                if (pbarChild != null)
                {
                    pbarChild.Dispose();
                }
                var result = ScenarioRunResult.Merge(resultList);
                resultBug.Add(result);
                return(result);
            };

            for (int i = 0; i < (ScenarioToRun.ConcurrentCopies * ScenarioToRun.Repeat); i += ScenarioToRun.Repeat)
            {
                int index = i;
                tasks.Add(Task <ScenarioRunResult> .Factory.StartNew(action, index, ct));
            }

            try
            {
                Task.WaitAll(tasks.ToArray());
                pbar?.AsProgress <float>().Report(1);
                return(ScenarioRunResult.Merge(resultBug.ToArray()));
            }
            catch (AggregateException e)
            {
                return(ScenarioRunResult.Fail(e));
            }
        }
Esempio n. 5
0
        private static async Task RunExtractorAndDownloader(Config config, string courseUrl)
        {
            Console.WriteLine(TUI.CONTINUEGLYPH + "Extracting Course Data. This might take some time...");
            var extractor = new Extractor(courseUrl, config.Quality, config.AuthenticationToken);

            if (!extractor.HasValidUrl())
            {
                TUI.ShowError("The course url you provided is not a recognized valid Linkedin Learning link");
                await RunWithConfig(config);

                return;
            }
            if (!await extractor.HasValidToken())
            {
                TUI.ShowError("The token you provided is not valid");
                await RunWithoutConfig();

                return;
            }
            Course course;

            try
            {
                using var pbarExtractor = new ProgressBar(10000, "Extracting Course Links - This will take some time", optionPbarExtractor);
                course = await extractor.GetCourse(pbarExtractor.AsProgress <float>());
            }
            catch (Exception ex)
            {
                TUI.ShowError(ex.Message);
                Log.Error(ex, ex.Message);
                await RunWithoutConfig();

                return;
            }
            Console.WriteLine(TUI.ENDGLYPH + "Course Extracted Successfully");
            Log.Information("Course Extracted. Downloading...");
            Console.WriteLine();
            CourseDownloader.DownloadCourse(course, config.CourseDirectory);
        }
        private static Course ExtractCourse(Config config)
        {
            Course course = new Course();

            Extractor.ExtractCourseStructure(out int videosCount);
            using (pbarExtractor = new ProgressBar(videosCount, "Extracting Course Links - This will take some time", optionPbarExtractor))
            {
                Retry.Do(
                    function: () =>
                {
                    Log.Information("Extracting...");
                    Extractor.ExtractionProgressChanged += Extractor_ExtractionProgressChanged;
                    course = Extractor.ExtractCourse(config.Quality);
                },
                    exceptionMessage: "An error occured while extracting the course",
                    actionOnError: () =>
                {
                    Extractor.CloseTabs();
                    var progress = pbarExtractor.AsProgress <float>();
                    progress?.Report(0);
                    Extractor.ExtractionProgressChanged -= Extractor_ExtractionProgressChanged;
                },
                    actionOnFatal: () =>
                {
                    TUI.ShowError("Failed to extract course. You can find more info in the logs");
                    Log.Error("Unknown error occured. Running app again");
                    TUI.ShowError("Unknown error occured");
                    TUI.ShowError("Restarting...");
                    Extractor.KillDrivers();
                    Extractor.ExtractionProgressChanged -= Extractor_ExtractionProgressChanged;
                    course = null;
                }
                    );
            }

            return(course);
        }
Esempio n. 7
0
 public ProgressBarAdapter()
 {
     _progressBar = new ProgressBar(MaxTicksBar, "Starting...");
     _progress = _progressBar.AsProgress<double>();
 }