Exemplo n.º 1
0
        /// <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);
        }
        private IContentLibraryMultimediaItem GetEclItem(string eclStubComponentId, out IContentLibraryContext eclContext)
        {
            _log.Debug("Retrieving ECL item for ECL Stub Component: " + eclStubComponentId);
            IEclUri eclUri = _eclSession.TryGetEclUriFromTcmUri(eclStubComponentId);

            if (eclUri == null)
            {
                throw new Exception("Unable to get ECL URI for ECL Stub Component: " + eclStubComponentId);
            }

            eclContext = _eclSession.GetContentLibrary(eclUri);
            // This is done this way to not have an exception thrown through GetItem, as stated in the ECL API doc.
            // The reason to do this, is because if there is an exception, the ServiceChannel is going into the aborted state.
            // GetItems allows up to 20 (depending on config) connections.
            IList <IContentLibraryItem>   eclItems = eclContext.GetItems(new[] { eclUri });
            IContentLibraryMultimediaItem eclItem  = (eclItems == null) ? null : eclItems.OfType <IContentLibraryMultimediaItem>().FirstOrDefault();

            if (eclItem == null)
            {
                eclContext.Dispose();
                throw new Exception(string.Format("ECL item '{0}' not found (TCM URI: '{1}')", eclUri, eclStubComponentId));
            }

            _log.Debug(string.Format("Retrieved ECL item for ECL Stub Component '{0}': {1}", eclStubComponentId, eclUri));
            return(eclItem);
        }
Exemplo n.º 3
0
        public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes)
        {
            List <IContentLibraryListItem> items = new List <IContentLibraryListItem>();

            // ToDo: consider using async calls for getting users and forms
            if (parentFolderUri.ItemType == EclItemTypes.MountPoint && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                // get users
                foreach (WufooData data in Provider.Wufoo.GetUsers())
                {
                    items.Add(new ListItem(parentFolderUri.PublicationId, data));
                }
            }

            // only return files if they are requested (itemTypes is EclItemTypes.File))
            else if (parentFolderUri.ItemType == EclItemTypes.Folder && parentFolderUri.SubType == "user" && itemTypes.HasFlag(EclItemTypes.File))
            {
                // get forms
                foreach (WufooData data in Provider.Wufoo.GetForms(parentFolderUri.ItemId))
                {
                    items.Add(new ListItem(parentFolderUri.PublicationId, data));
                }
            }

            return(Provider.HostServices.CreateFolderContent(parentFolderUri, items, CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId)));
        }
Exemplo n.º 4
0
        public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes)
        {
            List<IContentLibraryListItem> items = new List<IContentLibraryListItem>();

            // ToDo: consider using async calls for getting users and forms
            if (parentFolderUri.ItemType == EclItemTypes.MountPoint && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                // get users
                foreach (WufooData data in Provider.Wufoo.GetUsers())
                {
                    items.Add(new ListItem(parentFolderUri.PublicationId, data));
                }
            }

            // only return files if they are requested (itemTypes is EclItemTypes.File))
            else if (parentFolderUri.ItemType == EclItemTypes.Folder && parentFolderUri.SubType == "user" && itemTypes.HasFlag(EclItemTypes.File))
            {
                // get forms
                foreach (WufooData data in Provider.Wufoo.GetForms(parentFolderUri.ItemId))
                {
                    items.Add(new ListItem(parentFolderUri.PublicationId, data));
                }
            }

            return Provider.HostServices.CreateFolderContent(parentFolderUri, items, CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determine the parent uri for a given <paramref name="uri" />
        /// </summary>
        /// <param name="uri"><see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" /></param>
        /// <returns>Parent <see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" /></returns>
        public IEclUri GetParentUri(IEclUri uri)
        {
            if (_hostServices.IsNullOrNullEclUri(uri))
            {
                throw new ArgumentNullException("uri");
            }

            String[] parts = uri.ItemId.Split('/');

            if (parts.Length == 1)
            {
                return(_hostServices.CreateEclUri(
                           uri.PublicationId,
                           uri.MountPointId,
                           "root",
                           "mp",
                           EclItemTypes.MountPoint));
            }

            return(_hostServices.CreateEclUri(
                       uri.PublicationId,
                       uri.MountPointId,
                       uri.ItemId.Substring(0, uri.ItemId.Length - (parts.Last().Length + 1)),
                       Constants.S3_FOLDER_ID,
                       EclItemTypes.Folder));
        }
 public YouTubeListItem(int publicationId, String user)
 {
     User           = user;
     _id            = YouTubeProvider.HostServices.CreateEclUri(publicationId, YouTubeProvider.MountPointId, user, "usr", EclItemTypes.Folder);
     _displayTypeId = "usr";
     IsVideo        = false;
 }
Exemplo n.º 7
0
        public byte[] GetThumbnailImage(IEclUri eclUri, int maxWidth, int maxHeight)
        {
            if (eclUri.ItemType == EclItemTypes.File && (eclUri.SubType == "fls"))
            {
                WebClient webClient       = new WebClient();
                string    photoUrl        = S3Provider.S3.GetMediaUrl(eclUri.ItemId);
                byte[]    thumbnailDataIs = null;
                try
                {
                    thumbnailDataIs = webClient.DownloadData(photoUrl);
                    using (MemoryStream ms = new MemoryStream(thumbnailDataIs, false))
                    {
                        return(S3Provider.HostServices.CreateThumbnailImage(maxWidth, maxHeight, ms, null));
                    }
                }
                catch (WebException)
                {
                    return(null);
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(null);
        }
 public YouTubeListItem(int publicationId, Video video)
 {
     Video          = video;
     _id            = YouTubeProvider.HostServices.CreateEclUri(publicationId, YouTubeProvider.MountPointId, Video.VideoId, "vid", EclItemTypes.File);
     IsVideo        = true;
     _displayTypeId = "vid";
 }
        public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes)
        {
            int totalVideos = 0;
            var items       = new List <IContentLibraryListItem>();

            if (parentFolderUri.ItemType == EclItemTypes.MountPoint && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                items.AddRange(YouTubeProvider.Client.Users.Select(user => new YouTubeListItem(parentFolderUri.PublicationId, user)));
            }

            if (parentFolderUri.ItemType == EclItemTypes.Folder && parentFolderUri.SubType == "usr" && itemTypes.HasFlag(EclItemTypes.File))
            {
                canPaginate = true;
                items.AddRange(YouTubeProvider.Client.GetUploadsForUser(parentFolderUri.ItemId, pageIndex, out totalVideos).Select(v => new YouTubeListItem(parentFolderUri.PublicationId, v)));
            }

            if (pageIndex == 0 && items.Count < 50)
            {
                canPaginate = false;
            }

            if (canPaginate)
            {
                bool isLast = items.Count < 50 || ((pageIndex + 1) * 50 >= totalVideos);
                return(YouTubeProvider.HostServices.CreateFolderContent(parentFolderUri, pageIndex, isLast, items, CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId)));
            }
            else
            {
                return(YouTubeProvider.HostServices.CreateFolderContent(parentFolderUri, items, CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId)));
            }
        }
Exemplo n.º 10
0
        public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes)
        {
            List<IContentLibraryListItem> items = new List<IContentLibraryListItem>();

            if (parentFolderUri.ItemType == EclItemTypes.MountPoint && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                // get photosets
                foreach (FlickrInfo info in Provider.Flickr.GetPhotoSets())
                {
                    items.Add(new ListItem(parentFolderUri.PublicationId, info));
                }

                // oops, no photosets
                if(items.Count == 0)
                {
                    items.Add(new ErrorListItem(parentFolderUri.PublicationId, "There are no public photo sets in this Flickr account."));
                }
            }
            // only return files if they are requested (itemTypes is EclItemTypes.File))
            else if (parentFolderUri.ItemType == EclItemTypes.Folder && parentFolderUri.SubType == "set" && itemTypes.HasFlag(EclItemTypes.File))
            {
                // get photos
                foreach (FlickrInfo info in Provider.Flickr.GetPhotosInSet(parentFolderUri.ItemId))
                {
                    //items.Add(new FlickrPhoto(parentFolderUri.PublicationId, info));
                    items.Add(new ListItem(parentFolderUri.PublicationId, info));
                }
            }

            return Provider.HostServices.CreateFolderContent(parentFolderUri, items, CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId));
        }
Exemplo n.º 11
0
        public string ImportItem(string eclOrTcmUri, string folderUri, string schemaUri)
        {
            _folderUri = folderUri;
            _schemaUri = schemaUri;
            _username  = ServiceSecurityContext.Current.WindowsIdentity.Name;

            // create new tcm session for current user, so we can create an ecl session to get the ecl item and read its content
            using (Session tcmSession = new Session(_username))
                using (IEclSession eclSession = SessionFactory.CreateEclSession(tcmSession))
                {
                    IEclUri eclUri = eclOrTcmUri.StartsWith("tcm:") ? eclSession.TryGetEclUriFromTcmUri(eclOrTcmUri) : eclSession.HostServices.CreateEclUri(eclOrTcmUri);
                    if (eclUri != null)
                    {
                        using (_eclContentLibraryContext = eclSession.GetContentLibrary(eclUri))
                        {
                            if (eclUri.ItemType == EclItemTypes.Folder)
                            {
                                // loop over all ECL items in this folder
                                IFolderContent items = _eclContentLibraryContext.GetFolderContent(eclUri, 0, EclItemTypes.File);
                                IList <string> ids   = items.ChildItems.Select(item => ImportSingleItem(item.Id)).ToList();
                                return(string.Join(",", ids.ToArray()));
                            }

                            return(ImportSingleItem(eclUri));
                        }
                    }
                }

            throw new FaultException(string.Format("{0} does not exist.", eclOrTcmUri));
        }
Exemplo n.º 12
0
 /// <summary>
 /// Construct a new product item
 /// </summary>
 /// <param name="publicationId"></param>
 /// <param name="category"></param>
 /// <param name="product"></param>
 public ProductItem(int publicationId, Category category, Product product) : base(publicationId, product.Id, product.Name)
 {
     this.category = category;
     this.product  = product;
     this.id       = EclProvider.HostServices.CreateEclUri(publicationId, EclProvider.MountPointId,
                                                           product.Id, DisplayTypeId, EclItemTypes.File);
 }
Exemplo n.º 13
0
        public S3Info GetMediaInfo(IEclUri eclUri)
        {
            GetObjectResponse s3Obj;
            var mediaKey             = eclUri.ItemId;
            GetObjectRequest request = new GetObjectRequest
            {
                BucketName = BucketName,
                Key        = eclUri.ItemId,
            };

            try
            {
                s3Obj = s3Client.GetObject(request);
                var mediaUrl = GetMediaUrl(mediaKey);

                S3Info s3Info = new S3Info(s3Obj, mediaUrl, eclUri.ItemType.ToString());
                return(s3Info);
            }
            catch (KeyNotFoundException)
            {
                throw new KeyNotFoundException();
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 14
0
        public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes)
        {
            List <IContentLibraryListItem> items = new List <IContentLibraryListItem>();

            if (parentFolderUri.ItemType == EclItemTypes.MountPoint && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                // get photosets
                foreach (FlickrInfo info in Provider.Flickr.GetPhotoSets())
                {
                    items.Add(new ListItem(parentFolderUri.PublicationId, info));
                }

                // oops, no photosets
                if (items.Count == 0)
                {
                    items.Add(new ErrorListItem(parentFolderUri.PublicationId, "There are no public photo sets in this Flickr account."));
                }
            }
            // only return files if they are requested (itemTypes is EclItemTypes.File))
            else if (parentFolderUri.ItemType == EclItemTypes.Folder && parentFolderUri.SubType == "set" && itemTypes.HasFlag(EclItemTypes.File))
            {
                // get photos
                foreach (FlickrInfo info in Provider.Flickr.GetPhotosInSet(parentFolderUri.ItemId))
                {
                    //items.Add(new FlickrPhoto(parentFolderUri.PublicationId, info));
                    items.Add(new ListItem(parentFolderUri.PublicationId, info));
                }
            }

            return(Provider.HostServices.CreateFolderContent(parentFolderUri, items, CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId)));
        }
Exemplo n.º 15
0
        /// <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)));
        }
Exemplo n.º 16
0
 protected SelectableItem(int publicationId, string externalId, string title)
 {
     this.id = EclProvider.HostServices.CreateEclUri(publicationId, EclProvider.MountPointId,
                                                     externalId, DisplayTypeId, EclItemTypes.File);
     this.externalId = externalId;
     this.title      = title;
 }
Exemplo n.º 17
0
 public IList<IContentLibraryListItem> FindItem(IEclUri eclUri)
 {
     FotoWareProvider.HostServices.LogMessage(
         LoggingSeverity.Debug,
         string.Format("Finding item {0}", eclUri)
     );
     throw new NotImplementedException();
 }
        public IContentLibraryItem GetItem(IEclUri eclUri)
        {
            if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "vid")
            {
                return(new YouTubeVideo(eclUri.PublicationId, YouTubeProvider.Client.GetVideo(eclUri.ItemId)));
            }

            throw new NotSupportedException();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initialize a new <see cref="S3ListItem" />
        /// </summary>
        /// <param name="provider">Associated <see cref="S3Provider"/></param>
        /// <param name="session">Current <see cref="T:Tridion.ExternalContentLibrary.V2.IEclSession"/></param>
        /// <param name="parentUri"><see cref="Tridion.ExternalContentLibrary.V2.IEclUri" /></param>
        /// <param name="eclObject"><see cref="Amazon.S3.Model.S3Object"/></param>
        /// <remarks>Creating a <see cref="S3ListItem" /> directly from an <see cref="T:S3ECLProvider.API.S3ItemData"/></remarks>
        public S3ListItem(S3Provider provider, IEclSession session, IEclUri parentUri, S3ItemData eclObject)
        {
            Provider = provider;
            Session  = session;
            ParentId = parentUri;

            _itemData = eclObject;
            Id        = provider.GetUri(_itemData, parentUri);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Gets an URL to a page that can be used to upload new items on the external system.
        /// </summary>
        /// <param name="parentFolderUri">The <see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" /> of the parent folder the items should be uploaded to.</param>
        /// <returns>
        /// An URL to a page that can be used to upload items to the external system.
        /// </returns>
        /// <remarks>
        /// <para>
        /// The method should always return an URL for items that returns <c>true</c> from <see cref="P:Tridion.ExternalContentLibrary.V2.IFolderContent.CanGetUploadMultimediaItemsUrl" />,
        /// <see cref="P:Tridion.ExternalContentLibrary.V2.IContentLibraryListItem.CanGetUploadMultimediaItemsUrl" />, or <see cref="M:Tridion.ExternalContentLibrary.V2.IContentLibraryContext.CanGetUploadMultimediaItemsUrl(System.Int32)" />.
        /// </para>
        /// <para>
        /// The retrieved URL can contain a token that is only valid for a limited time period.
        /// </para></remarks>
        public string GetUploadMultimediaItemsUrl(IEclUri parentFolderUri)
        {
            NameValueCollection queryString = HttpUtility.ParseQueryString(String.Empty);

            queryString["id"]     = parentFolderUri.MountPointId;
            queryString["prefix"] = parentFolderUri.ItemId == "root" ? String.Empty : parentFolderUri.ItemId;

            return(String.Format("/WebUI/Editors/ECL/S3ECLUpload/upload.aspx?{0}", queryString.ToString()));
        }
        public string GetViewItemUrl(IEclUri eclUri)
        {
            //if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "vid")
            //{
            //    return YouTubeProvider.Client.GetVideo(eclUri.ItemId).WatchPage.ToString();
            //}

            throw new NotSupportedException();
        }
Exemplo n.º 22
0
        /// <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);
        }
Exemplo n.º 23
0
        public string GetViewItemUrl(IEclUri eclUri)
        {
            if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "img")
            {
                // format of photo item id: [flickr photo id]_[flickr photo secret]_[flickr photo set id]
                string[] ids = eclUri.ItemId.Split('_');
                return(Provider.Flickr.GetPhotoPageUrl(ids[0]));
            }

            throw new NotSupportedException();
        }
Exemplo n.º 24
0
 public byte[] GetThumbnailImage(IEclUri eclUri, int maxWidth, int maxHeight)
 {
     // no thumbnails are availabe so use largest icon
     if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "form")
     {
         byte[] thumbnailData = Provider.GetIconImage("form", 48);
         using (MemoryStream ms = new MemoryStream(thumbnailData, false))
         {
             return(Provider.HostServices.CreateThumbnailImage(maxWidth, maxHeight, ms, 48, 48, null));
         }
     }
     return(null);
 }
Exemplo n.º 25
0
        public IContentLibraryItem GetItem(IEclUri eclUri)
        {
            if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "fls")
            {
                return(new S3Media(eclUri, S3Provider.S3.GetMediaInfo(eclUri)));
            }

            if (eclUri.ItemType == EclItemTypes.Folder && eclUri.SubType == "fld")
            {
                return(new S3Media(eclUri, S3Provider.S3.GetMediaInfo(eclUri)));
            }

            throw new NotSupportedException();
        }
Exemplo n.º 26
0
        public string GetUploadMultimediaItemsUrl(IEclUri parentFolderUri)
        {
            if (parentFolderUri.ItemType == EclItemTypes.MountPoint)
            {
                return(Info.MediaUrl);
            }

            if (parentFolderUri.ItemType == EclItemTypes.Folder && parentFolderUri.SubType == "fld")
            {
                return(Info.MediaUrl);
            }

            throw new NotSupportedException();
        }
Exemplo n.º 27
0
        /// <summary>
        /// Gets the <see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" /> for an <paramref name="item"/>
        /// </summary>
        /// <param name="item"><see cref="T:S3ECLProvider.API.S3ItemData"/>.</param>
        /// <param name="contextUri"><see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" /></param>
        /// <returns><see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" />s</returns>
        public IEclUri GetUri(S3ItemData item, IEclUri contextUri)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return(_hostServices.CreateEclUri(
                       contextUri.PublicationId,
                       contextUri.MountPointId,
                       item.EclKey,
                       item.ItemType == S3ItemType.Folder ? Constants.S3_FOLDER_ID : Constants.S3_FILE_ID,
                       item.ItemType == S3ItemType.Folder ? EclItemTypes.Folder : EclItemTypes.File));
        }
Exemplo n.º 28
0
 public ListItem(int publicationId, FlickrInfo info)
 {
     Info = info;
     if (info.IsPhoto)
     {
         // format of photo item id: [flickr photo id]_[flickr photo secret]_[flickr photo set id]
         string itemId = string.Format("{0}_{1}_{2}", info.Id, info.Secret, info.PhotoSetId);
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, itemId, DisplayTypeId, EclItemTypes.File);
     }
     else
     {
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, info.Id, DisplayTypeId, EclItemTypes.Folder);
     }
 }
Exemplo n.º 29
0
        public string GetUploadMultimediaItemsUrl(IEclUri parentFolderUri)
        {
            if (parentFolderUri.ItemType == EclItemTypes.MountPoint)
            {
                return(string.Format(WufooWrapper.UserManagerUrl, Provider.Wufoo.UserName));
            }

            if (parentFolderUri.ItemType == EclItemTypes.Folder && parentFolderUri.SubType == "user")
            {
                return(string.Format(WufooWrapper.FormManagerUrl, Provider.Wufoo.UserName));
            }

            throw new NotSupportedException();
        }
Exemplo n.º 30
0
 public ListItem(int publicationId, FlickrInfo info)
 {
     Info = info;
     if (info.IsPhoto)
     {
         // format of photo item id: [flickr photo id]_[flickr photo secret]_[flickr photo set id]
         string itemId = string.Format("{0}_{1}_{2}", info.Id, info.Secret, info.PhotoSetId);
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, itemId, DisplayTypeId, EclItemTypes.File);
     }
     else
     {
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, info.Id, DisplayTypeId, EclItemTypes.Folder);
     }
 }
Exemplo n.º 31
0
        public string GetUploadMultimediaItemsUrl(IEclUri parentFolderUri)
        {
            if (parentFolderUri.ItemType == EclItemTypes.MountPoint)
            {
                return(Provider.Flickr.GetPhotoSetPageUrl(null));
            }

            if (parentFolderUri.ItemType == EclItemTypes.Folder && parentFolderUri.SubType == "set")
            {
                return(Provider.Flickr.GetPhotoSetPageUrl(parentFolderUri.ItemId));
            }

            throw new NotSupportedException();
        }
Exemplo n.º 32
0
        public string GetViewItemUrl(IEclUri eclUri)
        {
            if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "form")
            {
                // format of form itemId: [form user]_[form hash]
                string[] ids = eclUri.ItemId.Split('_');

                // load form data for getting form name
                WufooData formData = Provider.Wufoo.GetForm(ids[0], ids[1]);

                return(string.Format(WufooWrapper.FormEditUrl, ids[0], formData.Name));
            }

            throw new NotSupportedException();
        }
Exemplo n.º 33
0
 public ListItem(int publicationId, WufooData data)
 {
     Data = data;
     if (data.IsForm)
     {
         // format of form itemId: [form user]_[form hash]
         string itemId = string.Format("{0}_{1}", data.User, data.Hash);
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, itemId, DisplayTypeId, EclItemTypes.File);
     }
     else
     {
         // use username as itemId (also available in form itemId) 
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, data.Title, DisplayTypeId, EclItemTypes.Folder);
     }
 }
Exemplo n.º 34
0
 public ListItem(int publicationId, WufooData data)
 {
     Data = data;
     if (data.IsForm)
     {
         // format of form itemId: [form user]_[form hash]
         string itemId = string.Format("{0}_{1}", data.User, data.Hash);
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, itemId, DisplayTypeId, EclItemTypes.File);
     }
     else
     {
         // use username as itemId (also available in form itemId)
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, data.Title, DisplayTypeId, EclItemTypes.Folder);
     }
 }
Exemplo n.º 35
0
        public ListItem(IEclUri ecluri, S3Info info)
        {
            Info = info;

            if (Info.ContentType == "Folder")
            {
                string itemId = Info.Name;
                String.Format(itemId);
                _id = S3Provider.HostServices.CreateEclUri(ecluri.PublicationId, S3Provider.MountPointId, itemId, DisplayTypeId, EclItemTypes.Folder);
            }
            else
            {
                string itemId = Info.Name;
                _id = S3Provider.HostServices.CreateEclUri(ecluri.PublicationId, S3Provider.MountPointId, itemId, DisplayTypeId, EclItemTypes.File);
            }
        }
Exemplo n.º 36
0
        public IContentLibraryItem GetItem(IEclUri eclUri)
        {
            if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "form")
            {
                // format of form itemId: [form user]_[form hash]
                string[] ids = eclUri.ItemId.Split('_');
                return new Form(eclUri.PublicationId, Provider.Wufoo.GetForm(ids[0], ids[1]));
            }

            if (eclUri.ItemType == EclItemTypes.Folder && eclUri.SubType == "user")
            {
                return new User(eclUri.PublicationId, Provider.Wufoo.GetUser(eclUri.ItemId));
            }

            throw new NotSupportedException();
        }
Exemplo n.º 37
0
        public IContentLibraryItem GetItem(IEclUri eclUri)
        {
            if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "img")
            {
                // format of photo item id: [flickr photo id]_[flickr photo secret]_[flickr photo set id]
                string[] ids = eclUri.ItemId.Split('_');
                return new FlickrPhoto(eclUri.PublicationId, Provider.Flickr.GetPhotoInfo(ids[0], ids[1], ids[2]));
            }

            if (eclUri.ItemType == EclItemTypes.Folder && eclUri.SubType == "set")
            {
                return new FlickrPhotoSet(eclUri.PublicationId, Provider.Flickr.GetPhotoSetInfo(eclUri.ItemId));
            }

            throw new NotSupportedException();
        }
Exemplo n.º 38
0
        public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes)
        {
            FotoWareProvider.HostServices.LogMessage(LoggingSeverity.Debug,
                string.Format("Getting folder contents for {0}, page index {1} for item types {2}",
                    parentFolderUri.ToString(),
                    pageIndex,
                    itemTypes.ToString()
                )
            );

            List<IContentLibraryListItem> result = new List<IContentLibraryListItem>();

            if(parentFolderUri.ItemType == EclItemTypes.MountPoint && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                result.AddRange(GetRootFolderContent(parentFolderUri));
            }

            bool canUpload = CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId);
            bool canSearch = CanSearch(parentFolderUri.PublicationId);
            return FotoWareProvider.HostServices.CreateFolderContent(parentFolderUri, result, canUpload, canSearch);
        }
Exemplo n.º 39
0
        public byte[] GetThumbnailImage(IEclUri eclUri, int maxWidth, int maxHeight)
        {
            // only return thumbnails for the actual photos
            if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "img")
            {
                // format of photo item id: [flickr photo id]_[flickr photo secret]_[flickr photo set id]
                string[] ids = eclUri.ItemId.Split('_');
                FlickrInfo photo = Provider.Flickr.GetPhotoInfo(ids[0], ids[1], ids[2]);

                WebClient webClient = new WebClient();
                byte[] thumbnailData = webClient.DownloadData(Flickr.GetPhotoUrl(photo, maxWidth));
                using (MemoryStream ms = new MemoryStream(thumbnailData, false))
                {
                    return Provider.HostServices.CreateThumbnailImage(maxWidth, maxHeight, ms, Flickr.MaxWidth, Flickr.MaxHeight, null);
                }
            }
            return null;
        }
Exemplo n.º 40
0
        public string GetUploadMultimediaItemsUrl(IEclUri parentFolderUri)
        {
            if (parentFolderUri.ItemType == EclItemTypes.MountPoint)
            {
                return Provider.Flickr.GetPhotoSetPageUrl(null);
            }

            if (parentFolderUri.ItemType == EclItemTypes.Folder && parentFolderUri.SubType == "set")
            {
                return Provider.Flickr.GetPhotoSetPageUrl(parentFolderUri.ItemId);
            }

            throw new NotSupportedException();
        }
Exemplo n.º 41
0
 public IPaginatedFolderContent CreateFolderContent(IEclUri parentUri, int pageIndex, int totalNumberOfPages, IList<IContentLibraryListItem> childItems, bool canGetUploadMultimediaItemsUrl, bool canSearch)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 42
0
 public void StubComponentCreated(IEclUri eclUri, string tcmUri)
 {
     //TODO
 }
Exemplo n.º 43
0
 private string GetUniqueDocumentIdFromEclUri(IEclUri uri)
 {
     string result = null;
     if (uri != null && Model.Asset.DisplayTypeIdentifier.Equals(uri.SubType))
     {
         result = uri.ItemId.Replace(Model.Asset.WhitespaceReplacement, " ");
     }
     return result;
 }
Exemplo n.º 44
0
 public IContentLibraryContext GetContentLibrary(IEclUri eclUri)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 45
0
 public ErrorListItem(int publicationId, string errorMessage)
 {
     _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, "error", DisplayTypeId, EclItemTypes.Folder);
     _errorMessage = errorMessage;
 }
Exemplo n.º 46
0
        public string GetViewItemUrl(IEclUri eclUri)
        {
            if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "img")
            {
                // format of photo item id: [flickr photo id]_[flickr photo secret]_[flickr photo set id]
                string[] ids = eclUri.ItemId.Split('_');
                return Provider.Flickr.GetPhotoPageUrl(ids[0]);
            }

            throw new NotSupportedException();
        }
Exemplo n.º 47
0
 public IFolderContent Search(IEclUri contextUri, string searchTerm, int pageIndex, int numberOfItems)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 48
0
 public void StubComponentDeleted(IEclUri eclUri, string tcmUri)
 {
 }
Exemplo n.º 49
0
 public IList<IContentLibraryListItem> FindItem(IEclUri eclUri)
 {
     // return null so we force it to call GetItem(IEclUri)
     return null;
 }
Exemplo n.º 50
0
        public IContentLibraryItem GetItem(IEclUri eclUri)
        {
            FotoWareProvider.HostServices.LogMessage(
                LoggingSeverity.Debug,
                string.Format("Getting item {0}", eclUri)
            );

            IContentLibraryItem result = null;
            switch(eclUri.SubType)
            {
                case Model.Asset.DisplayTypeIdentifier:

                    // get first asset with supplied unique document ID
                    string uniqueId = GetUniqueDocumentIdFromEclUri(eclUri);
                    var assets = GetAssetsByMetadataValue(API.SearchFields.Metadata.UniqueDocumentId, uniqueId);
                    if(assets!=null)
                    {
                        var asset = assets.FirstOrDefault() as Model.Asset;
                        if(asset!=null)
                        {
                            asset.Id = eclUri;
                            result = asset;
                        }
                    }
                    break;

                case Model.Archive.DisplayTypeIdentifier:
                    break;

                default:
                    break;
            }

            return result;
        }
Exemplo n.º 51
0
 public string GetOrCreateTcmUriFromEclUri(IEclUri eclUri)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 52
0
        public IFolderContent Search(IEclUri contextUri, string searchTerm, int pageIndex, int numberOfItems)
        {
            // expand query to include unqiue document id in results
            // used to generate ECL URI
            searchTerm = string.Format("({0}) AND NOT ({1} contains (xnoword))",
                searchTerm,
                API.SearchFields.Metadata.UniqueDocumentId
            );

            FotoWareProvider.HostServices.LogMessage(LoggingSeverity.Debug,
                string.Format("Searching archive {0} for search term: {1}", contextUri, searchTerm)
            );

            List<IContentLibraryListItem> results = new List<IContentLibraryListItem>();

            int? archive = null;
            bool isLastPage = false;
            bool? hasMoreResults;
            bool includeFileInfo = false;
            bool includeMetadata = true; // required for unique document
            bool canUpload = CanGetUploadMultimediaItemsUrl(contextUri.PublicationId);
            bool canSearch = CanSearch(contextUri.PublicationId);

            if(contextUri.ItemType.HasFlag(EclItemTypes.MountPoint))
            {
                // for mountpoints, aggregate results from archives by passing a null reference
                archive = null;
            }
            else
            {
                // for archives, search only within the archive
                int parentId;
                if(int.TryParse(contextUri.ItemId, out parentId))
                {
                    archive = parentId;
                }

                // TODO: process auto-generated search folders

            }

            var items = FotoWareProvider.Client.GetSearchResults(archive, searchTerm, numberOfItems, pageIndex, includeFileInfo, includeMetadata, out hasMoreResults);
            if (hasMoreResults.HasValue)
            {
                isLastPage = !hasMoreResults.Value;
            }
            results.AddRange(items.ConvertAll(Model.Asset.FromXml));

            foreach(Model.Asset asset in results)
            {
                asset.ParentId = contextUri;
                asset.Id = FotoWareProvider.HostServices.CreateEclUri(
                    publicationId: contextUri.PublicationId,
                    mountPointId: contextUri.MountPointId,
                    itemId: asset.UniqueId,
                    subType: Model.Asset.DisplayTypeIdentifier,
                    itemType: EclItemTypes.File
                );
                FotoWareProvider.HostServices.LogMessage(LoggingSeverity.Debug,
                    string.Format("Asset {0} ({1}) has ECL URI {2}",
                        asset.Title,
                        asset.InternalId,
                        asset.Id)
                );
            }
            return FotoWareProvider.HostServices.CreateFolderContent(contextUri, pageIndex, isLastPage, results, canUpload, canSearch);
        }
Exemplo n.º 53
0
        private List<IContentLibraryListItem> GetRootFolderContent(IEclUri parentFolderUri)
        {
            FotoWareProvider.HostServices.LogMessage(LoggingSeverity.Debug, "Getting root folder content.");

            List<IContentLibraryListItem> result = new List<IContentLibraryListItem>();
            var archives = FotoWareProvider.Client.GetArchives();

            FotoWareProvider.HostServices.LogMessage(LoggingSeverity.Debug, string.Format("Retrieved {0} archives from FotoWeb", archives.Count));
            result.AddRange(archives.ConvertAll(Model.Archive.FromXml));
            FotoWareProvider.HostServices.LogMessage(LoggingSeverity.Debug, string.Format("Converted {0} archives to ECL folders", result.Count));

            foreach (Model.Archive archive in result)
            {
                archive.Id = FotoWareProvider.HostServices.CreateEclUri(
                    publicationId: parentFolderUri.PublicationId,
                    mountPointId: parentFolderUri.MountPointId,
                    itemId: archive.InternalId,
                    subType: Model.Archive.DisplayTypeIdentifier,
                    itemType: EclItemTypes.Folder
                );
                FotoWareProvider.HostServices.LogMessage(LoggingSeverity.Debug,
                    string.Format("Archive {0} ({1}) has ECL URI {2}",
                        archive.Title,
                        archive.InternalId,
                        archive.Id)
                );
            }
            return result;
        }
Exemplo n.º 54
0
 public string GetUploadMultimediaItemsUrl(IEclUri parentFolderUri)
 {
     FotoWareProvider.HostServices.LogMessage(
         LoggingSeverity.Debug,
         string.Format("Getting upload URL for folder {0}", parentFolderUri)
     );
     throw new NotImplementedException();
 }
Exemplo n.º 55
0
 public string TryGetTcmUriFromEclUri(IEclUri eclUri)
 {
     throw new NotImplementedException();
 }
        private string ImportSingleItem(IEclUri eclUri)
        {
            string id = "tcm:0-0-0";
            IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem)_eclContentLibraryContext.GetItem(eclUri);
            string extension = eclItem.Filename.Substring(eclItem.Filename.LastIndexOf('.') + 1);
            MemoryStream ms = null;
            string tempPath;
            try
            {
                // create some template attributes
                IList<ITemplateAttribute> attributes = CreateTemplateAttributes(eclItem);

                // determine if item has content or is available online
                string publishedPath = eclItem.GetDirectLinkToPublished(attributes);
                if (string.IsNullOrEmpty(publishedPath))
                {
                    // we can directly get the content 
                    IContentResult content = eclItem.GetContent(attributes);
                    ms = new MemoryStream();
                    content.Stream.CopyTo(ms);
                    ms.Position = 0;
                }
                else
                {
                    // read the content from the publish path
                    using (WebClient webClient = new WebClient())
                    {
                        byte[] thumbnailData = webClient.DownloadData(publishedPath);
                        ms = new MemoryStream(thumbnailData, false);
                    }
                }

                // upload binary (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) 
                using (StreamUploadClient suClient = new StreamUploadClient("streamUpload_netTcp_2012"))
                {
                    tempPath = suClient.UploadBinaryContent(eclItem.Filename, ms);
                }
            }
            finally
            {
                if (ms != null)
                {
                    ms.Dispose();
                }
            }

            // create tcm item
            var mmComponent = new ComponentData
            {
                Id = id,
                Title = eclItem.Title,
                Schema = new LinkToSchemaData { IdRef = _schemaUri },
                LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = _folderUri } }
            };

            // put binary data in tcm item (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) 
            using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012"))
            {
                // impersonate with current user
                client.Impersonate(_username);

                // set metadata
                var schemaFields = client.ReadSchemaFields(_schemaUri, true, new ReadOptions());
                if (schemaFields.MetadataFields.Any())
                {
                    var fields = Fields.ForMetadataOf(schemaFields, mmComponent);
                    if (!string.IsNullOrEmpty(eclItem.MetadataXml))
                    {
                        XNamespace ns = GetNamespace(eclItem.MetadataXml);
                        XDocument metadata = XDocument.Parse(eclItem.MetadataXml);
                        var children = metadata.Element(ns + "Metadata").Descendants();
                        for (int i = 0; i < children.Count(); i++)
                        {
                            fields.AddFieldElement(new ItemFieldDefinitionData { Name = "data" });
                            var embeddedFields = fields["data"].GetSubFields(i);
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "key" });
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "value" });
                            embeddedFields["key"].Value = children.ElementAt(i).Name.LocalName;
                            embeddedFields["value"].Value = children.ElementAt(i).Value;
                        }
                    }
                    mmComponent.Metadata = fields.ToString();
                }

                // find multimedia type
                var list = client.GetSystemWideList(new MultimediaTypesFilterData());
                var multimediaType = list.OfType<MultimediaTypeData>().Single(mt => mt.FileExtensions.Contains(extension));

                // set BinaryContent of a component
                mmComponent.BinaryContent = new BinaryContentData
                {
                    UploadFromFile = tempPath,
                    Filename = eclItem.Filename,
                    MultimediaType = new LinkToMultimediaTypeData { IdRef = multimediaType.Id }
                };

                // create (and save) component
                ComponentData data = (ComponentData)client.Create(mmComponent, new ReadOptions());
                id = data.Id;
            }

            //string result = string.Format("created {0}, from {1}, in {2}, using {3}, for {4}", id, eclUri, _folderUri, _schemaUri, _username);
            return id;
        }
Exemplo n.º 57
0
 public string GetViewItemUrl(IEclUri eclUri)
 {
     FotoWareProvider.HostServices.LogMessage(
         LoggingSeverity.Debug,
         string.Format("Getting preview URL for item {0}", eclUri)
     );
     string result = null;
     switch (eclUri.SubType)
     {
         case Model.Asset.DisplayTypeIdentifier:
             var uniqueId = GetUniqueDocumentIdFromEclUri(eclUri);
             var previewSize = new int[] { 2048 };
             var assets = GetAssetsByMetadataValue(API.SearchFields.Metadata.UniqueDocumentId, uniqueId, previewSize);
             if(assets!=null && assets.Count > 0)
             {
                 var asset = assets.FirstOrDefault();
                 var preview = asset != null && asset.Previews != null ? asset.Previews.FirstOrDefault() : null;
                 result = preview != null ? preview.Url.AbsoluteUri : null;
             }
             break;
         default:
             throw new NotImplementedException();
     }
     return result;
 }
Exemplo n.º 58
0
 public bool IsNullOrNullEclUri(IEclUri eclUri)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 59
0
 public IFolderContent CreateFolderContent(IEclUri parentUri, IList<IContentLibraryListItem> childItems, bool canGetUploadMultimediaItemsUrl, bool canSearch)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 60
0
        public byte[] GetThumbnailImage(IEclUri eclUri, int maxWidth, int maxHeight)
        {
            FotoWareProvider.HostServices.LogMessage(
                LoggingSeverity.Debug,
                string.Format("Getting thumbnail for item {0}", eclUri)
            );

            byte[] result = null;
            Uri thumbnailURL = null;

            switch(eclUri.ItemType)
            {
                case EclItemTypes.File:
                    string uniqueId = GetUniqueDocumentIdFromEclUri(eclUri);
                    var previewSizes = new int[] { maxWidth };
                    var assets = GetAssetsByMetadataValue(API.SearchFields.Metadata.UniqueDocumentId, uniqueId);
                    if(assets!=null && assets.Count > 0)
                    {
                        var asset = assets.FirstOrDefault();
                        var preview = asset != null && asset.Previews != null ? asset.Previews.FirstOrDefault() : null;
                        thumbnailURL = preview != null ? preview.Url : null;
                    }
                    break;
                default:
                    throw new NotImplementedException();
            }

            if(thumbnailURL!=null)
            {
                result = FotoWareProvider.Client.GetByteArrayAsync(thumbnailURL).Result;
            }
            return result;
        }