/// <summary> /// Wraps around the original RunTemplate in order to load debug classes when required /// </summary> /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param> /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package"/></param> /// <param name="templateUri"><see cref="T:Tridion.ContentManager.CommunicationManagement.Template"/></param> /// <param name="className">Class to execute</param> /// <remarks> /// The wrapper tries to load the specified class from available assemblies in the following order: /// 1) Assemblies configured as debug assemblies in the application configuration /// 2) Assemblies loaded in the application domain /// 3) Assembly with the same name as the template present in the application directory /// 4) Assembly stored in the Tridion database (default behavior of Tridion) /// </remarks> public static void RunTemplateWrapper(Engine engine, Package package, String templateUri, String className) { ITemplate template = null; // Try and obtain the requested template from the loaded debug assemblies template = GetTemplate(mDebugAssemblies, className); if (template != null) { mLogger.Info("Loaded {0} from debug assembly {1}.dll", className, template.GetType().Assembly.GetName().Name); template.Transform(engine, package); return; } // Try and obtain the requested template from the assemblies already loaded in the application domain template = GetTemplate(AppDomain.CurrentDomain.GetAssemblies(), className); if (template != null) { mLogger.Info("Loaded {0} from appdomain assembly {1}.dll", className, template.GetType().Assembly.GetName().Name); template.Transform(engine, package); return; } // Try and load the template specified assembly from local disk Template tridionTemplate = engine.GetObject(templateUri) as Template; if (tridionTemplate != null && tridionTemplate.TemplateType == "AssemblyTemplate" && tridionTemplate.BinaryContent != null) { Assembly assembly = LoadAssembly(tridionTemplate.BinaryContent.Filename); if (assembly != null) { template = GetTemplate(new Assembly[] { assembly }, className); if (template != null) { mLogger.Info("Loaded {0} from local assembly {1}.dll", className, template.GetType().Assembly.GetName().Name); template.Transform(engine, package); return; } } } // Run the original Tridion defined RunTemplate functionality CSharpSourceCodeMediator.RunTemplate(engine, package, templateUri, className); }
/// <summary> /// Initializes a new instance of the <see cref="WrappedCSharpMediator"/> class. /// </summary> public WrappedCSharpMediator() { mOriginalMediator = new CSharpSourceCodeMediator(); }