/// <summary> /// Gets an <see cref="T:Tridion.ExternalContentLibrary.V2.IFolderContent" /> representing the content of an external content folder or mount point. This list is used to build a tree structure when the user browse the content of the external library. /// </summary> /// <param name="parentFolderUri">The <see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" /> of the parent item. If <see cref="P:Tridion.ExternalContentLibrary.V2.IEclUri.ItemType" /> is <see cref="F:Tridion.ExternalContentLibrary.V2.EclItemTypes.MountPoint" /> the top level items are requested.</param> /// <param name="pageIndex">The 0 based index of the page to retrieve if the folder supports pagination.</param> /// <param name="itemTypes">Filters the item types to return. This can be used to for example only retrieve Folders for building up the tree structure.</param> /// <returns> /// A list of child items that should be displayed under the specified Folder. /// </returns> /// <remarks> /// A provider can use <see cref="M:Tridion.ExternalContentLibrary.V2.IHostServices.CreateFolderContent(Tridion.ExternalContentLibrary.V2.IEclUri,System.Collections.Generic.IList{Tridion.ExternalContentLibrary.V2.IContentLibraryListItem},System.Boolean,System.Boolean)" /> /// or one of the overloaded methods to initialize an instance of <see cref="T:Tridion.ExternalContentLibrary.V2.IFolderContent" />. /// </remarks> public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes) { String prefix = parentFolderUri.ItemId == "root" ? String.Empty : parentFolderUri.ItemId; IList <IContentLibraryListItem> items = new List <IContentLibraryListItem>(); foreach (S3ItemData itemData in _provider.S3.GetListing(prefix)) { S3ListItem item = null; if (itemData.ItemType == S3ItemType.Folder && itemTypes.HasFlag(EclItemTypes.Folder)) { item = new S3Folder(_provider, _session, parentFolderUri, itemData); } else if (itemTypes.HasFlag(EclItemTypes.File)) { item = new S3File(_provider, _session, parentFolderUri, itemData); } if (item != null) { _provider.Cache(item); items.Add(item); } } return(_session.HostServices.CreateFolderContent( parentFolderUri, items, CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId))); }
/// <summary> /// Returns requested item from provider cache /// </summary> /// <typeparam name="T"><see cref="T:S3ECLProvider.S3ListItem"/></typeparam> /// <param name="key">AWS S3 Key</param> /// <param name="contextUri">Context to return the item in</param> /// <returns>Requested item or null</returns> public S3ListItem Cached(String key, IEclUri contextUri) { S3ListItem item = _cache.Get(key) as S3ListItem; if (item != null) { // Item was cached in this context, return it if (item.Id.PublicationId == contextUri.PublicationId) { return(item); } // Contextualized item requested, create a shallow clone if (item is S3File) { return(new S3File(item, contextUri)); } if (item is S3Folder) { return(new S3Folder(item, contextUri)); } return(new S3ListItem(item, contextUri)); } return(null); }
/// <summary> /// Initialize a new <see cref="S3ListItem" /> in a given context /// </summary> /// <param name="item"><see cref="S3ListItem"/> to create a shallow clone from</param> public S3ListItem(S3ListItem item, IEclUri contextUri) { Provider = item.Provider; Session = item.Session; ParentId = item.ParentId; _itemData = item._itemData; Id = item.Id.GetInPublication(contextUri.PublicationId); }
/// <summary> /// Performs a search for external Items. /// </summary> /// <param name="contextUri">The <see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" /> of the Folder or Mount Point the search should be performed from.</param> /// <param name="searchTerm">The term to search for.</param> /// <param name="pageIndex">The 0 based index of the page to retrieve if the search result supports pagination.</param> /// <param name="numberOfItems">The number of items the user requested as the search result. If the provider supports pagination</param> /// <returns> /// A list of <see cref="T:Tridion.ExternalContentLibrary.V2.IContentLibraryListItem" /> matching the search term. /// </returns> /// <remarks> /// <para> /// This method should only be called when <see cref="M:Tridion.ExternalContentLibrary.V2.IContentLibraryContext.CanSearch(System.Int32)" />, <see cref="P:Tridion.ExternalContentLibrary.V2.IFolderContent.CanSearch" />, or <see cref="M:Tridion.ExternalContentLibrary.V2.IContentLibraryContext.CanSearch(System.Int32)" /> /// is <c>true</c> for the item identified by the <paramref name="contextUri" />. /// </para> /// <para> /// Ideally the provider should perform the search recursively across all subfolders of the Folder or Mount Point identified by the <paramref name="contextUri" />. The search /// should include the title and metadata on the external item. /// </para></remarks> public IFolderContent Search(IEclUri contextUri, string searchTerm, int pageIndex, int numberOfItems) { if (searchTerm != null) { String prefix = contextUri.ItemId == "root" ? String.Empty : contextUri.ItemId; IList <IContentLibraryListItem> items = new List <IContentLibraryListItem>(); String term = searchTerm.ToLowerInvariant(); foreach (S3ItemData itemData in _provider.S3.GetListing(prefix, true)) { if (itemData.Key.ToLowerInvariant().Contains(term)) { S3ListItem item = null; IEclUri parentUri = _provider.GetParentUri(_provider.GetUri(itemData, contextUri)); if (itemData.ItemType == S3ItemType.Folder) { item = new S3Folder(_provider, _session, parentUri, itemData); } else { item = new S3File(_provider, _session, parentUri, itemData); } if (item != null) { _provider.Cache(item); items.Add(item); } } } return(_session.HostServices.CreateFolderContent(contextUri, items, CanGetUploadMultimediaItemsUrl(contextUri.PublicationId), CanSearch(contextUri.PublicationId))); } throw new NotSupportedException(); }
/// <summary> /// Gets the item with the specified <see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" />. /// </summary> /// <param name="eclUri">The URI specifying the item to get.</param> /// <returns> /// The <see cref="T:Tridion.ExternalContentLibrary.V2.IContentLibraryItem" /> for the specified URI. If the item is not available or not accessible for the <see cref="T:Tridion.ExternalContentLibrary.V2.ITridionUser" /> /// of the current <see cref="T:Tridion.ExternalContentLibrary.V2.IEclSession" /> the provider must throw an exception. /// </returns> /// <remarks> /// To check if the user can read an item without having an exception thrown call <see cref="M:Tridion.ExternalContentLibrary.V2.IContentLibraryContext.GetItems(System.Collections.Generic.IList{Tridion.ExternalContentLibrary.V2.IEclUri})" /> with a single item and check if /// it is returned. /// </remarks> public IContentLibraryItem GetItem(IEclUri eclUri) { S3ListItem item = _provider.Cached(eclUri.ItemId, eclUri); if (item == null) { if (eclUri.ItemType == EclItemTypes.Folder) { item = new S3Folder(_provider, _session, eclUri); } if (eclUri.ItemType == EclItemTypes.File) { item = new S3File(_provider, _session, eclUri); } _provider.Cache(item); } return(item as IContentLibraryItem); }
/// <summary> /// Purges the item specified by <paramref name="key"/> from the cache /// </summary> /// <param name="item"><see cref="T:S3ECLProvider.S3ListItem"/></param> public void Purge(S3ListItem item) { _cache.Remove(item.Id.ItemId); }
/// <summary> /// Cache the <paramref name="item"/> in the provider cache /// </summary> /// <param name="item"><see cref="T:S3ECLProvider.S3ListItem"/></param> public void Cache(S3ListItem item) { _cache.Set(item.Id.ItemId, item, DateTime.Now.AddSeconds(_cacheTime)); }
/// <summary> /// Initialize a new <see cref="S3Folder" /> in a given context /// </summary> /// <param name="item"><see cref="S3Folder"/> to create a shallow clone from</param> public S3Folder(S3ListItem item, IEclUri contextUri) : base(item, contextUri) { }