Ejemplo n.º 1
0
 public void LogElementCompleted(ISyncElement element)
 {
     NewLogEntry(
         new string[]
     {
         GetTimeStamp() + "Elemento completato: " + element.Name
     });
 }
Ejemplo n.º 2
0
 public void LogElementStarting(ISyncElement element)
 {
     NewLogEntry(
         new string[]
     {
         GetTimeStamp() + "Avvio elemento: " + element.Name
     });
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks wheter the resource exists in the index and RemoteProperties
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private (bool existInIndex, bool existsRemote) CheckForElementExistance(ISyncElement element, IEnumerable <IRemoteProperty> remoteProperties,
                                                                                SyncIndexManager manager)
        {
            bool exstIndex  = GetIndexElement(manager, element) != null;
            bool exstRemote = GetProperty(remoteProperties, element) != null;

            return(exstIndex, exstRemote);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a SyncIndex Element fromt the given local and remote Elements
 /// </summary>
 /// <param name="localElement"></param>
 /// <param name="remoteElement"></param>
 /// <returns></returns>
 private SyncIndexElementDTO CreateIndexElement(ISyncElement localElement, IRemoteProperty remoteElement)
 {
     return(new SyncIndexElementDTO()
     {
         ReleativeFilePath = localElement.RelativePath,
         RemoteRevision = remoteElement == null ? "" : remoteElement.RemoteRevision,
         LocalRevision = localElement.Revision,
         ElementType = localElement.Type
     });
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Uploads the given ISync Element using the ISyncClient
        /// If success the Element will be added or an existing element will be updated with
        /// the new values
        /// </summary>
        /// <param name="element"></param>
        /// <param name="client"></param>
        /// <param name="indexManager"></param>
        private void Upload(CancellationToken cancleToken, ISyncElement element, ISyncClient client, SyncIndexManager indexManager)
        {
            IRemoteProperty uploaded = element.Upload(cancleToken, client);

            if (uploaded != null)
            {
                //Upload was successfull, add as tracked element to index
                indexManager.AddOrUpdate(CreateIndexElement(element, uploaded));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the IndexElement matching the given ISyncElement
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        private SyncIndexElementDTO GetIndexElement(SyncIndexManager manager, ISyncElement element)
        {
            IEnumerable <SyncIndexElementDTO> elements = manager.GetOrCreateIndexFile();

            if (elements != null)
            {
                return(elements.Where(x => x.ElementType == element.Type &&
                                      x.ReleativeFilePath == element.RelativePath
                                      ).FirstOrDefault());
            }
            return(null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Handles the synchronisation of the given ISyncElement
        /// </summary>
        /// <param name="element"></param>
        /// <param name="client"></param>
        /// <param name="properties"></param>
        /// <param name="indexManager"></param>
        private void HandleISyncElement(CancellationToken cancleToken, ISyncElement element, ISyncClient client, IEnumerable <IRemoteProperty> properties,
                                        SyncIndexManager indexManager, ILogger logger, Configuration config)
        {
            if (cancleToken.IsCancellationRequested)
            {
                return;
            }
            //The general rules defining when to synchronize what are the same
            //for all ISyncClients and they follow the following design:
            //
            //1. Iterate all local folder and their files, check for updates on server:
            //  Both:
            //      1. when it does not exist in index and server -> upload
            //      2. when it exists only in index -> delete (has been deleted remotely)
            //      3. when exists on server but not index -> update index
            //  Files:
            //      1. When is exists in server and index -> check for updates
            //2. Add all files that are not in index to local copy
            //3. Remove all files that exist in index and server but not local from server -> deleted local

            (bool existInIndex, bool existsRemote)existance = CheckForElementExistance(element, properties, indexManager);

            if (!existance.existInIndex && !existance.existsRemote)
            {
                //Not in index and not in remote -> upload
                logger.Debug(element.Type + " " + element.RelativePath + " does not exist in local Index and remote, " +
                             "File will be added to both");
                Upload(cancleToken, element, client, indexManager);
                //Set the Method to ignore Updates -> Just handle children in case of Directory
                //Because directly checking for updates may cause exceptions because the server is
                //slow and does not return the correct properties on request yet
                HandleISyncElementChildrenOrUpdates(cancleToken, element, client, properties, indexManager, logger, config, true);
            }
            else if (existance.existInIndex && !existance.existsRemote)
            {
                //In index but not remote -> delete (has been deleted remotely)
                logger.Debug(element.Type + " " + element.RelativePath + " exists in index but has been removed remote. Deleting " + element.Type);
                DeleteLocalElement(element, indexManager);
            }
            else if (!existance.existInIndex && existance.existsRemote)
            {
                //Remote but not in index -> Add to index
                logger.Debug(element.Type + " " + element.RelativePath + " was missing in the index -> will be added.");
                //As it cannot be said if there was changes remote, no remote revision is added
                indexManager.AddOrUpdate(CreateIndexElement(element, null));
                HandleISyncElementChildrenOrUpdates(cancleToken, element, client, properties, indexManager, logger, config, false);
            }
            else if (existance.existInIndex && existance.existsRemote)
            {
                HandleISyncElementChildrenOrUpdates(cancleToken, element, client, properties, indexManager, logger, config, false);
            }
        }
Ejemplo n.º 8
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);
         }
     }
 }
Ejemplo n.º 9
0
 public SyncElementViewModel(ISyncElement syncElement)
 {
     SyncElement = syncElement;
 }
Ejemplo n.º 10
0
 public virtual void SetParent(ISyncElement syncElement)
 {
     ParentElement = syncElement;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Returns the Remote Property that matching the given ISyncElement
 /// </summary>
 /// <param name="remoteProperties"></param>
 /// <param name="element"></param>
 /// <returns>Matching remote property or null if not found</returns>
 private IRemoteProperty GetProperty(IEnumerable <IRemoteProperty> remoteProperties, ISyncElement element)
 {
     //Remote properties seem to have a slash more at the beginning
     return(remoteProperties.Where(x => x.DecodedRelativeRemotePath.PathsEqual(element.RelativePath) &&
                                   x.ElementType == element.Type).FirstOrDefault());
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Checks for the given elements children or remote updates, has the option to only check the children and ignore updates in case
 /// Can be usefull to give the server enough time to index new files
 /// </summary>
 /// <param name="cancleToken"></param>
 /// <param name="element"></param>
 /// <param name="client"></param>
 /// <param name="properties"></param>
 /// <param name="indexManager"></param>
 /// <param name="logger"></param>
 /// <param name="config"></param>
 /// <param name="ignoreUpdates"></param>
 private void HandleISyncElementChildrenOrUpdates(CancellationToken cancleToken, ISyncElement element, ISyncClient client,
                                                  IEnumerable <IRemoteProperty> properties, SyncIndexManager indexManager, ILogger logger,
                                                  Configuration config, bool ignoreUpdates)
 {
     //File: check for updates
     //Directoy: process with going one hierarchy deeper
     if (element.Type.Equals(SyncElementType.File))
     {
         if (!ignoreUpdates)
         {
             CheckForFileUpdates(cancleToken, (FileSyncElement)element, client, properties, indexManager);
         }
     }
     else if (element.Type.Equals(SyncElementType.Directory))
     {
         GetDataAndHandleSync(cancleToken, element.AbsolutePath, client, logger, config, indexManager);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Ejemplo n.º 13
0
 public SubJob(ISyncElement targetElement)
 {
     Status        = JobStatus.OnQueue;
     TargetElement = targetElement;
     Dependencies  = new List <ISubJob>();
 }