Exemple #1
0
        /// <summary>
        /// Updates the last write time in UTC via UpdateProperties
        /// </summary>
        /// <returns>The result of UpdateProperties.</returns>
        /// <param name="obj">Fileable cmis object.</param>
        /// <param name="modificationDate">Modification date.</param>
        public static IObjectId UpdateLastWriteTimeUtc(this IFileableCmisObject obj, DateTime modificationDate)
        {
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.LastModificationDate, modificationDate);
            return(obj.UpdateProperties(properties, true));
        }
Exemple #2
0
        /// <summary>
        /// Should the local file/folder be made read-only?
        /// Check the permissions of the current user to the remote file/folder.
        /// </summary>
        public static void MakeReadOnlyIfCannotModifyRemote(IFileableCmisObject remoteObject, string localPath)
        {
            bool readOnly = !remoteObject.AllowableActions.Actions.Contains(PermissionMappingKeys.CanAddToFolderObject);

            if (readOnly)
            {
                new DirectoryInfo(localPath).Attributes = FileAttributes.ReadOnly;
            }
        }
Exemple #3
0
        private bool ComparisonByIdIfPossible(IFileableCmisObject folder, string name)
        {
            if (name.Contains("-"))
            {
                var id = name.Substring(0, name.IndexOf("-", StringComparison.Ordinal));
                return(folder.Name.Substring(0, folder.Name.IndexOf("-", StringComparison.Ordinal)) == id);
            }

            return(folder.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
        }
Exemple #4
0
        /// <summary>
        /// Updates the last write time in UTC via UpdateProperties
        /// </summary>
        /// <returns>The result of UpdateProperties.</returns>
        /// <param name="obj">Fileable cmis object.</param>
        /// <param name="modificationDate">Modification date.</param>
        public static IObjectId UpdateLastWriteTimeUtc(this IFileableCmisObject obj, DateTime modificationDate)
        {
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.LastModificationDate, modificationDate);
            try {
                return(obj.UpdateProperties(properties, true));
            } catch (CmisConstraintException e) {
                var oldObject = obj.ToLogString();
                obj.Refresh();
                throw new CmisConstraintException(string.Format("Old object: {0}{1}New object: {2}", oldObject, Environment.NewLine, obj.ToLogString()), e);
            }
        }
 /// <summary>
 /// Creates the event.
 /// </summary>
 /// <returns>The event.</returns>
 /// <param name="isFile">If set to <c>true</c> is file.</param>
 /// <param name="remoteObject">Remote object.</param>
 /// <param name="localObject">Local object.</param>
 /// <param name="remoteChange">Remote change.</param>
 /// <param name="localChange">Local change.</param>
 /// <param name="oldRemotePath">Old remote path.</param>
 /// <param name="oldLocalObject">Old local object.</param>
 /// <param name="src">Source of the creation.</param>
 public static AbstractFolderEvent CreateEvent(
     bool isFile,
     IFileableCmisObject remoteObject = null,
     IFileSystemInfo localObject = null,
     MetaDataChangeType remoteChange = MetaDataChangeType.NONE,
     MetaDataChangeType localChange = MetaDataChangeType.NONE,
     string oldRemotePath = null,
     IFileSystemInfo oldLocalObject = null,
     object src = null) {
     if (localChange != MetaDataChangeType.MOVED &&
         remoteChange != MetaDataChangeType.MOVED) {
         if (isFile) {
             return new FileEvent(
                 localObject as IFileInfo,
                 remoteObject as IDocument) {
                 Local = localChange,
                 Remote = remoteChange
             };
         } else {
             return new FolderEvent(
                 localObject as IDirectoryInfo,
                 remoteObject as IFolder,
                 src) {
                 Local = localChange,
                 Remote = remoteChange
             };
         }
     } else {
         if (isFile) {
             return new FileMovedEvent(
                 oldLocalObject as IFileInfo,
                 localObject as IFileInfo,
                 oldRemotePath,
                 remoteObject as IDocument) {
                 Local = localChange,
                 Remote = remoteChange
             };
         } else {
             return new FolderMovedEvent(
                 oldLocalObject as IDirectoryInfo,
                 localObject as IDirectoryInfo,
                 oldRemotePath,
                 remoteObject as IFolder,
                 src) {
                 Local = localChange,
                 Remote = remoteChange
             };
         }
     }
 }
 /// <summary>
 /// Creates the event.
 /// </summary>
 /// <returns>The event.</returns>
 /// <param name="remoteObject">Remote object.</param>
 /// <param name="localObject">Local object.</param>
 /// <param name="remoteChange">Remote change.</param>
 /// <param name="localChange">Local change.</param>
 /// <param name="oldRemotePath">Old remote path.</param>
 /// <param name="oldLocalObject">Old local object.</param>
 /// <param name="src">Source of the creation.</param>
 public static AbstractFolderEvent CreateEvent(
     IFileableCmisObject remoteObject = null,
     IFileSystemInfo localObject = null,
     MetaDataChangeType remoteChange = MetaDataChangeType.NONE,
     MetaDataChangeType localChange = MetaDataChangeType.NONE,
     string oldRemotePath = null,
     IFileSystemInfo oldLocalObject = null,
     object src = null) {
     return CreateEvent(
         remoteObject is IDocument || localObject is IFileInfo,
         remoteObject,
         localObject,
         remoteChange,
         localChange,
         oldRemotePath,
         oldLocalObject,
         src);
 }
Exemple #7
0
        public static string ToLogString(this IFileableCmisObject obj)
        {
            if (obj == null)
            {
                return("null");
            }

            var sb = new StringBuilder(obj.ToString());

            sb.AppendLine(string.Format("ID:           {0}", obj.Id));
            sb.AppendLine(string.Format("Name:         {0}", obj.Name));
            sb.AppendLine(string.Format("ChangeToken:  {0}", obj.ChangeToken));
            if (obj.LastModificationDate != null)
            {
                DateTime date = obj.LastModificationDate.Value;
                sb.AppendLine(string.Format("LastModified: {0} Ticks", date.Ticks));
            }
            else
            {
                sb.AppendLine(string.Format("LastModified: {0}", obj.LastModificationDate));
            }
            sb.AppendLine(string.Format("ObjectType:   {0}", obj.ObjectType));
            sb.AppendLine(string.Format("BaseType:     {0}", obj.BaseType.DisplayName));
            if (obj is IFolder)
            {
                var folder = obj as IFolder;
                sb.AppendLine(string.Format("Path:         {0}", folder.Path));
                sb.AppendLine(string.Format("ParentId:     {0}", folder.ParentId));
            }
            else if (obj is IDocument)
            {
                var doc = obj as IDocument;
                sb.AppendLine(string.Format("StreamLength: {0}", doc.ContentStreamLength));
                sb.AppendLine(string.Format("MimeType:     {0}", doc.ContentStreamMimeType));
                sb.AppendLine(string.Format("StreamName:   {0}", doc.ContentStreamFileName));
            }

            foreach (var prop in obj.Properties)
            {
                sb.AppendLine(string.Format("Property {0}: {1}", prop.DisplayName, prop.ValuesAsString));
            }

            return(sb.ToString());
        }
Exemple #8
0
 /// <summary>
 /// Creates the event.
 /// </summary>
 /// <returns>The event.</returns>
 /// <param name="remoteObject">Remote object.</param>
 /// <param name="localObject">Local object.</param>
 /// <param name="remoteChange">Remote change.</param>
 /// <param name="localChange">Local change.</param>
 /// <param name="oldRemotePath">Old remote path.</param>
 /// <param name="oldLocalObject">Old local object.</param>
 /// <param name="src">Source of the creation.</param>
 public static AbstractFolderEvent CreateEvent(
     IFileableCmisObject remoteObject = null,
     IFileSystemInfo localObject      = null,
     MetaDataChangeType remoteChange  = MetaDataChangeType.NONE,
     MetaDataChangeType localChange   = MetaDataChangeType.NONE,
     string oldRemotePath             = null,
     IFileSystemInfo oldLocalObject   = null,
     object src = null)
 {
     return(CreateEvent(
                remoteObject is IDocument || localObject is IFileInfo,
                remoteObject,
                localObject,
                remoteChange,
                localChange,
                oldRemotePath,
                oldLocalObject,
                src));
 }
        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);
        }
Exemple #10
0
 /// <summary>
 /// Should the local file/folder be made read-only?
 /// Check the permissions of the current user to the remote file/folder.
 /// </summary>
 public static void MakeReadOnlyIfCannotModifyRemote(IFileableCmisObject remoteObject, string localPath)
 {
     bool readOnly = !remoteObject.AllowableActions.Actions.Contains(PermissionMappingKeys.CanAddToFolderObject);
     if (readOnly)
     {
         new DirectoryInfo(localPath).Attributes = FileAttributes.ReadOnly;
     }
 }
        private void SyncNamesAndDates(IFileSystemInfo local, IFileableCmisObject remote, IMappedObject mappedObject)
        {
            DateTime?oldRemoteModificationDate = remote.LastModificationDate;
            DateTime oldLocalModificationDate  = local.LastWriteTimeUtc;

            // Sync Names
            if (mappedObject.Name != local.Name && mappedObject.Name == remote.Name)
            {
                // local has been renamed => rename remote
                remote.Rename(local.Name, true);
                mappedObject.Name = local.Name;
            }
            else if (mappedObject.Name == local.Name && mappedObject.Name != remote.Name)
            {
                // remote has been renamed => rename local
                if (local is IFileInfo)
                {
                    IFileInfo localFile = local as IFileInfo;
                    localFile.MoveTo(Path.Combine(localFile.Directory.FullName, remote.Name));
                }
                else if (local is IDirectoryInfo)
                {
                    IDirectoryInfo localFolder = local as IDirectoryInfo;
                    localFolder.MoveTo(Path.Combine(localFolder.Parent.FullName, remote.Name));
                }
                else
                {
                    throw new ArgumentException("Solved move conflict => invoke crawl sync to detect other changes");
                }

                mappedObject.Name = remote.Name;
            }
            else if (mappedObject.Name != local.Name && mappedObject.Name != remote.Name)
            {
                // both are renamed => rename to the latest change
                DateTime localModification  = local.LastWriteTimeUtc;
                DateTime remoteModification = (DateTime)remote.LastModificationDate;
                if (localModification > remoteModification)
                {
                    // local modification is newer
                    remote.Rename(local.Name, true);
                    mappedObject.Name = local.Name;
                }
                else
                {
                    // remote modification is newer
                    if (local is IFileInfo)
                    {
                        IFileInfo localFile = local as IFileInfo;
                        localFile.MoveTo(Path.Combine(localFile.Directory.FullName, remote.Name));
                    }
                    else if (local is IDirectoryInfo)
                    {
                        IDirectoryInfo localFolder = local as IDirectoryInfo;
                        localFolder.MoveTo(Path.Combine(localFolder.Parent.FullName, remote.Name));
                    }
                    else
                    {
                        throw new ArgumentException("Solved move conflict => invoke crawl sync to detect other changes");
                    }

                    local.LastWriteTimeUtc = (DateTime)remote.LastModificationDate;
                    mappedObject.Name      = remote.Name;
                }
            }

            // Sync modification dates
            if (oldRemoteModificationDate != null)
            {
                if (oldLocalModificationDate > oldRemoteModificationDate && this.ServerCanModifyDateTimes)
                {
                    remote.UpdateLastWriteTimeUtc(oldLocalModificationDate);
                    local.LastWriteTimeUtc = oldLocalModificationDate;
                }
                else if (oldLocalModificationDate < (DateTime)oldRemoteModificationDate)
                {
                    local.LastWriteTimeUtc = (DateTime)oldRemoteModificationDate;
                }
            }

            mappedObject.LastLocalWriteTimeUtc  = local.LastWriteTimeUtc;
            mappedObject.LastRemoteWriteTimeUtc = (DateTime)remote.LastModificationDate;
            mappedObject.ParentId        = remote.Parents[0].Id;
            mappedObject.LastChangeToken = remote.ChangeToken;
            mappedObject.Ignored         = remote.AreAllChildrenIgnored();
            this.Storage.SaveMappedObject(mappedObject);
        }
        private void SyncNamesAndDates(IFileSystemInfo local, IFileableCmisObject remote, IMappedObject mappedObject)
        {
            DateTime? oldRemoteModificationDate = remote.LastModificationDate;
            DateTime oldLocalModificationDate = local.LastWriteTimeUtc;

            // Sync Names
            if (mappedObject.Name != local.Name && mappedObject.Name == remote.Name) {
                // local has been renamed => rename remote
                remote.Rename(local.Name, true);
                mappedObject.Name = local.Name;
            } else if (mappedObject.Name == local.Name && mappedObject.Name != remote.Name) {
                // remote has been renamed => rename local
                if (local is IFileInfo) {
                    IFileInfo localFile = local as IFileInfo;
                    localFile.MoveTo(Path.Combine(localFile.Directory.FullName, remote.Name));
                } else if (local is IDirectoryInfo) {
                    IDirectoryInfo localFolder = local as IDirectoryInfo;
                    localFolder.MoveTo(Path.Combine(localFolder.Parent.FullName, remote.Name));
                } else {
                    throw new ArgumentException("Solved move conflict => invoke crawl sync to detect other changes");
                }

                mappedObject.Name = remote.Name;
            } else if (mappedObject.Name != local.Name && mappedObject.Name != remote.Name) {
                // both are renamed => rename to the latest change
                DateTime localModification = local.LastWriteTimeUtc;
                DateTime remoteModification = (DateTime)remote.LastModificationDate;
                if (localModification > remoteModification) {
                    // local modification is newer
                    remote.Rename(local.Name, true);
                    mappedObject.Name = local.Name;
                } else {
                    // remote modification is newer
                    if (local is IFileInfo) {
                        IFileInfo localFile = local as IFileInfo;
                        localFile.MoveTo(Path.Combine(localFile.Directory.FullName, remote.Name));
                    } else if (local is IDirectoryInfo) {
                        IDirectoryInfo localFolder = local as IDirectoryInfo;
                        localFolder.MoveTo(Path.Combine(localFolder.Parent.FullName, remote.Name));
                    } else {
                        throw new ArgumentException("Solved move conflict => invoke crawl sync to detect other changes");
                    }

                    local.LastWriteTimeUtc = (DateTime)remote.LastModificationDate;
                    mappedObject.Name = remote.Name;
                }
            }

            // Sync modification dates
            if (oldRemoteModificationDate != null) {
                if (oldLocalModificationDate > oldRemoteModificationDate && this.ServerCanModifyDateTimes) {
                    remote.UpdateLastWriteTimeUtc(oldLocalModificationDate);
                    local.LastWriteTimeUtc = oldLocalModificationDate;
                } else if (oldLocalModificationDate < (DateTime)oldRemoteModificationDate) {
                    local.LastWriteTimeUtc = (DateTime)oldRemoteModificationDate;
                }
            }

            mappedObject.LastLocalWriteTimeUtc = local.LastWriteTimeUtc;
            mappedObject.LastRemoteWriteTimeUtc = (DateTime)remote.LastModificationDate;
            mappedObject.ParentId = remote.Parents[0].Id;
            mappedObject.LastChangeToken = remote.ChangeToken;
            mappedObject.Ignored = remote.AreAllChildrenIgnored();
            this.Storage.SaveMappedObject(mappedObject);
        }
Exemple #13
0
 /// <summary>
 /// Creates the event.
 /// </summary>
 /// <returns>The event.</returns>
 /// <param name="isFile">If set to <c>true</c> is file.</param>
 /// <param name="remoteObject">Remote object.</param>
 /// <param name="localObject">Local object.</param>
 /// <param name="remoteChange">Remote change.</param>
 /// <param name="localChange">Local change.</param>
 /// <param name="oldRemotePath">Old remote path.</param>
 /// <param name="oldLocalObject">Old local object.</param>
 /// <param name="src">Source of the creation.</param>
 public static AbstractFolderEvent CreateEvent(
     bool isFile,
     IFileableCmisObject remoteObject = null,
     IFileSystemInfo localObject      = null,
     MetaDataChangeType remoteChange  = MetaDataChangeType.NONE,
     MetaDataChangeType localChange   = MetaDataChangeType.NONE,
     string oldRemotePath             = null,
     IFileSystemInfo oldLocalObject   = null,
     object src = null)
 {
     if (localChange != MetaDataChangeType.MOVED &&
         remoteChange != MetaDataChangeType.MOVED)
     {
         if (isFile)
         {
             return(new FileEvent(
                        localObject as IFileInfo,
                        remoteObject as IDocument)
             {
                 Local = localChange,
                 Remote = remoteChange
             });
         }
         else
         {
             return(new FolderEvent(
                        localObject as IDirectoryInfo,
                        remoteObject as IFolder,
                        src)
             {
                 Local = localChange,
                 Remote = remoteChange
             });
         }
     }
     else
     {
         if (isFile)
         {
             return(new FileMovedEvent(
                        oldLocalObject as IFileInfo,
                        localObject as IFileInfo,
                        oldRemotePath,
                        remoteObject as IDocument)
             {
                 Local = localChange,
                 Remote = remoteChange
             });
         }
         else
         {
             return(new FolderMovedEvent(
                        oldLocalObject as IDirectoryInfo,
                        localObject as IDirectoryInfo,
                        oldRemotePath,
                        remoteObject as IFolder)
             {
                 Local = localChange,
                 Remote = remoteChange
             });
         }
     }
 }
        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;
        }