private void UpdateDatabase()
        {
            using (EmailImportDataContext dc = new EmailImportDataContext())
            {
                var email = dc.Emails.Where(em => em.EmailID == Email.EmailID).FirstOrDefault();

                if (email != null)
                {
                    email.Errors = Email.Errors;
                    dc.SubmitChanges();
                }
            }
        }
Beispiel #2
0
 static Settings()
 {
     using (var ctx = new EmailImportDataContext())
     {
         try
         {
             LiteViewerAuthorisedPCs = ctx.Settings.Single(s => s.Name == "LiteViewerAuthorisedPCs").Value;
         }
         catch
         {
             LiteViewerAuthorisedPCs = null;
         }
     }
 }
Beispiel #3
0
        private void ShowEmails(MailboxProfile profile)
        {
            Cursor = Cursors.WaitCursor;

            listViewEmails.Items.Clear();

            var emails = GetEmails(profile);

            using (EmailImportDataContext dc = new EmailImportDataContext())
            {
                foreach (var email in emails)
                {
                    // If LiteViewer Mode then check if emails Profile is Lite Viewer Enabled
                    if (LiteViewerMode && !ProfileLiteViewerEnabled((Guid)email.MailboxGUID))
                    {
                        continue;
                    }

                    ListViewItem lvi = new ListViewItem(new string[] {
                        email.From,
                        email.Subject,
                        email.DateSent.HasValue ? email.DateSent.Value.ToString() : String.Empty,
                        email.DateReceived.HasValue ? email.DateReceived.Value.ToString() : String.Empty,
                        Convert.ToString(email.ProcessedCount.GetValueOrDefault()),
                        email.Status,
                        email.StartTime.HasValue ? email.StartTime.Value.ToString() : String.Empty,
                        email.EndTime.HasValue ? email.EndTime.Value.ToString() : String.Empty,
                        email.Errors != null ? "Y" : String.Empty
                    });
                    lvi.Tag = email;

                    listViewEmails.Items.Add(lvi);
                }
            };

            // If ListView contains Items then Select First 1 else display Message
            if (listViewEmails.Items.Count > 0)
            {
                listViewEmails.Items[0].Selected = true;
            }
            else
            {
                ListViewItem lvi = new ListViewItem(new string[] { null, NOEMailsMessage });
                listViewEmails.Items.Add(lvi);
            }

            Cursor = Cursors.Default;
        }
Beispiel #4
0
        private int ReprocessEmails(IEnumerable <Email> emails)
        {
            var emailIDs = emails.Select(e => e.EmailID);
            int n        = 0;

            using (EmailImportDataContext dc = new EmailImportDataContext())
            {
                var reprocessEmails = dc.Emails.Where(e => emailIDs.Contains(e.EmailID));

                foreach (var email in reprocessEmails)
                {
                    if (email.Status != null)
                    {
                        email.Status = null;
                        n++;
                    }
                }

                dc.SubmitChanges();
            }

            return(n);
        }
Beispiel #5
0
        private List <Email> GetEmails(MailboxProfile profile)
        {
            IEnumerable <Email> emails;
            int numberOfEmails = Int32.Parse(toolStripTextBoxMaximumEmails.Text);

            using (EmailImportDataContext dc = new EmailImportDataContext())
            {
                if (profile != null)
                {
                    emails = dc.Emails.Where(e => e.MailboxGUID == profile.MailboxGUID);
                }
                else
                {
                    emails = dc.Emails;
                }

                switch (filter.Type)
                {
                case FilterType.DateSent:
                    emails = emails.Where(e => e.DateSent >= filter.Date1 && e.DateSent < filter.Date2.AddDays(1));

                    break;

                case FilterType.DateReceived:
                    emails = emails.Where(e => e.DateReceived >= filter.Date1 && e.DateReceived < filter.Date2.AddDays(1));

                    break;

                case FilterType.Status:
                    emails = emails.Where(e => e.Status == filter.StringValue);

                    break;

                case FilterType.BatchNumber:
                    emails = emails.Where(e => e.BatchNumber.ToLower() == filter.StringValue.ToLower());

                    break;

                case FilterType.From:
                    emails = emails.Where(e => e.From.ToLower().Contains(filter.StringValue.ToLower()));

                    break;

                case FilterType.Subject:
                    emails = emails.Where(e => e.Subject.ToLower().Contains(filter.StringValue.ToLower()));

                    break;

                case FilterType.MessageID:
                    emails = emails.Where(e => e.MessageID.ToLower().Contains(filter.StringValue.ToLower()));

                    break;

                case FilterType.EmailID:
                    emails = emails.Where(e => e.EmailID == filter.LongValue);

                    break;
                }

                emails = emails.Take(numberOfEmails);

                return(emails.ToList());
            }
        }
Beispiel #6
0
        private void LoadProfiles()
        {
            listViewProfiles.Clear();
            listViewProfiles.Columns.Add("Mailbox", listViewProfiles.Width - 22);

            var profiles = new List <MailboxProfile>();

            using (var ctx = new EmailImportDataContext())
            {
                XmlSerializer serializer = new XmlSerializer(typeof(MailboxProfile));

                foreach (var mailbox in ctx.Mailboxes)
                {
                    try
                    {
                        using (TextReader reader = new StringReader(mailbox.ProfileObject))
                        {
                            var profile = (MailboxProfile)serializer.Deserialize(reader);
                            profile.OriginalSerializedObject = mailbox.ProfileObject;
                            profiles.Add(profile);
                        }
                    }
                    catch // Ignore bad objects for now
                    { }
                }

                // If running in LiteViewer Mode and Not Authorised
                if (this.LiteViewerMode && !PCLiteViewerEnabled)
                {
                    labelLiteViewError.Text    = PCNotAuthorisedLiteViewerError;
                    labelLiteViewError.Visible = true;
                    return;
                }

                labelLiteViewError.Visible = false;
            }

            // Do not add the All Mailbox if LiteViewer Mode
            if (!this.LiteViewerMode)
            {
                AddAllAllProfile();
            }

            LiteViewerMailboxesAvailable = false;
            foreach (var profile in profiles.OrderBy(p => p.Group).ThenBy(p => p.Description))
            {
                // If LiteViewer Mode and Profile not LiteviewerEnabled
                if (this.LiteViewerMode && !profile.LiteViewerEnabled)
                {
                    continue;
                }

                AddProfile(profile);
                LiteViewerMailboxesAvailable = true;
            }

            // If LiteViewer Mode and no LiteviewerEnabled Profiles
            if (this.LiteViewerMode && !LiteViewerMailboxesAvailable)
            {
                labelLiteViewError.Text    = NoProfilesLiteViewerError;
                labelLiteViewError.Visible = true;
            }
        }