示例#1
0
        public JobEditFrm(BackupJob job, bool addMode, int jobID, ReadOnlyCollection <SourceDef> sourceDefs)
        {
            InitializeComponent();
            this.sourceDefs = sourceDefs;
            this.Text       = addMode ? "Add Backup Job" : "Edit Backup Job";
            // if an existing job is passed in, copy the data to a new instance
            Result = (job == null) ? new BackupJob() : job.DeepCopyUsingJson();
            if (addMode)
            {
                Result.ID = jobID;
            }
            // only load as a backup in case combobox doesn't have text descriptions
            if (DeleteDetectCB.Items.Count == 0)
            {
                DeleteDetectCB.DataSource = Enum.GetNames(typeof(DeleteDetectHandling));
            }
            DeleteDetectCB.SelectedIndex = (int)Result.Options.DeleteHandling;
            PopulateSources();
            StopErrCntCB.DataSource = BackupSettings.MaxErrOptList;
            // try to find the index of the max errors setting
            var errNdx = BackupSettings.MaxErrOptList.ToList().FindIndex(n => n == Result.MaxErrors);

            // if not found, use default. Otherwise, use array index of the matched entry
            StopErrCntCB.SelectedIndex = (errNdx == -1) ? BackupSettings.MaxErrOptDefaultIndex : errNdx;
            JobIDTB.Text           = Result.ID.ToString();
            DestFolderNameTB.Text  = Result.Destination;
            MaintainHistCB.Checked = Result.Options.MaintainHistoryFolder;
        }
示例#2
0
        private bool Validate(bool simMode, bool debugMode)
        {
            RunError = string.Empty;
            Stats    = new BackupStats {
                JobID = this.JobID, RunInSimMode = simMode, RunInDebugMode = debugMode
            };
            job = Settings.Jobs.FirstOrDefault <BackupJob>(j => j.ID == JobID);
            if (job == null)
            {
                var eligibleList = string.Join(", ", Settings.Jobs.Select(j => j.ID.ToString()));
                RunError = $"Job {JobID} is an invalid Backup Job ID. Try one of: {eligibleList}";
                return(false);
            }
            // destination folder has JobID appended
            string destOutPath = Path.Combine(job.Destination, JobID.ToString());

            // append trailing slash for small performance improvement over time so it's not constantly added for each filename grafted later
            if (destOutPath[destOutPath.Length - 1] != Path.DirectorySeparatorChar)
            {
                destOutPath += Path.DirectorySeparatorChar;
            }
            // set the destination root, then the dependent log and stats file names
            Stats.DestPathRoot     = destOutPath;
            Stats.ErrLogFileName   = GetDestRootFileNameLog(ErrorFilePrefix);
            Stats.StatsLogFileName = GetDestRootFileNameLog(StatsFilePrefix);
            Stats.DebugFileName    = GetDestRootFileNameLog(DebugFilePrefix);

            // setup folder skips for delete detection. The paths must have a trailing slash so matching works correctly
            foldersToSkipForDeleteDetection.Clear();
            foldersToSkipForDeleteDetection.Add(Path.Combine(Stats.DestPathRoot, HistoryFolderName) + Path.DirectorySeparatorChar);
            foldersToSkipForDeleteDetection.Add(Path.Combine(Stats.DestPathRoot, TrashFolderName) + Path.DirectorySeparatorChar);

            // build a list of known Bum files to skip (based on prefix convention) for delete detection
            prefixesToSkipForDeleteDetection.Clear();
            prefixesToSkipForDeleteDetection.Add(Stats.DestPathRoot + ErrorFilePrefix + FileNameSegmentSep);
            prefixesToSkipForDeleteDetection.Add(Stats.DestPathRoot + StatsFilePrefix + FileNameSegmentSep);
            prefixesToSkipForDeleteDetection.Add(Stats.DestPathRoot + DebugFilePrefix + FileNameSegmentSep);
            // skip any Settings_* backup files
            prefixesToSkipForDeleteDetection.Add(Stats.DestPathRoot + BackupSettings.SettingsFilenameBase + FileNameSegmentSep);

            // make sure all folder structures exist including special folders for BUM
            FileUtils.CreateDestFolderStructure(Stats.DestPathRoot);
            if (Stats.RunInDebugMode)
            {
                AddDebugEntryToLog($"Creating root output folder (if not present): {Stats.DestPathRoot}");
            }
            foreach (var folderName in foldersToSkipForDeleteDetection)
            {
                FileUtils.CreateDestFolderStructure(folderName);
                if (Stats.RunInDebugMode)
                {
                    AddDebugEntryToLog($"Creating special output folder (if not present): {folderName}");
                }
            }
            sourcesToBackup = new List <SourceDef>();
            foreach (var id in job.SourceIDs)
            {
                SourceDef srcDef = Settings.SourceDefs.FirstOrDefault(s => s.ID == id);
                if (srcDef == null)
                {
                    RunError = $"Job {JobID} references an invalid source ID {id} that is not found in the current settings";
                    return(false);
                }
                sourcesToBackup.Add(srcDef);
                // create dictionary lookup of "SouceID-Foldername" for each known exclusion folder
                foreach (var folder in srcDef.KnownFolderExcludes)
                {
                    knownFolderExcludeDict.Add(MakeFolderExcludeDictKey(srcDef.ID, folder.Loc), folder);
                }
                for (int ndx = 0; ndx < srcDef.GlobalExcludeRules.Count; ndx++)
                {
                    // global rule lookup id will use SourceID-RuleListIndex
                    CompiledExclusionRule excRule = new CompiledExclusionRule(srcDef.GlobalExcludeRules[ndx]);
                    if (excRule.HasErrors)
                    {
                        RunError = $"Job {JobID} and Backup Source ID {srcDef.ID} have compile errors in rule {ndx + 1}";
                        return(false);
                    }
                    globalExcludeDict.Add(MakeCompiledCodeDictKey(srcDef.ID, ndx), excRule);
                }
            }

            return(true);
        }