Esempio n. 1
0
        private void OnChanged(object sender, FileSystemEventArgs e)
        {
            Logger.Verbose("OnChanged", "Entered" + e.ToFormattedString());

            var file       = GetDictionaryKey(e.FullPath);
            var changeType = e.ChangeType;
            var isDir      = false;

            var ruleResult = Rules.ProcessPath(file);

            if (ruleResult == RuleResult.Reject)
            {
                Logger.Verbose("OnChanged", file + " failed rules check; rejected");
                return;
            }

            if (File.Exists(e.FullPath) || Directory.Exists(e.FullPath))
            {
                try
                {
                    FileAttributes attr = File.GetAttributes(e.FullPath);
                    isDir = ((attr & FileAttributes.Directory) == FileAttributes.Directory);
                }
                catch (Exception ex)
                {
                    Logger.Error("Could not get file attributes for " + e.FullPath + "; " + ex.Message);
                }
            }

            Logger.Verbose("OnChanged", string.Format("({3}) {0}{1}; {2}", e.Name, (isDir ? " (directory)" : ""), e.FullPath, e.ChangeType));

            if (isDir)
            {
                //var _dirChanges = DiscoverChangesByDirectory(e.FullPath);

                //if (_dirChanges.Count == 0)
                //{
                return;
                //}
            }


            switch (changeType)
            {
            case WatcherChangeTypes.Changed:
                _changeQueue.Queue(new FileChange(ChangeAction.Sync, file, MaxRetries));
                break;

            case WatcherChangeTypes.Created:
                if (!_replDictionary.ContainsKey(file))
                {
                    _replDictionary.Add(file, new ReplInfo(file, _roots));
                }
                _changeQueue.Queue(new FileChange(ChangeAction.Sync, file, MaxRetries));
                break;

            case WatcherChangeTypes.Deleted:
                _changeQueue.Queue(new FileChange(ChangeAction.Remove, file, MaxRetries));
                break;
            }
            Logger.Verbose("OnChanged", "Exiting::file = " + file + "; changeType = " + changeType + "; isDir = " + isDir);
        }