Esempio n. 1
0
        /// <summary>
        /// Execute the template transformation with the given parameters
        /// </summary>
        /// <param name="itemUri">Tridion item URI.</param>
        /// <param name="templateUri">Tridion template URI.</param>
        /// <param name="publicationTargetUri">Tridion publication target URI.</param>
        /// <param name="logLevel">Log level.</param>
        /// <returns>Package "Output" item as <see cref="T:System.String" /></returns>
        public override String Execute(String itemUri, String templateUri, String publicationTargetUri = null)
        {
            String       sessionId    = Guid.NewGuid().ToString();
            DebugSession debugSession = null;

            try
            {
                String templateXml = mCompoundService.GetCompoundTemplateXml(templateUri);

                debugSession = new DebugSession(sessionId,
                                                templateUri,
                                                templateXml,
                                                itemUri,
                                                null,
                                                true,
                                                publicationTargetUri,
                                                DebuggerConfig.Instance.Templating.EnableImpersonation && !String.IsNullOrEmpty(DebuggerConfig.Instance.Templating.ImpersonationIdentity) ?
                                                DebuggerConfig.Instance.Templating.ImpersonationIdentity : WindowsIdentity.GetCurrent().Name,
                                                DebuggerConfig.Instance.Logging.IncludeTridionClasses,
                                                DebuggerConfig.Instance.Logging.Level);

                debugSession.SetPreviewLocations(
                    DebuggerConfig.Instance.CMS.PreviewDirectory,
                    PreviewServer.PreviewUrl);

                // Signal for any debuggers
                DebuggerHook();

                debugSession.Start();

                int lastMessageId = -1;

                while (debugSession.IsRunning())
                {
                    Thread.Sleep(1000);

                    lastMessageId = debugSession.WriteLogEntries(lastMessageId);
                }

                String postPackage      = debugSession.GetPostPackageName();
                String outputItemDataId = debugSession.GetPackageItemDataId(postPackage, "Output");

                return(debugSession.GetPackageItemString(outputItemDataId));
            }
            catch (Exception ex)
            {
                Logger.Log(System.Diagnostics.TraceEventType.Error, "Exception while executing DebugEngine for item {0}, template {1}: {2}", itemUri, templateUri, LoggerExtensions.TraceException(ex));
            }
            finally
            {
                if (debugSession != null)
                {
                    debugSession.Stop();
                }
            }

            return(String.Empty);
        }
        /// <summary>
        /// Execute the template transformation with the given parameters
        /// </summary>
        /// <param name="itemUri">Tridion item URI.</param>
        /// <param name="templateUri">Tridion template URI.</param>
        /// <param name="publicationTargetUri">Tridion publication target URI.</param>
        /// <param name="logLevel">Log level.</param>
        /// <returns>Package "Output" item as <see cref="T:System.String" /></returns>
        public override String Execute(String itemUri, String templateUri, String publicationTargetUri = null)
        {
            String sessionId = Guid.NewGuid().ToString();
            DebugSession debugSession = null;

            try
            {
                String templateXml = mCompoundService.GetCompoundTemplateXml(templateUri);

                debugSession = new DebugSession(sessionId,
                    templateUri,
                    templateXml,
                    itemUri,
                    null,
                    true,
                    publicationTargetUri,
                    DebuggerConfig.Instance.Templating.EnableImpersonation && !String.IsNullOrEmpty(DebuggerConfig.Instance.Templating.ImpersonationIdentity) ?
                        DebuggerConfig.Instance.Templating.ImpersonationIdentity : WindowsIdentity.GetCurrent().Name,
                    DebuggerConfig.Instance.Logging.IncludeTridionClasses,
                    DebuggerConfig.Instance.Logging.Level);

                debugSession.SetPreviewLocations(
                    DebuggerConfig.Instance.CMS.PreviewDirectory,
                    PreviewServer.PreviewUrl);

                // Signal for any debuggers
                DebuggerHook();

                debugSession.Start();

                int lastMessageId = -1;

                while (debugSession.IsRunning())
                {
                    Thread.Sleep(1000);

                    lastMessageId = debugSession.WriteLogEntries(lastMessageId);
                }

                String postPackage = debugSession.GetPostPackageName();
                String outputItemDataId = debugSession.GetPackageItemDataId(postPackage, "Output");

                return debugSession.GetPackageItemString(outputItemDataId);
            }
            catch (Exception ex)
            {
                Logger.Log(System.Diagnostics.TraceEventType.Error, "Exception while executing DebugEngine for item {0}, template {1}: {2}", itemUri, templateUri, LoggerExtensions.TraceException(ex));
            }
            finally
            {
                if (debugSession != null)
                    debugSession.Stop();
            }

            return String.Empty;
        }