コード例 #1
0
        public static void Main(string[] args)
        {
            if (AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                // RazorEngine cannot clean up from the default appdomain...
                //Console.WriteLine("Switching to second AppDomain...");
                AppDomainSetup adSetup = new AppDomainSetup();
                adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                var current = AppDomain.CurrentDomain;
                // You only need to add strongnames when your appdomain is not a full trust environment.
                var strongNames = new StrongName[0];

                var domain = AppDomain.CreateDomain(
                    "MyMainDomain", null,
                    current.SetupInformation, new PermissionSet(PermissionState.Unrestricted),
                    strongNames);
                try
                {
                    domain.ExecuteAssembly(Assembly.GetExecutingAssembly().Location, args);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error executing ContrastDvnr: " + ex.Message);
                    Trace.TraceError("Error executing ContrastDvnr: " + ex);
                    return;
                }
                return;
            }

            var traceOutput = new DvnrTraceListener("ContrastDvnr.log", "tracelog");

            Trace.Listeners.Add(traceOutput);
            Trace.AutoFlush = true;

            var arguments = new Docopt().Apply(usage, args, version: "ContrastDvnr 1.0", exit: true);

            Trace.TraceInformation("ContrastDvnr executed with arguments [{0}]", string.Join(" ", args));

            // ensure IIS is installed and we can use ServerManager
            if (!Reporting.PreFlightCheck())
            {
                return;
            }

            bool isXml  = arguments["xml"].IsTrue;
            bool isJson = arguments["json"].IsTrue;
            bool isText = arguments["text"].IsTrue;

            ReportFileType reportType = ReportFileType.Unknown;

            // default to xml if no format is specified
            if (!isXml && !isJson && !isText)
            {
                reportType = ReportFileType.Xml;
            }
            else if (isXml)
            {
                reportType = ReportFileType.Xml;
            }
            else if (isJson)
            {
                reportType = ReportFileType.Json;
            }
            else if (isText)
            {
                reportType = ReportFileType.Text;
            }

            string fileName = "report.xml";

            if (reportType == ReportFileType.Xml)
            {
                fileName = "report.xml";
            }
            else if (reportType == ReportFileType.Json)
            {
                fileName = "report.json";
            }
            else if (reportType == ReportFileType.Text)
            {
                fileName = "report.txt";
            }


            DvnrReport report;
            string     fromFilename = arguments.ContainsKey("--from") ? arguments["--from"]?.ToString() : "";

            if (!string.IsNullOrEmpty(fromFilename))
            {
                report = GenerateReportFromExisting(fromFilename, reportType);
            }
            else
            {
                report = GenerateReportFromCurrentMachine();
            }

            string directory = CreateOutputDirectory();

            if (arguments["--screen"].IsTrue)   // write to screen instead of file
            {
                if (reportType == ReportFileType.Xml)
                {
                    PrintReportXml(report, Console.Out);
                }
                if (reportType == ReportFileType.Json)
                {
                    PrintReportJson(report, Console.Out);
                }
                if (reportType == ReportFileType.Text)
                {
                    PrintReportText(report, Console.Out);
                }
            }
            else
            {   // write to file
                string dvnrReportPath = Path.Combine(directory, fileName);
                Console.WriteLine("Writing DVNR report.");
                WriteDvnrReportFile(reportType, dvnrReportPath, report);

                string compatReportPath = Path.Combine(directory, "compatSummary.md");
                Console.WriteLine("Writing compatibility report.");
                WriteCompatSummary(report, compatReportPath);
            }

            Trace.TraceInformation("ContrastDvnr exited");
            Trace.Flush();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            var traceOutput = new DvnrTraceListener("ContrastDvnr.log", "tracelog");
            Trace.Listeners.Add(traceOutput);
            Trace.AutoFlush = true;

            var arguments = new Docopt().Apply(usage, args, version: "ContrastDvnr 1.0", exit: true);

            Trace.TraceInformation("ContrastDvnr executed with arguments [{0}]", string.Join(" ", args));

            // ensure IIS is installed and we can use ServerManager
            if (!Reporting.PreFlightCheck())
            {
                return;
            }

            bool isXml = arguments["xml"].IsTrue;
            bool isJson = arguments["json"].IsTrue;
            bool isText = arguments["text"].IsTrue;

            // default to xml if no format is specified
            if (!isXml && !isJson && !isText)
                isXml = true;

            string fileName = "report.xml";
            string inFilename = arguments["--file"].ToString();
            if(inFilename != "report.xml")
            {
                fileName = inFilename;
            }
            else
            {   // set default report file names
                if (isXml) fileName = "report.xml";
                else if (isJson) fileName = "report.json";
                else if (isText) fileName = "report.txt";
            }
            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
            {
                MachineInformation = machineInformation,
                Sites = sites,
                AppPools = appPools,
                GacLibraries = gacLibraries
            };

            if (arguments["--screen"].IsTrue)   // write to screen instead of file
            {
                if (isXml) PrintReportXml(report, Console.Out);
                if (isJson) PrintReportJson(report, Console.Out);
                if (isText) PrintReportText(report, Console.Out);
            }
            else
            {   // write to file
                try
                {
                    string filePath = Path.Combine(Environment.CurrentDirectory, fileName);
                    File.Delete(filePath);

                    using (var file = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        using (var sw = new StreamWriter(file))
                        {
                            if (isXml) PrintReportXml(report, sw);
                            if (isJson) PrintReportJson(report, sw);
                            if (isText) 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");
                }
            }

            Trace.TraceInformation("ContrastDvnr exited");
            Trace.Flush();
        }