Ejemplo n.º 1
0
 /// <summary>
 /// Downloaded the given RemotePropery and adds it as a local file
 /// </summary>
 /// <param name="remoteProperty"></param>
 /// <param name="client"></param>
 /// <param name="conf"></param>
 /// <param name="logger"></param>
 /// <param name="indexManager"></param>
 private void FetchFileFromServer(CancellationToken cancleToken, IRemoteProperty remoteProperty, ISyncClient client, Configuration conf, ILogger logger, SyncIndexManager indexManager)
 {
     try
     {
         string localFilePath = conf.Local.LocalSyncDir + remoteProperty.DecodedRelativeRemotePath;
         if (!File.Exists(localFilePath))
         {
             //File does not exist local, will be downloaded and added
             _logger.Debug(remoteProperty.DecodedRelativeRemotePath + " does not exist locally. Will be downloaded and added to index");
             FileInfo temp = client.DownloadRemoteFileToTemp(cancleToken, remoteProperty.DecodedRelativeRemotePath);
             if (temp != null)
             {
                 FileInfo newFile = FileManager.CopyFile(temp.FullName, localFilePath, true, _logger);
                 if (newFile != null)
                 {
                     FileSyncElement newFileElement = new FileSyncElement(newFile, conf.Local.LocalSyncDir, logger);
                     indexManager.AddOrUpdate(CreateIndexElement(newFileElement, remoteProperty));
                 }
             }
         }
     } catch (Exception exc)
     {
         logger.Error("Unexpected error while fetching " + remoteProperty.RelativeRemotePath + " from server: ", exc);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Downloads the File from the ISync client and
        /// patches the current local file with the downloaded version
        /// or creates new file
        /// </summary>
        /// <returns>An IFileInfo property continaing information about the overwritten File, or null if download failed</returns>
        public FileInfo PatchLocalFile(CancellationToken cancleToken, ISyncClient client)
        {
            //Get Temp File from Remote
            _logger.Debug("Patching " + _relativePath + " with version from server");
            FileInfo tempFile = client.DownloadRemoteFileToTemp(cancleToken, _relativePath.UrlDecode());

            if (tempFile != null)
            {
                if (cancleToken.IsCancellationRequested)
                {
                    return(null);
                }
                _info = FileManager.CopyFile(tempFile.FullName, _rootDirPath + _relativePath, true, _logger);
                return(_info);
            }
            return(null);
        }