示例#1
0
        public void CanPostCutCopyPasteEvent()
        {
            // Arrange
            var log = new CutCopyPasteEvent
            {
                SenderId      = 1,
                SolutionName  = "Dummy Solution",
                EventActionId = (int)CutCopyPasteActions.Copy,
                CourseId      = 1,
                DocumentName  = "dummy document",
                Content       = "dummy content"
            };

            // Act
            var result = Posts.SaveEvent(log);

            // Assert
            using (var connection = new SqlConnection(StringConstants.ConnectionString))
            {
                var savedlog =
                    connection.Query <CutCopyPasteEvent>(
                        @"select b.EventLogId, a.EventTypeId, b.Content, a.SenderId, b.SolutionName, b.DocumentName, a.CourseId, EventActionId=b.EventAction
                            from EventLogs a
                            inner join CutCopyPasteEvents b on b.EventLogId=a.Id and a.Id=@id",
                        new { @Id = result }).SingleOrDefault();

                Assert.IsTrue(savedlog != null);
                Assert.IsTrue(savedlog.SenderId == log.SenderId);
                Assert.IsTrue(savedlog.EventType == log.EventType);
                Assert.IsTrue(savedlog.EventActionId == log.EventActionId);
                Assert.IsTrue(savedlog.SolutionName == log.SolutionName);
                Assert.IsTrue(savedlog.DocumentName == log.DocumentName);
                Assert.IsTrue(savedlog.Content == log.Content);
                Assert.IsTrue(savedlog.CourseId == log.CourseId);
            }
        }
示例#2
0
        public static IActivityEvent FromCommand(string commandName, DTE2 dte)
        {
            IActivityEvent oEvent = null;

            //debugging events
            if (DebugCommands.Contains(commandName))
            {
                var action = (DebugActions)Enum.Parse(typeof(DebugActions), commandName.Split('.')[1]);
                var debug  = new DebugEvent
                {
                    SolutionName = dte.Solution.FullName,
                };

                //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();
                        var 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)
                {
                    var debugWindow = dte.ToolWindows.OutputWindow.OutputWindowPanes.Item("Debug");
                    if (debugWindow != null)
                    {
                        var text      = debugWindow.TextDocument;
                        var selection = text.Selection;
                        selection.StartOfDocument();
                        selection.EndOfDocument(true);
                        debug.DebugOutput = selection.Text;
                        selection.EndOfDocument();
                    }
                }

                oEvent = debug;
            }
            else if (CutCopyPasteCommands.Contains(commandName))
            {
                var ccp = new CutCopyPasteEvent
                {
                    SolutionName  = dte.Solution.FullName,
                    EventActionId = (int)Enum.Parse(typeof(CutCopyPasteActions), commandName.Split('.')[1]),
                    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);
        }