/// <summary> /// Gets all Files and Directories at the given Path and handles their synchronisation /// </summary> /// <param name="absolutePath"></param> private void GetDataAndHandleSync(CancellationToken cancleToken, string absolutePath, ISyncClient client, ILogger logger, Configuration config, SyncIndexManager indexManager) { //Get the remote Properties, Files and Folder of the root folder IEnumerable <IRemoteProperty> remoteProperties = client.GetProperties(GetRemotePath(config, absolutePath)); IEnumerable <FileSyncElement> files = GetFiles(absolutePath, config, logger); IEnumerable <DirectorySyncElement> directories = GetDirectories(absolutePath, config, logger); //If there is no connection or something went wrong during request if (remoteProperties == null) { _logger.Error("Something went wrong during connection to server."); return; } //First the Directories -> ensure they are not deleted before processing everything else foreach (DirectorySyncElement dir in directories) { if (cancleToken.IsCancellationRequested) { return; } HandleISyncElement(cancleToken, dir, client, remoteProperties, indexManager, logger, config); } foreach (FileSyncElement file in files) { if (cancleToken.IsCancellationRequested) { return; } HandleISyncElement(cancleToken, file, client, remoteProperties, indexManager, logger, config); } }
/// <summary> /// Fetches the given Folder and its content from the server /// </summary> private void FetchFolderFromServer(CancellationToken cancleToken, string relativePath, ISyncClient client, Configuration conf, ILogger logger, SyncIndexManager indexManager) { if (cancleToken.IsCancellationRequested) { return; } //Check if folder exists locally -> else create string localDirectoryPath = conf.Local.LocalSyncDir + relativePath; try { if (!Directory.Exists(localDirectoryPath)) { _logger.Debug("Folder " + localDirectoryPath + " does not exist locally. Creating folder and adding to the index."); Directory.CreateDirectory(localDirectoryPath); indexManager.AddOrUpdate(CreateIndexElement(new DirectorySyncElement(new DirectoryInfo(localDirectoryPath), conf.Local.LocalSyncDir, logger), null)); } } catch (Exception exc) { _logger.Error("A error occured while creating local folder", exc); } //Get Properties and Process them IEnumerable <IRemoteProperty> remoteProperties = client.GetProperties(GetRemotePath(conf, localDirectoryPath)); //Something went wrong during the connection to the server if (remoteProperties == null) { _logger.Error("Something went wrong during connection to server."); return; } foreach (IRemoteProperty property in remoteProperties) { if (cancleToken.IsCancellationRequested) { return; } if (property.ElementType.Equals(SyncElementType.Directory)) { FetchFolderFromServer(cancleToken, property.DecodedRelativeRemotePath, client, conf, logger, indexManager); } else { FetchFileFromServer(cancleToken, property, client, conf, logger, indexManager); } } }