private static void FullMirrorWorkerAsync_(ICommandReporter commandReporter, string username, string password, string servername, string vaultname, string folder, CancellationToken ct, string subFolderTest) { bool useWorkingFolder = string.IsNullOrEmpty(folder); bool failOnError = true; FullMirrorCommand cmd = new FullMirrorCommand(commandReporter, username, password, servername, vaultname, folder, useWorkingFolder, failOnError, ct, subFolderTest); cmd.Execute(); }
static void Main() { // make sure that there is only 1 instance running // use a named mutex to lock out other instances. bool lockAcquired = false; string myName = Assembly.GetEntryAssembly().GetName().Name; using (Mutex appLock = new Mutex(true, myName, out lockAcquired)) { if (!lockAcquired) { Environment.Exit(0); } WebServiceManager.Initialize(); MainForm mainForm = new MainForm(); string [] args = Environment.GetCommandLineArgs(); // parse the command line arguments Commands command = Commands.UNKNOWN; string user = null; string pass = null; string server = null; string vault = null; string logfile = null; string mirrorFolder = null; string sSubPathTest = null; bool useWorkingFolder = false; bool failOnError = true; if (args != null && args.Length > 1) { m_silentMode = true; for (int i = 1; i < args.Length; i++) { if (String.Compare(args[i], "-PartialMirror", true) == 0) { if (command == Commands.UNKNOWN) { command = Commands.PARTIAL_MIRROR; } else if (command == Commands.FULL_MIRROR) { PrintErrorAndExit("Cannot use both -FullMirror and -PartialMirror"); } } else if (String.Compare(args[i], "-FullMirror", true) == 0) { if (command == Commands.UNKNOWN) { command = Commands.FULL_MIRROR; } else if (command == Commands.PARTIAL_MIRROR) { PrintErrorAndExit("Cannot use both -FullMirror and -PartialMirror"); } } else if (String.Compare(args[i], "-U", true) == 0) { if (args.Length <= i + 1) { PrintErrorAndExit("no username specified"); } user = args[++i]; } else if (String.Compare(args[i], "-P", true) == 0) { if (args.Length <= i + 1) { PrintErrorAndExit("no password specified"); } pass = args[++i]; } else if (String.Compare(args[i], "-S", true) == 0) { if (args.Length <= i + 1) { PrintErrorAndExit("no server specified"); } server = args[++i]; } else if (String.Compare(args[i], "-V", true) == 0) { if (args.Length <= i + 1) { PrintErrorAndExit("no vault specified"); } vault = args[++i]; } else if (String.Compare(args[i], "-L", true) == 0) { if (args.Length <= i + 1) { PrintErrorAndExit("no logfile specified"); } logfile = args[++i]; } else if (String.Compare(args[i], "-F", true) == 0) { if (args.Length <= i + 1) { PrintErrorAndExit("no mirror folder specified"); } mirrorFolder = args[++i]; } else if (String.Compare(args[i], "-WF", true) == 0) { useWorkingFolder = true; } else if (String.Compare(args[i], "-noFail", true) == 0) { failOnError = false; } else if (String.Compare(args[i], "-?", true) == 0) { PrintUsageAndExit(); } else if (String.Compare(args[i], "-SF", true) == 0) { if (args.Length <= i + 1) { PrintErrorAndExit("no sub folder filter specified"); } sSubPathTest = args[++i]; } else { PrintUsageAndExit(); } } try { if (logfile != null) { m_logFileStream = new StreamWriter(logfile, true); m_logFileStream.WriteLine("----------------------"); m_logFileStream.WriteLine(DateTime.Now.ToString()); } } catch (Exception e) { PrintErrorAndExit(e.Message); } if (command == Commands.UNKNOWN) { PrintErrorAndExit("Must use either -FullMirror and -PartialMirror"); } Settings settings = Settings.LoadSettings(); if (server == null) { // the server was not specified on the command line if (vault != null) { PrintErrorAndExit("The -V parameter must be used with -S"); } // if there is only one login stored, use it Login login = settings.GetOnlyLogin(); if (login == null) { PrintErrorAndExit("Use -S and -V to specify the server and vault name respectively."); } server = login.Server; vault = login.Vault; if (user == null) { user = login.Username; } if (pass == null) { pass = login.Password; } if (mirrorFolder == null) { mirrorFolder = login.MirrorFolder; } } else { if (vault == null) { PrintErrorAndExit("The -S parameter must be used with -V"); } if (user == null) { // username was not specified on command line, see if its stored Login login = settings.GetLogin(server, vault); if (login == null) { PrintErrorAndExit("Use -U and -P to specify the username and password respectively."); } user = login.Username; pass = login.Password; if (mirrorFolder == null) { mirrorFolder = login.MirrorFolder; } } // if no password is specified, assume a blank password if (pass == null) { pass = ""; } } if (mirrorFolder == null && !useWorkingFolder) { PrintErrorAndExit("Use -F to specify the mirror (output) folder or -WF to use your working folder."); } try { DateTime now = DateTime.Now; if (command == Commands.PARTIAL_MIRROR) { DateTime lastSyncTime = DateTime.MinValue; Login login = settings.GetLogin(server, vault); if (login != null) { lastSyncTime = login.LastSyncTime; } PartialMirrorCommand cmd = new PartialMirrorCommand(new SilentCommandReporter(), user, pass, server, vault, mirrorFolder, lastSyncTime, useWorkingFolder, failOnError, CancellationToken.None); cmd.Execute(); Print("Partial Mirror complete", "Success"); } else if (command == Commands.FULL_MIRROR) { FullMirrorCommand cmd = new FullMirrorCommand(new SilentCommandReporter(), user, pass, server, vault, mirrorFolder, useWorkingFolder, failOnError, CancellationToken.None, sSubPathTest); cmd.Execute(); Print("Full Mirror complete", "Success"); } else { // we should never hit this code Print("Error: Invalid command", "Error", true /* forceShowMessageBox */); } // save the login information, including the updated sync time settings.AddLogin(new Login(user, pass, server, vault, mirrorFolder, now, "")); settings.SaveSettings(); } catch (Exception e) { Print(e.ToString(), "Error", true /* forceShowMessageBox */); } } else { Application.Run(new MainForm()); } Cleanup(); } }