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)); }
public void Dispose() { if (_eclSession != null) { _eclSession.Dispose(); _eclSession = null; } }
/// <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); }
/// <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="uri"><see cref="Tridion.ExternalContentLibrary.V2.IEclUri" /></param> public S3ListItem(S3Provider provider, IEclSession session, IEclUri uri) { Provider = provider; Session = session; ParentId = provider.GetParentUri(uri); if (uri.ItemType == EclItemTypes.Folder) { _itemData = provider.S3.GetFolder(uri.ItemId); } else { _itemData = provider.S3.GetObject(uri.ItemId); } Id = provider.GetUri(_itemData, uri); }
public override IContentLibraryContext CreateContext(IEclSession tridionUser) { return(new FredhopperMountpoint()); }
/// <summary> /// Distill all useful information of a hyperlink string, and put the found data in a ParsedLinkInfo structure /// </summary> /// <param name="eclSession">The ECL Session provides access to the external items. </param> /// <param name="elementName">The name of the element being processed</param> /// <param name="hyperLinkText">The full tag to parse.</param> /// <param name="endStartTag">Within the hyperLinkText, where end-tag ends</param> /// <returns>A newly created ParsedLinkInfo object with all the found information filled out</returns> private ParsedLinkInfo ParseLinkInfo(IEclSession eclSession, string elementName, string hyperLinkText, int endStartTag) { string elementStartTagOpen = "<" + elementName; ParsedLinkInfo linkInfo = new ParsedLinkInfo(); // Determine hyperlink parts string startTag = hyperLinkText.Substring(0, endStartTag + 1); string startTagAttributes = hyperLinkText.Substring(elementStartTagOpen.Length, endStartTag - elementStartTagOpen.Length); linkInfo.LinkElementName = elementName; // Process attributes IDictionary<string, string> tridionAttributes = new Dictionary<string, string>(); linkInfo.RemainingAttributes = ParseTridionTagAttributes(startTagAttributes, tridionAttributes); // Determine target URI if (!tridionAttributes.ContainsKey(AttributeNameTridionHref)) { throw new InvalidDataException(string.Format("Could not find attribute {1} in tag {0}", startTag, "tridion:href")); } string tridionHrefValue = tridionAttributes[AttributeNameTridionHref]; string targetUriString = ProcessExpression(tridionHrefValue); // Check link URI and determine link-type if (targetUriString.StartsWith("ecl:")) { // resolve into stub uri targetUriString = eclSession.GetOrCreateTcmUriFromEclUri(eclSession.HostServices.CreateEclUri(targetUriString)); } if (!TcmUri.IsValid(targetUriString)) { throw new Exception(string.Format("Could not process href value '{0}' into uri", tridionHrefValue)); } linkInfo.TargetUri = new TcmUri(targetUriString); if (linkInfo.TargetUri.ItemType == ItemType.Page) { linkInfo.LinkType = AttributeTridionTypePage; } // Check for override of type in link itself if (tridionAttributes.ContainsKey(AttributeNameTridionType)) { linkInfo.LinkType = tridionAttributes[AttributeNameTridionType]; } // Check for anchor attribute if (tridionAttributes.ContainsKey(AttributeNameTridionAnchor)) { string anchorValue = ProcessExpression(tridionAttributes[AttributeNameTridionAnchor]); if (!String.IsNullOrEmpty(anchorValue)) { linkInfo.Anchor = anchorValue; } } // Output attribute (only for multimedia) if (tridionAttributes.ContainsKey(AttributeNameTargetAttribute)) { linkInfo.TargetAttribute = tridionAttributes[AttributeNameTargetAttribute]; } if ((linkInfo.LinkType == AttributeTridionTypeComponent) && String.IsNullOrEmpty(linkInfo.Anchor)) { // for component links where nothing is specified specifically do not add an anchor linkInfo.Anchor = "false"; } if (tridionAttributes.ContainsKey(AttributeNameTridionVariantid)) { linkInfo.VariantId = tridionAttributes[AttributeNameTridionVariantid]; } return linkInfo; }
internal FotoWareContext(IEclSession session) { this._session = session; }
public IContentLibraryContext CreateContext(IEclSession session) { HostServices.LogMessage(LoggingSeverity.Debug, string.Format("Creating context for session user {0} ({1})", session.TridionUser.FullName, session.TridionUser.Id)); return new FotoWareContext(session); }
/// <summary> /// Initializes a new instance of the <see cref="S3MountPoint"/> class. /// </summary> /// <param name="provider">Associated <see cref="S3Provider"/></param> /// <param name="session">The session.</param> public S3MountPoint(S3Provider provider, IEclSession session) { _provider = provider; _session = session; }
public abstract IContentLibraryContext CreateContext(IEclSession tridionUser);
public IContentLibraryContext CreateContext(IEclSession tridionUser) { return new Mountpoint(); }
/// <summary> /// Constructor. /// </summary> /// <param name="pipeline">The context Model Builder Pipeline.</param> internal ExternalContentLibrary(DataModelBuilderPipeline pipeline) { _pipeline = pipeline; _eclSession = SessionFactory.CreateEclSession(pipeline.Session); }
/// <summary> /// Initialize a new <see cref="S3Folder" /> /// </summary> /// <param name="provider">Associated <see cref="S3Provider"/></param> /// <param name="session">Current <see cref="T:Tridion.ExternalContentLibrary.V2.IEclSession"/></param> /// <param name="parentUri">Parent <see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" /></param> /// <param name="eclObject"><see cref="T:S3ECLProvider.API.S3ItemData"/></param> /// <remarks>Creating a <see cref="S3Folder" /> directly from an <see cref="Amazon.S3.Model.S3Object"/></remarks> public S3Folder(S3Provider provider, IEclSession session, IEclUri parentUri, S3ItemData eclObject) : base(provider, session, parentUri, eclObject) { }
/// <summary> /// Initialize a new <see cref="S3Folder" /> /// </summary> /// <param name="provider">Associated <see cref="S3Provider"/></param> /// <param name="session">Current <see cref="T:Tridion.ExternalContentLibrary.V2.IEclSession"/></param> /// <param name="uri"><see cref="T:Tridion.ExternalContentLibrary.V2.IEclUri" /></param> public S3Folder(S3Provider provider, IEclSession session, IEclUri uri) : base(provider, session, uri) { }
public S3MountPoint(IEclSession session) { _tridionUser = session.TridionUser; _session = session; }
public override IContentLibraryContext CreateContext(IEclSession tridionUser) { return(new DemandWareMountpoint()); }
protected virtual string GetECLUrl(string uri) { Component c = (Component)engine.GetObject(uri); if (c == null) { throw new Exception(string.Format("Error loading item with uri {0}", uri)); } log.Debug(System.Threading.Thread.CurrentThread.ManagedThreadId + ": Instantiating a new ECL Session"); using (IEclSession localSession = SessionFactory.CreateEclSession(engine.GetSession())) { IEclUri eclUri = localSession.TryGetEclUriFromTcmUri(uri); if (eclUri != null) // this is an ECL item { log.Debug(System.Threading.Thread.CurrentThread.ManagedThreadId + ": Fetching IContentLibraryContext"); using (IContentLibraryContext context = localSession.GetContentLibrary(eclUri)) { try { IContentLibraryMultimediaItem item = null; // This is done this way to not have an exception thrown through GetItem, as stated // in the API doc. // The reason to do this, is because if there is an exception, // the ServiceChannel is going into the aborted state... log.Debug(System.Threading.Thread.CurrentThread.ManagedThreadId + ": Get Items"); // GetItems allows up to 20 (depending on config) connections. // After that any new connection is aborted / not created. var items = context.GetItems(new IEclUri[] { eclUri }); if (items != null && items.Count == 1) { item = (IContentLibraryMultimediaItem)items.First(); log.Debug(System.Threading.Thread.CurrentThread.ManagedThreadId + ": Item Fetched"); } if (item == null) { log.Warning(System.Threading.Thread.CurrentThread.ManagedThreadId + ": Item with ECL URI: " + eclUri + " not found. This MM item is used in: " + c.Id); throw new Exception(string.Format("ECL item not found (ecl uri = {0}, tcm uri = {1}", eclUri, c.Id)); } string distributionUrl = item.GetDirectLinkToPublished(null); string result = distributionUrl.ToLower(); if (!string.IsNullOrEmpty(result)) { log.Debug(System.Threading.Thread.CurrentThread.ManagedThreadId + ": Returning: " + result); return(result); } } finally { log.Debug(System.Threading.Thread.CurrentThread.ManagedThreadId + ": Going out of the context using block statement."); } } } } return(string.Empty); }
/// <summary> /// Perform the actual function of this template, by iterating over all tags with tridion:href attributes in them and see if they belong to an ECL item. /// </summary> /// <param name="eclSession">The ECL Session provides access to the external items. </param> /// <param name="text">The text to process</param> /// <returns>The processed text (also stored in the member field)</returns> private string ResolveEclLinks(IEclSession eclSession, string text) { _text = text; string[] outputContainer = new[] { _text }; foreach (Match matchingElement in TemplateUtilities.GetRegexMatches(outputContainer, TridionHrefExpression)) { Log.Debug("Processing ECL link text"); outputContainer[0] = ProcessEclLink(eclSession, matchingElement); } // Process CSS references _text = ReplaceCssReferencesInText(eclSession, _text); return _text; }
public IContentLibraryContext CreateContext(IEclSession session) { return(new YouTubeMountPoint()); }
/// <summary> /// Perform the actual function of this template, by iterating over all tags with tridion:href attributes in them and see if they belong to an ECL item. /// </summary> /// <param name="eclSession">The ECL Session provides access to the external items. </param> /// <param name="document">The template document to process</param> private void ResolveEclLinks(IEclSession eclSession, XmlNode document) { XmlNodeList foundLinkNodes = TemplateUtilities.SelectNodes(document, "//*[@tridion:href]"); foreach (XmlNode foundLinkNode in foundLinkNodes) { Log.Debug(string.Format("Found link node: {0}", foundLinkNode.Name)); ParsedLinkInfo linkInfo = ParseLinkInfo(foundLinkNode); // check if link belongs to ECL item in package EclItemInPackage item; if (_eclItemsInPackage.TryGetValue(linkInfo.TargetUri, out item)) { string linkReplacementString = RenderEclItem(linkInfo, item); if (!string.IsNullOrEmpty(linkReplacementString)) { Log.Debug("Constructed link: " + linkReplacementString); // replacing the link node with the constructed output text ReplaceLinkNodeWithEclNode(foundLinkNode, linkReplacementString); } } } // Process the content (can be text-nodes or comments) of style-elements, replacing ECL URI references with published paths XmlNodeList styleElements = TemplateUtilities.SelectNodes(document, "//style|//html:style"); foreach (XmlNode styleElement in styleElements) { string styleContent = styleElement.InnerXml; styleContent = ReplaceCssReferencesInText(eclSession, styleContent); styleElement.InnerXml = styleContent; } }
public IContentLibraryContext CreateContext(IEclSession tridionUser) { return(new Mountpoint()); }
/// <summary> /// if tag belongs to an ECL item, replace it with the result from IContentLibraryMultimediaItem.GetTemplateFragment(attributes) /// The changes are made directly on the _text class member variable. /// </summary> /// <param name="eclSession">The ECL Session provides access to the external items. </param> /// <param name="matchingTag">A matching start-tag (so not the full tag) which contains at least a tridion:href attribute</param> /// <returns>The altered overall text</returns> private string ProcessEclLink(IEclSession eclSession, Match matchingTag) { Group foundMatch = matchingTag.Groups["tagwithlink"]; string elementName = matchingTag.Groups["tagname"].ToString(); int tagStartPosition; int tagLength; DetermineTagPositions(foundMatch, elementName, out tagStartPosition, out tagLength); // determine some more link positions string hyperLinkText = _text.Substring(tagStartPosition, tagLength); // ToDo: many text processing todo's here, but especially problematic is that no '>' is allowed in attribute values int endStartTag = hyperLinkText.IndexOf('>'); if (endStartTag == -1) { throw new InvalidDataException(string.Format("Tag '{0}' is not formatted correctly", hyperLinkText)); } // retrieve link information from the html tag fragment ParsedLinkInfo linkInfo = ParseLinkInfo(eclSession, elementName, hyperLinkText, endStartTag); // check if link belongs to ECL item in package EclItemInPackage item; if (_eclItemsInPackage.TryGetValue(linkInfo.TargetUri, out item)) { if (!string.IsNullOrEmpty(linkInfo.RemainingAttributes)) { // cleanup the xmlns:tridion attribute, if present linkInfo.RemainingAttributes = linkInfo.RemainingAttributes.Replace("xmlns:tridion="http://www.tridion.com/ContentManager/5.0"", string.Empty).Replace("xmlns:tridion=\"http://www.tridion.com/ContentManager/5.0\"", string.Empty); } string linkReplacementString = RenderEclItem(linkInfo, item); if (!string.IsNullOrEmpty(linkReplacementString)) { Log.Debug("Constructed link text: " + linkReplacementString); // alter the text output being processed, replacing the input link fragment by the constructed output text _text = _text.Substring(0, tagStartPosition) + linkReplacementString + _text.Substring(tagStartPosition + tagLength); } } return _text; }
internal EclProcessor(Engine engine, Tridion.ContentManager.TcmUri binariesStructureGroupId) { _engine = engine; _binariesStructureGroup = (binariesStructureGroupId == null) ? null : (StructureGroup)engine.GetObject(binariesStructureGroupId); _eclSession = SessionFactory.CreateEclSession(engine.GetSession()); }
/// <summary> /// Find all CSS URL references containing ECL URIs in an input text, and replace them with their string value. /// </summary> /// <param name="eclSession">The ECL Session provides access to the external items. </param> /// <param name="inputText">The text to process</param> /// <returns>The input, with CSS URL references containing ECL URIs replaced by their published paths (or error messages if they could not be resolved)</returns> private string ReplaceCssReferencesInText(IEclSession eclSession, string inputText) { string[] outputContainer = new[] { inputText }; foreach (Match matchingUrl in TemplateUtilities.GetRegexMatches(outputContainer, EclUriCssUrlExpression)) { Group eclUriGroup = matchingUrl.Groups["ecluri"]; string eclUri = eclUriGroup.ToString(); // Regex ensures this has the right format Log.Debug("Processing CSS URL reference for " + eclUri); if (eclUri.StartsWith("ecl:")) { eclUri = eclSession.GetOrCreateTcmUriFromEclUri(eclSession.HostServices.CreateEclUri(eclUri)); } if (!TcmUri.IsValid(eclUri)) { throw new Exception(string.Format("Could not process url value '{0}' into uri", eclUri)); } string targetUrl = eclUri; EclItemInPackage item; if (_eclItemsInPackage.TryGetValue(new TcmUri(eclUri), out item)) { // resolve (possibly publish) ECL item targetUrl = ResolveEclItem(item, new List<ITemplateAttribute>(), string.Empty, _targetStructureGroup); } inputText = inputText.Substring(0, eclUriGroup.Index) + targetUrl + inputText.Substring(eclUriGroup.Index + eclUriGroup.Length); outputContainer[0] = inputText; } return inputText; }
public IContentLibraryContext CreateContext(IEclSession eclSession) { return(new S3MountPoint(eclSession)); }
private void SetOrUpdateMetadata(Component subject, EventArgs args, EventPhases phase) { // quick first test for ECL stub Component if (!subject.Title.StartsWith("ecl:") || subject.ComponentType != ComponentType.Multimedia) { return; } using (IEclSession eclSession = SessionFactory.CreateEclSession(subject.Session)) { // determine if subject is an ECL stub Component from the list of available mountpoints IEclUri eclUri = eclSession.TryGetEclUriFromTcmUri(subject.Id); if (eclUri != null && MountPointIds.Contains(eclUri.MountPointId)) { // check if metadata field exists ItemFields metadataFields = new ItemFields(subject.Metadata, subject.MetadataSchema); if (metadataFields.Contains(_metadataXmlFieldName)) { // only set value when update is true or metadata is not set string metadata = ((SingleLineTextField)metadataFields[_metadataXmlFieldName]).Value; if (_update || string.IsNullOrEmpty(metadata)) { using (IContentLibraryContext context = eclSession.GetContentLibrary(eclUri)) { // load actual ECL item so you can access its properties and metadata IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem)context.GetItem(eclUri); try { // implement your custom code here to set the metadata value // currently this reads the configured ECL metadata field and sets its value in the stub metadata if (!string.IsNullOrEmpty(eclItem.MetadataXml)) { XNamespace ns = GetNamespace(eclItem.MetadataXml); XDocument eclMetadata = XDocument.Parse(eclItem.MetadataXml); XElement field = (from xml in eclMetadata.Descendants(ns + _metadataXmlFieldName) select xml).FirstOrDefault(); if (field != null) { string value = field.Value; // only save value when metadata is empty or update is true and value differs if (string.IsNullOrEmpty(metadata) || (_update && !metadata.Equals(value))) { // update metadata if (_asynchronous) { subject.CheckOut(); } ((SingleLineTextField)metadataFields[_metadataXmlFieldName]).Value = value; subject.Metadata = metadataFields.ToXml(); subject.Save(); if (_asynchronous) { subject.CheckIn(); } Logger.Write(string.Format("added {0} to metadata of {1}", value, eclUri), "EclStubComponentEventHandlerExtension", LoggingCategory.General, TraceEventType.Information); } } } } catch (Exception e) { Logger.Write(e, "EclStubComponentEventHandlerExtension", LoggingCategory.General); } } } } } } }