static void Main(string[] args) { Application.EnableVisualStyles(); Session epiSession = null; bool reSync = false; Parser.Default.ParseArguments <CommandLineParams>(args) .WithParsed(o => { currAction = o.Action; ShowProgressBar(); switch (o.Action) { case "Launch": { epiSession = GetEpiSession(o); if (epiSession != null) { launcher.LaunchInEpicor(o, epiSession, false, true); } } break; case "Add": { ShowProgressBar(false); LoginForm frm = new LoginForm(o.EpicorClientFolder); if (frm.ShowDialog() == DialogResult.OK) { ShowProgressBar(); o.Username = Settings.Default.Username; o.Password = Settings.Default.Password; o.ConfigFile = Settings.Default.Environment; o.Encrypted = "true"; epiSession = GetEpiSession(o); if (epiSession != null) { DownloadCustomization(o, epiSession); reSync = true; } else { reSync = false; } } else { reSync = false; } } break; case "Update": { epiSession = GetEpiSession(o); if (epiSession != null) { reSync = true; if (!UpdateCustomization(o, epiSession)) { if (MessageBox.Show("You've canceled the sync operation, would you like to download the latest copy of the customization from Epicor? This will over-write any changes you have made to the custom script since the last sync.", "Re-Download?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { reSync = false; } } } else { reSync = false; } } break; case "Download": { epiSession = GetEpiSession(o); if (epiSession != null) { reSync = true; } else { reSync = false; } } break; case "Edit": { epiSession = GetEpiSession(o); if (epiSession != null) { launcher.LaunchInEpicor(o, epiSession, true); reSync = true; } else { reSync = false; } } break; case "Debug": { epiSession = GetEpiSession(o); if (epiSession != null) { if (!string.IsNullOrEmpty(o.DNSpy)) { RunDnSpy(o); } launcher.LaunchInEpicor(o, epiSession, false, true); } } break; case "Toolbox": { epiSession = GetEpiSession(o); if (epiSession != null) { ShowProgressBar(false); NonModalWokIt win = new NonModalWokIt(epiSession, o); win.ShowDialog(); reSync = win.Sync; ShowProgressBar(true); } } break; } if (reSync) { if (o.Key2.Contains("MainController")) //Dashboard { launcher.DownloadAndSyncDashboard(epiSession, o); } else { launcher.DownloadAndSync(epiSession, o); } } ShowProgressBar(false); if (epiSession != null) { epiSession.OnSessionClosing(); epiSession = null; } if (!string.IsNullOrEmpty(o.NewConfig)) { try { File.Delete(o.NewConfig); } catch { } } if (!string.IsNullOrEmpty(o.Temp)) { try { Directory.Delete(o.Temp, true); } catch { } } }); }
//Main Program Launched from VS Code static void Main(string[] args) { Application.EnableVisualStyles(); Session epiSession = null; bool reSync = false; Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.File("CustomizationEditor.log", Serilog.Events.LogEventLevel.Verbose, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 10, shared: true, fileSizeLimitBytes: 10000000) .CreateLogger(); Log.Information("===========================================Application Launch=================================="); Parser.Default.ParseArguments <CommandLineParams>(args) .WithParsed(o => { try { currAction = o.Action; ShowProgressBar(); switch (o.Action) { case "Add": { Log.Information("Action was Add"); ShowProgressBar(false); LoginForm frm = new LoginForm(o.EpicorClientFolder); if (frm.ShowDialog() == DialogResult.OK) { ShowProgressBar(); o.Username = Settings.Default.Username; o.Password = Settings.Default.Password; o.ConfigFile = Settings.Default.Environment; o.Encrypted = "true"; epiSession = GetEpiSession(o); if (epiSession != null) { Log.Information("Got a valid Epicor Session"); if (DownloadCustomization(o, epiSession)) { reSync = true; } } else { reSync = false; } } else { reSync = false; } } break; case "Update": { Log.Information("Action was Update"); epiSession = GetEpiSession(o); if (epiSession != null) { Log.Information("Got a valid Epicor Session"); reSync = true; if (!UpdateCustomization(o, epiSession)) { if (MessageBox.Show("You've canceled the sync operation, would you like to download the latest copy of the customization from Epicor? This will over-write any changes you have made to the custom script since the last sync.", "Re-Download?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { reSync = false; } } } else { reSync = false; } } break; case "Download": { Log.Information("Action was Update"); epiSession = GetEpiSession(o); if (epiSession != null) { Log.Information("Got a valid Epicor Session"); reSync = true; } else { reSync = false; } } break; case "Toolbox": { Log.Information("Action was ToolBox"); epiSession = GetEpiSession(o); if (epiSession != null) { Log.Information("Got a valid Epicor Session"); ShowProgressBar(false); NonModalWokIt win = new NonModalWokIt(epiSession, o); win.ShowDialog(); reSync = win.Sync; ShowProgressBar(true); } } break; } if (reSync) { Log.Information("Sync down is True"); if (o.Key2.Contains("MainController")) { Log.Information("Download and Sync a Deployed Dashboard"); launcher.DownloadAndSyncDashboard(epiSession, o); } else { Log.Information("Download and Sync a regular customization"); launcher.DownloadAndSync(epiSession, o); } } ShowProgressBar(false); if (epiSession != null) { epiSession.OnSessionClosing(); epiSession = null; } if (!string.IsNullOrEmpty(o.NewConfig)) { try { File.Delete(o.NewConfig); } catch { } } if (!string.IsNullOrEmpty(o.Temp)) { try { Directory.Delete(o.Temp, true); } catch { } } } catch (Exception ex) { Log.Error(ex, "Main Application Error"); } finally { Log.Information("========================Application Close====================="); Log.CloseAndFlush(); } }); }