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 static int WriteLogEntries(this DebugSession debugSession, int lastLogMessageId = -1)
        {
            int startId = -1;

            if (lastLogMessageId != -1)
            {
                startId = lastLogMessageId + 1;
            }

            if (debugSession != null)
            {
                XElement logXml = XElement.Parse(debugSession.GetLogMessagesXml(-1, startId, -1));

                foreach (XElement logEntry in logXml.Descendants(templateDebuggingNamespace + "log"))
                {
                    startId = int.Parse(logEntry.Attribute("id").Value);

                    TraceEventType logType;
                    Enum.TryParse <TraceEventType>(logEntry.Attribute("type").Value, true, out logType);

                    Logger.Log(logType, logEntry.Value);
                }
            }

            return(startId);
        }
        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 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()
            };
        }