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 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)
            {
            }

        }
Beispiel #3
0
        /// <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;
        }
Beispiel #4
0
        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;
        }