Exemple #1
0
        private bool CopyFilesWithFilter(SyncRule rule, string filter)
        {
            try
            {
                _directory.CreateDirectory(rule.Dest);
            }
            catch (Exception ex)
            {
                _messenger.Send(new LogMessage(string.Format("Failed to create directory {0}: {1}", rule.Dest, ex.Message)));
                return(false);
            }

            foreach (var sourceFile in _directory.GetFiles(rule.Source, filter, SearchOption.AllDirectories))
            {
                if (!_enabled)
                {
                    break;
                }

                var destPath = GetFileDest(sourceFile, rule.Source, rule.Dest, rule.Flatten);
                if (ShouldSync(sourceFile, destPath))
                {
                    _messenger.Send(new LogMessage(string.Format("Copying {0} to {1}", sourceFile, destPath)));
                    CopyFile(sourceFile, destPath);
                }
            }

            return(true);
        }
Exemple #2
0
        private void CreateWatcher(SyncRule rule, string filter)
        {
            var watcher = _watcherFactory.Create(rule.Source);

            watcher.EnableRaisingEvents = true;
            watcher.Filter = filter;
            watcher.IncludeSubdirectories = true;
            watcher.Changed   += Watcher_Changed;
            watcher.Created   += Watcher_Changed;
            watcher.Renamed   += Watcher_Changed;
            _watchers[watcher] = rule;
        }