Esempio n. 1
0
        public void TextMatch()
        {
            Regex aRegex = new Regex(TextMatchPattern);

            TextMatchResult = aRegex.Matches(SampleText);
            LogController.Log($"文本匹配完成--{TextMatchPattern}");
        }
Esempio n. 2
0
        public void TextReplace()
        {
            Regex aRegex = new Regex(TextMatchPattern);

            TextReplaceResult = aRegex.Replace(SampleText, TextReplacePattern);
            LogController.Log($"文本替换完成--{TextReplacePattern}");
        }
Esempio n. 3
0
        private void OnAddPattern_Click(object sender, RoutedEventArgs e)
        {
            LogController.Log($"点击添加正则表达式按钮");

            _Model.AddPattern();
            ManagePopup.IsOpen = false;
        }
Esempio n. 4
0
        public void AddPattern()
        {
            RegexItem aRegexItem = new RegexItem();

            aRegexItem.RegexText  = PopupRegexPattern;
            aRegexItem.CreateTime = PopupTime;
            aRegexItem.Intro      = PopupIntro;
            if (PopupRegexType == "TextMatch")
            {
                aRegexItem.RegexType = "TextMatch";
                TextMatchRegexList.Add(aRegexItem);
            }
            else if (PopupRegexType == "TextReplace")
            {
                aRegexItem.RegexType = "TextReplace";
                TextReplaceRegexList.Add(aRegexItem);
            }
            else if (PopupRegexType == "FileMatch")
            {
                aRegexItem.RegexType = "FileMatch";
                FileMatchRegexList.Add(aRegexItem);
            }
            else if (PopupRegexType == "FileReplace")
            {
                aRegexItem.RegexType = "FileReplace";
                FileReplaceRegexList.Add(aRegexItem);
            }
            else
            {
                return;
            }
            LogController.Log($"添加表达式--{PopupRegexPattern}");
        }
Esempio n. 5
0
 private void OnSave_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         LogController.Log("保存文件");
         SaveFileDialog aDlg = new SaveFileDialog();
         if (aDlg.ShowDialog() != true)
         {
             return;
         }
         if (e.Parameter is string)
         {
             File.WriteAllText(aDlg.FileName, e.Parameter as string);
             LogController.Log($"写入样本文件--{aDlg.FileName}");
         }
         else if (e.Parameter is MatchCollection)
         {
             StringBuilder   aStringBuilder = new StringBuilder();
             MatchCollection mc             = e.Parameter as MatchCollection;
             foreach (Match aMatch in mc)
             {
                 aStringBuilder.Append(aMatch.Value);
                 aStringBuilder.Append("\r\n");
             }
             File.WriteAllText(aDlg.FileName, aStringBuilder.ToString());
             LogController.Log($"写入匹配结果--{aDlg.FileName}");
         }
     }
     catch (Exception ex)
     {
         LogController.Log($"写入文件错误--{ex.Message}");
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 6
0
 public void DoRename()
 {
     foreach (FileItem aFileItem in FileList)
     {
         LogController.Log($"执行重命名--{aFileItem.ItemFile}");
         aFileItem.DoRename();
     }
     LogController.Log($"重命名完成");
 }
Esempio n. 7
0
        public void FileReplace()
        {
            Regex aRegex = new Regex(FileMatchPattern);

            foreach (FileItem aFileItem in FileList)
            {
                LogController.Log($"替换文件名--{aFileItem.ItemFile} by {FileReplacePattern}");
                aFileItem.Replace(aRegex, FileReplacePattern);
            }
            LogController.Log($"替换文件名完成");
        }
Esempio n. 8
0
        private void OnAddPattern_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            LogController.Log($"添加正则表达式-呼出popup");
            AddPatternCommandParameters parameters = e.Parameter as AddPatternCommandParameters;

            _Model.PopupRegexPattern = parameters.RegexText;
            _Model.PopupRegexType    = parameters.RegexType;
            _Model.PopupTime         = DateTime.Now.ToString();
            _Model.PopupIntro        = null;
            ManagePopup.IsOpen       = false;
            ManagePopup.IsOpen       = true;
        }
Esempio n. 9
0
        public MainModel()
        {
            TextMatchRegexList   = new ObservableCollection <RegexItem>();
            TextReplaceRegexList = new ObservableCollection <RegexItem>();
            FileMatchRegexList   = new ObservableCollection <RegexItem>();
            FileReplaceRegexList = new ObservableCollection <RegexItem>();
            FileList             = new ObservableCollection <FileItem>();

            RegexTypeList = new ObservableCollection <string>(new string[] { "TextMatch", "TextReplace", "FileMatch", "FileReplace" });
            ManageRegexTypeSelectedItem = RegexTypeList.FirstOrDefault();
            LogController.Log($"初始化model完成");
        }
Esempio n. 10
0
 private void OnTextMatch_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         LogController.Log("文本匹配");
         _Model.TextMatch();
     }
     catch (Exception ex)
     {
         LogController.Log($"文本匹配错误--{ex.Message}");
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 11
0
 private void OnDoRename_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         LogController.Log($"文件重命名");
         _Model.DoRename();
     }
     catch (Exception ex)
     {
         LogController.Log($"文件重命名错误--{ex.Message}");
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 12
0
 private void OnDeletePattern_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         LogController.Log($"删除表达式");
         _Model.DeletePattern(e.Parameter as RegexItem);
     }
     catch (Exception ex)
     {
         LogController.Log($"删除表达式错误--{ex.Message}");
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 13
0
 private void OnFileReplace_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         LogController.Log($"文件替换");
         _Model.FileReplace();
     }
     catch (Exception ex)
     {
         LogController.Log($"文件替换错误--{ex.Message}");
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 14
0
 private void OnWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     try
     {
         LogController.Log($"程序关闭");
         LogController.Log($"保存表达式管理列表");
         _Model.SaveManageList();
     }
     catch (Exception ex)
     {
         LogController.Log($"保存表达式管理列表错误--{ex.Message}");
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 15
0
 public void FileMatch()
 {
     try
     {
         Regex aRegex = new Regex(FileMatchPattern);
         foreach (FileItem aFileItem in FileList)
         {
             LogController.Log($"匹配文件名--{aFileItem.ItemFile} by {FileMatchPattern}");
             aFileItem.Match(aRegex);
         }
         LogController.Log($"匹配文件名完成");
     }
     catch (Exception ex)
     {
         LogController.Log($"匹配文件错误--{ex.Message}");
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 16
0
        public MainWindow()
        {
            LogController.Log("程序启动");
            InitializeComponent();
            _Model           = new MainModel();
            this.DataContext = _Model;

            try
            {
                _Model.LoadManageList();
                LogController.Log("加载正则表达式管理列表");
            }
            catch (Exception ex)
            {
                LogController.Log($"正则表达式加载错误--{ex.Message}");
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 17
0
 public void RegexListChange(ListBox manageList)
 {
     if (ManageRegexTypeSelectedItem == "TextMatch")
     {
         manageList.ItemsSource = TextMatchRegexList;
     }
     else if (ManageRegexTypeSelectedItem == "TextReplace")
     {
         manageList.ItemsSource = TextReplaceRegexList;
     }
     else if (ManageRegexTypeSelectedItem == "FileMatch")
     {
         manageList.ItemsSource = FileMatchRegexList;
     }
     else if (ManageRegexTypeSelectedItem == "FileReplace")
     {
         manageList.ItemsSource = FileReplaceRegexList;
     }
     LogController.Log($"更换选择列表--{ManageRegexTypeSelectedItem}");
 }
Esempio n. 18
0
 public void DeletePattern(RegexItem regexItem)
 {
     if (regexItem.RegexType == "TextMatch")
     {
         TextMatchRegexList.Remove(regexItem);
     }
     else if (regexItem.RegexType == "TextReplace")
     {
         TextReplaceRegexList.Remove(regexItem);
     }
     else if (regexItem.RegexType == "FileMatch")
     {
         FileMatchRegexList.Remove(regexItem);
     }
     else if (regexItem.RegexType == "FileReplace")
     {
         FileReplaceRegexList.Remove(regexItem);
     }
     LogController.Log($"删除表达式完成--{regexItem.RegexText}");
 }
Esempio n. 19
0
        private void OnLoadSampleText_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LogController.Log("加载样本文件");

                OpenFileDialog aDlg = new OpenFileDialog();
                aDlg.Title  = "选择样本文件";
                aDlg.Filter = "文本文件 (.txt)|*.txt|所有文件 (*.*)|*.*";
                if (aDlg.ShowDialog() != true)
                {
                    return;
                }
                _Model.SampleText = File.ReadAllText(aDlg.FileName, Encoding.Default);
            }
            catch (Exception ex)
            {
                LogController.Log($"加载样本文件错误--{ex.Message}");
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 20
0
 private void OnOpenFileList_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         LogController.Log($"文件重名名选择多文件");
         OpenFileDialog aDlg = new OpenFileDialog();
         aDlg.Multiselect = true;
         aDlg.Title       = "选择文件列表";
         if (aDlg.ShowDialog() != true)
         {
             return;
         }
         _Model.ClearFileList();
         foreach (string aFullFileName in aDlg.FileNames)
         {
             _Model.AddFileItem(aFullFileName);
         }
     }
     catch (Exception ex)
     {
         LogController.Log($"选择多文件错误--{ex.Message}");
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 21
0
 private void OnRegexTypeChanged(object sender, SelectionChangedEventArgs e)
 {
     LogController.Log($"表达式类型选择改变");
     _Model.RegexListChange(ManageList);
 }
Esempio n. 22
0
 public void ClearFileList()
 {
     LogController.Log($"清除文件类表");
     FileList.Clear();
 }
Esempio n. 23
0
 public void AddFileItem(string aFullFileName)
 {
     LogController.Log($"添加文件--{aFullFileName}");
     FileList.Add(new FileItem(aFullFileName));
 }