Пример #1
0
        private async Task OnChanged(string fullPath, WatcherChangeTypes changeType, bool isAFolder)
        {
            _logger.LogInformation($"{nameof(OnChanged)}: Handling change = {changeType} for = {fullPath} which is a folder = {isAFolder}");
            switch (changeType)
            {
            case WatcherChangeTypes.Deleted:
                if (OnFileDeleted != null)
                {
                    await OnFileDeleted.Invoke(fullPath, isAFolder);
                }
                break;

            case WatcherChangeTypes.Changed:
                if (OnFileChanged != null)
                {
                    await OnFileChanged.Invoke(fullPath, isAFolder);
                }
                break;

            case WatcherChangeTypes.Created:
                if (OnFileCreated != null)
                {
                    await OnFileCreated.Invoke(fullPath, isAFolder);
                }
                break;
            }
        }
Пример #2
0
        public void SystemWatcher_Created(object sender, FileSystemEventArgs e)
        {
            var isRuleFound = false;

            OnFileCreated?.Invoke(this, null);
            foreach (RuleElement rule in configSection.RulesForFiles)
            {
                if (Regex.IsMatch(e.Name, rule.Rule, RegexOptions.IgnoreCase))
                {
                    OnRuleFound?.Invoke(this, null);
                    MoveToNewPath(e.FullPath, rule.Destination, rule.AddDate, rule.AddNumber);
                    OnFileMovedToDestinstion?.Invoke(this, null);
                    isRuleFound = true;
                    break;
                }
            }
            if (!isRuleFound)
            {
                OnRuleNotFound?.Invoke(this, null);
                MoveToNewPath(e.FullPath, _defFolder, false, false);
                OnFileMovedToDefault?.Invoke(this, null);
            }
        }