public static int Main(string[] args) { var telemetryClient = GetTelemiteryClient(); Log.Logger = BuildLogger(); ///////////////////////////////////////////////////////// Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); // TODO: Remove once Trace replaced with log var oldlogPath = Path.Combine(CreateLogsPath(), "old-migration.log"); // TODO: Remove once Trace replaced with log Trace.Listeners.Add(new TextWriterTraceListener(oldlogPath, "myListener")); // TODO: Remove once Trace replaced with log /////////////////////////////////////////////////////////////////////////// ApplicationStartup(args); var doService = new DetectOnlineService(telemetryClient); if (doService.IsOnline()) { var dvService = new DetectVersionService(telemetryClient); Version latestVersion = dvService.GetLatestVersion(); Log.Information("Latest version detected as {Version_Latest}", latestVersion); var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; if (latestVersion > version) { Log.Warning("You are currently running version {Version_Current} and a newer version ({Version_Latest}) is available. You should upgrade now using Chocolatey command 'choco upgrade vsts-sync-migrator' from the command line.", version, latestVersion); #if !DEBUG Console.WriteLine("Do you want to continue? (y/n)"); if (Console.ReadKey().Key != ConsoleKey.Y) { Log.Warning("User aborted to update version"); return(2); } #endif } } int result = (int)Parser.Default.ParseArguments <InitOptions, ExecuteOptions>(args).MapResult( (InitOptions opts) => RunInitAndReturnExitCode(opts, telemetryClient), (ExecuteOptions opts) => RunExecuteAndReturnExitCode(opts, telemetryClient, AddPlatformSpecificServices, ExecuteEntryPoint), (ExportADGroupsOptions opts) => ExportADGroupsCommand.Run(opts, oldlogPath), errs => 1); ApplicationShutdown(); #if DEBUG Log.Information("App paused so you can check the output. Press a key to close."); Console.ReadKey(); #endif return(result); }
public static int Main(string[] args) { mainTimer.Start(); Telemetry.Current.TrackEvent("ApplicationStart"); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; ////////////////////////////////////////////////// string logsPath = CreateLogsPath(); ////////////////////////////////////////////////// Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); var logPath = Path.Combine(logsPath, "migration.log"); Trace.Listeners.Add(new TextWriterTraceListener(logPath, "myListener")); Console.WriteLine("Writing log to " + logPath); ////////////////////////////////////////////////// Version thisVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Trace.WriteLine(string.Format("Running version detected as {0}", thisVersion), "[Info]"); if (IsOnline()) { Version latestVersion = GetLatestVersion(); Trace.WriteLine(string.Format("Latest version detected as {0}", latestVersion), "[Info]"); if (latestVersion > thisVersion) { Trace.WriteLine( string.Format("You are currently running version {0} and a newer version ({1}) is available. You should upgrade now using Chocolatey command 'choco upgrade vsts-sync-migrator' from the command line.", thisVersion, latestVersion ), "[Warning]"); #if !DEBUG Console.WriteLine("Do you want to continue? (y/n)"); if (Console.ReadKey().Key != ConsoleKey.Y) { Trace.WriteLine("User aborted to update version", "[Warning]"); return(2); } #endif } } Trace.WriteLine(string.Format("Telemetry Enabled: {0}", Telemetry.Current.IsEnabled().ToString()), "[Info]"); Trace.WriteLine("Telemetry Note: We use Application Insights to collect telemetry on performance & feature usage for the tools to help our developers target features. This data is tied to a session ID that is generated and shown in the logs. This can help with debugging."); Trace.WriteLine(string.Format("SessionID: {0}", Telemetry.Current.Context.Session.Id), "[Info]"); Trace.WriteLine(string.Format("User: {0}", Telemetry.Current.Context.User.Id), "[Info]"); Trace.WriteLine(string.Format("Start Time: {0}", startTime.ToUniversalTime().ToLocalTime()), "[Info]"); AsciiLogo(thisVersion); ////////////////////////////////////////////////// int result = (int)Parser.Default.ParseArguments <InitOptions, RunOptions, ExportADGroupsOptions>(args).MapResult( (InitOptions opts) => RunInitAndReturnExitCode(opts), (RunOptions opts) => RunExecuteAndReturnExitCode(opts), (ExportADGroupsOptions opts) => ExportADGroupsCommand.Run(opts, logsPath), errs => 1); ////////////////////////////////////////////////// Trace.WriteLine("-------------------------------END------------------------------", "[Info]"); mainTimer.Stop(); Telemetry.Current.TrackEvent("ApplicationEnd", null, new Dictionary <string, double> { { "ApplicationDuration", mainTimer.ElapsedMilliseconds } }); if (Telemetry.Current != null) { Telemetry.Current.Flush(); // Allow time for flushing: System.Threading.Thread.Sleep(1000); } Trace.WriteLine(string.Format("Duration: {0}", mainTimer.Elapsed.ToString("c")), "[Info]"); Trace.WriteLine(string.Format("End Time: {0}", DateTime.Now.ToUniversalTime().ToLocalTime()), "[Info]"); #if DEBUG Trace.WriteLine("App paused so you can check the output. Press a key to close."); Console.ReadKey(); #endif return(result); }
public static int Main(string[] args) { mainTimer.Start(); Telemetry.Current.TrackEvent("ApplicationStart"); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; ///////////////////////////////////////////////// string logsPath = CreateLogsPath(); ////////////////////////////////////////////////// Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); Trace.Listeners.Add(new TextWriterTraceListener(Path.Combine(logsPath, "VstsSyncMigrator.log"), "myListener")); ////////////////////////////////////////////////// Trace.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, "[Info]"); Version thisVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Trace.WriteLine(string.Format("Running version detected as {0}", thisVersion), "[Info]"); if (IsOnline()) { Version latestVersion = GetLatestVersion(); Trace.WriteLine(string.Format("Latest version detected as {0}", latestVersion), "[Info]"); if (latestVersion > thisVersion) { Trace.WriteLine( string.Format("You are currenlty running version {0} and a newer version ({1}) is available. You should upgrade now using Chocolatey command 'choco update vsts-sync-migrator' from the command line.", thisVersion, latestVersion ), "[Warning]"); #if !DEBUG Console.WriteLine("Do you want to continue? (y/n)"); if (Console.ReadKey().Key != ConsoleKey.Y) { Trace.WriteLine("User aborted to update version", "[Warning]"); return(2); } #endif } } Trace.WriteLine(string.Format("Telemitery Enabled: {0}", Telemetry.Current.IsEnabled().ToString()), "[Info]"); Trace.WriteLine(string.Format("SessionID: {0}", Telemetry.Current.Context.Session.Id), "[Info]"); Trace.WriteLine(string.Format("User: {0}", Telemetry.Current.Context.User.Id), "[Info]"); Trace.WriteLine(string.Format("Start Time: {0}", startTime.ToUniversalTime()), "[Info]"); Trace.WriteLine("------------------------------START-----------------------------", "[Info]"); ////////////////////////////////////////////////// int result = (int)Parser.Default.ParseArguments <InitOptions, RunOptions, ExportADGroupsOptions>(args).MapResult( (InitOptions opts) => RunInitAndReturnExitCode(opts), (RunOptions opts) => RunExecuteAndReturnExitCode(opts), (ExportADGroupsOptions opts) => ExportADGroupsCommand.Run(opts, logsPath), errs => 1); ////////////////////////////////////////////////// Trace.WriteLine("-------------------------------END------------------------------", "[Info]"); mainTimer.Stop(); Telemetry.Current.TrackEvent("ApplicationEnd", null, new Dictionary <string, double> { { "ApplicationDuration", mainTimer.ElapsedMilliseconds } }); if (Telemetry.Current != null) { Telemetry.Current.Flush(); // Allow time for flushing: System.Threading.Thread.Sleep(1000); } Trace.WriteLine(string.Format("Duration: {0}", mainTimer.Elapsed.ToString("c")), "[Info]"); Trace.WriteLine(string.Format("End Time: {0}", startTime.ToUniversalTime()), "[Info]"); #if DEBUG Console.ReadKey(); #endif return(result); }