示例#1
0
        public void Create(
            [Description("The root of the directory which should be saved")]
            [Required]
            string workingDirectory,
            [Description("The path of the backup directory")]
            [Required]
            string resultPath,
            [DefaultValue(null)]
            [Description("Defines the issuer of this backup")]
            string issuer,
            [DefaultValue("HEAD")]
            [Description("Defines the branch of this backup")]
            string branch,
            [DefaultValue(null)]
            [Description("Defines the comment of this backup")]
            string comment,
            [DefaultValue(false)]
            [Description("If this is set to true the backup itself is standalone")]
            bool fullBackup)
        {
            var backupRepo = new ZipBackupRepository(resultPath);

            if(!Directory.Exists(workingDirectory))
                throw new DirectoryNotFoundException("Working directory could not be found");

            var backup = backupRepo.GetBackup(branch);

            if (backup == null)
                throw new BackupNotFoundException("Could not find any backup that fits to the given branch.");

            using (backup)
            using (var prototype = backupRepo.CreateBackup ())
            {
                Trace.WriteLine(fullBackup ? "Creating full backup" : "Creating backup", "File Tool");
                prototype.SetCreationDate(DateTime.Now);
                prototype.SetCreator(issuer);
                prototype.SetDescription(comment);
                prototype.SetParentBackup(backup);

                var source = new DirectoryBackupSource(workingDirectory);

                var patch = fullBackup ? Patch.CreateFromSource(source) : Patch.Compare(source, backup.GetChain());

                patch.ApplyPatch(prototype);

                if(fullBackup)
                    prototype.SetFullBackup(true);

                prototype.Save ();

                if (backupRepo.HeadExists(branch))
                    backupRepo.UpdateHead(branch, prototype.Name);
                else
                    Trace.WriteLine("Backup created without having a branch pointing at it.");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            string workingDirectory = @"F:\Documents\Visual Studio 10\Projects\BigIntegerTest";
            string branch = "HEAD";
            string issuer = "pdelvo";
            string comment = "HUHU";

            var backupRepo = new EntityRepository();

            if (!Directory.Exists(workingDirectory))
                throw new DirectoryNotFoundException("Working directory could not be found");

            IBackup backup = null;

            try
            {
                backup = backupRepo.GetBackup(branch);
            }
            catch
            {
            }

            var chain = backup.GetChain ();

            var list = chain.ToList ();

            using (backup)
            using (var prototype = backupRepo.CreateBackup())
            {
                Trace.WriteLine("Creating backup", "File Tool");
                prototype.SetCreationDate(DateTime.Now);
                prototype.SetCreator(issuer);
                prototype.SetDescription(comment);
                prototype.SetParentBackup(backup);

                var source = new DirectoryBackupSource(workingDirectory);

                var patch = Patch.Compare(source, backup.GetChain());

                patch.ApplyPatch(prototype);

                prototype.Save();

                backupRepo.UpdateHead(branch, prototype.Name);
            }
        }
示例#3
0
 public DirectoryBackupFile(string path, DirectoryBackupSource source)
 {
     Path = path;
     Source = source;
 }