예제 #1
0
        /// <returns>null if not found in the dom</returns>
        public static ChorusBackupMaker CreateFromDom(XmlDocument dom, CheckinDescriptionBuilder checkinDescriptionBuilder)
        {
            var node = dom.SelectSingleNode("//backupPlan");

            if (node == null)
            {
                return(null);
            }
            using (var reader = new StringReader(node.OuterXml))
            {
                XmlSerializer serializer  = new XmlSerializer(typeof(ChorusBackupMaker));
                var           backupMaker = (ChorusBackupMaker)serializer.Deserialize(reader);
                backupMaker.CheckinDescriptionBuilder = checkinDescriptionBuilder;
                return(backupMaker);
            }
        }
예제 #2
0
        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
            }
        }
예제 #3
0
 public ChorusBackupMaker(CheckinDescriptionBuilder checkinDescriptionBuilder)
 {
     CheckinDescriptionBuilder = checkinDescriptionBuilder;
 }