public DebuggingStatusResult GetDebuggingState(String debuggerSessionId, String lastLogMessageId)
        {
            int logId = -1;

            if (!int.TryParse(lastLogMessageId, out logId))
            {
                logId = -1;
            }

            if (logId != -1)
            {
                logId++;
            }

            String logMessages = mDebugSession.GetLogMessagesXml(-1, logId, -1);

            WriteLog(logMessages);

            return(new DebuggingStatusResult()
            {
                SessionId = mSessionId,
                IsRunning = mDebugSession.IsRunning(),
                ExecutionStatus = StripXmlDeclaration(mDebugSession.GetExecutionStatusXml()),
                Log = StripXmlDeclaration(logMessages),
                Error = mDebugSession.GetLastException()
            });
        }
        public DebuggingStatusResult StartDebuggingWithItemUri(String compoundTemplateId, String compoundTemplateXml, String itemId, bool includeSystemLog, System.Diagnostics.TraceEventType logLevel)
        {
            try
            {
                mDebugSession = new DebugSession(mSessionId,
                                                 compoundTemplateId,
                                                 compoundTemplateXml,
                                                 itemId,
                                                 null,
                                                 true,
                                                 "tcm:0-0-0",
                                                 DebuggerConfig.Instance.Templating.EnableImpersonation && !String.IsNullOrEmpty(DebuggerConfig.Instance.Templating.ImpersonationIdentity) ?
                                                 DebuggerConfig.Instance.Templating.ImpersonationIdentity : WindowsIdentity.GetCurrent().Name,
                                                 includeSystemLog,
                                                 logLevel);

                // Signal for any debuggers
                DebuggerHook();

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

                mDebugSession.Start();
            }
            catch (Exception ex)
            {
                Logger.Log(System.Diagnostics.TraceEventType.Error, LoggerExtensions.TraceException(ex));
            }

            String logMessages = mDebugSession.GetLogMessagesXml(-1, -1, -1);

            WriteLog(logMessages);

            return(new DebuggingStatusResult()
            {
                SessionId = mSessionId,
                IsRunning = mDebugSession.IsRunning(),
                ExecutionStatus = StripXmlDeclaration(mDebugSession.GetExecutionStatusXml()),
                Log = StripXmlDeclaration(logMessages),
                Error = mDebugSession.GetLastException()
            });
        }
        public static String GetPostPackageName(this DebugSession debugSession)
        {
            if (debugSession != null)
            {
                XElement statusXml = XElement.Parse(debugSession.GetExecutionStatusXml());

                XElement lastInvocationXml = statusXml.Descendants(templateDebuggingNamespace + "Invocation").LastOrDefault();

                if (lastInvocationXml != null)
                {
                    XAttribute postPackageAttribute = lastInvocationXml.Attribute("PostPackage");

                    if (postPackageAttribute != null)
                    {
                        return(postPackageAttribute.Value);
                    }
                }
            }

            return(String.Empty);
        }
        public DebuggingStatusResult StartDebuggingWithPackage(String compoundTemplateId, String compoundTemplateXml, String packageXml, bool includeSystemLog, System.Diagnostics.TraceEventType logLevel)
        {
            try
            {
                mDebugSession = new DebugSession(mSessionId,
                    compoundTemplateId,
                    compoundTemplateXml,
                    null,
                    packageXml,
                    true,
                    "tcm:0-0-0",
                    DebuggerConfig.Instance.Templating.EnableImpersonation && !String.IsNullOrEmpty(DebuggerConfig.Instance.Templating.ImpersonationIdentity) ?
                        DebuggerConfig.Instance.Templating.ImpersonationIdentity : WindowsIdentity.GetCurrent().Name,
                    DebuggerConfig.Instance.Logging.IncludeTridionClasses,
                    logLevel);

                // Signal for any debuggers
                DebuggerHook();

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

                mDebugSession.Start();
            }
            catch (Exception ex)
            {
                Logger.Log(System.Diagnostics.TraceEventType.Error, LoggerExtensions.TraceException(ex));
            }

            String logMessages = mDebugSession.GetLogMessagesXml(-1, -1, -1);
            WriteLog(logMessages);

            return new DebuggingStatusResult()
            {
                SessionId = mSessionId,
                IsRunning = mDebugSession.IsRunning(),
                ExecutionStatus = StripXmlDeclaration(mDebugSession.GetExecutionStatusXml()),
                Log = StripXmlDeclaration(logMessages),
                Error = mDebugSession.GetLastException()
            };
        }