Пример #1
0
        /// <summary>
        /// Executes the synchronisation for the given configuration and using the
        /// given Client
        /// This Method can be called multiple times using different configurations or client
        /// to achive different synchronisations
        /// </summary>
        public void ExcecuteSynchronisation(CancellationToken cancleToken, Configuration config, ISyncClient client)
        {
            _logger.Debug("Executing synchronisation for Directory " + config.Local.LocalSyncDir + " using client of type " + client.GetType());
            //Check if default dir extists, else delete
            if (!Directory.Exists(config.Local.LocalSyncDir))
            {
                _logger.Debug("Creating sync directory at " + config.Local.LocalSyncDir);
                Directory.CreateDirectory(config.Local.LocalSyncDir);
            }

            //Read or create the index File
            _logger.Debug("Reading index File");
            SyncIndexManager indexManager = new SyncIndexManager(_logger, config);

            //The following three steps are performed for a synchronisation:
            //1. Iterate all local folder and their files, check for updates on server
            //2. Remove all files that exist in index and server but not local from server -> deleted local
            //3. Add all files that are not in index to local copy
            //Start getting Files at the root Folder
            GetDataAndHandleSync(cancleToken, config.Local.LocalSyncDir, client, _logger, config, indexManager);

            if (cancleToken.IsCancellationRequested)
            {
                return;
            }

            DetectLocalDeletedElements(cancleToken, config, client, _logger, indexManager);

            if (cancleToken.IsCancellationRequested)
            {
                return;
            }

            FetchNewFilesFromServer(cancleToken, config, client, _logger, indexManager);

            _logger.Debug("Synchronisation finished");
        }