Esempio n. 1
0
        public static bool ExecuteCode(Script <bool> script, GlobalScriptVars glob, out string err)
        {
            err = string.Empty;
            bool ret = false;

            try {
                script.RunAsync(glob).ContinueWith(s => ret = s.Result.ReturnValue).Wait();
                return(ret);
            }
            catch (CompilationErrorException e) {
                err = e.Message;
                return(ret);
            }
        }
Esempio n. 2
0
        private void OnFileFilter(FileInfo fileInfo, ref bool skip)
        {
            string           err;
            GlobalScriptVars glob = new GlobalScriptVars(fileInfo, Stats.DtTmStarted);

            // Check if any of the global exclude rules tell us to skip processing on file
            // If any of the rules indicate skip, set flag and bail out
            for (int ndx = 0; ndx < sourcesToBackup[currentSrcNdx].GlobalExcludeRules.Count; ndx++)
            {
                string key = MakeCompiledCodeDictKey(sourcesToBackup[currentSrcNdx].ID, ndx);
                CompiledExclusionRule rule = globalExcludeDict[key];
                if (rule.AppliesTo == RuleAppliesTo.Files)
                {
                    bool doSkip = ScriptRunner.ExecuteCode(rule.CompiledCode, glob, out err);
                    if (err == string.Empty)
                    {
                        if (doSkip)
                        {
                            Stats.FilesExcluded++;
                            skip = doSkip;
                            if (Stats.RunInDebugMode)
                            {
                                AddDebugEntryToLog($"Scripting rule {ndx} triggered skip of file: {fileInfo.FullName}");
                            }
                            return;
                        }
                    }
                    else
                    {
                        AddError($"File: {fileInfo.FullName} failed to process compiled script exclusion rule {ndx} on backup source {currentSrcNdx}");
                        skip = true;
                        if (Stats.RunInDebugMode)
                        {
                            AddDebugEntryToLog($"Auto-skipped file {fileInfo.FullName} due to scripting compile/execution error on rule {ndx}");
                        }
                        return;
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>Custom folder filtering event. We use it for fast dictionary lookup of excluded names for each Source Backup ID</summary>
        /// <param name="folderInfo">DirectoryInfo representing the folder being processed</param>
        /// <param name="skip">set skip flag to inform DirSearch component to skip the current folder</param>
        /// <param name="skipChildFolders">set skipChildFolders flag to inform DirSearch component to skip the current folder's children</param>
        private void OnFolderFilter(DirectoryInfo folderInfo, ref bool skip, ref bool skipChildFolders)
        {
            string err;
            // check known folder excludes first
            string key = MakeFolderExcludeDictKey(sourcesToBackup[currentSrcNdx].ID, folderInfo.FullName);

            if (knownFolderExcludeDict.ContainsKey(key))
            {
                skip             = true;
                skipChildFolders = knownFolderExcludeDict[key].AllSubs;
                Stats.FoldersExcluded++;
                if (Stats.RunInDebugMode)
                {
                    if (skipChildFolders)
                    {
                        AddDebugEntryToLog($"Fixed folder rule triggered skip of folder (and subfolders): {folderInfo.FullName}");
                    }
                    else
                    {
                        AddDebugEntryToLog($"Fixed folder rule triggered skip of folder: {folderInfo.FullName}");
                    }
                }
                return;
            }
            // check folder-based rules
            GlobalScriptVars glob = new GlobalScriptVars(folderInfo, Stats.DtTmStarted);

            // Check if any of the global exclude rules tell us to skip processing on folder
            // If any of the rules indicate skip, set flag and bail out of folder and subfolders
            for (int ndx = 0; ndx < sourcesToBackup[currentSrcNdx].GlobalExcludeRules.Count; ndx++)
            {
                key = MakeCompiledCodeDictKey(sourcesToBackup[currentSrcNdx].ID, ndx);
                CompiledExclusionRule rule = globalExcludeDict[key];
                if (rule.AppliesTo == RuleAppliesTo.FolderAndSubfolders || rule.AppliesTo == RuleAppliesTo.ParentFolderOnly)
                {
                    bool doSkip = ScriptRunner.ExecuteCode(rule.CompiledCode, glob, out err);
                    if (err == string.Empty)
                    {
                        if (doSkip)
                        {
                            skip             = doSkip;
                            skipChildFolders = (rule.AppliesTo == RuleAppliesTo.FolderAndSubfolders);
                            Stats.FoldersExcluded++;
                            if (Stats.RunInDebugMode)
                            {
                                if (skipChildFolders)
                                {
                                    AddDebugEntryToLog($"Scripting rule {ndx} triggered skip of folder (and subfolders): {folderInfo.FullName}");
                                }
                                else
                                {
                                    AddDebugEntryToLog($"Scripting rule {ndx} triggered skip of folder: {folderInfo.FullName}");
                                }
                            }
                            return;
                        }
                    }
                    else
                    {
                        AddError($"Folder: {folderInfo.FullName} failed to process compiled script exclusion rule {ndx} on backup source {currentSrcNdx}");
                        skip = true;
                        if (Stats.RunInDebugMode)
                        {
                            AddDebugEntryToLog($"Auto-skipped folder {folderInfo.FullName} due to scripting compile/execution error on rule {ndx}");
                        }
                        return;
                    }
                }
            }
        }