Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Deletes the given ISyncElement and removes it from index if successfull
 /// </summary>
 /// <param name="element"></param>
 /// <param name="indexManager"></param>
 private void DeleteLocalElement(ISyncElement element, SyncIndexManager indexManager)
 {
     if (element.Delete())
     {
         SyncIndexElementDTO dto = GetIndexElement(indexManager, element);
         if (element.Type == SyncElementType.Directory)
         {
             //If a Directory was removed, remove all sub Element that
             //have been contained in that directory
             indexManager.RemoveAll(x => x.ReleativeFilePath.Length >= dto.ReleativeFilePath.Length &&
                                    x.ReleativeFilePath.Substring(0, dto.ReleativeFilePath.Length) == dto.ReleativeFilePath);
         }
         else
         {
             indexManager.Remove(dto);
         }
     }
 }