/// <summary> /// Load the <see cref="T:System.Reflection.Assembly" /> specified by the filename /// </summary> /// <param name="fileName">Assembly filename</param> /// <returns>Loaded <see cref="T:System.Reflection.Assembly" /> or null</returns> /// <remarks>Additionally loads the assembly symbols (.pdb) if available</remarks> private static Assembly LoadAssembly(String fileName) { String file = Path.GetFileNameWithoutExtension(fileName); String filePath = Path.Combine(mBasePath, file + ".dll"); String pdbPath = Path.Combine(mBasePath, file + ".pdb"); // Verify if a full filename was given if (File.Exists(fileName)) { filePath = fileName; pdbPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(fileName) + ".pdb"); } if (File.Exists(filePath)) { Byte[] assemblyContent = File.ReadAllBytes(filePath); if (File.Exists(pdbPath)) { Byte[] symbolsContent = File.ReadAllBytes(pdbPath); mLogger.Info("Loading templating debug assembly {0}.", file + ".dll", file + ".pdb"); return(Assembly.Load(assemblyContent, symbolsContent)); } else { mLogger.Info("Loading templating debug assembly {0}.", file + ".dll"); return(Assembly.Load(assemblyContent)); } } return(null); }
public static TcmUri GetLocalUri(TcmUri uriPublication, TcmUri uriItem) { TcmUri uriReturn = new TcmUri(uriItem.ItemId, uriItem.ItemType, uriPublication.ItemId); TemplatingLogger log = TemplatingLogger.GetLogger(typeof(TemplateUtilities)); log.Info("(getLocalUri)Old URI was:" + uriItem.ToString()); log.Info("(getLocalUri)New URI is:" + uriReturn.ToString()); return(uriReturn); }
/// <summary> /// Log an information message /// </summary> /// <param name="format">Message format string</param> /// <param name="ex">Associated exception to output</param> /// <param name="args">Format string parameters</param> public static void Info(this TemplatingLogger logger, String format, Exception ex, params Object[] args) { if (logger != null) { logger.Info(String.Format("{0}\n{1}", String.Format(format, args), TraceException(ex))); } }
/// <summary> /// Log an information message /// </summary> /// <param name="format">Message / Message format string</param> /// <param name="args">Format string parameters</param> public static void Info(this TemplatingLogger logger, String format, params Object[] args) { if (logger != null) { logger.Info(String.Format(format, args)); } }
/// <summary> /// Log an information message /// </summary> /// <param name="message">The message to log</param> /// <param name="ex">Associated exception to output</param> public static void Info(this TemplatingLogger logger, String message, Exception ex) { if (logger != null) { logger.Info(String.Format("{0}\n{1}", message, TraceException(ex))); } }
public void Transform(Engine engine, Package package) { TemplatingLogger log = TemplatingLogger.GetLogger(GetType()); RepositoryLocalObject context; if (package.GetByName(Package.PageName) != null) { context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.PageName)); log.Debug("Setting context to page with ID " + context.Id); } else { log.Info("This template building block should only run on a page. Exiting."); return; } if (!(context is Page)) { return; } Page page = (Page)context; package.PushItem(SiteEditPageContext, package.CreateStringItem(ContentType.Text, page.OwningRepository.Id)); package.PushItem(SiteEditPublishContext, package.CreateStringItem(ContentType.Text, page.ContextRepository.Id)); if (page.ComponentPresentations.Count <= 0) { return; } Component component = page.ComponentPresentations[0].Component; package.PushItem(SiteEditComponentContext, package.CreateStringItem(ContentType.Text, component.OwningRepository.Id)); }
public void Transform(Engine engine, Package package) { TemplatingLogger log = TemplatingLogger.GetLogger(GetType()); if (package.GetByName(Package.PageName) == null) { log.Info("Do not use this template building block in Component Templates"); return; } Page page = (Page)engine.GetObject(package.GetByName(Package.PageName)); string output; if (page.Title.ToLower().Contains("index")) { output = StripNumbersFromTitle(page.OrganizationalItem.Title); } else { output = GetLinkToSgIndexPage((StructureGroup)page.OrganizationalItem, engine.GetSession()) + Separator + StripNumbersFromTitle(page.Title); } foreach (OrganizationalItem parent in page.OrganizationalItem.GetAncestors()) { output = GetLinkToSgIndexPage((StructureGroup)parent, engine.GetSession()) + Separator + output; } package.PushItem("breadcrumb", package.CreateStringItem(ContentType.Html, output)); }
public void Transform(Engine engine, Package package) { TemplatingLogger log = TemplatingLogger.GetLogger(GetType()); if (package.GetByName(Package.ComponentName) == null) { log.Info("This template should only be used with Component Templates. Could not find component in package, exiting"); return; } var c = (Component)engine.GetObject(package.GetByName(Package.ComponentName)); var container = (Folder)c.OrganizationalItem; var filter = new OrganizationalItemItemsFilter(engine.GetSession()) { ItemTypes = new[] { ItemType.Component } }; // Always faster to use GetListItems if we only need limited elements foreach (XmlNode node in container.GetListItems(filter)) { string componentId = node.Attributes["ID"].Value; string componentTitle = node.Attributes["Title"].Value; } // If we need more info, use GetItems instead foreach (Component component in container.GetItems(filter)) { // If your filter is messed up, GetItems will return objects that may // not be a Component, in which case the code will blow up with an // InvalidCastException. Be careful with filter.ItemTypes[] Schema componentSchema = component.Schema; SchemaPurpose purpose = componentSchema.Purpose; XmlElement content = component.Content; } }
/// <summary> /// Resolves the absolute URI from the base and relative URIs. /// </summary> /// <param name="baseUri">The base URI used to resolve the relative URI.</param> /// <param name="relativeUri">The URI to resolve. The URI can be absolute or relative. If absolute, this value effectively replaces the <paramref name="baseUri" /> value. If relative, it combines with the <paramref name="baseUri" /> to make an absolute URI.</param> /// <returns> /// A <see cref="T:System.Uri" /> representing the absolute URI, or null if the relative URI cannot be resolved. /// </returns> public override Uri ResolveUri(Uri baseUri, String relativeUri) { mTemplatingLogger.Info("ResolveUri: baseUri '{0}', relativeUri: '{1}'.", baseUri, relativeUri); if (relativeUri.StartsWith("/webdav", StringComparison.OrdinalIgnoreCase)) { return(new Uri("webdav:" + relativeUri)); } return(base.ResolveUri(baseUri, relativeUri)); }
public static Publication GetPublicationFromContext(Package package, Engine engine) { TemplatingLogger log = TemplatingLogger.GetLogger(typeof(TridionUtils)); Publication myPublication = null; Item contextItem = package.GetByName("Page"); if (contextItem != null) { log.Info("(GetPublicationFromContext) Retrieving for context publication from the Page"); TcmUri uriDataSource = new TcmUri(contextItem.GetAsSource().GetValue("ID")); Page mycontextItem = engine.GetObject(uriDataSource) as Page; myPublication = (Publication)mycontextItem.ContextRepository; } else { log.Info("(GetPublicationFromContext) Retrieving for context publication from the Component"); contextItem = package.GetByName("Component"); TcmUri uriDataSource = new TcmUri(contextItem.GetAsSource().GetValue("ID")); Component mycontextItem = engine.GetObject(uriDataSource) as Component; myPublication = (Publication)mycontextItem.ContextRepository; } log.Info("(GetPublicationFromContext) Context publication is:" + myPublication.Title); return(myPublication); }
// ReSharper disable MethodOverloadWithOptionalParameter public void Info(string message) { _logger.Info(message); }
/// <summary> /// Logs a Info message /// </summary> /// <param name="message">Message</param> public void Info(String message) { mTemplatingLogger.Info(message); }
public Binary PublishBinary(Component mComponent, Session session, Package package, Engine engine, TemplatingLogger logger, string strFileName) { string rootFolderId = package.GetValue("RootFolder"); string rootSGId = package.GetValue("RootStructureGroup"); logger.Debug(string.Format("Using root Structure Group with Webdav Url: {0}", rootFolderId)); Folder rootFolder = session.GetObject(rootFolderId) as Folder; StructureGroup parentSG = session.GetObject(rootSGId) as StructureGroup; Stack <string> sgNames = new Stack <string>(); GetStructureGroupToBeCreated(mComponent.OrganizationalItem, rootFolder.Id, sgNames); OrganizationalItemItemsFilter sgFilter = new OrganizationalItemItemsFilter(session); sgFilter.Recursive = false; sgFilter.ItemTypes = new Tridion.ContentManager.ItemType[] { Tridion.ContentManager.ItemType.StructureGroup }; //string strCoreServicesUrl = package.GetValue("CoreServicesUrl"); while (sgNames.Count > 0) { string sgName = sgNames.Pop(); IEnumerable <StructureGroup> list = parentSG.GetItems(sgFilter). Where(w => w.Title.Equals(sgName)).Select(s => (StructureGroup)s); if (list.Count() == 0) { /* * TO DO: Enable tha auto creation of the Structure Group * StructureGroupData newSG = SaveStructureGroup(sgName, parentSG.Id.ToString(), session.User.Title, strCoreServicesUrl); * parentSG = new StructureGroup(new TcmUri(newSG.Id), session); * * logger.Debug(string.Format("New Structure Group needs {0} created at: {1}", newSG.Title, parentSG.Path)); * */ logger.Info(string.Format("Utilities.PublishBinary New Structure Group needs {0} created at: {1}", parentSG.Title, parentSG.Path)); } else { StructureGroup existingSG = list.First <StructureGroup>(); logger.Info(string.Format("Utilities.PublishBinary Existing Structure Group {0} found at: {1}", existingSG.Title, existingSG.Path)); parentSG = existingSG; } } Binary binary = null; if (strFileName == null) { binary = engine.PublishingContext.RenderedItem.AddBinary(mComponent, parentSG, mComponent.BinaryContent.Filename); } else { MemoryStream msStream = new MemoryStream(); mComponent.BinaryContent.WriteToStream(msStream); msStream.Seek(0, SeekOrigin.Begin); binary = engine.PublishingContext.RenderedItem.AddBinary(msStream, strFileName, parentSG, strFileName.Replace(" ", string.Empty), "text/xml"); } logger.Debug(string.Format("Binary {0} being published to {1}", mComponent.BinaryContent.Filename, parentSG.PublishLocationUrl)); return(binary); }
public Binary PublishBinary(Component mComponent, Session session, Package package, Engine engine, TemplatingLogger logger, string strFileName) { string rootFolderId = package.GetValue("RootFolder"); string rootSGId = package.GetValue("RootStructureGroup"); logger.Debug(string.Format("Using root Structure Group with Webdav Url: {0}", rootFolderId)); Folder rootFolder = session.GetObject(rootFolderId) as Folder; StructureGroup parentSG = session.GetObject(rootSGId) as StructureGroup; Stack<string> sgNames = new Stack<string>(); GetStructureGroupToBeCreated(mComponent.OrganizationalItem, rootFolder.Id, sgNames); OrganizationalItemItemsFilter sgFilter = new OrganizationalItemItemsFilter(session); sgFilter.Recursive = false; sgFilter.ItemTypes = new Tridion.ContentManager.ItemType[] { Tridion.ContentManager.ItemType.StructureGroup }; //string strCoreServicesUrl = package.GetValue("CoreServicesUrl"); while (sgNames.Count > 0) { string sgName = sgNames.Pop(); IEnumerable<StructureGroup> list = parentSG.GetItems(sgFilter). Where(w => w.Title.Equals(sgName)).Select(s => (StructureGroup)s); if (list.Count() == 0) { /* * TO DO: Enable tha auto creation of the Structure Group StructureGroupData newSG = SaveStructureGroup(sgName, parentSG.Id.ToString(), session.User.Title, strCoreServicesUrl); parentSG = new StructureGroup(new TcmUri(newSG.Id), session); logger.Debug(string.Format("New Structure Group needs {0} created at: {1}", newSG.Title, parentSG.Path)); * */ logger.Info(string.Format("Utilities.PublishBinary New Structure Group needs {0} created at: {1}", parentSG.Title, parentSG.Path)); } else { StructureGroup existingSG = list.First<StructureGroup>(); logger.Info(string.Format("Utilities.PublishBinary Existing Structure Group {0} found at: {1}", existingSG.Title, existingSG.Path)); parentSG = existingSG; } } Binary binary = null; if (strFileName == null) { binary = engine.PublishingContext.RenderedItem.AddBinary(mComponent, parentSG, mComponent.BinaryContent.Filename); } else { MemoryStream msStream = new MemoryStream(); mComponent.BinaryContent.WriteToStream(msStream); msStream.Seek(0, SeekOrigin.Begin); binary = engine.PublishingContext.RenderedItem.AddBinary(msStream, strFileName, parentSG, strFileName.Replace(" ", string.Empty), "text/xml"); } logger.Debug(string.Format("Binary {0} being published to {1}", mComponent.BinaryContent.Filename, parentSG.PublishLocationUrl)); return binary; }