Example #1
0
        private static DvnrReport GenerateReportFromCurrentMachine()
        {
            Console.Out.WriteLine("Gathering machine information");
            var machineInformation = Reporting.GetMachineInformation();

            Console.Out.WriteLine("Gathering site information");
            var sites = Reporting.GetSites();

            Console.Out.WriteLine("Gathering app pool information");
            var appPools = Reporting.GetAppPools();

            // set number of apps using each pool and remove ones that aren't used
            foreach (var appPool in appPools)
            {
                appPool.NumApplications = sites.SelectMany(s => s.Applications).Select(s => s.AppPoolName).Count(name => name == appPool.Name);
            }
            appPools.RemoveAll(pool => pool.NumApplications == 0);

            Console.Out.WriteLine("Gathering GAC library information");
            var gacLibraries = Reporting.GetGACLibraries();

            var report = new DvnrReport
            {
                Version            = typeof(DvnrReport).Assembly.GetName().Version.ToString(),
                MachineInformation = machineInformation,
                Sites        = sites,
                AppPools     = appPools,
                GacLibraries = gacLibraries
            };

            return(report);
        }
Example #2
0
        private static void PrintReportJson(DvnrReport report, TextWriter tw)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(report.GetType());

            using (var ms = new MemoryStream())
            {
                serializer.WriteObject(ms, report);
                string str = Encoding.Default.GetString(ms.ToArray());

                tw.Write(str);
            }
        }
Example #3
0
        private static void WriteCompatSummary(DvnrReport report, string compatFilePath)
        {
            try
            {
                var           summaryReport    = SummaryReporting.GenerateCompatReport(report);
                List <string> connectionErrors = TeamServerConnectivityChecker.CheckForConnectionProblems(false);
                List <string> noCertConnectionErrors;
                if (connectionErrors.Count > 0)
                {
                    noCertConnectionErrors = TeamServerConnectivityChecker.CheckForConnectionProblems(true);
                }
                else
                {
                    noCertConnectionErrors = new List <string>();
                }

                var config = new TemplateServiceConfiguration();
                config.DisableTempFileLocking = true;
                config.Language             = RazorEngine.Language.CSharp;
                config.EncodedStringFactory = new RazorEngine.Text.RawStringFactory();


                var templateService = RazorEngineService.Create(config);

                string filePath = Path.Combine(Environment.CurrentDirectory, compatFilePath);

                string templatePath = "MarkdownTemplate.txt";
                if (!File.Exists(templatePath))
                {
                    Console.WriteLine("Could not find compat test template at " + templatePath);
                    return;
                }
                string template = File.ReadAllText(templatePath);

                DynamicViewBag viewData = new DynamicViewBag();
                viewData.AddValue("ConnErrors", connectionErrors);
                viewData.AddValue("NoCertConnErrors", noCertConnectionErrors);

                var result =
                    templateService.RunCompile(template, "templateKey", null,
                                               summaryReport, viewData);

                File.WriteAllText(filePath, result);
                Console.WriteLine("Compatibility report was written to " + filePath);
            }
            catch (Exception ex)
            {
                Trace.TraceError("Could not write compatibility report. Error: {0}", ex.ToString());
                Console.WriteLine("Error writing compatibility report");
            }
        }
        public static SummaryReport GenerateCompatReport(DvnrReport report)
        {
            var apps = report.Sites.SelectMany(s => s.Applications).OrderBy(a => a.Path).ToList();

            var appPoolsDict = report.AppPools.ToDictionary(a => a.Name);

            var appList = new List <ApplicationInfo>();

            foreach (var app in apps)
            {
                var    site    = report.Sites.Where(s => s.Applications.Contains(app)).SingleOrDefault();
                var    appPool = appPoolsDict[app.AppPoolName];
                string bitness = appPool.X64 ? "64bit" : "32bit";

                appList.Add(new ApplicationInfo
                {
                    Path       = app.Path,
                    AppPool    = appPool.Name,
                    Site       = site?.Name,
                    ClrVersion = appPool.CLRVersion,
                    Bitness    = bitness,
                    NumLibs    = app.Libraries.Count,
                    Pipeline   = appPool.PipelineMode
                });
            }

            var poolList = new List <AppPoolInfo>();

            foreach (var appPool in report.AppPools.OrderBy(a => a.Name))
            {
                string bitness           = appPool.X64 ? "64bit" : "32bit";
                var    appsInPool        = apps.Where(a => a.AppPoolName == appPool.Name).OrderBy(a => a.Path).Select(a => a.Path == "/" ? "/" : a.Path.TrimStart('/')).ToArray();
                string appsInPoolDisplay = string.Join(", ", appsInPool);
                string rating            = CalcAppPoolRating(appPool);

                poolList.Add(new AppPoolInfo
                {
                    Name            = appPool.Name,
                    NumApplications = appPool.NumApplications,
                    AppNames        = appsInPoolDisplay,
                    Bitness         = bitness,
                    ClrVersion      = appPool.CLRVersion,
                    Pipeline        = appPool.PipelineMode,
                    Rating          = rating
                });
            }

            var summaryReport = new SummaryReport
            {
                Applications     = appList,
                AppPools         = poolList,
                GacLibraryIssues = report.GacLibraries.Where(l => l.Issue != null).ToList(),
                AppLibraryIssues = apps.Where(a => a.Libraries.Any(l => l.Issue != null))
                                   .SelectMany(a => a.Libraries.Where(l => l.Issue != null).Select(l => new AppIssue {
                    AppName = a.Path, Library = l
                }))
                                   .ToList()
            };

            return(summaryReport);
        }
Example #5
0
        private static void PrintReportText(DvnrReport report, TextWriter tw)
        {
            var machineInfo = report.MachineInformation;
            var appPools    = report.AppPools;
            var sites       = report.Sites;
            var gacLibs     = report.GacLibraries;

            string lineBreak    = "----------------------------------------------------";
            string sectionBreak = "====================================================";


            tw.WriteLine(sectionBreak);
            tw.WriteLine("MACHINE INFORMATION");
            tw.WriteLine(sectionBreak);
            tw.WriteLine("OS: {0}", machineInfo.OsVersion);
            tw.WriteLine("OS Architecture: {0}", machineInfo.OsArchitecture);
            tw.WriteLine("Processor: {0}", machineInfo.ProcessorID);
            tw.WriteLine("Cores (Logical): {0}", machineInfo.ProcessorLogicalCores);
            tw.WriteLine("Cores (Physical): {0}", machineInfo.ProcessorPhysicalCores);
            tw.WriteLine("RAM: {0}", machineInfo.MemoryAvailable);
            tw.WriteLine("System Drive: {0}", machineInfo.SystemDrive);
            tw.WriteLine("IIS Installed: {0}", machineInfo.IsIISInstalled);
            if (machineInfo.IsIISInstalled)
            {
                tw.WriteLine("IIS Version: {0}", machineInfo.IISVersion);
            }
            tw.WriteLine("IIS Express Installed: {0}", machineInfo.IsIISExpressInstalled);
            if (machineInfo.IsIISExpressInstalled)
            {
                tw.WriteLine("IIS Express Version: {0}", machineInfo.IISExpressVersion);
            }
            tw.WriteLine(".NET Versions: {0}", string.Join(", ", machineInfo.DotnetFrameworkVersions));


            tw.WriteLine(sectionBreak);
            tw.WriteLine("APP POOLS");
            tw.WriteLine(sectionBreak);
            foreach (var appPool in appPools)
            {
                tw.WriteLine("Name: {0}", appPool.Name);
                tw.WriteLine("Pipeline Mode: {0}", appPool.PipelineMode);
                tw.WriteLine("64bit: {0}", appPool.X64);
                tw.WriteLine("Identity: {0}", appPool.Identity);
                tw.WriteLine("Username: {0}", appPool.UserName);
                tw.WriteLine("CLR Version: {0}", appPool.CLRVersion);
                tw.WriteLine(lineBreak);
            }

            tw.WriteLine(sectionBreak);
            tw.WriteLine("SITES");
            tw.WriteLine(sectionBreak);
            foreach (var site in sites)
            {
                tw.WriteLine("Name: {0}", site.Name);
                tw.WriteLine("Default AppPool: {0}", site.DefaultAppPoolName);
                tw.WriteLine(lineBreak);
                tw.WriteLine("{0} Applications ({1})", site.Name, site.Applications.Count);
                tw.WriteLine(lineBreak);
                foreach (var app in site.Applications)
                {
                    tw.WriteLine("Path: {0}", app.Path);
                    tw.WriteLine("Physical Path: {0}", app.PhysicalPath);
                    tw.WriteLine("AppPool: {0}", app.AppPoolName);
                    tw.WriteLine("Logon Method: {0}", app.AuthenticationLogonMethod);
                    tw.WriteLine("Protocols: {0}", app.EnabledProtocols);
                    tw.WriteLine("Enable Preload: {0}", app.EnablePreload);
                    tw.WriteLine("User: {0}", app.SpecificUser);
                    tw.WriteLine("Libraries ({0})", app.Libraries.Count);
                    foreach (var lib in app.Libraries)
                    {
                        tw.WriteLine("\tFilename: {0}", lib.Filename);
                        tw.WriteLine("\tName: {0}", lib.Name);
                        tw.WriteLine("\tProcessor Architecture: {0}", lib.ProcessorArchitecture);
                        tw.WriteLine("\tPublic Key Token: {0}", lib.PublicKeyToken);
                        tw.WriteLine("\tMD5 Hash: {0}", lib.Md5Hash);
                        tw.WriteLine("\tSHA1 Hash: {0}", lib.SHA1Hash);
                        tw.WriteLine("\tAssembly Version: {0}", lib.AssemblyVersion);
                        tw.WriteLine("\tFile Version: {0}", lib.Version);
                        tw.WriteLine("\tProduct Name: {0}", lib.ProductName);
                        tw.WriteLine("\tProduct Version: {0}", lib.ProductVersion);
                        tw.WriteLine("\tFile Description: {0}", lib.FileDescription);
                        tw.WriteLine("\tCopyright: {0}", lib.Copyright);

                        tw.WriteLine("\t" + lineBreak);
                    }
                    tw.WriteLine("HttpModules ({0})", app.Modules.Count);
                    foreach (var module in app.Modules)
                    {
                        tw.WriteLine("\tName: {0}", module.Name);
                        tw.WriteLine("\tType: {0}", module.Type);
                        tw.WriteLine("\t" + lineBreak);
                    }
                    tw.WriteLine(sectionBreak);
                }
                tw.WriteLine("{0} Bindings ({1})", site.Name, site.Bindings.Count);
                tw.WriteLine(sectionBreak);
                foreach (var binding in site.Bindings)
                {
                    tw.WriteLine("Protocol: {0}", binding.Protocol);
                    tw.WriteLine("Hostname: {0}", binding.Hostname);
                    tw.WriteLine("Port: {0}", binding.Port);
                    tw.WriteLine("IP Address: {0}", binding.IpAddress);
                    tw.WriteLine("Binding Information: {0}", binding.BindingInformation);
                    tw.WriteLine(lineBreak);
                }

                tw.WriteLine(sectionBreak);
                tw.WriteLine("GAC LIBRARIES ({0})", gacLibs.Count);
                tw.WriteLine(sectionBreak);

                foreach (var lib in gacLibs)
                {
                    tw.WriteLine("\tFilename: {0}", lib.Filename);
                    tw.WriteLine("\tName: {0}", lib.Name);
                    tw.WriteLine("\tProcessor Architecture: {0}", lib.ProcessorArchitecture);
                    tw.WriteLine("\tPublic Key Token: {0}", lib.PublicKeyToken);
                    tw.WriteLine("\tMD5 Hash: {0}", lib.Md5Hash);
                    tw.WriteLine("\tSHA1 Hash: {0}", lib.SHA1Hash);
                    tw.WriteLine("\tAssembly Version: {0}", lib.AssemblyVersion);
                    tw.WriteLine("\tFile Version: {0}", lib.Version);
                    tw.WriteLine("\tProduct Name: {0}", lib.ProductName);
                    tw.WriteLine("\tProduct Version: {0}", lib.ProductVersion);
                    tw.WriteLine("\tFile Description: {0}", lib.FileDescription);
                    tw.WriteLine("\tCopyright: {0}", lib.Copyright);

                    tw.WriteLine("\t" + lineBreak);
                }
            }
        }
Example #6
0
        private static void PrintReportXml(DvnrReport report, TextWriter tw)
        {
            string reportXml = XmlUtils.XmlSerializeToString(report);

            tw.Write(reportXml);
        }
Example #7
0
        private static void WriteDvnrReportFile(ReportFileType reportType, string dvnrFilePath, DvnrReport report)
        {
            try
            {
                string filePath = Path.Combine(Environment.CurrentDirectory, dvnrFilePath);
                File.Delete(filePath);

                using (var file = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    using (var sw = new StreamWriter(file))
                    {
                        if (reportType == ReportFileType.Xml)
                        {
                            PrintReportXml(report, sw);
                        }
                        if (reportType == ReportFileType.Json)
                        {
                            PrintReportJson(report, sw);
                        }
                        if (reportType == ReportFileType.Text)
                        {
                            PrintReportText(report, sw);
                        }

                        Console.WriteLine("Report was written to: {0}", filePath);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Could not save report file. Error: {0}", ex.ToString());
                Console.WriteLine("Could not save report file");
            }
        }