Exemplo n.º 1
0
        /// <summary>
        /// Gets the attachment metadata.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public virtual string GetAttachmentMetadata(string containerTitle, Guid entityId, string fileName, string key)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            SPFile attachment;

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, entityId, fileName, out attachment) == false)
            {
                return(null);
            }

            if (attachment.Properties.ContainsKey(Constants.MetadataPrefix + key))
            {
                return(attachment.Properties[Constants.MetadataPrefix + key] as string);
            }
            return(null);
        }
        /// <summary>
        /// Lists the entity versions.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <returns></returns>
        public IList <EntityVersion> ListEntityVersions(string containerTitle, Guid entityId)
        {
            var result = new List <EntityVersion>();

            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            SPFile defaultEntityPart;

            if (SPDocumentStoreHelper.TryGetDocumentStoreDefaultEntityPart(list, folder, entityId, out defaultEntityPart) == false)
            {
                return(null);
            }

            result.AddRange(defaultEntityPart.Item.Versions.OfType <SPListItemVersion>().Select(ver => new EntityVersion
            {
                Comment            = ver.ListItem.File.CheckInComment,
                Created            = ver.Created.ToLocalTime(),
                CreatedByLoginName = ver.CreatedBy.User.LoginName,
                Entity             = SPDocumentStoreHelper.MapEntityFromSPListItemVersion(ver),
                IsCurrentVersion   = ver.IsCurrentVersion,
                VersionId          = ver.VersionId,
                VersionLabel       = ver.VersionLabel,
            }));

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the container in the document store with new values.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <returns></returns>
        public virtual bool UpdateContainer(Container container)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, container.Title, out list, out folder, String.Empty) == false)
            {
                return(false);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                list.Title       = container.Title;
                list.Description = container.Description;
                list.Update();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the attachment metadata.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public virtual bool SetAttachmentMetadata(string containerTitle, Guid entityId, string fileName, string key, string value)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(false);
            }

            SPFile attachment;

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, entityId, fileName, out attachment) == false)
            {
                return(false);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                attachment.Properties[Constants.MetadataPrefix + key] = value;
                attachment.Update();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(true);
        }
Exemplo n.º 5
0
        private static EntityContents GetEntityContents(SPWeb web, string containerTitle, Guid entityId)
        {
            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            SPFile defaultEntityPart;

            if (SPDocumentStoreHelper.TryGetDocumentStoreDefaultEntityPart(list, folder, entityId, out defaultEntityPart) == false)
            {
                return(null);
            }

            EntityContents entityContents = SPDocumentStoreHelper.GetEntityContentsEntityPart(web, list, defaultEntityPart.ParentFolder);

            if (entityContents == null)
            {
                throw new NotImplementedException(); // TODO: Build it, update the hash yada yada.
            }
            return(entityContents);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the specified untyped entity in the specified path without its data property populated.
        /// </summary>
        /// <param name="containerTitle"></param>
        /// <param name="entityId"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public virtual Entity GetEntityLight(string containerTitle, Guid entityId, string path)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            DocumentSet entityDocumentSet;

            if (!SPDocumentStoreHelper.TryGetDocumentStoreEntityDocumentSetDirect(web, containerTitle, path, entityId,
                                                                                  out entityDocumentSet))
            {
                SPList   list;
                SPFolder folder;
                if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) == false)
                {
                    return(null);
                }

                if (
                    SPDocumentStoreHelper.TryGetDocumentStoreEntityDocumentSet(list, folder, entityId,
                                                                               out entityDocumentSet) == false)
                {
                    return(null);
                }
            }

            var entity = SPDocumentStoreHelper.MapEntityFromDocumentSet(entityDocumentSet, null, null);

            return(entity);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Deletes the specified entity from the specified container.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <returns></returns>
        public virtual bool DeleteEntity(string containerTitle, Guid entityId)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(false);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                var documentSet = SPDocumentStoreHelper.GetDocumentStoreEntityDocumentSet(list, list.RootFolder, entityId);
                if (documentSet == null)
                {
                    return(false);
                }

                documentSet.Folder.Recycle();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(true);
        }
        /// <summary>
        /// Lists the attachments associated with the specified entity.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <returns></returns>
        public virtual IList <Attachment> ListAttachments(string containerTitle, Guid entityId)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            DocumentSet documentSet;

            if (SPDocumentStoreHelper.TryGetDocumentStoreEntityDocumentSet(list, folder, entityId, out documentSet) == false)
            {
                return(null);
            }

            var attachmentContentTypeId     = new SPContentTypeId(Constants.DocumentStoreEntityAttachmentContentTypeId);
            var listAttachmentContentTypeId = list.ContentTypes.BestMatch(attachmentContentTypeId);
            var attachmentContentType       = list.ContentTypes[listAttachmentContentTypeId];

            return(documentSet.Folder.Files.OfType <SPFile>()
                   .Where(f => attachmentContentType != null && f.Item.ContentTypeId == attachmentContentType.Id)
                   .Select(SPDocumentStoreHelper.MapAttachmentFromSPFile)
                   .ToList());
        }
        /// <summary>
        /// Deletes the attachment from the document store.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public virtual bool DeleteAttachment(string containerTitle, Guid entityId, string fileName)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(false);
            }

            SPFile attachment;

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, entityId, fileName, out attachment) == false)
            {
                return(false);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                attachment.Recycle();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(true);
        }
        /// <summary>
        /// Adds a comment to the specified attachment.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="comment">The comment.</param>
        /// <returns></returns>
        public virtual Comment AddAttachmentComment(string containerTitle, Guid entityId, string fileName, string comment)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPFile   attachment;
            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) ==
                false)
            {
                return(null);
            }

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, entityId, fileName, out attachment) ==
                false)
            {
                return(null);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                attachment.Item[Constants.CommentFieldId] = comment;
                attachment.Item.Update();

                return(SPDocumentStoreHelper.MapCommentFromSPListItem(attachment.Item));
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }
        }
        /// <summary>
        /// Downloads the attachment as a stream.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public virtual Stream DownloadAttachment(string containerTitle, Guid entityId, string fileName)
        {
            var result = new MemoryStream();

            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            SPFile attachment;

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, entityId, fileName, out attachment) == false)
            {
                return(null);
            }

            var attachmentStream = attachment.OpenBinaryStream();

            DocumentStoreHelper.CopyStream(attachmentStream, result);

            result.Seek(0, SeekOrigin.Begin);
            return(result);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Removes the principal role from attachment.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="principalName">Name of the principal.</param>
        /// <param name="principalType">Type of the principal.</param>
        /// <param name="roleName">Name of the role.</param>
        /// <returns></returns>
        public virtual bool RemovePrincipalRoleFromAttachment(string containerTitle, Guid guid, string fileName, string principalName, string principalType, string roleName)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(false);
            }

            SPFile attachment;

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, guid, fileName, out attachment) == false)
            {
                return(false);
            }

            var currentPrincipal = PermissionsHelper.GetPrincipal(web, principalName, principalType);

            if (currentPrincipal == null)
            {
                return(false);
            }

            var roleType = PermissionsHelper.GetRoleType(web, roleName);

            return(PermissionsHelper.RemoveListItemPermissionsForPrincipal(web, attachment.Item, currentPrincipal, roleType, false));
        }
        public virtual bool RenameEntityPart(string containerTitle, string path, Guid entityId, string partName, string newPartName)
        {
            CheckIfFileNameIsReserved(newPartName + Constants.DocumentSetEntityPartExtension);

            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) == false)
            {
                return(false);
            }

            SPFile entityPartFile;

            if (SPDocumentStoreHelper.TryGetDocumentStoreEntityPart(list, folder, entityId, partName, out entityPartFile) == false)
            {
                return(false);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                entityPartFile.Item["Name"] = newPartName + Constants.DocumentSetEntityPartExtension;
                entityPartFile.Item.UpdateOverwriteVersion();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(true);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Resets the entity permissions.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public virtual PermissionsInfo ResetEntityPermissions(string containerTitle, Guid guid)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            DocumentSet documentSet;

            if (SPDocumentStoreHelper.TryGetDocumentStoreEntityDocumentSet(list, folder, guid, out documentSet) == false)
            {
                return(null);
            }

            web.AllowUnsafeUpdates = true;

            try
            {
                documentSet.Item.ResetRoleInheritance();
                documentSet.Item.Update();
                documentSet.Folder.Update();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(PermissionsHelper.MapPermissionsFromSPSecurableObject(documentSet.Item));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Adds the principal role to entity part.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="partName">Name of the part.</param>
        /// <param name="principalName">Name of the principal.</param>
        /// <param name="principalType">Type of the principal.</param>
        /// <param name="roleName">Name of the role.</param>
        /// <returns></returns>
        public virtual PrincipalRoleInfo AddPrincipalRoleToEntityPart(string containerTitle, Guid guid, string partName, string principalName, string principalType, string roleName)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            SPFile entityPart;

            if (SPDocumentStoreHelper.TryGetDocumentStoreEntityPart(list, folder, guid, partName, out entityPart) == false)
            {
                return(null);
            }

            SPPrincipal currentPrincipal = PermissionsHelper.GetPrincipal(web, principalName, principalType);

            if (currentPrincipal == null)
            {
                return(null);
            }

            SPRoleType roleType = PermissionsHelper.GetRoleType(web, roleName);

            PermissionsHelper.AddListItemPermissionsForPrincipal(web, entityPart.Item, currentPrincipal, roleType);

            return(PermissionsHelper.MapPrincipalRoleInfoFromSPSecurableObject(entityPart.Item, currentPrincipal));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Adds the principal role to container.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="principalName">Name of the principal.</param>
        /// <param name="principalType">Type of the principal.</param>
        /// <param name="roleName">Name of the role.</param>
        /// <returns></returns>
        public virtual PrincipalRoleInfo AddPrincipalRoleToContainer(string containerTitle, string principalName, string principalType, string roleName)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList list;

            if (SPDocumentStoreHelper.TryGetListForContainer(web, containerTitle, out list) == false)
            {
                throw new InvalidOperationException("A Container with the specified title does not exist.");
            }

            var currentPrincipal = PermissionsHelper.GetPrincipal(web, principalName, principalType);

            if (currentPrincipal == null)
            {
                return(null);
            }

            var roleType = PermissionsHelper.GetRoleType(web, roleName);

            PermissionsHelper.AddListPermissionsForPrincipal(web, list, currentPrincipal, roleType);

            return(PermissionsHelper.MapPrincipalRoleInfoFromSPSecurableObject(list, currentPrincipal));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Resets the container permissions.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <returns></returns>
        public virtual PermissionsInfo ResetContainerPermissions(string containerTitle)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList list;

            if (SPDocumentStoreHelper.TryGetListForContainer(web, containerTitle, out list) == false)
            {
                throw new InvalidOperationException("A Container with the specified title does not exist.");
            }

            web.AllowUnsafeUpdates = true;

            try
            {
                list.ResetRoleInheritance();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(PermissionsHelper.MapPermissionsFromSPSecurableObject(list));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Renames the specified folder to the new folder name.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="path">The path.</param>
        /// <param name="newFolderName">New name of the folder.</param>
        /// <returns></returns>
        public virtual Folder RenameFolder(string containerTitle, string path, string newFolderName)
        {
            //Get a new web in case we're executing in elevated permissions.
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) == false)
            {
                return(null);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                folder.Item["Name"] = newFolderName;
                folder.Item.Update();

                folder = list.GetItemByUniqueId(folder.UniqueId).Folder;

                return(SPDocumentStoreHelper.MapFolderFromSPFolder(folder));
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Returns a stream that contains an export of the entity.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <returns></returns>
        public virtual Stream ExportEntity(string containerTitle, Guid entityId)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            DocumentSet documentSet;

            if (SPDocumentStoreHelper.TryGetDocumentStoreEntityDocumentSet(list, folder, entityId, out documentSet) == false)
            {
                return(null);
            }

            var ms = new MemoryStream();

            documentSet.Export(ms);
            ms.Flush();
            ms.Seek(0, SeekOrigin.Begin);
            return(ms);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Gets the attachment permissions for principal.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="principalName">Name of the principal.</param>
        /// <param name="principalType">Type of the principal.</param>
        /// <returns></returns>
        public virtual PrincipalRoleInfo GetAttachmentPermissionsForPrincipal(string containerTitle, Guid guid, string fileName, string principalName, string principalType)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            SPFile attachment;

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, guid, fileName, out attachment) == false)
            {
                return(null);
            }

            var currentPrincipal = PermissionsHelper.GetPrincipal(list.ParentWeb, principalName, principalType);

            return(currentPrincipal == null
                ? null
                : PermissionsHelper.MapPrincipalRoleInfoFromSPSecurableObject(attachment.Item, currentPrincipal));
        }
        public virtual EntityPart GetEntityPart(string containerTitle, string path, Guid entityId, string partName)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPFile entityPartFile;

            if (!SPDocumentStoreHelper.TryGetDocumentStoreEntityPartDirect(web, containerTitle, path, entityId, partName,
                                                                           out entityPartFile))
            {
                SPList   list;
                SPFolder folder;
                if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) == false)
                {
                    return(null);
                }


                if (
                    SPDocumentStoreHelper.TryGetDocumentStoreEntityPart(list, folder, entityId, partName,
                                                                        out entityPartFile) == false)
                {
                    return(null);
                }
            }

            var result = SPDocumentStoreHelper.MapEntityPartFromSPFile(entityPartFile, null);

            ProcessEntityPartFile(containerTitle, entityId, partName, entityPartFile, result);

            return(result);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Resets the attachment permissions.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public virtual PermissionsInfo ResetAttachmentPermissions(string containerTitle, Guid guid, string fileName)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            SPFile attachment;

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, guid, fileName, out attachment) == false)
            {
                return(null);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                attachment.Item.ResetRoleInheritance();
                attachment.Item.Update();
                attachment.Update();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(PermissionsHelper.MapPermissionsFromSPSecurableObject(attachment.Item));
        }
        /// <summary>
        /// Renames the attachment with the specified filename to the new filename.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="newFileName">New name of the file.</param>
        /// <returns></returns>
        public virtual bool RenameAttachment(string containerTitle, Guid entityId, string fileName, string newFileName)
        {
            CheckIfFileNameIsReserved(newFileName);

            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(false);
            }

            SPFile attachment;

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, entityId, fileName, out attachment) == false)
            {
                return(false);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                attachment.Item["Name"] = newFileName;
                attachment.Item.Update();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(true);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Sets the container metadata.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public virtual bool SetContainerMetadata(string containerTitle, string key, string value)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(false);
            }

            web.AllowUnsafeUpdates = true;
            try
            {
                list.RootFolder.Properties[Constants.MetadataPrefix + key] = value;
                list.RootFolder.Update();
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }

            return(true);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Lists all containers contained in the document store.
        /// </summary>
        /// <returns></returns>
        public virtual IList <Container> ListContainers()
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            return(SPDocumentStoreHelper.GetContainers(web)
                   .Select(w => SPDocumentStoreHelper.MapContainerFromSPList(w))
                   .ToList());
        }
Exemplo n.º 26
0
        /// <summary>
        /// Creates the folder with the specified path in the container.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public virtual Folder CreateFolder(string containerTitle, string path)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            var currentFolder = CreateFolderInternal(web, containerTitle, path);

            return(SPDocumentStoreHelper.MapFolderFromSPFolder(currentFolder));
        }
Exemplo n.º 27
0
        /// <summary>
        /// Gets the folder with the specified path that is contained in the container.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public virtual Folder GetFolder(string containerTitle, string path)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            return(SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) == false
                ? null
                : SPDocumentStoreHelper.MapFolderFromSPFolder(folder));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Gets the container with the specified title from the document store.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <returns></returns>
        public virtual Container GetContainer(string containerTitle)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            return(SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false
                ? null
                : SPDocumentStoreHelper.MapContainerFromSPList(list));
        }
Exemplo n.º 29
0
        public override EntityPart GetEntityPart(string containerTitle, Guid entityId, string partName)
        {
            //Get a new web in case we're executing in elevated permissions.
            using (var site = new SPSite(this.DocumentStoreUrl))
            {
                using (var web = site.OpenWeb())
                {
                    var contentsHash = SPDocumentStoreHelper.GetEntityContentsHash(web, containerTitle, entityId);

                    //If the contents hash is not set, fall back on just retrieving the entity.
                    if (String.IsNullOrEmpty(contentsHash))
                    {
                        return(base.GetEntityPart(containerTitle, entityId, partName));
                    }

                    //If we found it in the cache, return the entity value.
                    var cachedValue = HttpRuntime.Cache[EntityContentsCachePrefix + "_" + entityId + "_" + contentsHash];
                    if (cachedValue is EntityContents)
                    {
                        var cachedEntityContents = cachedValue as EntityContents;

                        //If it hasn't changed, return a clone of the entity part.
                        if (cachedEntityContents.Entity.ContentsETag == contentsHash)
                        {
                            if (cachedEntityContents.EntityParts.ContainsKey(partName) == false)
                            {
                                return(null);
                            }

                            return(DocumentStoreHelper.CloneObject(cachedEntityContents.EntityParts[partName]));
                        }
                    }

                    var entityContents = GetEntityContents(web, containerTitle, entityId);

                    HttpRuntime.Cache.Add(EntityContentsCachePrefix + "_" + entityId + "_" + contentsHash,
                                          entityContents,
                                          null,
                                          Cache.NoAbsoluteExpiration,
                                          CacheSlidingExpiration,
                                          CacheItemPriority.Normal,
                                          null);

                    if (entityContents.EntityParts.ContainsKey(partName) == false)
                    {
                        return(null);
                    }

                    return(DocumentStoreHelper.CloneObject(entityContents.EntityParts[partName]));
                }
            }
        }
        public virtual IList <Comment> ListEntityPartComments(string containerTitle, Guid entityId, string partName,
                                                              string path)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPFile entityPart;

            if (!SPDocumentStoreHelper.TryGetDocumentStoreEntityPartDirect(web, containerTitle, path, entityId, partName,
                                                                           out entityPart))
            {
                SPList   list;
                SPFolder folder;
                if (
                    SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) ==
                    false)
                {
                    return(null);
                }

                if (
                    SPDocumentStoreHelper.TryGetDocumentStoreEntityPart(list, folder, entityId, partName, out entityPart) ==
                    false)
                {
                    return(null);
                }
            }

            var result = new List <Comment>();

            Comment[] lastComment =
            {
                new Comment
                {
                    CommentText = null
                }
            };

            var versions = entityPart.Item.Versions;

            foreach (var itemVersion in versions.OfType <SPListItemVersion>()
                     .OrderBy(v => Double.Parse(v.VersionLabel))
                     .Where(itemVersion => String.CompareOrdinal(itemVersion["DocumentEntityComments"] as string, lastComment[0].CommentText) != 0))
            {
                lastComment[0] = SPDocumentStoreHelper.MapCommentFromSPListItemVersion(itemVersion);
                result.Add(lastComment[0]);
            }

            result.Reverse();
            return(result);
        }