Example #1
0
 /// <summary>
 /// Loads the job into Controller for use.
 /// Loads null if the job is not found.
 /// </summary>
 /// <param name="jobName">Name of the job.</param>
 public void loadJob(string jobName)
 {
     if (jobList.Exists(delegate(Job tempJob) { return tempJob.getJobName() == jobName && tempJob.getCompName() == Environment.MachineName; }))
     {
         job = (jobList.Single<Job>(delegate(Job tempJob) { return tempJob.getJobName() == jobName && tempJob.getCompName() == Environment.MachineName; }));
     }
     else
     {
         job = null;
     }
 }
Example #2
0
        /// <summary>
        /// Creates a new job based on the parameters.
        /// </summary>
        /// <param name="jobName">Name of the Job.</param>
        /// <param name="jobType">The type of Job</param>
        /// <param name="srcPath">The full path of the Source location.</param>
        /// <param name="trgPath">The full path of the Target location.</param>
        /// <returns>True if the job has been created and false otherwise.</returns>
        public bool createNewJob(string jobName, int jobType, string srcPath, string trgPath)
        {
            // Returns due to the job being in the same location.
            if (srcPath.ToLower() == trgPath.ToLower())
                return false;

            string jobSrc, jobTrg;

            if (jobType == Job.SYNC_JOB)
            {
                #region Searching for a Synchronization job that matches the specification.

                foreach (Job temp in jobList)
                {
                    if (temp.getJobType() != Job.SYNC_JOB)
                        continue;
                    if (temp.getCompName() != Environment.MachineName)
                        continue;

                    jobSrc = temp.getSource().getPath().ToLower();
                    jobTrg = temp.getTarget().getPath().ToLower();

                    // There must not be a matching job such that:
                    // 1) the source and target folders can be found on another job and vice-versa
                    // 2) the source and target folders cannot be a parent or child on another job.
                    // 3) Any combination of the above 2.
                    if ((jobSrc == srcPath.ToLower() && jobTrg == trgPath.ToLower()) ||
                            (jobSrc == trgPath.ToLower() && jobTrg == srcPath.ToLower()) ||
                            (Job.isParent(temp.getSource().getPath(), srcPath) && Job.isParent(temp.getTarget().getPath(), trgPath)) ||
                            (Job.isParent(temp.getSource().getPath(), trgPath) && Job.isParent(temp.getTarget().getPath(), srcPath)) ||
                            (jobSrc == srcPath.ToLower() && Job.isParent(temp.getTarget().getPath(), trgPath)) ||
                            (jobTrg == trgPath.ToLower() && Job.isParent(temp.getSource().getPath(), srcPath)) ||
                            (jobSrc == trgPath.ToLower() && Job.isParent(temp.getTarget().getPath(), srcPath)) ||
                            (jobTrg == srcPath.ToLower() && Job.isParent(temp.getSource().getPath(), trgPath)))
                    {
                        return false;
                    }

                }

                #endregion
            }
            else if (jobType == Job.DIFF_BACKUP_JOB)
            {
                #region Searching for a Backup job that matches the specification.

                foreach (Job temp in jobList)
                {
                    if (temp.getJobType() != Job.DIFF_BACKUP_JOB)
                        continue;
                    if (temp.getCompName() != Environment.MachineName)
                        continue;

                    jobSrc = temp.getSource().getPath().ToLower();
                    jobTrg = temp.getTarget().getPath().ToLower();

                    // There must not be a matching job such that:
                    // 1) the source and target folders can be found on another job
                    // 2) the source and target folders cannot be a parent or child on another job.
                    // 3) Any combination of the above 2.
                    if ((jobSrc == srcPath.ToLower() && jobTrg == trgPath.ToLower()) ||
                        (Job.isParent(temp.getSource().getPath(), srcPath) && Job.isParent(temp.getTarget().getPath(), trgPath)) ||
                        (jobSrc == srcPath.ToLower() && Job.isParent(temp.getTarget().getPath(), trgPath)) ||
                        (jobTrg == trgPath.ToLower() && Job.isParent(temp.getSource().getPath(), srcPath)))
                        return false;

                }

                #endregion
            }

            Job newJob = new Job(jobName, jobType, new Album(srcPath), new Album(trgPath));

            // Adding to the Job list based on type.
            // Invalid types are ignored.
            switch (jobType)
            {

                case Job.SYNC_JOB:
                case Job.DIFF_BACKUP_JOB:
                    jobList.Add(newJob);
                    jobNameList.Add(jobName);
                    return true;
                default:
                    Debug.Assert(false,"No such job");
                    return false;
            }
        }
Example #3
0
        /// <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());
        }
Example #4
0
 /// <summary>
 /// Unloads the job from Controller.
 /// </summary>
 public void unloadJob()
 {
     job = null;
 }
Example #5
0
        /// <summary>
        /// Add the job using the source path
        /// </summary>
        /// <param name="sourcePath">The source path of the job</param>
        public void addJob(string sourcePath)
        {
            string computerName = Environment.MachineName;
            Computer tempComp = getComp(computerName);
            string jobName = tempComp.RunningJobSize;

            Album sourceAlbum = new Album(string.Empty, sourcePath);
            Album targetAlbum = new Album(string.Empty, string.Empty);
            Job jobToAdd = new Job(jobName, Job.DIFF_BACKUP_JOB, sourceAlbum, targetAlbum);

            tempComp.addJob(jobToAdd);
        }
Example #6
0
        /// <summary>
        /// Link the Computer to allow back up
        /// </summary>
        /// <param name="targetPath">The target path inside the computer</param>
        /// <returns>True if successful, else false</returns>
        public bool linkJob(string targetPath)
        {
            string computerName = Environment.MachineName;
            Computer tempComp = getComp(computerName);

            #region Linked Check
            if (tempComp.isLinked())
                return false;
            #endregion

            #region Exist Check
            if (!System.IO.Directory.Exists(targetPath))
                return false;
            #endregion

            #region Read/Write Check
            if (!isWriteAccessible(targetPath))
                return false;
            #endregion

            Album target = new Album(string.Empty, targetPath);
            Album source = new Album(string.Empty, string.Empty);
            Job tempJob = new Job(string.Empty, Job.DIFF_BACKUP_JOB, source, target);

            tempComp.link(tempJob);

            return true;
        }