public RuleDataModel ReadCustomRules() { string line = String.Empty; RuleDataModel ruleDataObj = new RuleDataModel(); try { var fileName = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Ruleset.xml"; if (!File.Exists(fileName)) { CreateXml(); } using (XmlTextReader reader = new XmlTextReader(fileName)) { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "AllowBody": reader.Read(); ruleDataObj.SearchForBodyTags = reader.Value.Split(',').ToList(); break; case "AllowSubject": reader.Read(); ruleDataObj.SearchForSubject = reader.Value.Split(',').ToList(); break; case "AllowTo": reader.Read(); ruleDataObj.SearchForToRecepients = reader.Value.Split(',').ToList(); break; case "DenyBody": reader.Read(); ruleDataObj.SearchForDenyBodyTags = reader.Value.Split(',').ToList(); break; case "DenySubject": reader.Read(); ruleDataObj.SearchForDenySubject = reader.Value.Split(',').ToList(); break; case "DenyDepartments": reader.Read(); ruleDataObj.SearchForDenyDepartments = reader.Value.Split(',').ToList(); break; } } } } } catch (System.Exception ex) { } return ruleDataObj; }
public void LoadDefaultRule() { Rules readRuleObj = new Rules(); RuleDataModel readRuleDataModelObj = new RuleDataModel(); try { readRuleDataModelObj = readRuleObj.ReadCustomRules(); this.txtBx_Subject.Text = String.Join(",", readRuleDataModelObj.SearchForSubject); this.txtBx_Text.Text = string.Join(",", readRuleDataModelObj.SearchForBodyTags); this.txtBx_To.Text = string.Join(",", readRuleDataModelObj.SearchForToRecepients); this.txtBx_DenyBodyTag.Text = String.Join(",", readRuleDataModelObj.SearchForDenyBodyTags); this.txtBx_DenyDepartment.Text = String.Join(",", readRuleDataModelObj.SearchForDenyDepartments); this.txtBx_DenySubject.Text = String.Join(",", readRuleDataModelObj.SearchForDenySubject); } 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; }
/// <summary> /// Module for getting the Department Analysis /// </summary> /// <param name="count"></param> /// <param name="searchInFolders"></param> /// <returns></returns> public Dictionary<string, int> GetDepartmentInterest_UpdatedApi(int count, List<string> searchInFolders) { Dictionary<string, int> filterList = new Dictionary<string, int>(); string department = String.Empty; int countnum = 0; string filter = String.Empty; List<MAPIFolder> searchFolders = new List<MAPIFolder>(); RuleDataModel ruleObj = new RuleDataModel(); Rules readRulesObj = new Rules(); string filterCriteria = String.Empty; DateTime date = DateTime.Now.AddDays(-count); string filterDate = date.ToString("MM/dd/yyyy hh:mm t", CultureInfo.InvariantCulture); try { outlookFolders.Clear(); filterList.Clear(); ruleObj = readRulesObj.ReadCustomRules(); // string subject = "WinFabric"; searchFolders = SearchSelectedFolders (searchInFolders); filter = "[ReceivedTime]>='"+filterDate+ "'"; foreach (MAPIFolder folder in searchFolders) { var outlookItems = folder.Items.Restrict(filter); for (int i = 1; i <= outlookItems.Count; i++) { // Task taskResult = Task.Factory.StartNew(() => // { try { MailItem itm = (MailItem)outlookItems[i]; //if (itm.SentOn > DateTime.Now.AddDays(-count) || count == 0) //{ if (itm.Body.ContainsAny(ruleObj.SearchForBodyTags) || itm.To.ContainsAny(ruleObj.SearchForToRecepients)) { department = itm.Sender.GetExchangeUser().Department; if (!department.ContainsAny(ruleObj.SearchForDenyDepartments) && !itm.Body.ContainsAny(ruleObj.SearchForDenyBodyTags) && !itm.Subject.ContainsAny(ruleObj.SearchForDenySubject)) { if (filterList.ContainsKey(department)) { filterList[department]++; } else { filterList.Add(department, 1); } } // } } countnum++; } catch (System.Exception ex) { countnum--; } //}); } } } catch (System.Exception ex) { LoggerClass.WriteException(DateTime.Now, "Logic", ex.Message); } filterList = (from entry in filterList orderby entry.Value descending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); return filterList; }
public List<EmailDataModel> GetIndividualInterest(int count, List<string> searchInFolders) { Dictionary<string, EmailDataModel> filterDictionary = new Dictionary<string, EmailDataModel>(); List<EmailDataModel> filterList = new List<EmailDataModel>(); List<MAPIFolder> searchFolders = new List<MAPIFolder>(); string department = String.Empty; string name = String.Empty; string picturePath = String.Empty; string contact = String.Empty; RuleDataModel ruleObj = new RuleDataModel(); Rules readRulesObj = new Rules(); string filter = String.Empty; DateTime date = DateTime.Now.AddDays(-count); string filterDate = date.ToString("MM/dd/yyyy hh:mm t", CultureInfo.InvariantCulture); try { outlookFolders.Clear(); ruleObj = readRulesObj.ReadCustomRules(); searchFolders = SearchSelectedFolders(searchInFolders); filter = "[ReceivedTime]>='" + filterDate + "'"; foreach (MAPIFolder folder in searchFolders) { var outlookItems = folder.Items.Restrict(filter); for (int i = 1; i <= outlookItems.Count; i++) { try { MailItem itm = (MailItem)outlookItems[i]; if (itm.SentOn > DateTime.Now.AddDays(-count) || count == 0) { if (itm.Body.ContainsAny(ruleObj.SearchForBodyTags) || itm.To.ContainsAny(ruleObj.SearchForToRecepients)) { department = itm.Sender.GetExchangeUser().Department; if (!department.ContainsAny(ruleObj.SearchForDenyDepartments) && !itm.Body.ContainsAny(ruleObj.SearchForDenyBodyTags) && !itm.Subject.ContainsAny(ruleObj.SearchForDenySubject)) { contact = itm.Sender.GetExchangeUser().MobileTelephoneNumber; name = itm.Sender.Name; if (filterDictionary.ContainsKey(name)) { filterDictionary[name].SenderParticipation++; } else { EmailDataModel emailObj = new EmailDataModel(); emailObj.SenderName = name; emailObj.SenderGroup = department; emailObj.SenderImage = contact; emailObj.SenderParticipation = 1; filterDictionary.Add(name, emailObj); } } } } } catch (System.Exception ex) { LoggerClass.WriteException(DateTime.Now, "Logic", ex.Message); } } } foreach (var itm in filterDictionary) { filterList.Add(itm.Value); } } catch (System.Runtime.InteropServices.COMException ex) { Console.WriteLine(ex.ToString()); LoggerClass.WriteException(DateTime.Now, "Logic", ex.Message); } catch (System.Exception ex) { LoggerClass.WriteException(DateTime.Now, "Logic", ex.Message); } filterList = filterList.OrderByDescending(e => e.SenderParticipation).ToList(); CreateIndividualCSV(filterList); return filterList; }