Beispiel #1
0
        IOsbideEvent IOsbideEvent.FromDict(Dictionary <string, object> values)
        {
            DebugEvent evt = new DebugEvent();

            if (values.ContainsKey("Id"))
            {
                evt.Id = (int)values["Id"];
            }
            if (values.ContainsKey("EventLogId"))
            {
                evt.EventLogId = (int)values["EventLogId"];
            }
            if (values.ContainsKey("EventLog"))
            {
                evt.EventLog = (EventLog)values["EventLog"];
            }
            if (values.ContainsKey("EventDate"))
            {
                evt.EventDate = (DateTime)values["EventDate"];
            }
            if (values.ContainsKey("SolutionName"))
            {
                evt.SolutionName = values["SolutionName"].ToString();
            }
            if (values.ContainsKey("ExecutionAction"))
            {
                evt.ExecutionAction = (int)values["ExecutionAction"];
            }
            if (values.ContainsKey("DocumentName"))
            {
                evt.DocumentName = values["DocumentName"].ToString();
            }
            if (values.ContainsKey("LineNumber"))
            {
                evt.LineNumber = (int)values["LineNumber"];
            }
            if (values.ContainsKey("DebugOutput"))
            {
                evt.DebugOutput = values["DebugOutput"].ToString();
            }
            return(evt);
        }
Beispiel #2
0
        public static IOsbideEvent FromCommand(string commandName, DTE2 dte)
        {
            IOsbideEvent oEvent = null;

            //debugging events
            if (debugCommands.Contains(commandName))
            {
                DebugActions action = (DebugActions)debugCommands.IndexOf(commandName);
                DebugEvent   debug  = new DebugEvent();
                debug.SolutionName = dte.Solution.FullName;
                debug.EventDate    = DateTime.UtcNow;

                //sometimes document name can be null
                try
                {
                    debug.DocumentName = dte.ActiveDocument.Name;
                }
                catch (Exception)
                {
                    debug.DocumentName = dte.Solution.FullName;
                }

                //add line number if applicable
                if (action == DebugActions.StepInto ||
                    action == DebugActions.StepOut ||
                    action == DebugActions.StepOver
                    )
                {
                    //line number can be null if there is no document open
                    try
                    {
                        TextSelection debugSelection = dte.ActiveDocument.Selection;
                        debugSelection.SelectLine();
                        int lineNumber = debugSelection.CurrentLine;
                        debug.LineNumber  = lineNumber;
                        debug.DebugOutput = debugSelection.Text;
                    }
                    catch (Exception)
                    {
                        debug.LineNumber = 0;
                    }
                }

                //kind of reappropriating this for our current use.  Consider refactoring.
                debug.ExecutionAction = (int)action;

                //throw the content of the output window into the event if we just stopped debugging
                if (action == DebugActions.StopDebugging)
                {
                    OutputWindowPane debugWindow = dte.ToolWindows.OutputWindow.OutputWindowPanes.Item("Debug");
                    if (debugWindow != null)
                    {
                        TextDocument  text      = debugWindow.TextDocument;
                        TextSelection selection = text.Selection;
                        selection.StartOfDocument();
                        selection.EndOfDocument(true);
                        debug.DebugOutput = selection.Text;
                        selection.EndOfDocument();
                    }
                }

                oEvent = debug;
            }
            else if (cutCopyPasteCommands.Contains(commandName))
            {
                CutCopyPasteEvent ccp = new CutCopyPasteEvent();
                ccp.SolutionName = dte.Solution.FullName;
                ccp.EventDate    = DateTime.UtcNow;
                ccp.EventAction  = cutCopyPasteCommands.IndexOf(commandName);
                ccp.Content      = Clipboard.GetText();
                //sometimes document name can be null
                try
                {
                    ccp.DocumentName = dte.ActiveDocument.Name;
                }
                catch (Exception)
                {
                    ccp.DocumentName = dte.Solution.FullName;
                }
                oEvent = ccp;
            }

            return(oEvent);
        }