public void UndoCheckOut(Guid libraryId, DocumentGetOptions options)
        {
            var document = Get(libraryId, options);

            fileService.UndoCheckOut(document.Library.SPWebUrl, document.Library.Id, document.Id);
            ExpireTags(document.Library.Id);
        }
        public void Delete(Guid libraryId, DocumentGetOptions options)
        {
            var documentId           = options.Id.HasValue ? options.Id.Value.ToString(CultureInfo.InvariantCulture) : options.ContentId.ToString("N");
            var documentBeforeDelete = Get(libraryId, options);

            if (documentBeforeDelete == null)
            {
                return;
            }

            try
            {
                Events.OnBeforeDelete(documentBeforeDelete);
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the PublicApi.Documents.Events.OnBeforeDelete() method for LibraryId: {1}, DocumentId: {2}. The exception message is: {3}", ex.GetType(), libraryId, documentId, ex.Message);
                SPLog.UnKnownError(ex, message);
            }

            listItemService.Delete(libraryId, options);
            ExpireTags(libraryId);

            try
            {
                Events.OnAfterDelete(documentBeforeDelete);
            }
            catch (Exception ex)
            {
                string message = string.Format("An exception of type {0} occurred in the PublicApi.Documents.Events.OnAfterDelete() method for LibraryId: {1}, DocumentId: {2}. The exception message is: {3}", ex.GetType(), libraryId, documentId, ex.Message);
                SPLog.UnKnownError(ex, message);
            }
        }
        public SPDocumentInfo GetDetails(Guid libraryId, DocumentGetOptions options)
        {
            var detailsCacheId  = GetDetailsCacheId(libraryId, options);
            var documentDetails = (SPDocumentInfo)cacheService.Get(detailsCacheId, CacheScope.Context | CacheScope.Process);

            if (documentDetails == null)
            {
                var document = Get(libraryId, options);
                documentDetails = fileService.GetDetails(document.Library.SPWebUrl, document.Library.Id, document.Id);
                cacheService.Put(detailsCacheId, documentDetails, CacheScope.Context | CacheScope.Process, new[] { DocumentPropertiesTag(document.ContentId) }, CacheTimeOut);
            }
            return(documentDetails);
        }
        public ApiList <SPDocumentVersion> GetVersions(Guid libraryId, DocumentGetOptions options)
        {
            var versionsCacheId     = GetVersionsCacheId(libraryId, options);
            var documentVersionList = (ApiList <SPDocumentVersion>)cacheService.Get(versionsCacheId, CacheScope.Context | CacheScope.Process);

            if (documentVersionList == null)
            {
                var document = Get(libraryId, options);
                documentVersionList = new ApiList <SPDocumentVersion>(fileService.GetVersions(document.Library.SPWebUrl, document.Library.Id, document.Id));
                cacheService.Put(versionsCacheId, documentVersionList, CacheScope.Context | CacheScope.Process, new[] { DocumentPropertiesTag(document.ContentId) }, CacheTimeOut);
            }
            return(documentVersionList);
        }
        public Document Get(Guid libraryId, DocumentGetOptions options)
        {
            var cacheId  = GetCacheId(libraryId, options);
            var document = (Document)cacheService.Get(cacheId, CacheScope.Context | CacheScope.Process);

            if (document == null)
            {
                if (string.IsNullOrEmpty(options.Url))
                {
                    options.Url = GetUrl(libraryId);
                }

                document = new Document(listItemService.Get(libraryId, options));
                cacheService.Put(cacheId, document, CacheScope.Context | CacheScope.Process, new[] { Tag(libraryId) }, CacheTimeOut);
            }
            return(document);
        }
 private static string GetCacheId(Guid applicationId, DocumentGetOptions options)
 {
     return(string.Concat("Documents.Get:", applicationId.ToString("N"), ":", GetDocumentId(options)));
 }
 private static string GetDocumentId(DocumentGetOptions options)
 {
     return(options.ContentId != Guid.Empty ? options.ContentId.ToString("N") : options.Id.GetValueOrDefault().ToString(CultureInfo.InvariantCulture));
 }