コード例 #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Nạp CSDL để biết những khả năng đổi tên mình có thể

            var prototype1 = new ReplaceOperation()
            {
                Args = new ReplaceArgs()
                {
                    From = "From",
                    To   = "To"
                }
            };

            var prototype2 = new NewCaseOperation()
            {
                Args = new NewCaseArgs()
                {
                    Value = NewCaseStringValue.Lowercase
                }
            };
            var prototype3 = new NameNormalizeOperation()
            {
                Args = new NameNormalizeArg()
                {
                    From = "From",
                    To   = "To"
                }
            };
            var prototype4 = new MoveOperation()
            {
                Args = new MoveArgs()
                {
                    Length = " ",
                    Des    = " ",
                    Start  = " ",
                }
            };
            var prototype5 = new UniqueNameOperation()
            {
                Args = new UniqueNameArgs()
                {
                    From = "",
                    To   = "",
                }
            };

            _prototypes.Add(prototype1);
            _prototypes.Add(prototype2);
            _prototypes.Add(prototype3);
            _prototypes.Add(prototype4);
            _prototypes.Add(prototype5);
            ActionsListView.ItemsSource   = _prototypes;
            operationsListBox.ItemsSource = _actions;
        }
コード例 #2
0
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            _actions.Clear();
            // open file dialog
            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog()
            {
                InitialDirectory = @"D:\",
                Title            = "Browse Text Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt       = "txt",
                Filter           = "txt files (*.txt)|*.txt",
                FilterIndex      = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly    = true
            };

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // get filename
                string filename = openFileDialog1.FileName;

                // read all lines in filename
                List <string> lines = new List <string>();
                InputOutput.ReadFromFile(filename, ref lines);

                // each line, parse arguments to corresponding action and create new action
                foreach (var line in lines)
                {
                    try
                    {
                        List <string> tokens = new List <string>();
                        if (InputOutput.SplitString(line, ref tokens) == 0)
                        {
                            string actionName = tokens[0];
                            tokens.Remove(tokens[0]);
                            List <string> actionArguments = tokens;
                            if (actionName == "Move")
                            {
                                var action3 = new MoveOperation()
                                {
                                    Args = new MoveArgs()
                                    {
                                        Start = tokens[0],

                                        Length = tokens[1],
                                        Des    = tokens[2],
                                    }
                                };
                                var action4 = action3 as StringOperation;

                                _actions.Add(action4.Clone());
                            }
                            if (actionName == "NameNormalize")
                            {
                                var action3 = new NameNormalizeOperation()
                                {
                                    Args = new NameNormalizeArg()
                                    {
                                        From = "",
                                        To   = "",
                                    }
                                };
                                var action4 = action3 as StringOperation;

                                _actions.Add(action4.Clone());
                            }
                            if (actionName == "UniqueName")
                            {
                                var action3 = new UniqueNameOperation()
                                {
                                    Args = new UniqueNameArgs()
                                    {
                                        From = "",
                                        To   = "",
                                    }
                                };
                                var action4 = action3 as StringOperation;

                                _actions.Add(action4.Clone());
                            }
                            if (actionName == "Replace")
                            {
                                var Action3 = new ReplaceOperation()
                                {
                                    Args = new ReplaceArgs()
                                    {
                                        From = tokens[0],
                                        To   = tokens[1],
                                        Area = tokens[2],
                                    }
                                };
                                var action4 = Action3 as StringOperation;
                                _actions.Add(action4.Clone());
                            }
                            if (actionName == "NewCase")
                            {
                                var Action3 = new NewCaseOperation()
                                {
                                    Args = new NewCaseArgs()
                                    {
                                        Value = tokens[0],
                                    }
                                };
                                var action4 = Action3 as StringOperation;
                                _actions.Add(action4.Clone());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }