Esempio n. 1
0
        /// <summary>
        /// The get default filter parameters.
        /// </summary>
        /// <returns>
        /// The <see cref="FilterParametersData"/>.
        /// </returns>
        public static FilterParametersData GetDefault()
        {
            var filterParameters = new FilterParametersData
            {
                StartDateTime  = DateTime.Now,
                FinishDateTime = DateTime.Now.AddDays(-1),
                SubjectContain = string.Empty
            };

            return(filterParameters);
        }
        private static bool CheckStatusFilter(FilterParametersData filterParameters, EmailStatus status)
        {
            var condition = true;

            if (filterParameters.NonDeliveryStatus || filterParameters.UnknownStatus || filterParameters.DeliveryStatus)
            {
                var ndr = filterParameters.NonDeliveryStatus && (status == EmailStatus.Nodelivery);
                var unk = filterParameters.UnknownStatus && (status == EmailStatus.Unknown);
                var dr  = filterParameters.DeliveryStatus && (status == EmailStatus.Delivery);
                if (!(ndr || unk || dr))
                {
                    condition = false;
                }
            }

            return(condition);
        }
        /// <summary>
        /// The update email status data grid.
        /// </summary>
        /// <param name="filterParametersData"></param>
        private void UpdateMonitorDataGrid(FilterParametersData filterParametersData)
        {
            var currentCursor = Cursor.Current;

            try
            {
                this.Cursor = Cursors.WaitCursor;
                Application.DoEvents();

                this.GetFilterParams();

                if (this.FolderComboBox.SelectedItem != null)
                {
                    var inboxFolder = (Outlook.MAPIFolder) this.FolderComboBox.SelectedItem;
                    ThisAddIn.thisApplication.ActiveExplorer().CurrentFolder = inboxFolder;
                    ThisAddIn.thisApplication.ActiveExplorer().CurrentFolder.Display();

                    this.emailParsingDataList          = GpiOutlookWrapper.GetMailBoxContent(inboxFolder, filterParametersData);
                    this.InfoToolStripStatusLabel.Text = $"Обнаружено: {this.emailParsingDataList.Count}";

                    this.MonitorStatusDataGridView.DataSource = this.emailParsingDataList;
                    if (this.emailParsingDataList.Count > 0)
                    {
                        this.MonitorStatusDataGridView.SelectedRows[0].Selected = true;
                        this.MonitorStatusDataGridViewSelectionChanged(null, null);
                    }
                }
            }
            catch (Exception ex)
            {
                this.InfoListBox.Items.Add("UpdateMonitorDataGrid " + ex.Message);
                this.InfoListBox.Items.Add(ex.StackTrace);
                foreach (var err in GpiOutlookWrapper.ErrorList)
                {
                    this.InfoListBox.Items.Add(err);
                }
            }
            finally
            {
                this.Cursor = currentCursor;
                Application.DoEvents();
            }
        }
        private static string GenerateFilter(FilterParametersData filterParameters, string messageClass)
        {
            var minDateTime = filterParameters.StartDateTime < filterParameters.FinishDateTime
                                  ? filterParameters.StartDateTime.Date
                                  : filterParameters.FinishDateTime.Date;
            var maxDateTime = filterParameters.StartDateTime > filterParameters.FinishDateTime
                                  ? filterParameters.StartDateTime.Date
                                  : filterParameters.FinishDateTime.Date;

            minDateTime = minDateTime.AddDays(-1);
            maxDateTime = maxDateTime.AddDays(1);

            var filter = $"[CreationTime] < '{maxDateTime.Day:00}/{maxDateTime.Month:00}/{maxDateTime.Year:0000}' and [CreationTime] > '{minDateTime.Day:00}/{minDateTime.Month:00}/{minDateTime.Year:0000}'";

            if (messageClass != string.Empty)
            {
                var addFilter = " and [MessageClass] = '" + messageClass + "'";
                filter += addFilter;
            }

            return(filter);
        }
Esempio n. 5
0
        /// <summary>
        /// The update email status data grid.
        /// </summary>
        private void UpdateNdrDataGrid()
        {
            try
            {
                var inboxFolder = (Outlook.MAPIFolder) this.FolderComboBox.SelectedItem;
                ThisAddIn.thisApplication.ActiveExplorer().CurrentFolder = inboxFolder;
                ThisAddIn.thisApplication.ActiveExplorer().CurrentFolder.Display();

                var fp = FilterParametersData.GetDefault();
                this.emailParsingDataList          = GpiOutlookWrapper.GetMailBoxContent(inboxFolder, fp, "REPORT.IPM.Note.NDR");
                this.InfoToolStripStatusLabel.Text = string.Format("Обнаружено NDR: {0}", this.emailParsingDataList.Count);

                this.NdrDataGridView.DataSource = this.emailParsingDataList;
                if (this.emailParsingDataList.Count > 0)
                {
                    this.NdrDataGridView.SelectedRows[0].Selected = true;
                    this.EmailStatusDataGridViewSelectionChanged(null, null);
                }
            }
            catch (Exception ex)
            {
                this.InfoListBox.Items.Add("FolderComboBoxSelectedIndexChanged " + ex.Message);
            }
        }
        /// <summary>
        /// The monitro user control load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void MonitroUserControlLoad(object sender, EventArgs e)
        {
            try
            {
                this.filterParameters                  = FilterParametersData.GetDefault();
                this.FinishDateTimePicker.Value        = this.filterParameters.StartDateTime;
                this.StartDateTimePicker.Value         = this.filterParameters.FinishDateTime;
                this.SubjectContainTextBox.Text        = this.filterParameters.SubjectContain;
                this.NonDeliveryStatusCheckBox.Checked = this.filterParameters.NonDeliveryStatus;
                this.UnknownStatusCheckBox.Checked     = this.filterParameters.UnknownStatus;
                this.DeliveryStatusCheckBox.Checked    = this.filterParameters.DeliveryStatus;

                this.MonitorStatusDataGridView.AutoGenerateColumns = false;

                var dataGridViewColumn = this.MonitorStatusDataGridView.Columns["CreationTimeColumn"];
                if (dataGridViewColumn != null)
                {
                    dataGridViewColumn.DefaultCellStyle.Format = "dd'.'MM'.'yyyy HH:mm:ss";
                }

                this.webBrowser.Url          = new Uri("about:blank");
                this.webBrowser.DocumentText = "<html><body>Ожидание...</body></html>";
                this.Width = 400;

                this.FolderComboBox.Items.Clear();
                var count         = 0;
                var selectedIndex = 0;
                foreach (dynamic folder in ThisAddIn.thisApplication.GetNamespace("MAPI").Folders)
                {
                    var subFolders = GpiOutlookWrapper.GetFolder(folder.FolderPath);
                    foreach (Outlook.MAPIFolder subFolder in subFolders.Folders)
                    {
                        this.FolderComboBox.Items.Add(subFolder);
                        //// if (subFolder.FullFolderPath.Contains("*****@*****.**") && subFolder.FullFolderPath.Contains("Отправленные"))
                        if (subFolder.FullFolderPath.Contains("Отправленные") &&
                            (subFolder.FullFolderPath.Contains("Канцелярия") || subFolder.FullFolderPath.Contains("kancelaria")))
                        {
                            selectedIndex = count;
                        }

                        count++;
                    }

                    Marshal.ReleaseComObject(subFolders);
                }

                this.FolderComboBox.SelectedIndex = selectedIndex;

                this.MonitorStatusDataGridView.SelectionChanged += this.MonitorStatusDataGridViewSelectionChanged;
                this.MainToolTip.SetToolTip(this.FilterButton, @"Показать/скрыть фильтр");
                this.MainToolTip.SetToolTip(this.UpdateButton, @"Обновить список писем");
                this.MainToolTip.SetToolTip(this.FolderComboBox, @"Выбор источника для сканирования отправленных писем");
                this.MainToolTip.SetToolTip(this.StartDateTimePicker, @"Начальная дата");
                this.MainToolTip.SetToolTip(this.FinishDateTimePicker, @"Конечная дата");
                this.MainToolTip.SetToolTip(this.SubjectContainTextBox, @"Фильтр по теме");
                this.MainToolTip.SetToolTip(this.NonDeliveryStatusCheckBox, @"Недоставленный письма");
                this.MainToolTip.SetToolTip(this.DeliveryStatusCheckBox, @"Доставленные письма");
                this.MainToolTip.SetToolTip(this.UnknownStatusCheckBox, @"Нет информации по письму");

                this.MainToolTip.SetToolTip(this.MonitorStatusDataGridView, @"Монитор писем");
            }
            catch (Exception ex)
            {
                this.InfoListBox.Items.Add("EmailStatusUserControlLoad " + ex.Message);
                this.InfoListBox.Items.Add("EmailStatusUserControlLoad " + ex.StackTrace);
            }
        }
        /// <summary>
        /// The get mail box content.
        /// </summary>
        /// <param name="inboxFolder">
        /// The inbox folder.
        /// </param>
        /// <param name="filterParameters">
        /// The filter Parameters.
        /// </param>
        /// <param name="messageClass">
        /// The message Class.
        /// </param>
        /// <returns>
        /// The list of EmailParsingData.
        /// </returns>
        public static List <EmailParsingData> GetMailBoxContent(Outlook.MAPIFolder inboxFolder, FilterParametersData filterParameters, string messageClass = "IPM.Note")
        {
            var mailBoxContent = new List <EmailParsingData>();

            if (inboxFolder == null)
            {
                return(mailBoxContent);
            }

            Outlook.Items folderItems = null;

            var start = DateTime.MinValue;

            try
            {
                folderItems = inboxFolder.Items;
                folderItems.Sort("[CreationTime]", true);

                start = DateTime.Now;

                var deliveryReportFilter = GenerateFilter(filterParameters, "REPORT.IPM.Note.DR");

                var deliveryReportList = GetDeliveryReportList(deliveryReportFilter);

                var filter = GenerateFilter(filterParameters, messageClass);
                var item   = folderItems.Find(filter);
                while (item != null)
                {
                    if (!CheckSubjectFilter(filterParameters, item.Subject))
                    {
                        Marshal.ReleaseComObject(item);
                        item = folderItems.FindNext();
                        continue;
                    }

                    var parsingData = GetEmailParsingData(item);

                    if (parsingData.Subject.Contains(@"15292"))
                    {
                        var x = 0;
                    }

                    parsingData.Status = GetEmailStatusFromConversation(item, parsingData.CreationTime);
                    if (parsingData.Status == EmailStatus.Unknown)
                    {
                        parsingData.Status = GetEmailStatusFromSubject(item.Subject, deliveryReportList);
                    }

                    if (!CheckStatusFilter(filterParameters, parsingData.Status))
                    {
                        Marshal.ReleaseComObject(item);
                        item = folderItems.FindNext();
                        continue;
                    }

                    mailBoxContent.Add(parsingData);

                    Marshal.ReleaseComObject(item);
                    item = folderItems.FindNext();
                }
            }
            catch (Exception ex)
            {
                ErrorList.Add(MethodBase.GetCurrentMethod().Name + " " + ex.Message);
            }
            finally
            {
                if (folderItems != null)
                {
                    Marshal.ReleaseComObject(folderItems);
                }
            }

            var dyration = (DateTime.Now - start).TotalSeconds;

            return(mailBoxContent.OrderByDescending(c => c.CreationTime).ToList());
        }
        private static bool CheckSubjectFilter(FilterParametersData filterParameters, string subject)
        {
            var condition = subject.ToLower().Contains(filterParameters.SubjectContain);

            return(condition);
        }