/// <summary> /// Public Constructor: /// Creates the Controller object. /// </summary> public Controller() { comparator = new Comparator(); mover = new Mover(); smartGroup = new SmartGroup(); job_List_File = System.Windows.Forms.Application.StartupPath.ToString() + Comparator.PATH_DELIMITER + JOBLIST_FILENAME; job_Name_List_File = System.Windows.Forms.Application.StartupPath.ToString() + Comparator.PATH_DELIMITER + JOBNAMELIST_FILENAME; compList_File = System.Windows.Forms.Application.StartupPath.ToString() + Comparator.PATH_DELIMITER + COMPLIST_FILENAME; }
/// <summary> /// Backup method used with MultiSnap /// </summary> /// <param name="thisJob">Job used for backing up.</param> private void backup(Job thisJob) { #region Assertion for valid Job Debug.Assert(job != null, "Loaded job is null."); Debug.Assert(job.getSource() != null, "Loaded job has a null Source."); Debug.Assert(job.getTarget() != null, "Loaded job has a null Target."); #endregion Comparator multisnap = new Comparator(); if (!Directory.Exists(thisJob.getSource().getPath())) throw new Exception("Source folder:" + thisJob.getSource().getPath() + " does not exist."); if (!Directory.Exists(thisJob.getTarget().getPath())) Directory.CreateDirectory(thisJob.getTarget().getPath()); string jobTypePrint = thisJob.getJobType() == Job.SYNC_JOB ? Logger.SYNC_JOB_TYPE : Logger.BACK_UP_JOB_TYPE; mover.getLogger().logJobStarted(thisJob.getJobName(), jobTypePrint, thisJob.getSource().getPath(), thisJob.getTarget().getPath()); string sourcePath = thisJob.getSource().getPath(); string targetPath = thisJob.getTarget().getPath(); DiffResult difference = multisnap.compare(sourcePath, targetPath); unable_to_move = difference.isUAEThrown(); string srcPath, trgPath; #region Backing up from Source to Target // Back up folders. foreach (Album temp in difference.getResult().getSubAlbum()) { srcPath = temp.getPath(); trgPath = srcPath.Replace(thisJob.getSource().getPath(), thisJob.getTarget().getPath()); mover.move(srcPath, trgPath, Mover.MOVE_BACK_UP); } // Back up files. foreach (Files temp in difference.getResult().getMetadata()) { srcPath = temp.getFullpath(); trgPath = srcPath.Replace(thisJob.getSource().getPath(), thisJob.getTarget().getPath()); mover.move(srcPath, trgPath, Mover.MOVE_BACK_UP); } #endregion if (mover.getMoverError()) MessageBox.Show("Some file are unable to move. Check the log file for details.", "Error on Moving"); //Reset mover and log the completion of the job. mover.resetMover(); mover.getLogger().logJobEnded(thisJob.getJobName()); }