示例#1
0
        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);
            }
        }