Exemplo n.º 1
0
        public void MailingCallback(IAsyncResult ar)
        {
            // Restore orginial state
            ASyncMailingState mailingState = (ASyncMailingState)ar.AsyncState;

            //retrieve the object on which End needs to be called
            ASyncMailing mailing = mailingState.AsyncMailing;

            mailing.EndMailIt(ar);

            // Let the world know that mailing is finished
            SyncDataStore.SetRecords(mailingState.SessionId, true);
        }
Exemplo n.º 2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            LocalizePage();
            // Header.SurveyId = SurveyId;
            ((Wap)Master).HeaderControl.SurveyId = SurveyId;

            try
            {
                // Check if the task has been finished
                object obj = SyncDataStore.GetRecords(Session.SessionID);
                if (obj != null)
                {
                    AllInvitationsSendMessage.Text     = GetPageResource("AllInvitationSendMessage");
                    AllInvitationsSendMessage.CssClass = "SuccessMessage";
//                  Response.Write(GetPageResource("AllInvitationSendMessage"));
                    ProgressBar.Visible = false;
                    SyncDataStore.ClearAll();
                }
                else
                {
                    object error = SyncDataStore.GetRecords(Session.SessionID + ":" + "Error");
                    if (error != null)
                    {
                        SyncDataStore.Remove(Session.SessionID + ":" + "Error");
                        throw (Exception)error;
                    }
                    else
                    {
                        // Retrieve the current progress of the task
                        object mailingProgress = SyncDataStore.GetRecords(Session.SessionID + ":" + "Progress");
                        if (mailingProgress != null)
                        {
                            ProgressBar.Progress = int.Parse(mailingProgress.ToString());
                        }
                        else
                        {
                            ProgressBar.Progress = 0;
                        }

                        object failedEmails = SyncDataStore.GetRecords(Session.SessionID + ":" + "FailedEmails");
                        if (failedEmails != null)
                        {
                            FailedSendingLabel.Text = "Number of failed emails : " + failedEmails.ToString();
                        }

                        ProgressBar.TableWidth = Unit.Pixel(950);
                        Response.AddHeader("Refresh", "2");
                    }
                }
            }
            catch (Exception ex)
            {
                //if (ex.InnerException != null && ex.InnerException.InnerException != null)
                //{
                //    Response.Write(@"<script type='text/javascript' language='javascript'>alert('" + ex.InnerException.InnerException.Message.Replace("'", "\\'").Replace(Environment.NewLine, "\\n") + "')</script>");
                //}
                //else
                //{
                //    Response.Write(@"<script type='text/javascript' language='javascript'>alert('" + ex.Message.Replace("'", "\\'").Replace(Environment.NewLine, "\\n") + "')</script>");
                //}
                Response.Write(@"<script type='text/javascript' language='javascript'>alert('An error has occurred')</script>");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// description: ......
        /// </summary>
        /// <param name="sessionId">description .....</param>
        /// <param name="surveyId">description ....</param>
        /// <param name="anonymousEntries">description ..</param>
        /// <param name="mailingEmails">description .......</param>
        /// <param name="message">description ......</param>
        public void MailIt(string sessionId, int surveyId, bool anonymousEntries, string mailingEmails, EmailingMessage message)
        {
            IEmailing mailService   = EmailingFactory.Create();
            string    guid          = null,
                      taggedMessage = message.Body,
                      email;

            string[] mailingList = mailingEmails.Split(',');

            SyncDataStore.SetRecords(sessionId + ":" + "Progress", 0);
            SyncDataStore.SetRecords(sessionId + ":" + "FailedEmails", 0);

            int failedEmails = 0;

            // Send the invitation email to the list
            for (int i = 0; i < mailingList.Length; i++)
            {
                email = mailingList[i].Trim();
                guid  = null;
                try
                {
                    guid            = new Voter().GenerateVoterInvitationUId(surveyId, email, anonymousEntries);
                    message.Body    = message.Body.Replace("[--invitationid-]", guid);
                    message.ToEmail = email;
                    mailService.SendEmail(message);
                    message.Body = taggedMessage;
                }
                catch (Exception ex)
                {
                    try
                    {
                        if (guid != null)
                        {
                            // rollback db state if an email has been saved
                            new Voter().DeleteVoterInvitation(surveyId, email);
                        }

                        InvitationLogData invitationLogs = new InvitationLogData();
                        InvitationLogData.InvitationLogsRow invitationLog = invitationLogs.InvitationLogs.NewInvitationLogsRow();
                        invitationLog.ExceptionMessage = (ex.InnerException != null && ex.InnerException.InnerException != null) ?
                                                         ex.InnerException.InnerException.Message : ex.Message.ToString();
                        invitationLog.ExceptionType = (ex.InnerException != null && ex.InnerException.InnerException != null) ?
                                                      ex.InnerException.InnerException.GetType().ToString() : ex.GetType().ToString();
                        invitationLog.SurveyId  = surveyId;
                        invitationLog.Email     = email;
                        invitationLog.ErrorDate = DateTime.Now;
                        invitationLogs.InvitationLogs.AddInvitationLogsRow(invitationLog);

                        // Log error in the database
                        new Voter().LogInvitationError(invitationLogs);
                        failedEmails++;
                    }
                    catch (Exception e)
                    {
                        SyncDataStore.SetRecords(sessionId + ":" + "Error", e);
                    }
                }

                SyncDataStore.UpdateRecords(sessionId + ":" + "Progress", (i * 100) / mailingList.Length);
                SyncDataStore.UpdateRecords(sessionId + ":" + "FailedEmails", failedEmails);
            }
        }