示例#1
0
        private static void AddProcess(StringBuilder builder, DiagnosticReport report)
        {
            var maxHeaderLength = ProcessHeaders.Max(h => h.Length);
            var formatter       = "{0,-" + (maxHeaderLength + 1) + "}";

            var sectionIndex = builder.Length;

            Format(ProcessHeaders[0], report.ProcessDetails.PID);
            Format(ProcessHeaders[1], report.ProcessDetails.Name);
            Format(ProcessHeaders[2], report.ProcessDetails.Started.ToString("dd-MM-yyyy HH:mm:ss.fff (zzzz)"));
            Format(ProcessHeaders[3], report.ProcessDetails.LoadedIn);
            Format(ProcessHeaders[17], report.ProcessDetails.IsInteractive);
            Format(ProcessHeaders[4], report.ProcessDetails.IsOptimized);
            Format(ProcessHeaders[5], report.ProcessDetails.Is64Bit);
            Format(ProcessHeaders[19], report.ProcessDetails.IsServerGC);
            Format(ProcessHeaders[6], report.ProcessDetails.IsLargeAddressAware);
            Format(ProcessHeaders[16], report.ProcessDetails.WorkingSetInMegaBytes.ToString("N0") + "MB");
            Format(ProcessHeaders[20], report.ProcessDetails.ThreadCount.ToString("N0"));
            Format(ProcessHeaders[21], $"{report.ProcessDetails.ThreadPoolMinCompletionPortCount:N0} <-> {report.ProcessDetails.ThreadPoolMaxCompletionPortCount:N0}");
            Format(ProcessHeaders[22], $"{report.ProcessDetails.ThreadPoolMinWorkerCount:N0} <-> {report.ProcessDetails.ThreadPoolMaxWorkerCount:N0}");
            Format(ProcessHeaders[12], report.ProcessDetails.FileVersion);
            Format(ProcessHeaders[13], report.ProcessDetails.ProductVersion);
            Format(ProcessHeaders[14], report.ProcessDetails.Language);
            Format(ProcessHeaders[15], report.ProcessDetails.Copyright);
            Format(ProcessHeaders[10], report.ProcessDetails.OriginalFileName);
            Format(ProcessHeaders[11], report.ProcessDetails.FileName);
            Format(ProcessHeaders[7], report.ProcessDetails.ModuleName);
            Format(ProcessHeaders[8], report.ProcessDetails.ModuleFileName);
            Format(ProcessHeaders[9], report.ProcessDetails.ProductName);
            Format(ProcessHeaders[18], report.ProcessDetails.CommandLine[0]);

            var cmdArgs = report.ProcessDetails.CommandLine;

            for (var i = 1; i < cmdArgs.Length; i++)
            {
                builder
                .Append(LinePrefix)
                .Append(Space).Append(Space)
                .AppendFormat(formatter, string.Empty)
                .Append(Space).Append(Space)
                .AppendLine(cmdArgs[i]);
            }

            var maxLineLength = GetMaximumLineLength(builder, sectionIndex);

            builder.Insert(sectionIndex, GetSeperator("Process", maxLineLength));

            void Format(string key, object value)
            {
                builder
                .Append(LinePrefix)
                .Append(Dot)
                .Append(Space)
                .AppendFormat(formatter, key)
                .Append(Colon)
                .Append(Space)
                .AppendLine(value?.ToString());
            }
        }
示例#2
0
        private static void AddAssemblies(StringBuilder builder, DiagnosticReport report)
        {
            var sectionIndex = builder.Length;

            var maxHeaderLength = AssemblyHeaders.Max(h => h.Length);

            var nameFormatter = "{0}{1:D3}{2} {3,-" + (maxHeaderLength + 1) + "}: {4}{5}";
            var formatter     = "{0,-" + (maxHeaderLength + 1) + "}";

            var assCounter = 1;

            report.Assemblies
            .OrderByDescending(a => a.IsGAC)
            .ForEach(ass =>
            {
                builder.AppendFormat(nameFormatter, LinePrefix, assCounter, Pipe, AssemblyHeaders[0], ass.Name, NewLine);

                Format(AssemblyHeaders[1], ass.IsGAC);
                Format(AssemblyHeaders[2], ass.Is64Bit);
                Format(AssemblyHeaders[3], ass.IsOptimized);
                Format(AssemblyHeaders[4], ass.Framework);
                Format(AssemblyHeaders[5], ass.Location);
                Format(AssemblyHeaders[6], ass.CodeBase);

                if (assCounter != report.Assemblies.Length)
                {
                    builder.Append(LinePrefix).AppendLine();
                }

                assCounter++;
            });

            var maxLineLength = GetMaximumLineLength(builder, sectionIndex);

            builder.Insert(sectionIndex, GetSeperator("Assemblies", maxLineLength));

            void Format(string key, object value)
            {
                builder
                .Append(LinePrefix)
                .Append(Space).Append(Space).Append(Space)
                .Append(Dot)
                .Append(Space)
                .AppendFormat(formatter, key)
                .Append(Colon)
                .Append(Space)
                .AppendLine(value?.ToString());
            }
        }
示例#3
0
        private static void AddSystem(StringBuilder builder, DiagnosticReport report)
        {
            var maxHeaderLength = SystemHeaders.Max(h => h.Length);
            var formatter       = "{0,-" + (maxHeaderLength + 1) + "}";

            var sectionIndex = builder.Length;

            Format(SystemHeaders[0], report.SystemDetails.OSName);
            Format(SystemHeaders[1], report.SystemDetails.OSType);
            Format(SystemHeaders[2], report.SystemDetails.Is64BitOS);
            Format(SystemHeaders[3], report.SystemDetails.DotNetFrameworkVersion);
            Format(SystemHeaders[4], report.SystemDetails.MachineName);
            Format(SystemHeaders[5], report.SystemDetails.FQDN);
            Format(SystemHeaders[9], report.SystemDetails.User);
            Format(SystemHeaders[7], report.SystemDetails.CPU);
            Format(SystemHeaders[8], report.SystemDetails.CPUCoreCount);
            Format(SystemHeaders[6], report.SystemDetails.InstalledRAMInGigaBytes.ToString("N0") + "GB");
            Format(SystemHeaders[10], report.SystemDetails.SystemDirectory);
            Format(SystemHeaders[11], report.SystemDetails.CurrentDirectory);
            Format(SystemHeaders[12], report.SystemDetails.RuntimeDirectory);

            var upTimeStr = "-";

            if (report.SystemDetails.Uptime != TimeSpan.MinValue)
            {
                upTimeStr = report.SystemDetails.Uptime.ToString(@"dd\D\a\y\ hh\H\o\u\r\ mm\M\i\n\ ss\S\e\c");
            }

            Format(SystemHeaders[13], upTimeStr);

            var maxLineLength = GetMaximumLineLength(builder, sectionIndex);

            builder.Insert(sectionIndex, GetSeperator("System", maxLineLength));

            void Format(string key, object value)
            {
                builder
                .Append(LinePrefix)
                .Append(Dot)
                .Append(Space)
                .AppendFormat(formatter, key)
                .Append(Colon)
                .Append(Space)
                .AppendLine(value?.ToString());
            }
        }
示例#4
0
        private static void AddDrives(StringBuilder builder, DiagnosticReport report)
        {
            var values = new List <string[]>();

            foreach (var d in report.DriveDetails)
            {
                var row = new string[7];
                row[0] = d.Name;
                row[1] = d.Type;
                row[2] = d.Format;
                row[3] = d.Label;
                row[4] = d.TotalCapacityInGigaBytes.ToString("N0");
                row[5] = d.FreeCapacityInGigaBytes.ToString("N0");
                row[6] = d.AvailableCapacityInGigaBytes.ToString("N0");
                values.Add(row);
            }

            WrapInTable(builder, DrivesHeaders, values);
        }
示例#5
0
        private static string GenerateImpl(DiagnosticReport report)
        {
            var builder = new StringBuilder();

            foreach (var section in ReportSections)
            {
                if (IsReportEnabled(report.Type, section))
                {
                    SectionToFormattingMap[section](builder, report);
                }
            }

            builder.Insert(
                0,
                $"/{NewLine}{Pipe}Diagnostic Report generated at: " +
                $"{report.Timestamp:dd-MM-yyyy HH:mm:ss.fff (zzzz)} in: " +
                $"{report.TimeTaken.TotalMilliseconds} milliseconds.{NewLine}");
            builder.Append('\\');
            return(builder.ToString());
        }
示例#6
0
        private static void AddEnvironmentVariables(StringBuilder builder, DiagnosticReport report)
        {
            var envKeyVals = report.EnvironmentVariables
                             .OrderBy(kv => kv.Key)
                             .ToDictionary(kv => kv.Key, kv => kv.Value);

            var sectionIndex = builder.Length;

            var envVarCounter = 1;
            var maxKeyLength  = envKeyVals.Keys.Max(key => key.Length);
            var format        = "{0}{1:D3}{2} {3,-" + maxKeyLength + "} : {4}{5}";

            envKeyVals.ForEach(kv =>
            {
                builder.AppendFormat(format, LinePrefix, envVarCounter, Dot, kv.Key, kv.Value, NewLine);
                envVarCounter++;
            });

            var maxLineLength = GetMaximumLineLength(builder, sectionIndex);

            builder.Insert(sectionIndex, GetSeperator("Environment-Variables", maxLineLength));
        }
示例#7
0
        private static void AddNetwork(StringBuilder builder, DiagnosticReport report)
        {
            var net = report.NetworkingDetails;

            var sectionIndex = builder.Length;

            builder.Append(LinePrefix)
            .Append(Dot).Append(Space)
            .AppendLine("Windows IP Configuration")
            .Append(LinePrefix)
            .Append(Space).Append(Space)
            .AppendLine("-------------------------");

            var maxKeyLength = NetworkHeaders.Max(h => h.Length);
            var format       = "{0}  {1} {2,-" + maxKeyLength + "} : {3}{4}";

            Format(NetworkHeaders[0], net.Host);
            Format(NetworkHeaders[1], net.Domain);
            Format(NetworkHeaders[2], net.DHCPScope);
            Format(NetworkHeaders[3], net.NodeType);
            Format(NetworkHeaders[4], net.IsWINSProxy);

            builder.Append(LinePrefix).AppendLine();

            foreach (var item in net.InterfaceDetails)
            {
                builder.Append(LinePrefix)
                .Append(Dot).Append(Space)
                .AppendLine(item.Interface.Description)
                .Append(LinePrefix)
                .Append(Space).Append(Space)
                .AppendLine(new string('-', item.Interface.Description.Length + 1));

                Format(NetworkHeaders[5], item.Interface.Name);
                Format(NetworkHeaders[6], item.MAC);
                Format(NetworkHeaders[7], item.Interface.NetworkInterfaceType);
                Format(NetworkHeaders[8], item.Interface.OperationalStatus);
                Format(NetworkHeaders[10], item.Interface.SupportsMulticast);

                if (ApplicationHelper.IsWindows)
                {
                    Format(NetworkHeaders[9], item.Interface.IsReceiveOnly);
                    Format(NetworkHeaders[11], (item.Interface.Speed / 1000000).ToString("N0") + " Mbit/s");
                }

                if (item.Addresses.Any())
                {
                    var ipAddresses = "[" + string.Join(" | ", item.Addresses.Select(i => i.ToString())) + "]";
                    Format(NetworkHeaders[12], ipAddresses);
                }

                builder.Append(LinePrefix).AppendLine();
            }

            var maxLineLength = GetMaximumLineLength(builder, sectionIndex);

            builder.Insert(sectionIndex, GetSeperator("Networks", maxLineLength));

            void Format(string key, object value)
            {
                // ReSharper disable once RedundantToStringCall
                builder.AppendFormat(format, LinePrefix, Pipe.ToString(), key, value?.ToString(), NewLine);
            }
        }