예제 #1
0
        public async Task SynchronizeNowAsync(string localFolderPath, string remoteFolderPath, IFileManager fileManager, bool syncOnConflictsFromRemoteFolder = true)
        {
            //Save current userHandledConflicts List to restore it later
            List <SyncConflictType> current = _userHandledConflicts;

            //By default, all conflicts will sync from Remote. If this param is false, user will receive conflict calls.
            if (syncOnConflictsFromRemoteFolder)
            {
                _userHandledConflicts = new List <SyncConflictType>(); //Empty userHandled List. Have them all handled by default Action
            }
            //The folders to sync
            _localSyncFolder  = localFolderPath;
            _remoteSyncFolder = remoteFolderPath;

            //The File Api to save/read files
            _fileManager = fileManager;

            //Add the RemoteSyncFolder to the ServerApi
            _serverManager.SetRemoteSyncFolder(_remoteSyncFolder);

            //Check the FolderStatus
            _folderSyncState = new FolderStatusManager(_localSyncFolder, _remoteSyncFolder, _fileManager);
            await startUpSyncFolderAsync();

            //Restore the conflict types that will be handled by the user
            if (syncOnConflictsFromRemoteFolder)
            {
                _userHandledConflicts = current;
            }
        }
예제 #2
0
        public async Task StartWatcherAsync(string localFolderPath, string remoteFolderPath, IFileManager fileManager)
        {
            //The folders to sync
            _localSyncFolder  = localFolderPath;
            _remoteSyncFolder = remoteFolderPath;

            //The File Api to save/read files
            _fileManager = fileManager;

            //Add the RemoteSyncFolder to the ServerApi
            _serverManager.SetRemoteSyncFolder(_remoteSyncFolder);

            //Check the FolderStatus
            _folderSyncState = new FolderStatusManager(_localSyncFolder, _remoteSyncFolder, _fileManager);
            await startUpSyncFolderAsync();

            //If there was another folder being watched, drop it
            if (_watcher != null)
            {
                _watcher.Created -= new FileSystemEventHandler(onWatcherCreated);
                _watcher.Changed -= new FileSystemEventHandler(onWatcherChanged);
                _watcher.Dispose();
                _watcher = null;

                _deleteWatcher.Deleted -= new FileSystemEventHandler(onWatcherDeleted);
                _deleteWatcher.Dispose();
                _deleteWatcher = null;
            }

            //Watcher for Copy and Modify actions
            _watcher                     = new FileSystemWatcher();
            _watcher.Path                = _localSyncFolder;
            _watcher.NotifyFilter        = NotifyFilters.LastWrite; //Need another watcher for Delete because this filter invalidates Delete
            _watcher.Filter              = "*.*";
            _watcher.Changed            += new FileSystemEventHandler(onWatcherChanged);
            _watcher.Created            += new FileSystemEventHandler(onWatcherCreated);
            _watcher.EnableRaisingEvents = true;

            //Watcher for Delete action
            _deleteWatcher                     = new FileSystemWatcher();
            _deleteWatcher.Path                = _localSyncFolder;
            _deleteWatcher.Filter              = "*.*";
            _deleteWatcher.Deleted            += new FileSystemEventHandler(onWatcherDeleted);
            _deleteWatcher.EnableRaisingEvents = true;

            //_autoSync.Clear();
        }