コード例 #1
0
ファイル: MainForm.cs プロジェクト: mzkabbani/cSharpProjects
 private void AddRuleToAppDirectory(Rules rules)
 {
     string workingDirectory = Directory.GetCurrentDirectory();
     if (!Directory.Exists(rulesDirectory)) {
         Directory.CreateDirectory(rulesDirectory);
     }
     StreamWriter writer = new StreamWriter(rulesDirectory + @"\" + rules.ruleName + ".txt");
     try {
         writer.Write(rules.oldEvent + "\n#End#\n" + rules.newEvent + "\n#End#\n" + rules.regexMode.ToString() + "\n#End#\n" + rules.filterEvent.ToString() + "\n#End#\n" + rules.ActionToolBar.ToString());
     } finally {
         if (writer != null) {
             writer.Close();
         }
     }
 }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: mzkabbani/cSharpProjects
 private void FetchSavedRule(string savedRule)
 {
     StreamReader reader = new StreamReader(savedRule);
     try {
         string ruleFileSaved = reader.ReadToEnd();
         string[] delimiter = new string[] { "\n#End#\n" };
         string[] ruleDetailes = ruleFileSaved.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
         Rules rules = new Rules();
         bool isRegexMode = false;
         bool isFilterEvent = false;
         bool isActionToolbar = false;
         if (ruleDetailes.Length > 2) {
             if (string.Equals(ruleDetailes[2], "True", StringComparison.InvariantCulture)) {
                 isRegexMode = true;
             }
             if (ruleDetailes.Length > 3) {
                 if (string.Equals(ruleDetailes[3], "True", StringComparison.InvariantCulture)) {
                     isFilterEvent = true;
                 }
                 if (ruleDetailes.Length > 4) {
                     if (string.Equals(ruleDetailes[4], "True", StringComparison.InvariantCulture)) {
                         isActionToolbar = true;
                     }
                 }
             }
         }
         rules.ruleName = Path.GetFileNameWithoutExtension(savedRule);
         rules.oldEvent = ruleDetailes[0];
         rules.newEvent = ruleDetailes[1];
         rules.regexMode = isRegexMode;
         rules.filterEvent = isFilterEvent;
         rules.ActionToolBar = isActionToolbar;
         lbSavedRules.Items.Add(rules);
     } finally {
         if (reader != null)
             reader.Close();
     }
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: mzkabbani/cSharpProjects
 private void btnAddRule_Click(object sender, EventArgs e)
 {
     try {
         if (IsValidToAddRule(txtOldEvent.Text, txtNewEvent.Text, txtRuleName.Text)) {
             Rules rules = new Rules();
             rules.ruleName = txtRuleName.Text;
             rules.oldEvent = txtOldEvent.Text;
             rules.newEvent = txtNewEvent.Text;
             rules.regexMode = chkRegexMode.Checked;
             rules.filterEvent = chkFilter.Checked;
             rules.ActionToolBar = chkActionTB.Checked;
             lbSavedRules.Items.Add(rules);
             AddRuleToAppDirectory(rules);
             InsertLog("Added rule :" + rules.ruleName + "\r\n");
             txtRuleName.ReadOnly = true;
         }
     } catch (Exception ex) {
         ShowCustomError(ex.Message, false);
     }
 }