Ejemplo n.º 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //load operations to prototype to show in combobox
            var prototype1 = new Replace()
            {
                Arguments = new ReplaceArguments()
                {
                    oldPattern = "old",
                    newPattern = "new"
                }
            };

            var prototype2 = new NewCase()
            {
                Arguments = new NewCaseArguments()
                {
                    isUpper    = 1,
                    isLower    = 0,
                    isSentence = 0
                }
            };

            var prototype3 = new Normalize()
            {
                Arguments = new NormalizeArguments()
                {
                }
            };

            var prototype4 = new MoveCharacters()
            {
                Arguments = new MoveCharactersArguments()
                {
                    numbersOfChar = 3,
                    isToFirst     = 0,
                    isToLast      = 1
                }
            };

            var prototype5 = new GUIDGenerate()
            {
                Arguments = new GUIDGenerateArguments()
                {
                }
            };

            _prototypes.Add(prototype1);
            _prototypes.Add(prototype2);
            _prototypes.Add(prototype3);
            _prototypes.Add(prototype4);
            _prototypes.Add(prototype5);

            comboBoxToChooseOperations.ItemsSource   = _prototypes;
            comboBoxToChooseOperations.SelectedIndex = 0;

            listBoxOperations.ItemsSource = readyLoadOper;
        }
Ejemplo n.º 2
0
        //load preset(template of a chain of operations) in a simple txt file
        private void loadPresetButton(object sender, RoutedEventArgs e)
        {
            while (readyLoadOper.Count > 0) //reset listbox
            {
                readyLoadOper.RemoveAt(0);
            }

            var screen = new CommonOpenFileDialog(); // show dialog to chose directory

            screen.IsFolderPicker = false;           //file pick option

            if (screen.ShowDialog() == CommonFileDialogResult.Ok)
            {
                try
                {
                    string[] lines = File.ReadAllLines(screen.FileName);
                    foreach (var line in lines)
                    {
                        const string Separator = "|";
                        string[]     tokens    = line.Split(new string[] { Separator }, StringSplitOptions.RemoveEmptyEntries);

                        if (tokens[0] == "Replace")
                        {
                            Replace          item = new Replace();
                            ReplaceArguments args = new ReplaceArguments()
                            {
                                oldPattern = tokens[1], newPattern = tokens[2]
                            };
                            item.Arguments = args;

                            readyLoadOper.Add(item.Clone());
                        }
                        else
                        if (tokens[0] == "Move")
                        {
                            var item = new MoveCharacters();
                            var args = new MoveCharactersArguments()
                            {
                                numbersOfChar = Convert.ToInt32(tokens[1]), isToLast = Convert.ToInt32(tokens[2]), isToFirst = Convert.ToInt32(tokens[3])
                            };
                            item.Arguments = args;

                            readyLoadOper.Add(item.Clone());
                        }
                        else
                        if (tokens[0] == "GUID")
                        {
                            var item = new GUIDGenerate();
                            var args = new GUIDGenerateArguments();
                            item.Arguments = args;

                            readyLoadOper.Add(item.Clone());
                        }
                        else
                        if (tokens[0] == "Normalize")
                        {
                            var item = new Normalize();
                            var args = new NormalizeArguments();
                            item.Arguments = args;

                            readyLoadOper.Add(item.Clone());
                        }
                        else
                        {
                            var item = new NewCase();
                            var args = new NewCaseArguments()
                            {
                                isUpper = Convert.ToInt32(tokens[1]), isLower = Convert.ToInt32(tokens[2]), isSentence = Convert.ToInt32(tokens[3])
                            };
                            item.Arguments = args;

                            readyLoadOper.Add(item.Clone());
                        }
                    }
                }
                catch (Exception error)
                {
                    // thong bao loi.
                    MessageBox.Show("Error when open file!");
                    MessageBox.Show(error.Message);
                }
            }
        }