Beispiel #1
0
    private void WriteImpl(LogLevel level, Exception exception, string messageTemplate, object[] args, int sourceLine, string sourceFile)
    {
        try
        {
            var message =
                $"[{DateTime.UtcNow:O}] [{level}] {string.Format(messageTemplate, args)} {Environment.NewLine}";
            _sink.Write(message);

            if (exception != null)
            {
                var exceptionMessage = $"Exception: {exception.Message}{Environment.NewLine}{exception}{Environment.NewLine}";
                _sink.Write(exceptionMessage);
            }
        }
        catch
        {
            try
            {
                var ex         = exception is null ? string.Empty : $"; {exception}";
                var properties = args.Length == 0
                    ? string.Empty
                    : "; " + string.Join(", ", args);
                Console.Error.WriteLine($"{messageTemplate}{properties}{ex}");
            }
            catch
            {
                // ignore
            }
        }
    }
Beispiel #2
0
 private async Task WriteWorkItemDetails(WorkItem workitem, ISink sink)
 {
     await sink.Write(
         new string[]
     {
         workitem.Id.ToString(),
         GetField(workitem, TeamProjectFieldName),
         GetField(workitem, TitleFieldName),
         GetField(workitem, AreaPathFieldName),
         GetField(workitem, IterationPathFieldName),
         GetField(workitem, WorkItemTypeFieldName),
         GetField(workitem, StateFieldName),
         GetField(workitem, ReasonFieldName),
         GetField(workitem, AssignedToFieldName),
         GetField(workitem, CreatedDateFieldName),
         GetField(workitem, CreatedByFieldName),
         GetField(workitem, ChangedDateFieldName),
         GetField(workitem, ChangedByFieldName),
         GetField(workitem, ResolvedDateFieldName),
         GetField(workitem, ResolvedByFieldName),
         GetField(workitem, ClosedDateFieldName),
         GetField(workitem, ClosedByFieldName),
         GetField(workitem, PriorityFieldName),
         GetField(workitem, SeverityFieldName),
     });
 }
Beispiel #3
0
        private async Task WriteBuildDetails(Build build, List <TestRun> testRuns, CodeCoverageSummary coverage, ISink sink)
        {
            CodeCoverageStatistics linesCovered = coverage?.CoverageData?.FirstOrDefault()?.CoverageStats?.FirstOrDefault(s => s.Label == LinesCoverageStatsLabel);

            int totalTests   = testRuns?.Sum(r => r.TotalTests) ?? 0;
            int passedTests  = testRuns?.Sum(r => r.PassedTests) ?? 0;
            int ignoredTests = testRuns?.Sum(r => r.IncompleteTests + r.NotApplicableTests + r.UnanalyzedTests) ?? 0;

            await sink.Write(
                new string[]
            {
                build.Id.ToString(),
                build.BuildNumber,
                build.Definition?.Name,
                build.RequestedBy?.DisplayName,
                build.RequestedFor?.DisplayName,
                build.Repository?.Name,
                build.QueueTime?.ToString("s"),
                build.StartTime?.ToString("s"),
                build.FinishTime?.ToString("s"),
                build.SourceBranch,
                build.SourceVersion,
                build.Result.ToString(),
                totalTests.ToString(),
                passedTests.ToString(),
                ignoredTests.ToString(),
                linesCovered?.Covered.ToString(),
                linesCovered?.Total.ToString()
            });
        }
Beispiel #4
0
 private async Task WriteCommitDetails(GitRepository repository, GitCommitRef commit, string workItemId, ISink sink)
 {
     await sink.Write(
         new string[]
     {
         repository.Name,
         commit.CommitId,
         commit.Author.Date.ToString("s"),
         commit.Author.Name,
         commit.Comment,
         workItemId
     });
 }
Beispiel #5
0
        public async Task JobEntry(string name, int interval, ISource source, IEnumerable <IIntermedia> intermedias, ISink sink, CancellationToken ct)
        {
            try
            {
                while (true)
                {
                    //Read data set from source filter
                    DataSet dataset = await source.Read(ct);

                    if (dataset == null || !dataset.Any())
                    {
                        //Skip current loop if no data read, or filter is in status "stopping"
                        goto loop;
                    }

                    //Process data set by intermedia filters
                    foreach (var intermedia in intermedias)
                    {
                        //dataset = await intermedia.Process(dataset, ct);
                        dataset = await intermedia.Process(dataset, ct, DeviceId);//Chris Han add DeviceId to Json

                        if (dataset == null || !dataset.Any())
                        {
                            //Skip current loop if no data read, or filter is in status "stopping"
                            goto loop;
                        }
                    }

                    //Individually sink each data, to help down-stream Job in aggregating
                    foreach (var data in dataset)
                    {
                        await sink.Write(data, ct);
                    }

loop:
                    await Task.Delay(interval, ct);
                }
            }
            catch (OperationCanceledException)
            {
                Trace.TraceInformation(string.Format(CultureInfo.InvariantCulture, "Job {0}.{1} finished", DeviceId, name));
            }
            catch (Exception ex)
            {
                Trace.TraceError(string.Format(CultureInfo.InvariantCulture, "Job {0}.{1} stopped due to exception {2}", DeviceId, name, ex.ToString()));
            }
        }
Beispiel #6
0
 private static void DoLogging(IFakeObjectCall call, ISink sink, IMessageSource messageSource)
 {
     try
     {
         var msgCfg       = messageSource.GetMessageConfiguration(call.Method.Name);
         var formattedMsg = msgCfg.Text;
         var level        = msgCfg.Level;
         try
         {
             formattedMsg = string.Format(msgCfg.Text, call.Arguments.ToArray());
         }
         catch (Exception)
         {
             // do the needful
         }
         //IFormattable abs = $"123 {0}, {call.Arguments[0]}";
         sink.Write(formattedMsg, level);
     } catch (Exception e)
     {
         // ok, so one of the components failed.
         Trace.Write(e);
     }
 }
        public async Task JobEntry(string name, int interval, ISource source, IEnumerable<IIntermedia> intermedias, ISink sink, CancellationToken ct)
        {
            try
            {
                while (true)
                {
                    //Read data set from source filter
                    DataSet dataset = await source.Read(ct);
                    if (dataset == null || !dataset.Any())
                    {
                        //Skip current loop if no data read, or filter is in status "stopping"
                        goto loop;
                    }

                    //Process data set by intermedia filters
                    foreach (var intermedia in intermedias)
                    {
                        //dataset = await intermedia.Process(dataset, ct);
                        dataset = await intermedia.Process(dataset, ct, DeviceId);//Chris Han add DeviceId to Json
                        if (dataset == null || !dataset.Any())
                        {
                            //Skip current loop if no data read, or filter is in status "stopping"
                            goto loop;
                        }
                    }

                    //Individually sink each data, to help down-stream Job in aggregating
                    foreach (var data in dataset)
                    {
                        await sink.Write(data, ct);
                    }

                    loop:
                    await Task.Delay(interval, ct);
                }
            }
            catch (OperationCanceledException)
            {
                Trace.TraceInformation(string.Format(CultureInfo.InvariantCulture, "Job {0}.{1} finished", DeviceId, name));
            }
            catch (Exception ex)
            {
                Trace.TraceError(string.Format(CultureInfo.InvariantCulture, "Job {0}.{1} stopped due to exception {2}", DeviceId, name, ex.ToString()));
            }
        }
Beispiel #8
0
        /// <param name="gapAnalysis">A path to the course (html) of your gap analysis</param>
        /// <param name="showGaps">Whether to only show gaps defaults to true</param>
        /// <param name="nvqSpecification">The path to the nvq specification file</param>
        /// <param name="lookAt">A module to print out i.e. EAMD4-114</param>
        /// /// <param name="sinkType">The type of sink to use to write output</param>
        static void Main(FileInfo gapAnalysis, FileInfo nvqSpecification = null, string lookAt = null, bool showGaps = true, AvailableSinks sinkType = AvailableSinks.Console)
        {
            switch (sinkType)
            {
            default:
                throw new ArgumentException("Invalid sink type value.");

            case AvailableSinks.Console:
                _sink = new ConsoleSink();
                break;
            }


            if (nvqSpecification == null)
            {
                nvqSpecification = new FileInfo("nvq_specification.xml");
            }
            _nvq = NvqSpecification.Load(nvqSpecification.FullName);

            _sink.Write($"Loaded NVQ Specification, version {_nvq.Version}.");


            if (gapAnalysis is null)
            {
                _sink.WriteError($@"Please provide a file to process or use the -h option to see the help menu.");
                return;
            }

            if (!gapAnalysis.Exists)
            {
                _sink.WriteError($@"{gapAnalysis} cannot be found to process");
                return;
            }

            var html = new HtmlDocument();

            html.Load(gapAnalysis.FullName);

            var root         = html.DocumentNode;
            var courseFolder = root.Descendants().Where(d => d.HasClass("course-folder")).ToList();
            var folder       = courseFolder.FirstOrDefault();

            if (folder is null)
            {
                _sink.WriteError("Cannot find a node with the class course-folder");
                return;
            }

            var chapterBlocks = folder.Descendants().Where(d => d.HasClass("chapter-block")).ToList();

            _sink.Write($"Found {chapterBlocks.Count} modules");

            foreach (var block in chapterBlocks)
            {
                var title = block.Descendants().First(d => d.HasClass("hr-text"));
                _sink.Write($"Processing {title.InnerText}");

                var table      = block.Descendants().First(d => d.HasClass("table"));
                var body       = table.Descendants().First(d => d.Name == "tbody");
                var row        = body.Descendants().First(d => d.Name == "tr");
                var cols       = body.Descendants().Where(d => d.Name == "td").ToList();
                var contentCol = cols[1];

                var module = _nvq.GetModule(title.ChildNodes.First().InnerText);

                if (module == null)
                {
                    _sink.WriteWarning($"Module with the name {title.ChildNodes.First().InnerText} cannot be found!");
                    continue;
                }

                var pTags = contentCol.Descendants().Where(d => d.Name == "p").ToList();
                foreach (var tag in pTags)
                {
                    var badge  = tag.Descendants().FirstOrDefault(d => d.HasClass("badge"));
                    var strong = tag.Descendants().FirstOrDefault(d => d.Name == "strong");
                    if (badge is { } && strong is { })
 public void Log(string message)
 {
     _sink.Write(message);
 }