private string ConvertToValidName(string OriginalName) { HashSet <string> invalidCharacter = RegularExpression.GetMatchData(OriginalName, SystemConfiguration.GetValue("InvalidCharacter")); string newFileName = OriginalName; if (invalidCharacter.Count > 0) { //find invalid character foreach (string key in invalidCharacter) { string replacement = CharacterDictionary.GetValue(key); if (replacement == null) { //Others invalid character newFileName = RegularExpression.Replace(newFileName, "[" + key + "]", CharacterDictionary.OthersReplacement); } else { newFileName = RegularExpression.Replace(newFileName, "[" + key + "]", CharacterDictionary.GetValue(key)); } } } return(newFileName); }
/// <summary> /// Initial form objects /// </summary> public void Initial() { //Initial Global System Configuration SystemConfiguration.Initial(System.Windows.Forms.Application.ExecutablePath); //Inital Global LogClass LoggerHelper.Initial(this.rtxtLog, SystemConfiguration.LoggerClassName); LoggerHelper.Clear(); // LoadConfigurations(); // RegexRegularClass.Initial(SystemConfiguration.GetValue("RegexRegular_Invalid")); //Clear TextBox.Text this.txtOriginalDir.Clear(); //this.txtOriginalDir.Text = @"c:\test"; this.textBox1.Visible = false; this.textBox2.Visible = false; //this.button1.Visible = false; //rtn.SetFileNameRegexRegular(SystemConfiguration.GetValue("NavigationSourceFileNameRegex")); //rtn.SetFileNameRegexReplacement(SystemConfiguration.GetValue("NavigationReplacementFileNameRegex")); this.txtFileNameSearchReg.Text = SystemConfiguration.GetValue("NavigationSourceFileNameRegex"); this.txtFileNameReplacementReg.Text = SystemConfiguration.GetValue("NavigationReplacementFileNameRegex"); this.txtHTMSearchReg.Text = SystemConfiguration.GetValue("NavigationSourceHTMLRegex"); this.txtHTMLReplacementReg.Text = SystemConfiguration.GetValue("NavigationReplacementHTMLRegex"); //Initial CharacterDictionay CharacterDictionary.Initial(lstvReplacement.Items[0].SubItems[3].Text.Trim()); foreach (ListViewItem item in lstvReplacement.Items) { if (item.Text == "1") { continue; } CharacterDictionary.Add(item.SubItems[1].Text, item.SubItems[3].Text); } foreach (var item in CharacterDictionary.Keys) { LoggerHelper.Debug("key=" + item + ";value=" + CharacterDictionary.GetValue(item).ToString() + "\r\n"); } }