private void BtnSetRules_Click(object sender, RoutedEventArgs e) { SetRuleString setRuleObj = new SetRuleString(); Rules readRulesObj = new Rules(); string shouldContainText = this.txtBx_Text.Text; string shouldContainSubject = this.txtBx_Subject.Text; string shouldContainTo = this.txtBx_To.Text; string shouldNotContainDepartment = this.txtBx_DenyDepartment.Text; string shouldNotContainBody = this.txtBx_DenyBodyTag.Text; string shouldNotContainSubject = this.txtBx_DenySubject.Text; try { setRuleObj.AllowBodyTags = shouldContainText; setRuleObj.AllowSubjectTags = shouldContainSubject; setRuleObj.AllowToPeople = shouldContainTo; setRuleObj.DenyBodyTags = shouldNotContainBody; setRuleObj.DenyDepartment = shouldNotContainDepartment; setRuleObj.DenySubject = shouldNotContainSubject; bool isSuccess = readRulesObj.SetCustomRules(setRuleObj); if (isSuccess) { MessageBox.Show("Succesfully updated"); } } catch (Exception ex) { } }
public bool SetCustomRules(SetRuleString setRuleObj) { string line = String.Empty; bool isSuccess = false; RuleDataModel ruleDataObj = new RuleDataModel(); try { XDocument xDoc = new XDocument( new XElement("Rules", new XElement("SetRules", new XElement("AllowBody", setRuleObj.AllowBodyTags), new XElement("AllowSubject", setRuleObj.AllowSubjectTags), new XElement("AllowTo", setRuleObj.AllowToPeople) ), new XElement("ExcludeRules", new XElement("DenyBody", setRuleObj.DenyBodyTags), new XElement("DenySubject", setRuleObj.DenySubject), new XElement("DenyDepartments", setRuleObj.DenyDepartment)))); var fileName = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+"\\Ruleset.xml"; xDoc.Save(fileName); isSuccess = true; } catch (System.Exception ex) { throw; isSuccess = false; } return isSuccess; }