public void Execute(object parameter) { var values = (object[])parameter; var showSections = (bool)values[0]; var menueAction = (string)values[1]; if (menueAction == "menuIniNew") { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Text Files|*.txt"; if (dialog.ShowDialog() != true) { return; } FileName = dialog.FileName; } var _textFile = new StreamReader(FileName); var tree = new TreeLogic(); tree.ShowSections = showSections; string line; string matchViews; string matchPartitionsPath; char[] trim = { ' ' }; try { while ((line = _textFile.ReadLine()) != null) { line = line.TrimEnd(trim); matchViews = Regex.Match(line, "ViewsToDisplay: ?(.+)").Groups[1].Value; matchPartitionsPath = Regex.Match(line, "PartitionsFile: ?(.+)").Groups[1].Value; if (!String.IsNullOrEmpty(matchViews)) { Enum.TryParse(matchViews, out ViewEnum viewMode); vm.SelectView(viewMode); } else if (!String.IsNullOrEmpty(matchPartitionsPath)) { Task4.TextReader text = new Task4.TextReader(matchPartitionsPath); MemoryPartitionsParser mpp = new MemoryPartitionsParser(text.Text); vm.PopulatePartitionsTree(mpp.GetMemoryPartitions()); } else { string[] words = line.Split(','); tree.AddStructure(words); } } vm.PopulateTree(tree.Root); } catch { MessageBox.Show("Incorrect file format!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void ParseText_ShouldntFindSelectionPartitionInIncorrectText(string text) { //Arrange //Act MemoryPartitionsParser mpp = new MemoryPartitionsParser(text); //Assert Assert.Equal <IMemorySection>(new List <IMemorySection>(), mpp.GetMemoryPartitions()); Assert.True(mpp.GetMemoryPartitions().Count == 0); }
public void ParseText_ShouldFindSelectionPartitionInText() { //Arrange string text = @"/* MPU region: ram__dspr0__VP_D */ /* .StartAddress = */ (uint32)BeginOf_ram__dspr0__VP_D, /* PRQA S 0306 */ /* MD_Os_Hal_Rule11.4_0306 */ /* .EndAddress = */ (uint32)EndOf_ram__dspr0__VP_D /* PRQA S 0306 */ /* MD_Os_Hal_Rule11.4_0306 */"; IMemorySection newPartition = new MemorySection <string>("ram__dspr0__VP_D", "BeginOf_ram__dspr0__VP_D", "EndOf_ram__dspr0__VP_D", false); //Act MemoryPartitionsParser mpp = new MemoryPartitionsParser(text); //Assert Assert.True(mpp.GetMemoryPartitions().Count == 1); Assert.Contains <IMemorySection>(newPartition, mpp.GetMemoryPartitions()); }