/// <summary>
        /// Creates the local events and returns the creationEvents, the other Events are stored in the eventMap, handled objects are removed from storedObjects.
        /// </summary>
        /// <returns>
        /// The remote events.
        /// </returns>
        /// <param name='storedObjects'>
        /// Stored objects.
        /// </param>
        /// <param name='remoteTree'>
        /// Remote tree.
        /// </param>
        /// <param name='eventMap'>
        /// Event map.
        /// </param>
        public List <AbstractFolderEvent> CreateEvents(
            List <IMappedObject> storedObjects,
            IObjectTree <IFileableCmisObject> remoteTree,
            Dictionary <string, Tuple <AbstractFolderEvent, AbstractFolderEvent> > eventMap,
            ISet <IMappedObject> handledStoredObjects)
        {
            List <AbstractFolderEvent> createdEvents = new List <AbstractFolderEvent>();
            var storedParent = storedObjects.Find(o => o.RemoteObjectId == remoteTree.Item.Id);

            foreach (var child in remoteTree.Children)
            {
                var storedMappedChild = storedObjects.Find(o => o.RemoteObjectId == child.Item.Id);
                if (storedMappedChild != null)
                {
                    AbstractFolderEvent newEvent = this.CreateRemoteEventBasedOnStorage(child.Item, storedParent, storedMappedChild);
                    eventMap[child.Item.Id] = new Tuple <AbstractFolderEvent, AbstractFolderEvent>(null, newEvent);
                }
                else
                {
                    // Added
                    AbstractFolderEvent addEvent = FileOrFolderEventFactory.CreateEvent(child.Item, null, MetaDataChangeType.CREATED, src: this);
                    createdEvents.Add(addEvent);
                }

                createdEvents.AddRange(this.CreateEvents(storedObjects, child, eventMap, handledStoredObjects));
                if (storedMappedChild != null)
                {
                    handledStoredObjects.Add(storedMappedChild);
                }
            }

            return(createdEvents);
        }
        private AbstractFolderEvent CreateLocalEventBasedOnStorage(IFileSystemInfo fsObject, IMappedObject storedParent, IMappedObject storedMappedChild)
        {
            AbstractFolderEvent createdEvent = null;

            if (storedMappedChild.ParentId == storedParent.RemoteObjectId)
            {
                // Renamed, Updated or Equal
                #if __COCOA__
                if (fsObject.Name.Normalize(NormalizationForm.FormD) == storedMappedChild.Name.Normalize(NormalizationForm.FormD) && fsObject.LastWriteTimeUtc == storedMappedChild.LastLocalWriteTimeUtc)
                {
                #else
                if (fsObject.Name == storedMappedChild.Name && fsObject.LastWriteTimeUtc == storedMappedChild.LastLocalWriteTimeUtc)
                {
                #endif
                    // Equal
                    createdEvent = null;
                }
                else
                {
                    // Updated or Renamed
                    createdEvent = FileOrFolderEventFactory.CreateEvent(null, fsObject, localChange: MetaDataChangeType.CHANGED, src: this);
                }
            }
            else
            {
                // Moved
                IFileSystemInfo oldLocalPath = fsObject is IFileInfo ? (IFileSystemInfo)this.fsFactory.CreateFileInfo(this.storage.GetLocalPath(storedMappedChild)) : (IFileSystemInfo)this.fsFactory.CreateDirectoryInfo(this.storage.GetLocalPath(storedMappedChild));
                createdEvent = FileOrFolderEventFactory.CreateEvent(null, fsObject, localChange: MetaDataChangeType.MOVED, oldLocalObject: oldLocalPath, src: this);
            }

            return(createdEvent);
        }
        public void CreateFileAddedEvent()
        {
            var ev = FileOrFolderEventFactory.CreateEvent(Mock.Of <IDocument>(), null, MetaDataChangeType.CREATED);

            Assert.That(ev is FileEvent);
            Assert.That((ev as FileEvent).Remote, Is.EqualTo(MetaDataChangeType.CREATED));
        }
 private void AddDeletedObjectsToMergableEvents(
     List <IMappedObject> storedObjectList,
     Dictionary <string, Tuple <AbstractFolderEvent, AbstractFolderEvent> > eventMap,
     bool areLocalEvents)
 {
     foreach (var deleted in storedObjectList)
     {
         string          path     = this.storage.GetLocalPath(deleted);
         IFileSystemInfo info     = deleted.Type == MappedObjectType.File ? (IFileSystemInfo)this.fsFactory.CreateFileInfo(path) : (IFileSystemInfo)this.fsFactory.CreateDirectoryInfo(path);
         var             newEvent = FileOrFolderEventFactory.CreateEvent(
             null,
             info,
             areLocalEvents ? MetaDataChangeType.NONE : MetaDataChangeType.DELETED,
             areLocalEvents ? MetaDataChangeType.DELETED : MetaDataChangeType.NONE,
             areLocalEvents ? this.storage.GetRemotePath(deleted) : null,
             areLocalEvents ? null : info,
             src: this);
         if (!eventMap.ContainsKey(deleted.RemoteObjectId))
         {
             eventMap[deleted.RemoteObjectId] = new Tuple <AbstractFolderEvent, AbstractFolderEvent>(
                 areLocalEvents ? newEvent : null,
                 areLocalEvents ? null : newEvent);
         }
         else
         {
             eventMap[deleted.RemoteObjectId] = new Tuple <AbstractFolderEvent, AbstractFolderEvent>(
                 areLocalEvents ? newEvent : eventMap[deleted.RemoteObjectId].Item1,
                 areLocalEvents ? eventMap[deleted.RemoteObjectId].Item2 : newEvent);
         }
     }
 }
示例#5
0
 private void InformAboutRemoteObjectsDeleted(IEnumerable <IFileSystemInfo> objects)
 {
     foreach (var deleted in objects)
     {
         AbstractFolderEvent deletedEvent = FileOrFolderEventFactory.CreateEvent(null, deleted, MetaDataChangeType.DELETED, src: this);
         this.Queue.AddEvent(deletedEvent);
     }
 }
        private void MergeAndSendEvents(Dictionary <string, Tuple <AbstractFolderEvent, AbstractFolderEvent> > eventMap)
        {
            foreach (var entry in eventMap)
            {
                if (entry.Value == null)
                {
                    continue;
                }
                else if (entry.Value.Item1 == null && entry.Value.Item2 == null)
                {
                    continue;
                }
                else if (entry.Value.Item1 == null)
                {
                    if (entry.Value.Item2.Remote != MetaDataChangeType.NONE)
                    {
                        this.queue.AddEvent(entry.Value.Item2);
                    }
                }
                else if (entry.Value.Item2 == null)
                {
                    if (entry.Value.Item1.Local != MetaDataChangeType.NONE)
                    {
                        this.queue.AddEvent(entry.Value.Item1);
                    }
                }
                else
                {
                    var localEvent  = entry.Value.Item1;
                    var remoteEvent = entry.Value.Item2;

                    var newEvent = FileOrFolderEventFactory.CreateEvent(
                        remoteEvent is FileEvent ? (IFileableCmisObject)(remoteEvent as FileEvent).RemoteFile : (IFileableCmisObject)(remoteEvent as FolderEvent).RemoteFolder,
                        localEvent is FileEvent ? (IFileSystemInfo)(localEvent as FileEvent).LocalFile : (IFileSystemInfo)(localEvent as FolderEvent).LocalFolder,
                        remoteEvent.Remote,
                        localEvent.Local,
                        remoteEvent.Remote == MetaDataChangeType.MOVED ? (remoteEvent is FileMovedEvent ? (remoteEvent as FileMovedEvent).OldRemoteFilePath : (remoteEvent as FolderMovedEvent).OldRemoteFolderPath) : null,
                        localEvent.Local == MetaDataChangeType.MOVED ? (localEvent is FileMovedEvent ? (IFileSystemInfo)(localEvent as FileMovedEvent).OldLocalFile : (IFileSystemInfo)(localEvent as FolderMovedEvent).OldLocalFolder) : null,
                        this);
                    if (newEvent is FileEvent)
                    {
                        (newEvent as FileEvent).LocalContent  = (localEvent as FileEvent).LocalContent;
                        (newEvent as FileEvent).RemoteContent = (remoteEvent as FileEvent).RemoteContent;
                    }

                    this.queue.AddEvent(newEvent);
                }
            }
        }
示例#7
0
        private void FindReportAndRemoveMutualDeletedObjects(IDictionary <string, IFileSystemInfo> removedRemoteObjects, IDictionary <string, IFileSystemInfo> removedLocalObjects)
        {
            IEnumerable <string> intersect = removedRemoteObjects.Keys.Intersect(removedLocalObjects.Keys);
            IList <string>       mutualIds = new List <string>();

            foreach (var id in intersect)
            {
                AbstractFolderEvent deletedEvent = FileOrFolderEventFactory.CreateEvent(null, removedLocalObjects[id], MetaDataChangeType.DELETED, MetaDataChangeType.DELETED, src: this);
                mutualIds.Add(id);
                this.Queue.AddEvent(deletedEvent);
            }

            foreach (var id in mutualIds)
            {
                removedLocalObjects.Remove(id);
                removedRemoteObjects.Remove(id);
            }
        }
        private AbstractFolderEvent CreateLocalEventBasedOnStorage(IFileSystemInfo fsObject, IMappedObject storedParent, IMappedObject storedMappedChild)
        {
            AbstractFolderEvent createdEvent = null;

            if (storedParent == null)
            {
                throw new ArgumentNullException("storedParent", "stored parent is null. Stored child: " + storedMappedChild.ToString() + Environment.NewLine + "local object is: " + fsObject.FullName);
            }

            if (storedMappedChild.ParentId == storedParent.RemoteObjectId)
            {
                // Renamed, Updated or Equal
                #if __COCOA__
                if (fsObject.Name.Normalize(NormalizationForm.FormD) == storedMappedChild.Name.Normalize(NormalizationForm.FormD) && fsObject.LastWriteTimeUtc == storedMappedChild.LastLocalWriteTimeUtc)
                {
                #else
                if (fsObject.Name == storedMappedChild.Name &&
                    fsObject.LastWriteTimeUtc == storedMappedChild.LastLocalWriteTimeUtc &&
                    fsObject.ReadOnly == storedMappedChild.IsReadOnly)
                {
                #endif
                    // Equal
                    createdEvent = null;
                }
                else
                {
                    // Updated or Renamed
                    createdEvent = FileOrFolderEventFactory.CreateEvent(null, fsObject, localChange: MetaDataChangeType.CHANGED, src: this);
                }
            }
            else
            {
                // Moved
                IFileSystemInfo oldLocalPath = fsObject is IFileInfo ? (IFileSystemInfo)this.fsFactory.CreateFileInfo(this.storage.GetLocalPath(storedMappedChild)) : (IFileSystemInfo)this.fsFactory.CreateDirectoryInfo(this.storage.GetLocalPath(storedMappedChild));
                createdEvent = FileOrFolderEventFactory.CreateEvent(null, fsObject, localChange: MetaDataChangeType.MOVED, oldLocalObject: oldLocalPath, src: this);
            }

            return(createdEvent);
        }
        private AbstractFolderEvent CreateRemoteEventBasedOnStorage(IFileableCmisObject cmisObject, IMappedObject storedParent, IMappedObject storedMappedChild)
        {
            AbstractFolderEvent newEvent = null;

            if (storedParent != null && storedMappedChild.ParentId == storedParent.RemoteObjectId)
            {
                // Renamed or Equal
                if (storedMappedChild.Name == cmisObject.Name)
                {
                    // Equal or property update
                    if (storedMappedChild.LastChangeToken != cmisObject.ChangeToken)
                    {
                        // Update
                        newEvent = FileOrFolderEventFactory.CreateEvent(cmisObject, null, MetaDataChangeType.CHANGED, src: this);
                        AddRemoteContentChangeTypeToFileEvent(newEvent as FileEvent, storedMappedChild, cmisObject as IDocument);
                    }
                    else
                    {
                        // Equal
                        newEvent = null;
                    }
                }
                else
                {
                    // Renamed
                    newEvent = FileOrFolderEventFactory.CreateEvent(cmisObject, null, MetaDataChangeType.CHANGED, src: this);
                    AddRemoteContentChangeTypeToFileEvent(newEvent as FileEvent, storedMappedChild, cmisObject as IDocument);
                }
            }
            else
            {
                // Moved
                newEvent = FileOrFolderEventFactory.CreateEvent(cmisObject, null, MetaDataChangeType.MOVED, oldRemotePath: this.storage.GetRemotePath(storedMappedChild), src: this);
                AddRemoteContentChangeTypeToFileEvent(newEvent as FileEvent, storedMappedChild, cmisObject as IDocument);
            }

            return(newEvent);
        }
 private AbstractFolderEvent GenerateCreatedEvent(IFileSystemInfo fsInfo)
 {
     return(FileOrFolderEventFactory.CreateEvent(null, fsInfo, localChange: MetaDataChangeType.CREATED, src: this));
 }
        public void CreateFolderMovedEvent()
        {
            var ev = FileOrFolderEventFactory.CreateEvent(Mock.Of <IFolder>(), null, MetaDataChangeType.MOVED, oldRemotePath: "oldPath");

            Assert.That(ev is FolderMovedEvent);
        }
        public void CreateFileEvent()
        {
            var ev = FileOrFolderEventFactory.CreateEvent(null, Mock.Of <IFileInfo>());

            Assert.That(ev is FileEvent);
        }