예제 #1
0
        /// <summary>
        /// Checks wheter
        /// </summary>
        /// <param name="file"></param>
        /// <param name="client"></param>
        /// <param name="properties"></param>
        /// <param name="indexManager"></param>
        private void CheckForFileUpdates(CancellationToken cancleToken, FileSyncElement file, ISyncClient client, IEnumerable <IRemoteProperty> properties, SyncIndexManager indexManager)
        {
            //Get Index and property instances
            SyncIndexElementDTO index    = GetIndexElement(indexManager, file);
            IRemoteProperty     property = GetProperty(properties, file);

            //Compare the change dates
            if (!index.LocalRevision.Equals(file.Revision) && index.RemoteRevision.Equals(property.RemoteRevision))
            {
                //File has been changed locally
                _logger.Debug("File " + file.RelativePath + " has been changed locally. Index rev: " + index.LocalRevision + " current file rev: " + file.Revision);
                Upload(cancleToken, file, client, indexManager);
            }
            else if (index.LocalRevision.Equals(file.Revision) && !index.RemoteRevision.Equals(property.RemoteRevision))
            {
                //File has been changed remotely
                _logger.Debug("File " + file.RelativePath + " has been changed remotely. Index remote rev: " + index.RemoteRevision + " current remote rev: " + property.RemoteRevision);
                PatchLocalFile(cancleToken, file, client, indexManager, properties);
            }
            else if (!index.LocalRevision.Equals(file.Revision) && !index.RemoteRevision.Equals(property.RemoteRevision))
            {
                //Conflict! Remote and server version has been changed!
                //Priorise server version, patch Local file
                _logger.Debug("File " + file.RelativePath + " has been changed remote and locally. Will fetch server version over local version");
                _logger.Debug("File " + file.RelativePath + " local index local rev: " + index.LocalRevision + " file local rev: " + file.Revision);
                _logger.Debug("File " + file.RelativePath + " remote index rev: " + index.RemoteRevision + " file remote rev: " + property.RemoteRevision);
                PatchLocalFile(cancleToken, file, client, indexManager, properties);
            }
        }
예제 #2
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);
     }
 }
예제 #3
0
        /// <summary>
        /// Patches the local file with the current File version provided by the ISyncClient
        /// </summary>
        /// <param name="file"></param>
        /// <param name="client"></param>
        /// <param name="indexManager"></param>
        private void PatchLocalFile(CancellationToken cancleToken, FileSyncElement file, ISyncClient client, SyncIndexManager indexManager,
                                    IEnumerable <IRemoteProperty> remoteProperties)
        {
            //File has been changed remotely
            FileInfo update = file.PatchLocalFile(cancleToken, client);

            if (update != null)
            {
                //Updte Index Manager
                indexManager.AddOrUpdate(CreateIndexElement(file, GetProperty(remoteProperties, file)));
            }
        }