Esempio n. 1
0
        /// <summary>
        /// Routine that attempts to resend emails that previously failed.
        /// </summary>
        /// <returns>List of emails that were successfully resent.</returns>
        /// <remarks>Uses internally maintained queue of emails that failed to send.</remarks>
        public PFListEx <stEmailArchiveEntry> ResendEmails()
        {
            PFListEx <stEmailArchiveEntry> successfulResends = new PFListEx <stEmailArchiveEntry>();
            PFListEx <stEmailArchiveEntry> failedResends     = new PFListEx <stEmailArchiveEntry>();

            _emailResendQueue = PFListEx <stEmailArchiveEntry> .LoadFromXmlFile(_emailResendQueueFile);

            _emailLastResendList.Clear();

            foreach (stEmailArchiveEntry emailEntry in _emailResendQueue)
            {
                stEmailSendResult res = this.SendEmail(emailEntry.emailMessage, false);

                if (res.emailSendResult == enEmailSendResult.Success)
                {
                    stEmailArchiveEntry successEntry = new stEmailArchiveEntry(res, emailEntry.emailMessage);
                    successEntry.numRetries       = emailEntry.numRetries + 1;
                    successEntry.firstSendAttempt = emailEntry.firstSendAttempt;
                    successEntry.lastSendAttempt  = DateTime.Now;
                    successfulResends.Add(successEntry);
                }
                else
                {
                    stEmailArchiveEntry failedEntry = new stEmailArchiveEntry(res, emailEntry.emailMessage);
                    failedEntry.firstSendAttempt = emailEntry.firstSendAttempt;
                    failedEntry.lastSendAttempt  = DateTime.Now;
                    failedEntry.numRetries       = emailEntry.numRetries + 1;
                    failedResends.Add(failedEntry);
                }
            }

            _emailResendQueue.Clear();
            if (failedResends.Count > 0)
            {
                foreach (stEmailArchiveEntry entry in failedResends)
                {
                    if (entry.numRetries < _maxNumResendAttempts)
                    {
                        stEmailArchiveEntry newEntry = new stEmailArchiveEntry(entry.sendResult, entry.emailMessage);
                        newEntry.firstSendAttempt = entry.firstSendAttempt;
                        newEntry.lastSendAttempt  = entry.lastSendAttempt;
                        newEntry.numRetries       = entry.numRetries;
                        _emailResendQueue.Add(newEntry);
                    }
                    else
                    {
                        stEmailArchiveEntry lastEntry = new stEmailArchiveEntry(entry.sendResult, entry.emailMessage);
                        lastEntry.firstSendAttempt = entry.firstSendAttempt;
                        lastEntry.lastSendAttempt  = entry.lastSendAttempt;
                        lastEntry.numRetries       = entry.numRetries;
                        _emailLastResendList.Add(lastEntry);
                    }
                }
            }

            _emailResendQueue.SaveToXmlFile(_emailResendQueueFile);

            return(successfulResends);
        }
Esempio n. 2
0
        /// <summary>
        /// Sends the specified email.
        /// </summary>
        /// <param name="emailMsg">Email message object.</param>
        /// <param name="resendOnError">If true, email manager will attempt to resend a message that fails due to an SMTP error.</param>
        /// <returns>True if email sent successfully; otherwise false if an error occurred and email was not sent.</returns>
        /// <remarks>Email manager will retry up to MaxNumResendAttempts times.</remarks>
        public stEmailSendResult SendEmail(PFEmailMessage emailMsg, bool resendOnError)
        {
            stEmailSendResult result = new stEmailSendResult(enEmailSendResult.Unknown, enEmailFailedReason.Unknown);
            bool queueForResend      = false;

            try
            {
                emailMsg.Send();
                result.emailSendResult   = enEmailSendResult.Success;
                result.emailFailedReason = enEmailFailedReason.NoError;
                result.failureMessages   = string.Empty;
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Attempt to send email to ");
                _msg.Append(emailMsg.ToAddress);
                _msg.Append(" failed. Error Message: ");
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                result.emailSendResult = enEmailSendResult.Failed;
                result.failureMessages = _msg.ToString();
                if (ex is SmtpException)
                {
                    result.emailFailedReason = enEmailFailedReason.SmtpException;
                    queueForResend           = true;
                }
                else if (ex is SmtpFailedRecipientException)
                {
                    result.emailFailedReason = enEmailFailedReason.SmtpRecipientsException;
                    queueForResend           = true;
                }
                else if (ex is InvalidOperationException)
                {
                    result.emailFailedReason = enEmailFailedReason.InvalidOperationsException;
                }
                else if (ex is ArgumentNullException)
                {
                    result.emailFailedReason = enEmailFailedReason.ArgumentNullException;
                }
                else
                {
                    result.emailFailedReason = enEmailFailedReason.GeneralError;
                }
            }
            finally
            {
                if (queueForResend && resendOnError)
                {
                    stEmailArchiveEntry newEntry = new stEmailArchiveEntry(result, emailMsg);
                    newEntry.firstSendAttempt = DateTime.Now;
                    newEntry.lastSendAttempt  = DateTime.Now;
                    _emailResendQueue.Add(newEntry);
                    _emailResendQueue.SaveToXmlFile(_emailResendQueueFile);
                }
            }

            return(result);
        }
Esempio n. 3
0
        private void SaveLogMessageToRetryQueue(PFLogMessage logMessage)
        {
            _logRetryQueue.Add(logMessage);

            SaveRetryQueue();
        }
Esempio n. 4
0
        public static void KeyValueListMergeTest()
        {
            PFKeyValueListEx <int, string> list1 = new PFKeyValueListEx <int, string>();
            PFKeyValueListEx <int, string> list2 = new PFKeyValueListEx <int, string>();
            PFKeyValueListEx <int, string> list3 = new PFKeyValueListEx <int, string>();

            try
            {
                _msg.Length = 0;
                _msg.Append("KeyValueListMergeTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                list1.Add(new pfKeyValuePair <int, string>(1, "First"));
                list1.Add(new pfKeyValuePair <int, string>(2, "Second"));
                list1.Add(new pfKeyValuePair <int, string>(3, "Third"));

                list2.Add(new pfKeyValuePair <int, string>(4, "fourth"));
                list2.Add(new pfKeyValuePair <int, string>(5, "fifth"));
                list2.Add(new pfKeyValuePair <int, string>(6, "sixth"));

                list3.Add(new pfKeyValuePair <int, string>(7, "Seventh"));
                list3.Add(new pfKeyValuePair <int, string>(8, "Eighth"));
                list3.Add(new pfKeyValuePair <int, string>(9, "Ninth"));
                list3.Add(new pfKeyValuePair <int, string>(10, "Tenth"));

                PFKeyValueListEx <int, string>[]           listArray   = { list1, list2, list3 };
                PFListEx <PFKeyValueListEx <int, string> > listOfLists = new PFListEx <PFKeyValueListEx <int, string> >();
                listOfLists.Add(list1);
                listOfLists.Add(list2);
                listOfLists.Add(list3);

                PFKeyValueListEx <int, string> concatListFromArray = PFKeyValueListEx <int, string> .ConcatenateLists(listArray);

                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Concatenated list from Array");
                _msg.Append(Environment.NewLine);
                _msg.Append(concatListFromArray.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());


                PFKeyValueListEx <int, string> concatListFromList = PFKeyValueListEx <int, string> .ConcatenateLists(listOfLists);

                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Concatenated list from List");
                _msg.Append(Environment.NewLine);
                _msg.Append(concatListFromList.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());

                PFKeyValueListEx <int, string> mergedList = list1.Merge(list2);
                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Merged list");
                _msg.Append(Environment.NewLine);
                _msg.Append(mergedList.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());

                mergedList.Clear();
                mergedList = list3.Merge(new PFKeyValueListEx <int, string>[2] {
                    list1, list2
                });
                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Merged list from Array");
                _msg.Append(Environment.NewLine);
                _msg.Append(mergedList.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());

                mergedList.Clear();
                mergedList = list3.Merge(new PFListEx <PFKeyValueListEx <int, string> > {
                    list2, list1
                });
                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Merged list from List");
                _msg.Append(Environment.NewLine);
                _msg.Append(mergedList.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... KeyValueListMergeTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
Esempio n. 5
0
        //tests

        public static void GenericListTest()
        {
            PFListEx <string> testList         = new PFListEx <string>();
            PFListEx <string> testList2        = new PFListEx <string>();
            PFListEx <string> testList3        = new PFListEx <string>();
            PFListEx <string> testList4        = new PFListEx <string>();
            string            testListXmlFile  = @"c:\temp\testlist.xml";
            string            connectionString = string.Empty;
            string            configValue      = string.Empty;

            try
            {
                _msg.Length = 0;
                _msg.Append("GenericListTest started ...");
                Program._messageLog.WriteLine(_msg.ToString());

                configValue = AppConfig.GetStringValueFromConfigFile("ListsDatabaseFile", string.Empty);
                if (configValue.Length > 0)
                {
                    connectionString = configValue;
                }
                else
                {
                    connectionString = _listsDatabaseConnectionString;
                }


                _msg.Length = 0;
                _msg.Append("First = ");
                _msg.Append(testList.FirstItem == null ? "<null>" : testList.FirstItem);
                Program._messageLog.WriteLine(_msg.ToString());

                testList.Add("First item");
                testList.Add("Second item");
                testList.Add("Third item");

                _msg.Length = 0;
                _msg.Append("Number of items in list: ");
                Program._messageLog.WriteLine(_msg.ToString());

                foreach (string s in testList)
                {
                    _msg.Length = 0;
                    _msg.Append(s);
                    Program._messageLog.WriteLine(_msg.ToString());
                }

                _msg.Length = 0;
                _msg.Append("First = ");
                _msg.Append(testList.FirstItem);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Last = ");
                _msg.Append(testList.LastItem);
                Program._messageLog.WriteLine(_msg.ToString());


                _msg.Length = 0;
                _msg.Append("NextItem loop: ");
                Program._messageLog.WriteLine(_msg.ToString());

                string res = testList.FirstItem;
                while (!testList.EOF)
                {
                    _msg.Length = 0;
                    _msg.Append(res);
                    Program._messageLog.WriteLine(_msg.ToString());
                    res = testList.NextItem;
                }

                _msg.Length = 0;
                _msg.Append("PrevItem loop: ");
                Program._messageLog.WriteLine(_msg.ToString());

                res = testList.LastItem;
                while (!testList.EOF)
                {
                    _msg.Length = 0;
                    _msg.Append(res);
                    Program._messageLog.WriteLine(_msg.ToString());
                    res = testList.PrevItem;
                }

                _msg.Length = 0;
                _msg.Append("ToString Test: ");
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append(testList.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("SaveToXmlFile Test: ");
                _msg.Append(testListXmlFile);
                Program._messageLog.WriteLine(_msg.ToString());

                testList.SaveToXmlFile(testListXmlFile);

                _msg.Length = 0;
                _msg.Append("LoadFromXmlFile Test: ");
                _msg.Append(testListXmlFile);
                Program._messageLog.WriteLine(_msg.ToString());

                testList2 = PFListEx <string> .LoadFromXmlFile(testListXmlFile);

                _msg.Length = 0;
                _msg.Append("testList2 ToString Test: ");
                Program._messageLog.WriteLine(_msg.ToString());
                _msg.Length = 0;
                _msg.Append(testList2.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                //save and read to database tests next
                testList.SaveToDatabase(connectionString, "TestprogListObjects_testList");

                testList3 = PFListEx <string> .LoadFromDatabase(connectionString, "TestprogListObjects_testList");

                _msg.Length = 0;
                _msg.Append("testList3 ToXmlString Test: ");
                Program._messageLog.WriteLine(_msg.ToString());
                _msg.Length = 0;
                _msg.Append(testList3.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());


                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("testList4 Sort Test: ");
                Program._messageLog.WriteLine(_msg.ToString());

                testList4.Add("First item");
                testList4.Add("ZFourth item");
                testList4.Add("Third item");
                testList4.Add("Second item");

                _msg.Length = 0;
                _msg.Append("Number of items in list4: ");
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("List4 Before Sort: ");
                Program._messageLog.WriteLine(_msg.ToString());

                foreach (string s in testList4)
                {
                    _msg.Length = 0;
                    _msg.Append(s);
                    Program._messageLog.WriteLine(_msg.ToString());
                }

                testList4.Sort();

                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("List4 After Sort: ");
                Program._messageLog.WriteLine(_msg.ToString());

                foreach (string s in testList4)
                {
                    _msg.Length = 0;
                    _msg.Append(s);
                    Program._messageLog.WriteLine(_msg.ToString());
                }

                Program._messageLog.WriteLine(Environment.NewLine);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("... GenericListTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }//end GenericListTest