コード例 #1
0
        public static ConcurrentDictionary <(RESULT_TYPE, CHANGE_TYPE), ConcurrentQueue <CompareResult> > CompareRuns(CompareCommandOptions opts)
        {
            if (opts is null)
            {
                throw new ArgumentNullException(nameof(opts));
            }

            if (opts.SaveToDatabase)
            {
                DatabaseManager.InsertCompareRun(opts.FirstRunId, opts.SecondRunId, RUN_STATUS.RUNNING);
            }

            comparators = new List <BaseCompare>();

            Dictionary <string, string> EndEvent = new Dictionary <string, string>();
            BaseCompare c     = new BaseCompare();
            var         watch = System.Diagnostics.Stopwatch.StartNew();

            if (!c.TryCompare(opts.FirstRunId, opts.SecondRunId))
            {
                Log.Warning(Strings.Get("Err_Comparing") + " : {0}", c.GetType().Name);
            }

            watch.Stop();
            TimeSpan t      = TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds);
            string   answer = string.Format(CultureInfo.InvariantCulture, "{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
                                            t.Hours,
                                            t.Minutes,
                                            t.Seconds,
                                            t.Milliseconds);

            Log.Information(Strings.Get("Completed"), "Comparing", answer);

            if (opts.Analyze)
            {
                watch = Stopwatch.StartNew();
                Analyzer analyzer = new Analyzer(DatabaseManager.RunIdToPlatform(opts.FirstRunId), opts.AnalysesFile);

                var violations = analyzer.VerifyRules();

                if (violations.Any())
                {
                    foreach (var violation in violations)
                    {
                        Log.Warning(violation);
                    }
                    Log.Error("Encountered {0} issues with rules in {1}. Skipping analysis.", violations.Count, opts.AnalysesFile ?? "Embedded");
                }
                else
                {
                    if (c.Results.Count > 0)
                    {
                        foreach (var key in c.Results.Keys)
                        {
                            if (c.Results[key] is ConcurrentQueue <CompareResult> queue)
                            {
                                Parallel.ForEach(queue, (res) =>
                                {
                                    res.Rules    = analyzer.Analyze(res);
                                    res.Analysis = res.Rules.Max(x => x.Flag);
                                });
                            }
                        }
                    }
                }

                watch.Stop();
                t      = TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds);
                answer = string.Format(CultureInfo.InvariantCulture, "{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
                                       t.Hours,
                                       t.Minutes,
                                       t.Seconds,
                                       t.Milliseconds);
                Log.Information(Strings.Get("Completed"), "Analysis", answer);
            }

            watch = Stopwatch.StartNew();

            if (opts.SaveToDatabase)
            {
                foreach (var key in c.Results.Keys)
                {
                    if (c.Results.TryGetValue(key, out ConcurrentQueue <CompareResult>?obj))
                    {
                        if (obj is ConcurrentQueue <CompareResult> Queue)
                        {
                            foreach (var result in Queue)
                            {
                                DatabaseManager.InsertAnalyzed(result);
                            }
                        }
                    }
                }
            }

            watch.Stop();
            t      = TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds);
            answer = string.Format(CultureInfo.InvariantCulture, "{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
                                   t.Hours,
                                   t.Minutes,
                                   t.Seconds,
                                   t.Milliseconds);
            Log.Information(Strings.Get("Completed"), "Flushing", answer);

            if (opts.SaveToDatabase)
            {
                DatabaseManager.UpdateCompareRun(opts.FirstRunId, opts.SecondRunId, RUN_STATUS.COMPLETED);
            }

            DatabaseManager.Commit();
            AsaTelemetry.TrackEvent("End Command", EndEvent);
            return(c.Results);
        }
コード例 #2
0
        public static Dictionary <string, object> CompareRuns(CompareCommandOptions opts)
        {
            if (opts is null)
            {
                throw new ArgumentNullException(nameof(opts));
            }

            if (opts.SaveToDatabase)
            {
                DatabaseManager.InsertCompareRun(opts.FirstRunId, opts.SecondRunId, RUN_STATUS.RUNNING);
            }

            var results = new Dictionary <string, object>();

            comparators = new List <BaseCompare>();

            Dictionary <string, string> EndEvent = new Dictionary <string, string>();
            BaseCompare c     = new BaseCompare();
            var         watch = System.Diagnostics.Stopwatch.StartNew();

            if (!c.TryCompare(opts.FirstRunId, opts.SecondRunId))
            {
                Log.Warning(Strings.Get("Err_Comparing") + " : {0}", c.GetType().Name);
            }

            c.Results.ToList().ForEach(x => results.Add(x.Key, x.Value));

            watch.Stop();
            TimeSpan t      = TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds);
            string   answer = string.Format(CultureInfo.InvariantCulture, "{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
                                            t.Hours,
                                            t.Minutes,
                                            t.Seconds,
                                            t.Milliseconds);

            Log.Information(Strings.Get("Completed"), "Comparing", answer);

            if (opts.Analyze)
            {
                watch = System.Diagnostics.Stopwatch.StartNew();
                Analyzer analyzer;

                analyzer = new Analyzer(DatabaseManager.RunIdToPlatform(opts.FirstRunId), opts.AnalysesFile);

                if (results.Count > 0)
                {
                    foreach (var key in results.Keys)
                    {
                        try
                        {
                            Parallel.ForEach(results[key] as ConcurrentQueue <CompareResult>, (result) =>
                            {
                                result.Analysis = analyzer.Analyze(result);
                            });
                        }
                        catch (ArgumentNullException)
                        {
                        }
                    }
                }

                watch.Stop();
                t      = TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds);
                answer = string.Format(CultureInfo.InvariantCulture, "{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
                                       t.Hours,
                                       t.Minutes,
                                       t.Seconds,
                                       t.Milliseconds);
                Log.Information(Strings.Get("Completed"), "Analysis", answer);
            }

            watch = System.Diagnostics.Stopwatch.StartNew();


            if (opts.SaveToDatabase)
            {
                foreach (var key in results.Keys)
                {
                    try
                    {
                        foreach (var result in (results[key] as ConcurrentQueue <CompareResult>))
                        {
                            DatabaseManager.InsertAnalyzed(result);
                        }
                    }
                    catch (NullReferenceException)
                    {
                        Log.Debug(key);
                    }
                }
            }


            watch.Stop();
            t      = TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds);
            answer = string.Format(CultureInfo.InvariantCulture, "{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
                                   t.Hours,
                                   t.Minutes,
                                   t.Seconds,
                                   t.Milliseconds);
            Log.Information(Strings.Get("Completed"), "Flushing", answer);

            if (opts.SaveToDatabase)
            {
                DatabaseManager.UpdateCompareRun(opts.FirstRunId, opts.SecondRunId, RUN_STATUS.COMPLETED);
            }

            DatabaseManager.Commit();
            AsaTelemetry.TrackEvent("End Command", EndEvent);
            return(results);
        }