Ejemplo n.º 1
0
        /// <summary>
        /// Parses the email addresses and creates in-memory work items.
        /// </summary>
        /// <remarks>
        /// During parsing, duplicates and invalid addresses are discarded.
        /// The work items has not been saved.
        /// </remarks>
        /// <param name="emailAddresses">The email addresses as a separated string to parse. Separators are ";, \n"</param>
        /// <returns>The email addresses as JobWorkItem objects</returns>
        public static JobWorkItems ParseEmailAddressesToWorkItems(string emailAddresses, JobWorkStatus defaultStatus)
        {
            JobWorkItems items = new JobWorkItems();

            string[] emailAddressArray = emailAddresses.Split(new char[] { ';', ',', ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string emailAddress in emailAddressArray)
            {
                // Clean address
                string emailAddressCleaned = NewsLetterUtil.CleanEmailAddress(emailAddress);

                // Validate email address
                if (EmailSyntaxValidator.Validate(emailAddressCleaned) == true)
                {
                    // Check if already added.
                    JobWorkItem workItem = items.FirstOrDefault(j => j.EmailAddress.Equals(emailAddressCleaned));

                    if (workItem == null)
                    {
                        // Handle duplicates - try to load it first
                        workItem = new JobWorkItem(emailAddressCleaned, defaultStatus);

                        // Add to collection
                        items.Add(workItem);
                    }
                }
            }
            return(items);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Imports email addresses as work items for this job
        /// </summary>
        /// <param name="emailArray">The email addresses to import.</param>
        /// <param name="invalidEmailAddresses">A list of all available email addresses that could not be parsed as a valid address</param>
        /// <param name="duplicateAddresses">A list of duplicate email addresses added</param>
        /// <returns>The number of email addresses imported as new work items. Duplicates are not part of this number.</returns>
        public int ImportEmailAddresses(string[] emailArray, out List <string> invalidEmailAddresses, out List <string> duplicateAddresses)
        {
            JobWorkItems importedItems = new JobWorkItems();

            invalidEmailAddresses = new List <string>();
            duplicateAddresses    = new List <string>();

            int numberOfNewItems = 0;

            foreach (string emailAddress in emailArray)
            {
                // TODO: This can be optimized by checking the
                // existence of these email addresses in batches

                // Clean address (this is done on save, so we need to make sure it's correct)
                string emailAddressCleaned = NewsLetterUtil.CleanEmailAddress(emailAddress);

                // Validate email address
                if (EmailSyntaxValidator.Validate(emailAddressCleaned) == false)
                {
                    // Invalid email address, skip it.
                    invalidEmailAddresses.Add(emailAddressCleaned);
                }
                else
                {
                    // Check if already imported. This is the quickest duplicate check
                    JobWorkItem workItem = importedItems.Items.FirstOrDefault(j => j.EmailAddress.Equals(emailAddressCleaned));

                    if (workItem == null)
                    {
                        // Handle duplicates - try to load it first
                        workItem = JobWorkItem.Load(Id, emailAddressCleaned);
                        if (workItem == null)
                        {
                            // Create it, and save it. It is automatically
                            // added to the WorkItems collection
                            workItem = this.CreateWorkItem(emailAddressCleaned);
                            workItem.Save();
                            numberOfNewItems++;
                        }
                        else
                        {
                            // Duplicate
                            duplicateAddresses.Add(emailAddressCleaned);
                        }

                        // Add to imported collection, for quick
                        // in memory duplicate check
                        importedItems.Items.Add(workItem);
                    }
                }
            }

            // Counters are no longer valid
            ResetStatusCounters();

            return(numberOfNewItems);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the specified work item based on a job id and an email address.
        /// </summary>
        /// <param name="jobId">The job id.</param>
        /// <param name="emailAddress">The email address.</param>
        /// <returns>A JobWorkItem if job and email found, null it not</returns>
        public static JobWorkItem Load(int jobId, string emailAddress)
        {
            WorkItemData dataUtil = GetWorker();
            // Get it, making sure we pass a washed address
            DataRow workRow = dataUtil.WorkItemGet(jobId, NewsLetterUtil.CleanEmailAddress(emailAddress));

            if (workRow != null)
            {
                return(new JobWorkItem(workRow));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        public static EmailAddress Load(int recipientListId, string emailAddress)
        {
            RecipientData dataUtil = GetWorker();

            // Get it, making sure we pass a washed address
            DataRow emailRow = dataUtil.RecipientListGetItem(recipientListId, NewsLetterUtil.CleanEmailAddress(emailAddress));

            if (emailRow != null)
            {
                return(new EmailAddress(emailRow));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Removes emailaddresses from the recipient list.
        /// Validates the input email address to prevent sql statements in the input.
        /// </summary>
        /// <param name="emailAddressArray">Array of emailadrresses</param>
        /// <returns></returns>
        private int RemoveEmailAddresses(string[] emailAddressArray)
        {
            int numberOfDeletedItems = 0;

            RecipientData recipientUtil = GetWorker();

            foreach (string emailAddress in emailAddressArray)
            {
                string emailAddressCleaned = NewsLetterUtil.CleanEmailAddress(emailAddress);

                if (EmailSyntaxValidator.Validate(emailAddressCleaned))
                {
                    recipientUtil.RecipientListRemoveItem(_id, emailAddressCleaned);
                    numberOfDeletedItems++;
                }
            }
            ClearEmailAddressCount();
            return(numberOfDeletedItems);
        }
Ejemplo n.º 6
0
        public void LoadWorkItemsForProcessing()
        {
            int batchSize = NewsLetterUtil.GetSendBatchSize();

            LoadWorkItemsForProcessing(batchSize);
        }