示例#1
0
        public void BeginEndBulkOperationTest()
        {
            CollectionChangedEventArgs args = null;

            var collection = new BulkObservableCollection <int>();

            collection.CollectionChanged += (sender, e) => args = e;

            collection.BeginBatch();
            collection.Add(1);
            Assert.IsNull(args);
            collection.Add(2);
            Assert.IsNull(args);
            collection.EndBatch();
            Assert.IsNotNull(args);

            args = null;
            collection.BeginBatch();
            collection.AddRange(new[] { 1, 2, 3 });
            Assert.IsNull(args);
            collection.Add(4);
            Assert.IsNull(args);
            collection.Remove(4);
            Assert.IsNull(args);
            collection.Insert(0, 5);
            Assert.IsNull(args);
            collection.Move(0, 1);
            Assert.IsNull(args);
            collection.RemoveAt(0);
            Assert.IsNull(args);
            collection.Clear();
            Assert.IsNull(args);
            collection.EndBatch();
            Assert.IsNotNull(args);
        }
示例#2
0
        private void Update()
        {
            if (debuggerService.State != DebuggerState.Running)
            {
                var frames = debuggerService.Machine.GetStackFrames();

                stackFrames.BeginBulkOperation();
                try
                {
                    stackFrames.Clear();

                    for (int i = 0; i < frames.Length; i++)
                    {
                        var  frame         = frames[i];
                        uint jumpToAddress = 0;
                        if (i == 0)
                        {
                            jumpToAddress = (uint)debuggerService.Machine.PC;
                        }
                        else
                        {
                            jumpToAddress = frames[i - 1].ReturnAddress;
                        }

                        stackFrames.Add(new StackFrameViewModel(frame, routineService.RoutineTable, jumpToAddress));
                    }
                }
                finally
                {
                    stackFrames.EndBulkOperation();
                }
            }
        }
示例#3
0
        static void FillCompletionList(AsyncServerMessage.CompleteWord msg, BulkObservableCollection <Completion> completions)
        {
            foreach (var elem in msg.completionList)
            {
                switch (elem)
                {
                case CompletionElem.Literal literal:
                    completions.Add(new NitraCompletion(literal.text, literal.text, "literal", null, null));
                    break;

                case CompletionElem.Symbol symbol:
                    completions.Add(new NitraCompletion(symbol.name, symbol.name, symbol.description, null, null));
                    break;
                }
            }
        }
示例#4
0
        public void AddRangeTest()
        {
            CollectionChangedEventArgs args = null;

            var collection = new BulkObservableCollection <int>();

            collection.CollectionChanged += (sender, e) => args = e;

            collection.Add(1);
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
            Assert.AreEqual(1, args.NewItems.Count);
            Assert.AreEqual(1, args.NewItems[0]);

            args = null;
            collection.AddRange(new[] { 2, 3, 4, 5 });
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
            Assert.AreEqual(4, args.NewItems.Count);
            Assert.AreEqual(2, args.NewItems[0]);
            Assert.AreEqual(5, args.NewItems[3]);
            Assert.AreEqual(5, collection.Count);

            args = null;
            collection.AddRange(new[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
            Assert.AreEqual(10, args.NewItems.Count);
            Assert.AreEqual(6, args.NewItems[0]);
            Assert.AreEqual(15, args.NewItems[9]);
            Assert.AreEqual(15, collection.Count);
        }
示例#5
0
        private void UpdateAnalyzers()
        {
            if (_analyzerItems == null)
            {
                // The set of AnalyzerItems hasn't been realized yet. Just signal that HasItems
                // may have changed.

                NotifyPropertyChanged(nameof(HasItems));
                return;
            }

            var project = _analyzersFolder.Workspace.CurrentSolution.GetProject(
                _analyzersFolder.ProjectId
                );

            if (project != null && project.AnalyzerReferences != _analyzerReferences)
            {
                _analyzerReferences = project.AnalyzerReferences;

                _analyzerItems.BeginBulkOperation();

                var itemsToRemove = _analyzerItems
                                    .Where(item => !_analyzerReferences.Contains(item.AnalyzerReference))
                                    .ToArray();

                var referencesToAdd = GetFilteredAnalyzers(_analyzerReferences, project)
                                      .Where(r => !_analyzerItems.Any(item => item.AnalyzerReference == r))
                                      .ToArray();

                foreach (var item in itemsToRemove)
                {
                    _analyzerItems.Remove(item);
                }

                foreach (var reference in referencesToAdd)
                {
                    _analyzerItems.Add(
                        new AnalyzerItem(
                            _analyzersFolder,
                            reference,
                            _commandHandler.AnalyzerContextMenuController
                            )
                        );
                }

                var sorted = _analyzerItems
                             .OrderBy(item => item.AnalyzerReference.Display)
                             .ToArray();
                for (var i = 0; i < sorted.Length; i++)
                {
                    _analyzerItems.Move(_analyzerItems.IndexOf(sorted[i]), i);
                }

                _analyzerItems.EndBulkOperation();

                NotifyPropertyChanged(nameof(HasItems));
            }
        }
示例#6
0
        public void OperationCollapseTest()
        {
            var argsList   = new List <CollectionChangedEventArgs>();
            var collection = new BulkObservableCollection <int>();

            collection.CollectionChanged += (sender, e) => argsList.Add(e);

            collection.BeginBatch();
            collection.Add(1);                      //  \
            collection.Add(2);                      //   > collapse into 1 add
            collection.Add(3);                      //  /
            collection.Remove(1);                   //  \
            collection.Remove(2);                   //   > collapse into 1 remove
            collection.Remove(3);                   //  /
            collection.AddRange(new[] { 1, 2, 3 }); //  \
            collection.Add(4);                      //   > collapse into 1 add
            collection.AddRange(new[] { 5, 6, 7 }); //  /
            collection.Remove(7);                   //  \
            collection.Remove(6);                   //   > collapse into 1 clear
            collection.Clear();                     //  /
            collection.Add(1);                      //  \
            collection.Add(2);                      //   > collapse into 1 add
            collection.Add(3);                      //  /
            collection[0] = 1337;                   // no collapse
            collection.Remove(1337);                // no collapse
            collection.Move(0, 1);                  // no collapse
            collection.Clear();                     // no collapse
            Assert.AreEqual(0, argsList.Count);
            collection.EndBatch();

            Assert.AreEqual(9, argsList.Count);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[0].Action);
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, argsList[0].NewItems);

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, argsList[1].Action);
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, argsList[1].OldItems);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[2].Action);
            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6, 7 }, argsList[2].NewItems);

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, argsList[3].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[4].Action);
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, argsList[4].NewItems);

            Assert.AreEqual(NotifyCollectionChangedAction.Replace, argsList[5].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, argsList[6].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Move, argsList[7].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, argsList[8].Action);
        }
示例#7
0
        //private void MemoryChanged(object sender, MemoryEventArgs e)
        //{
        //    // Replace affected lines
        //    int firstLineIndex = e.Address / 16;
        //    int lastLineIndex = (e.Address + e.Length) / 16;

        //    var reader = e.Memory.CreateReader(firstLineIndex * 16);

        //    for (int i = firstLineIndex; i <= lastLineIndex; i++)
        //    {
        //        var address = reader.Address;
        //        var count = Math.Min(8, reader.RemainingBytes);
        //        var values = reader.NextWords(count);

        //        lines[i] = new MemoryLineViewModel(address, values);
        //    }

        //    // TODO: Highlight modified memory
        //}

        private void StoryService_StoryOpened(object sender, StoryOpenedEventArgs e)
        {
            var reader = new MemoryReader(e.Story.Memory, 0);

            lines.BeginBulkOperation();
            try
            {
                while (reader.RemainingBytes > 0)
                {
                    var address = reader.Address;

                    ushort[] values;

                    if (reader.RemainingBytes >= 16 || reader.RemainingBytes % 2 == 0)
                    {
                        var count = Math.Min(8, reader.RemainingBytes / 2);
                        values = reader.NextWords(count);
                    }
                    else
                    {
                        // if the last line is an odd number of bytes...

                        // TODO: memory view always shows even number of bytes
                        // (padding with zeroes if necessry). Need to fix it to show odd
                        // number of bytes if that's the case.
                        var valueList = new List <ushort>();
                        while (reader.RemainingBytes > 0)
                        {
                            if (reader.RemainingBytes > 2)
                            {
                                valueList.Add(reader.NextWord());
                            }
                            else
                            {
                                valueList.Add((ushort)(reader.NextByte() << 8));
                            }
                        }

                        values = valueList.ToArray();
                    }

                    lines.Add(new MemoryLineViewModel(address, values));
                }
            }
            finally
            {
                lines.EndBulkOperation();
            }

            PropertyChanged("HasStory");
        }
示例#8
0
        private void StoryService_StoryOpened(object sender, StoryOpenedEventArgs e)
        {
            objects.BeginBulkOperation();
            try
            {
                foreach (var obj in e.Story.ObjectTable)
                {
                    objects.Add(new ObjectViewModel(obj));
                }
            }
            finally
            {
                objects.EndBulkOperation();
            }

            PropertyChanged("HasStory");
        }
示例#9
0
        private void AddNewLog(string fullName)
        {
            if (logs.Any(x => x.FileInfo.FullName == fullName))
            {
                return;
            }

            if (!LogCache.TryGetLogData(fullName, out var log))
            {
                log = new LogData(new FileInfo(fullName));
            }

            if (log.ParsingStatus != ParsingStatus.Parsed)
            {
                LogDataProcessor.Schedule(log);
            }

            logs.Add(log);
        }
示例#10
0
        private void Update()
        {
            if (debuggerService.State != DebuggerState.Running)
            {
                var frames = debuggerService.Machine.GetStackFrames();

                stackFrames.BeginBulkOperation();
                try
                {
                    stackFrames.Clear();

                    foreach (var frame in frames)
                    {
                        stackFrames.Add(new StackFrameViewModel(frame, routineService.RoutineTable));
                    }
                }
                finally
                {
                    stackFrames.EndBulkOperation();
                }
            }
        }
示例#11
0
        public void AddTest()
        {
            CollectionChangedEventArgs args = null;

            var collection = new BulkObservableCollection <int>();

            collection.CollectionChanged += (sender, e) => args = e;

            for (int i = 0; i < 50; i++)
            {
                args = null;
                collection.Add(i);
                Assert.IsNotNull(args);
                Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
                Assert.AreEqual(1, args.NewItems.Count);
                Assert.AreEqual(i, args.NewItems[0]);
                Assert.AreEqual(i, args.NewIndex);
                Assert.AreEqual(0, args.OldItems.Count);
                Assert.IsNull(args.OldIndex);
                Assert.AreEqual(i + 1, collection.Count);
            }
        }
示例#12
0
 public void SendError(string message)
 {
     messages.Add(MessageViewModel.CreateError(message));
 }
示例#13
0
        private void DebuggerService_MachineCreated(object sender, MachineCreatedEventArgs e)
        {
            var reader = new MemoryReader(storyService.Story.Memory, 0);

            DisassemblyLineViewModel ipLine;

            lines.BeginBulkOperation();
            try
            {
                var routineTable = routineService.RoutineTable;

                for (int rIndex = 0; rIndex < routineTable.Count; rIndex++)
                {
                    var routine = routineTable[rIndex];

                    if (rIndex > 0)
                    {
                        var lastRoutine = routineTable[rIndex - 1];
                        if (lastRoutine.Address + lastRoutine.Length < routine.Address)
                        {
                            var addressGapLine = new DisassemblyAddressGapLineViewModel(lastRoutine, routine)
                            {
                                ShowBlankBefore = true
                            };

                            lines.Add(addressGapLine);
                        }
                    }

                    var routineHeaderLine = new DisassemblyRoutineHeaderLineViewModel(routine)
                    {
                        ShowBlankBefore = rIndex > 0,
                        ShowBlankAfter  = true
                    };

                    routineAddressAndIndexList.Add(new AddressAndIndex(routineHeaderLine.Address, lines.Count));
                    lines.Add(routineHeaderLine);
                    addressToLineMap.Add(routine.Address, routineHeaderLine);

                    var instructions = routine.Instructions;
                    var lastIndex    = instructions.Length - 1;
                    for (int i = 0; i <= lastIndex; i++)
                    {
                        var instruction     = instructions[i];
                        var instructionLine = new DisassemblyInstructionLineViewModel(instruction, i == lastIndex);

                        if (breakpointService.Exists(instruction.Address))
                        {
                            instructionLine.HasBreakpoint = true;
                        }

                        lines.Add(instructionLine);
                        addressToLineMap.Add(instruction.Address, instructionLine);
                    }
                }

                ipLine       = GetLineByAddress(debuggerService.Machine.PC);
                ipLine.HasIP = true;
            }
            finally
            {
                lines.EndBulkOperation();
            }

            BringLineIntoView(ipLine);

            routineService.RoutineTable.RoutineAdded += RoutineTable_RoutineAdded;
        }