public void Launch(Form parentForm, ProjectInfo projectInfo) { var configuration = (Chorus.sync.ProjectFolderConfiguration) projectInfo.ServiceProvider.GetService(typeof(Chorus.sync.ProjectFolderConfiguration)); using (var dlg = new SyncDialog(configuration, SyncUIDialogBehaviors.Lazy, SyncUIFeatures.NormalRecommended)) { dlg.Text = "WeSay Send/Receive"; dlg.SyncOptions.DoMergeWithOthers = true; dlg.SyncOptions.DoPullFromOthers = true; dlg.SyncOptions.DoSendToOthers = true; dlg.SetSynchronizerAdjunct(new LiftSynchronizerAdjunct(projectInfo.PathToLIFT)); // leave it with the default, for now... dlg.SyncOptions.RepositorySourcesToTry.Clear(); //dlg.SyncOptions.CheckinDescription = CheckinDescriptionBuilder.GetDescription(); dlg.ShowDialog(parentForm); if (dlg.SyncResult != null && dlg.SyncResult.DidGetChangesFromOthers) { // This loop is an attempt to handle a collection-modified-while-iterating exception that is thrown in Application.Restart, // which http://social.msdn.microsoft.com/Forums/windows/en-US/5ad73551-81bd-4525-aa40-fe2772817a99/applicationrestart-throw-exception-collection-was-modified-enumeration-operation-may-not // attributes to closing a window in its OnClosing event. I can't find where we're doing this, but a // plausible workaround seems to be to close all the windows, using a loop which carefully copies the collection // first, and also tries to avoid closing ones that are already closed. foreach (Form form in Application.OpenForms.Cast <object>().Cast <Form>().ToList()) { if (form.Visible) { form.Close(); } } Application.Restart(); } } }
public void BackupNow(string pathToProjectDirectory, string localizationLanguageId, string pathToLiftFile) { if (pathToProjectDirectory.ToLower().IndexOf(@"sampleprojects\pretend") >= 0) { return; //no way... if you want a unit test that includes CHorus, do it without //that now deprecated monstrosity. } _timeOfLastBackupAttempt = DateTime.Now; //nb: we're not really using the message yet, at least, not showing it to the user if (!string.IsNullOrEmpty(HgRepository.GetEnvironmentReadinessMessage(localizationLanguageId))) { Palaso.Reporting.Logger.WriteEvent("Backup not possible: {0}", HgRepository.GetEnvironmentReadinessMessage("en")); } try { var configuration = new ProjectFolderConfiguration(pathToProjectDirectory); LiftFolder.AddLiftFileInfoToFolderConfiguration(configuration); // projectFolder.IncludePatterns.Add(project.ProjectDirectoryPath); // if (!string.IsNullOrEmpty(PathToParentOfRepositories)) // { // if (!Directory.Exists(PathToParentOfRepositories)) // { // ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "There was a problem during auto backup: Could not Access the backup path, {0}", PathToParentOfRepositories); // //no, we still want to check in... return; // } // else // { // var projectName = Path.GetFileName(pathToProjectDirectory); // var backupSource = Chorus.VcsDrivers.RepositoryAddress.Create("backup", Path.Combine(PathToParentOfRepositories, projectName), // false); // options.RepositorySourcesToTry.Add(backupSource); // } // } using (var dlg = new SyncDialog(configuration, SyncUIDialogBehaviors.StartImmediatelyAndCloseWhenFinished, SyncUIFeatures.Minimal)) { dlg.Text = "WeSay Automatic Backup"; dlg.SyncOptions.DoMergeWithOthers = false; dlg.SyncOptions.DoPullFromOthers = false; dlg.SyncOptions.DoSendToOthers = true; dlg.SyncOptions.RepositorySourcesToTry.Clear(); dlg.SyncOptions.CheckinDescription = CheckinDescriptionBuilder.GetDescription(); dlg.UseTargetsAsSpecifiedInSyncOptions = true; dlg.SetSynchronizerAdjunct(new LiftSynchronizerAdjunct(pathToLiftFile)); //in addition to checking in, will we be doing a backup to another media (e.g. sd card)? if (!string.IsNullOrEmpty(PathToParentOfRepositories)) { var projectName = Path.GetFileName(pathToProjectDirectory); var backupSource = Chorus.VcsDrivers.RepositoryAddress.Create("test-backup-media", Path.Combine(PathToParentOfRepositories, projectName), false); dlg.SyncOptions.RepositorySourcesToTry.Add(backupSource); } dlg.ShowDialog(); if (dlg.FinalStatus.WarningEncountered || //not finding the backup media only counts as a warning dlg.FinalStatus.ErrorEncountered) { ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "There was a problem during auto backup. Chorus said:\r\n\r\n" + dlg.FinalStatus.LastWarning + "\r\n" + dlg.FinalStatus.LastError); } } CheckinDescriptionBuilder.Clear(); } catch (Exception error) { Palaso.Reporting.Logger.WriteEvent("Error during Backup: {0}", error.Message); //TODO we need some passive way indicating the health of the backup system } }