private static void Main(string[] args) { // Default execution options Options options = new Options() { Mode = EngineMode.Debugger, ItemURI = null, TemplateURI = null, PublicationTargetURI = null }; InitializeConsole(); if (Parser.Default.ParseArguments(args, options)) { LegacyInterface legacyInterface = null; try { using (new PreviewServer()) { // Initialize TcmDebugger.COM legacyInterface = new LegacyInterface(); legacyInterface.SetProvider(new LegacyProvider()); switch (options.Mode) { case EngineMode.LocalServer: using (new CompoundTemplateService2011()) { Logger.Log(System.Diagnostics.TraceEventType.Information, "Press any key to exit."); Console.ReadKey(); } break; case EngineMode.Debugger: case EngineMode.Publisher: if (String.IsNullOrEmpty(options.ItemURI)) throw new Exception("ItemUri is required for Debugger or Publisher engines"); if (!TcmUri.IsValid(options.ItemURI)) throw new Exception(String.Format("Invalid tcm uri {0}", options.ItemURI)); TcmUri tcmItemUri = new TcmUri(options.ItemURI); if (tcmItemUri.ItemType != ItemType.Page || options.Mode != EngineMode.Publisher) { if (String.IsNullOrEmpty(options.TemplateURI)) throw new Exception("Template tcm uri is required for non-page type objects or debug engine"); if (!TcmUri.IsValid(options.TemplateURI)) throw new Exception(String.Format("Invalid template tcm uri {0}", options.TemplateURI)); } if (!String.IsNullOrEmpty(options.PublicationTargetURI) && !TcmUri.IsValid(options.PublicationTargetURI)) throw new Exception(String.Format("Invalid publication target tcm uri {0}", options.TemplateURI)); Engine engine = null; switch (options.Mode) { case EngineMode.Debugger: engine = new Engines.DebugEngine(); break; case EngineMode.Publisher: engine = new RenderEngine(); break; } String output = engine.Execute(options.ItemURI, options.TemplateURI, options.PublicationTargetURI); output += ""; Console.WriteLine(); Console.WriteLine("{0} [!] {1}", DateTime.Now.ToString("HH:mm:ss"), "Execution finished. Press any key to exit."); Console.ReadKey(); break; } } } catch (Exception ex) { Logger.Log(System.Diagnostics.TraceEventType.Error, ex.Message); } finally { if (legacyInterface != null) Marshal.ReleaseComObject(legacyInterface); } } }
private ActionResult GetView(string itemUri, string templateUri, string path) { using (new PreviewServer()) { DebugEngine engine = new DebugEngine(); string output = engine.Execute(itemUri, templateUri); //now Engine and Template instances are created return View(path); } }
private static void Main(string[] args) { // Default execution options Options options = new Options() { Mode = EngineMode.Debugger, ItemURI = null, TemplateURI = null, PublicationTargetURI = null }; InitializeConsole(); if (Parser.Default.ParseArguments(args, options)) { LegacyInterface legacyInterface = null; try { using (new PreviewServer()) { // Initialize TcmDebugger.COM legacyInterface = new LegacyInterface(); legacyInterface.SetProvider(new LegacyProvider()); switch (options.Mode) { case EngineMode.LocalServer: using (new CompoundTemplateService2011()) { Logger.Log(System.Diagnostics.TraceEventType.Information, "Press any key to exit."); Console.ReadKey(); } break; case EngineMode.Debugger: case EngineMode.Publisher: if (String.IsNullOrEmpty(options.ItemURI)) { throw new Exception("ItemUri is required for Debugger or Publisher engines"); } if (!TcmUri.IsValid(options.ItemURI)) { throw new Exception(String.Format("Invalid tcm uri {0}", options.ItemURI)); } TcmUri tcmItemUri = new TcmUri(options.ItemURI); if (tcmItemUri.ItemType != ItemType.Page || options.Mode != EngineMode.Publisher) { if (String.IsNullOrEmpty(options.TemplateURI)) { throw new Exception("Template tcm uri is required for non-page type objects or debug engine"); } if (!TcmUri.IsValid(options.TemplateURI)) { throw new Exception(String.Format("Invalid template tcm uri {0}", options.TemplateURI)); } } if (!String.IsNullOrEmpty(options.PublicationTargetURI) && !TcmUri.IsValid(options.PublicationTargetURI)) { throw new Exception(String.Format("Invalid publication target tcm uri {0}", options.TemplateURI)); } Engine engine = null; switch (options.Mode) { case EngineMode.Debugger: engine = new Engines.DebugEngine(); break; case EngineMode.Publisher: engine = new RenderEngine(); break; } String output = engine.Execute(options.ItemURI, options.TemplateURI, options.PublicationTargetURI); output += ""; Console.WriteLine(); Console.WriteLine("{0} [!] {1}", DateTime.Now.ToString("HH:mm:ss"), "Execution finished. Press any key to exit."); Console.ReadKey(); break; } } } catch (Exception ex) { Logger.Log(System.Diagnostics.TraceEventType.Error, ex.Message); } finally { if (legacyInterface != null) { Marshal.ReleaseComObject(legacyInterface); } } } }