Exemplo n.º 1
0
        private bool UpdateMessage(string id, string updateAction)
        {
            var msg = CmoMessage.GetMessage(id);

            if (msg != null)
            {
                CmoMessage.MessageAction action = null;
                switch (updateAction)
                {
                case ActionName_Archive:
                    action = msg.Archive;
                    break;

                case ActionName_Unarchive:
                    action = msg.Unarchive;
                    break;

                case ActionName_Flag:
                    action = msg.SetFlag;
                    break;

                case ActionName_ClearFlag:
                    action = msg.ClearFlag;
                    break;
                }
                return(action != null && action((User.Identity.Name)));
            }
            return(false);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Attempts to display a CMO message in a new <see cref="CmoMessageForm"/>.
 /// </summary>
 /// <param name="uniqueId">The unique identifer of the CMO message to display.</param>
 private void ShowMessage(string uniqueId)
 {
     this.Cursor = Cursors.WaitCursor;
     new MethodInvoker(() =>
     {
         CmoMessage message = CmoMessage.GetMessage(uniqueId);
         this.BeginInvoke(new MethodInvoker(() =>
         {
             try
             {
                 if (message == null)
                 {
                     MessageBox.Show(this, string.Format("Unable to retrieve campaign message with ID \"{0}\". Please check the message ID and retry your request.", uniqueId), "Message Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     CmoMessageForm form = new CmoMessageForm();
                     form.SetMessage(message);
                     form.ShowAsMdiSiblingOf(this);
                 }
             }
             finally
             {
                 this.Cursor = Cursors.Default;
             }
         }));
     }).BeginInvoke(null, null);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Handles the event that occurs when opening a Campaign Messages Online message by ID.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">An <see cref="EventArgs"/> that contains the event data.</param>
 private void OpenMessage(object sender, EventArgs e)
 {
     using (InputDialog dialog = new InputDialog()
     {
         Title = "Open Message",
         Prompt = "Message ID:",
         ValidationErrorText = "Invalid ID specified or message not found.",
         Icon = Properties.Resources.Email
     })
     {
         CmoMessage selection = null;
         dialog.ValidatingResponse += (string value) =>
         {
             selection = CmoProviders.DataProvider.GetCmoMessage(value);
             return(selection != null);
         };
         if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             this.SpawnMdiChild <CmoMessageForm>((CmoMessageForm m) =>
             {
                 m.Message = selection;
             });
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Gets a specific Campaign Messages Online message.
        /// </summary>
        /// <param name="uniqueID">The unique message identifier.</param>
        /// <returns>The requested message if found; otherwise, null.</returns>
        public CmoMessage GetCmoMessage(string uniqueID)
        {
            string candidateID;
            int    messageID;

            return(CmoMessage.TryParseUniqueID(uniqueID, out candidateID, out messageID) ? GetCmoMessage(candidateID, messageID) : null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets a delegate reference to a method for a Campaign Messages Online message.
        /// </summary>
        /// <param name="commandName">A command name value representing the type of method delegate to get.</param>
        /// <param name="message">The targeted <see cref="CmoMessage"/> object.</param>
        /// <returns>A <see cref="CmoMessage.MessageAction"/> delegate reference if a matching method is found.</returns>
        public static CmoMessage.MessageAction GetAction(string commandName, CmoMessage message)
        {
            CmoMessage.MessageAction ma = null;
            if (message != null)
            {
                switch (commandName)
                {
                case ArchiveCommandName:
                    ma = message.Archive;
                    break;

                case UnarchiveCommandName:
                    ma = message.Unarchive;
                    break;

                case FlagCommandName:
                    ma = message.SetFlag;
                    break;

                case ClearFlagCommandName:
                    ma = message.ClearFlag;
                    break;
                }
            }
            return(ma);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Updates a CMO message instance in the persistence storage medium by overwriting the existing record.
 /// </summary>
 /// <param name="message">The CMO message to update.</param>
 /// <returns>true if the CMO message instance was saved successfuly; otherwise, false.</returns>
 public bool Update(CmoMessage message)
 {
     if (message != null && !message.IsPosted)
     {
         using (Data.CmoEntities context = new Data.CmoEntities())
         {
             var ret = context.CmoSaveMessage(message.CandidateID, message.ID, message.ElectionCycle, message.Title, message.Body, message.Creator, message.OpenReceiptEmail, message.CategoryID, message.Version).FirstOrDefault();
             if (!ret.HasValue || ret.Value != message.ID)
             {
                 return(false);
             }
             // update metadata
             if (!SetCmoMessageAuditReviewNumber(message))
             {
                 return(false);
             }
             if (!SetCmoMessagePostElectionAuditRequestType(message))
             {
                 return(false);
             }
             if (!SetCmoMessageTolling(message))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Exemplo n.º 7
0
        public ActionResult Attachment(string messageid, string id)
        {
            // check for valid, opened message
            var message = CmoMessage.GetMessage(messageid);

            if (message == null)
            {
                return(HttpNotFound());
            }
            if (!message.IsOpened)
            {
                return(RedirectToAction(ActionName_Details, new { id = messageid }));
            }

            // find attachment and download
            var attachment = CmoAttachment.GetAttachment(string.Join("-", messageid, id));

            if (attachment == null)
            {
                return(HttpNotFound());
            }
            Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", attachment.FileName));
            return(new FilePathResult("~/App_Data/SampleAttachment.pdf", "application/octet-stream")
            {
                FileDownloadName = attachment.FileName
            });
        }
Exemplo n.º 8
0
 /// <summary>
 /// Gets the unique message ID for a specific payment letter's corresponding CMO message.
 /// </summary>
 /// <param name="candidateID">The ID of the candidate context.</param>
 /// <param name="paymentRun">The payment run number.</param>
 /// <returns>The unique ID of the CMO message for the specified payment run if found; otherwise, null.</returns>
 public string GetPaymentMessageID(string candidateID, byte paymentRun)
 {
     using (Data.CmoEntities context = new Data.CmoEntities())
     {
         var message = context.CmoMessages.OrderByDescending(m => m.PostDate).FirstOrDefault(m => m.CandidateId == candidateID && m.PostDate.HasValue && m.CmoAuditReview.ReviewNumber == paymentRun);
         return(message == null ? null : CmoMessage.ToUniqueID(message.CandidateId, message.MessageId));
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Sets tolling information for a tolling letter CMO message.
        /// </summary>
        /// <param name="candidateID">The ID of the candidate context.</param>
        /// <param name="messageID">The ID of the message to update.</param>
        /// <param name="eventNumber">The tolling letter event number.</param>
        /// <param name="letter">The tolling letter to set or clear.</param>
        /// <returns>true if the tolling letter codes were set successfully; otherwise, false.</returns>
        /// <remarks>The tolling letter codes can only be set if the message already exists and is of the tolling letter category.</remarks>
        public bool SetCmoMessageTolling(string candidateID, int messageID, int eventNumber, TollingLetter letter)
        {
            CmoMessage message = GetCmoMessage(candidateID, messageID);

            message.TollingLetter      = letter;
            message.TollingEventNumber = eventNumber;
            return(SetCmoMessageTolling(message));
        }
Exemplo n.º 10
0
 /// <summary>
 /// Sets the message's archived status.
 /// </summary>
 /// <param name="message">The message to archive.</param>
 /// <param name="archived">true if the message is to be archived; otherwise, false to unarchive the message.</param>
 /// <param name="username">The C-Access username of the user changing the message archived status.</param>
 /// <returns>true if the message archived status was changed successfully; otherwise, false.</returns>
 public bool SetArchiveStatus(CmoMessage message, bool archived, string username)
 {
     if (message == null)
     {
         return(false);
     }
     using (DataClient client = new DataClient()) { return(client.SetCmoMessageArchiveStatus(message.CandidateID, message.ID, archived, username, message.Version)); }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Sets the tolling information for a tolling letter CMO message.
        /// </summary>
        /// <param name="message">The CMO message to update.</param>
        /// <returns>true if the tolling information was set or cleared successfully; otherwise, false.</returns>
        /// <remarks>The tolling information can only be successfully set if the message is a tolling letter and cleared if the message is not a tolling letter. The information will automatically be cleared for messages that are not tolling letters regardless of the message's tolling values.</remarks>
        private bool SetCmoMessageTolling(CmoMessage message)
        {
            if (message == null)
            {
                return(false);
            }

            string        candidateID = message.CandidateID;
            int           messageID   = message.ID;
            TollingLetter letter      = message.TollingLetter;

            if (message.IsInadequateResponseLetter)
            {
                // force interpretation of inadequate response letters as tolling letters
                if (letter == null)
                {
                    letter = message.TollingLetter = GetTollingLetter(CPConvert.ToCfisCode(AuditReportType.IdrInadequateResponse), message.IsIdrAdditionalInadequateLetter || message.IsDarAdditionalInadequateLetter ? "ADDINA" : "INARES", "INAD");
                }
                if (!message.TollingEventNumber.HasValue)
                {
                    message.TollingEventNumber = int.MinValue;
                }
            }
            bool hasTolling = message.TollingEventNumber.HasValue && letter != null;
            bool isTolling  = message.IsTollingLetter;

            using (Data.CmoEntities context = new Data.CmoEntities())
            {
                var tl = context.CmoTollingLetters.FirstOrDefault(l => l.CandidateId == message.CandidateID && l.MessageId == message.ID);
                if (tl != null)
                {
                    if (isTolling)
                    {
                        tl.EventNumber = message.TollingEventNumber ?? int.MinValue;
                    }
                    else
                    {
                        context.DeleteObject(tl);
                    }
                }
                else if (isTolling)
                {
                    context.AddToCmoTollingLetters(Data.CmoTollingLetter.CreateCmoTollingLetter(candidateID, messageID, message.TollingEventNumber ?? int.MinValue, letter.ID));
                }
                try
                {
                    int updates = context.SaveChanges();
                    return(isTolling ? updates > 0 : !hasTolling);
                }
                catch (OptimisticConcurrencyException)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Updates the post election dates corresponding to a CMO post election audit message in CFIS.
        /// </summary>
        /// <param name="message">The post election audit message to update.</param>
        /// <returns>true if the post election dates were successfully updated in CFIS; otherwise, false.</returns>
        private bool UpdatePostElectionDates(CmoMessage message)
        {
            if (message == null)
            {
                return(false);
            }
            AuditReportType type;

            if (message.IsInitialDocumentationRequest)
            {
                type = AuditReportType.InitialDocumentationRequest;
            }
            else if (message.IsIdrInadequateResponseLetter)
            {
                type = AuditReportType.IdrInadequateResponse;
            }
            else if (message.IsIdrAdditionalInadequateLetter)
            {
                type = AuditReportType.IdrAdditionalInadequateResponse;
            }
            else if (message.IsDarInadequateResponseLetter)
            {
                type = AuditReportType.DarInadequateResponse;
            }
            else if (message.IsDarAdditionalInadequateLetter)
            {
                type = AuditReportType.DarAdditionalInadequateResponse;
            }
            else
            {
                return(false);
            }
            using (PostElectionTableAdapter ta = new PostElectionTableAdapter())
            {
                object retObj;                                   // SQL error code as object
                int    retVal;                                   // SQL error code
                int?   eventNumber = message.TollingEventNumber; // number of event generated or source tolling event, as appropriate
                retObj = ta.UpdatePostElectionDates(message.CandidateID, message.ElectionCycle, CPConvert.ToCfisCode(type), message.PostElectionAuditRequestType == AuditRequestType.SecondRequest || message.PostElectionAuditRequestType == AuditRequestType.SecondRepost ? "Y" : "N", ref eventNumber);
                if (retObj != null && int.TryParse(retObj.ToString(), out retVal))
                {
                    if (retVal == 0)
                    {
                        // save event number for tolling letters
                        if (eventNumber.HasValue && message.IsTollingLetter)
                        {
                            message.TollingEventNumber = eventNumber;
                            SetCmoMessageTolling(message);
                        }
                        return(true);
                    }
                }
                return(false);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Retrieves a message from the current mailbox.
        /// </summary>
        /// <param name="UniqueID">The unique message ID of the message to retrieve.</param>
        /// <returns>A <see cref="CmoMessage"/> representing the requested message if found; otherwise, null.</returns>
        /// <remarks>Retrieving the message will initiate a fetch of the mailbox message contents as well as attempt to populate the previous message ID, next message ID, and current message index properties.</remarks>
        private CmoMessage GetMessage(string UniqueID)
        {
            _mailbox.GetMessages();
            CmoMessage message = _mailbox.OpenMessage(UniqueID, out _previousId, out _nextId, out _messageIndex);

            if (message == null)
            {
                message = _mailbox.OpenMessage(UniqueID);
            }
            return(message);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Determines whether or not a CMO message has a valid post election audit request type.
 /// </summary>
 /// <param name="message">The message to validate.</param>
 /// <param name="secondExists">Whether or not a second request already exists.</param>
 /// <returns>true if the message violates post election audit workflow.</returns>
 private bool HasValidPostElectionRequestType(CmoMessage message, bool secondExists)
 {
     if (message != null && message.PostElectionAuditRequestType.HasValue)
     {
         AuditRequestType type     = message.PostElectionAuditRequestType.Value;
         bool             isRepost = type == AuditRequestType.FirstRepost || type == AuditRequestType.SecondRepost;
         bool             isSecond = type == AuditRequestType.SecondRepost || type == AuditRequestType.SecondRequest;
         // since a current status already exists, only allow reposts and original second requests
         return((isRepost && isSecond == secondExists) || (isSecond && !secondExists));
     }
     return(true);
 }
Exemplo n.º 15
0
 public static MessageHeaderViewModel MessageHeaderFrom(CmoMessage source)
 {
     return(source == null || !source.IsPosted ? new MessageHeaderViewModel() : new MessageHeaderViewModel
     {
         ID = source.UniqueID,
         ElectionCycle = source.ElectionCycle,
         Title = source.Title,
         Flagged = source.NeedsFollowUp,
         HasAttachments = source.HasAttachment,
         OpenedDate = source.OpenDate,
         Posted = source.PostDate.Value
     });
 }
Exemplo n.º 16
0
 /// <summary>
 /// Rolls back a CMO message.
 /// </summary>
 /// <param name="message">The <see cref="CmoMessage"/> to roll back.</param>
 private static void RollBack(CmoMessage message)
 {
     if (message != null)
     {
         for (int i = 0; i < Properties.Settings.Default.MaxCleanupRetryCount; i++)
         {
             message.Reload();
             if (message.Delete())
             {
                 return;
             }
         }
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Attaches a file attachment to the message using the default CMO attachment repository.
        /// </summary>
        /// <param name="message">The CMO message to attach to.</param>
        /// <param name="data">The binary data contents of the attachment.</param>
        /// <param name="name">The filename of the attachment.</param>
        /// <returns>A <see cref="CmoAttachment"/> for the attachment if the file was attached successfully; otherwise, null.</returns>
        public CmoAttachment Attach(CmoMessage message, byte[] data, string name)
        {
            if (message.IsPosted)
            {
                return(null);
            }
            CmoAttachment attachment = this.AddCmoAttachment(message.CandidateID, message.ID, data, name);

            if (attachment != null)
            {
                message.Attachments.Add(attachment.ID, attachment);
                return(attachment);
            }
            return(null);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Sends an email notification for a posted CMO message.
 /// </summary>
 /// <param name="message">The message to send posted notifications for.</param>
 /// <param name="loadCandidate">A delegate for handling requests for candidate information.</param>
 /// <param name="recipients">A collection of users who will receive the notifications.</param>
 /// <returns>true if and only if all recipients were successfully notified; otherwise, false.</returns>
 public static bool SendFor(CmoMessage message, LoadCandidateEventHandler loadCandidate = null, IEnumerable <CPUser> recipients = null)
 {
     if (loadCandidate == null)
     {
         loadCandidate = CPProviders.DataProvider.GetCandidate;
     }
     if (recipients == null)
     {
         recipients = CPSecurity.Provider.GetCampaignUsers(message.CandidateID, message.ElectionCycle, false);
     }
     using (CmoPostedMessageNotice notice = new CmoPostedMessageNotice(message))
     {
         notice.LoadCandidate += loadCandidate;
         notice.Recipients     = recipients;
         return(notice.Send());
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CmoOpenedMessageReceipt"/> class.
 /// </summary>
 /// <param name="message">The newly posted CMO message.</param>
 /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
 /// <exception cref="ArgumentException"><paramref name="message"/> has not been posted.</exception>
 public CmoOpenedMessageReceipt(CmoMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message", "CMO message must not be null.");
     }
     _message = message;
     if (!message.IsOpened)
     {
         throw new ArgumentException("message", "CMO message must be opened first before a receipt can be sent.");
     }
     _mail         = new CPMailMessage();
     _mail.Sender  = new MailAddress(_mail.Sender.Address);
     _mail.Subject = string.Format(OpenReceiptSubjectFormat, _message.UniqueID);
     _mail.AddRecipients(message.OpenReceiptEmail);
     _mail.IsBodyHtml = true;
 }
Exemplo n.º 20
0
        /// <summary>
        /// Sets the post election audit request type for an audit review CMO message.
        /// </summary>
        /// <param name="message">The CMO message to update.</param>
        /// <returns>true if the type was set or cleared successfully; otherwise, false.</returns>
        /// <remarks>The post election audit request type can only be successfully set if the message is a post election audit request and cleared if the message is not a post election audit request. The type will automatically be cleared for messages that are not post election audit requests regardless of the value in <paramref name="message"/>.</remarks>
        private bool SetCmoMessagePostElectionAuditRequestType(CmoMessage message)
        {
            if (message == null)
            {
                return(false);
            }
            AuditRequestType?type           = message.PostElectionAuditRequestType;
            bool             hasRequestType = type.HasValue;
            bool             isPea          = message.IsPostElectionAudit && hasRequestType;
            bool             isRepost       = hasRequestType && (type == AuditRequestType.FirstRepost || type == AuditRequestType.SecondRepost);
            bool             isSecond       = hasRequestType && (type == AuditRequestType.SecondRepost || type == AuditRequestType.SecondRequest);

            using (Data.CmoEntities context = new Data.CmoEntities())
            {
                var request = context.CmoPostElectionRequests.FirstOrDefault(r => r.CandidateId == message.CandidateID && r.MessageId == message.ID);
                if (request != null)
                {
                    // update or delete existing row
                    if (isPea)
                    {
                        request.Repost        = isRepost;
                        request.SecondRequest = isSecond;
                    }
                    else
                    {
                        // always delete row if not a request, but return true only if there is no longer a request type
                        context.DeleteObject(request);
                    }
                }
                else if (isPea)
                {
                    // no post election audit request entries were found, so try to add a new one if applicable
                    context.AddToCmoPostElectionRequests(Data.CmoPostElectionRequest.CreateCmoPostElectionRequest(message.CandidateID, message.ID, isRepost, isSecond));
                }
                try
                {
                    int updates = context.SaveChanges();
                    return(isPea ? updates > 0 : !hasRequestType);
                }
                catch (OptimisticConcurrencyException)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Gets a collection of IDs for all post election audit reports for a specific candidate and election cycle.
 /// </summary>
 /// <param name="candidateID">The CFIS ID of the reviewed candidate.</param>
 /// <param name="electionCycle">The election cycle of the reviews.</param>
 /// <returns>A collection of unique IDs for all post election audit report CMO messages found.</returns>
 public Dictionary <AuditReportType, string> GetAuditReportMessageIDs(string candidateID, string electionCycle)
 {
     using (Data.CmoEntities context = new Data.CmoEntities())
     {
         var categories = new List <byte> {
             CmoCategory.IdrCategoryID, CmoCategory.IdrInadequateCategoryID, CmoCategory.IdrAdditionalInadequateCategoryID, CmoCategory.DarCategoryID, CmoCategory.DarInadequateCategoryID, CmoCategory.DarAdditionalInadequateCategoryID, CmoCategory.FarCategoryID
         };
         var messages = from m in context.CmoMessages
                        join c in context.CmoCategories
                        on m.CmoCategory.CategoryId equals c.CategoryId
                        where m.CandidateId == candidateID && m.ElectionCycle == electionCycle && m.PostDate.HasValue && categories.Contains(m.CmoCategory.CategoryId)
                        group m by m.CmoCategory.CategoryId into mgroup
                        select new { CategoryID = mgroup.Key, MessageID = mgroup.Max(m => m.MessageId) };
         return((from m in messages.AsEnumerable().Select(m => new { AuditReportType = CmoCategory.ToAuditReportType(m.CategoryID), m.MessageID })
                 where m.AuditReportType.HasValue
                 select m).ToDictionary(m => m.AuditReportType.Value, m => CmoMessage.ToUniqueID(candidateID, m.MessageID)));
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Detaches a file attachment from the message using the default CMO attachment repository.
        /// </summary>
        /// <param name="message">The CMO message to detach from.</param>
        /// <param name="attachmentID">The ID of the attachment to detach.</param>
        /// <returns>true if the attachment was removed successfully; otherwise, false.</returns>
        public bool Detach(CmoMessage message, byte attachmentID)
        {
            if (message.IsPosted)
            {
                return(false);
            }
            CmoAttachment attachment;

            if (message.Attachments.TryGetValue(attachmentID, out attachment))
            {
                if (this.Delete(attachment))
                {
                    message.Attachments.Remove(attachment.ID);
                    return(true);
                }
            }
            return(true);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmoPostedMessageNotice"/> class.
        /// </summary>
        /// <param name="message">The newly posted CMO message.</param>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="message"/> has not been posted.</exception>
        private CmoPostedMessageNotice(CmoMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message", "CMO message must not be null.");
            }
            _message = message;
            if (!message.IsPosted)
            {
                throw new ArgumentException("message", "CMO message must be posted first before a notification can be sent.");
            }
            _mail = new CPMailMessage();
            ISettingsProvider settings = CPProviders.SettingsProvider;

            _mail.Sender     = settings == null ? new MailAddress(_mail.Sender.Address) : new MailAddress(settings.MessageSenderEmail, settings.MessageSenderDisplayName);
            _mail.Subject    = message.Title;
            _mail.IsBodyHtml = true;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            context.CheckPitStops();
            // process query string for attachment
            string id = context.Request.Path;

            if (id.EndsWith("/"))
            {
                context.Server.RedirectPageNotFound();
            }
            if (id.Contains("/"))
            {
                id = id.Substring(id.LastIndexOf('/') + 1);
            }
            if (id.Contains("."))
            {
                id = id.Substring(0, id.IndexOf('.'));
            }
            CmoAttachment attachment = CmoAttachment.GetAttachment(id);

            if (attachment == null || !attachment.CandidateID.Equals(CPSecurity.Provider.GetCid(context.User.Identity.Name), StringComparison.InvariantCultureIgnoreCase))
            {
                context.Server.RedirectPageNotFound();
            }
            CmoMessage owner = CmoMessage.GetMessage(attachment.CandidateID, attachment.MessageID);

            if ((owner == null) || !owner.IsOpened)
            {
                // if owner message is not posted, open the message first
                context.Response.Redirect(string.Format("/Messages/View.aspx?id={0}", owner.UniqueID));
            }
            else
            {
                context.Response.Clear();
                context.Response.Expires     = 0;
                context.Response.ContentType = context.Response.GetContentType(attachment.FileName);
                // BUGFIX #49 - content-disposition filename need to be surrounded by quotes
                context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", attachment.FileName));
                context.Response.AddHeader("Content-Length", new FileInfo(attachment.Path).Length.ToString());
                // BUGFIX #32 - KB823409: Response.WriteFile cannot download a large file so read/write file in chunks
                context.Response.TransmitFile(attachment.Path);
            }
            context.ApplicationInstance.CompleteRequest();
        }
Exemplo n.º 25
0
 /// <summary>
 /// Converts a <see cref="CmoMessage"/> object into its HTML equivalent.
 /// </summary>
 /// <param name="message">The <see cref="CmoMessage"/> to convert.</param>
 /// <returns>An HTML <see cref="String"/> for displaying the details of <paramref name="message"/> in a web browser.</returns>
 string ToHtml(CmoMessage message)
 {
     if (message == null)
     {
         return(string.Empty);
     }
     else
     {
         string unopenedClass = message.IsOpened ? string.Empty : NewMessageCssClass;
         return(string.Format(MessageTemplate,
                              unopenedClass,
                              message.UniqueID,
                              message.IsOpened ? OpenImageHtml : NewImageHtml,
                              message.ElectionCycle,
                              message.Title,
                              message.HasAttachment ? AttachmentImageHtml : null,
                              message.PostDate,
                              message.NeedsFollowUp ? FlagImageHtml : null));
     }
 }
Exemplo n.º 26
0
        /// <summary>
        /// Handles the <see cref="Control.OnLoad" /> event that occurs as an instance of the page is being created.
        /// </summary>
        /// <param name="e">An <see cref="EventArgs" /> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            string UniqueID = Request.QueryString[CmoMailboxMessageList.MessageIdParameterName];

            _mailbox          = CmoMailbox.GetMailbox(CPProfile.Cid, CPProfile.Elections, Request.QueryString);
            _mailbox.Username = User.Identity.Name;
            if (!Page.IsPostBack)
            {
                _datasource = GetMessage(UniqueID);
                this.DataBind();
            }
            Messages master = this.Master as Messages;

            if (master != null)
            {
                master.DataSource = _mailbox;
                master.DataBind();
            }
        }
Exemplo n.º 27
0
 private void printToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ListView.SelectedListViewItemCollection selection = this.ResultsListView.SelectedItems;
     if (!this.ConfirmMultipleAction("Printing", selection.Count))
     {
         return;
     }
     foreach (ListViewItem item in selection)
     {
         CmoMessage message = CmoMessage.GetMessage(item.Name);
         if (message != null)
         {
             using (CmoMessageForm form = new CmoMessageForm())
             {
                 form.Message = message;
                 form.PrintMessage(false);
             }
         }
     }
 }
Exemplo n.º 28
0
        /// <summary>
        /// Sets the audit review number for an audit review CMO message.
        /// </summary>
        /// <param name="message">The CMO message to update.</param>
        /// <returns>true if the number was set or cleared successfully; otherwise, false.</returns>
        /// <remarks>The audit review number can only be successfully set if the message is an audit review and cleared if the message is not an audit review. The number will automatically be cleared for messages that are not audit reviews regardless of the message's review number value.</remarks>
        private bool SetCmoMessageAuditReviewNumber(CmoMessage message)
        {
            if (message == null)
            {
                return(false);
            }
            bool hasNumber = message.AuditReviewNumber.HasValue;
            bool isReview  = message.IsAuditReview && hasNumber;

            using (Data.CmoEntities context = new Data.CmoEntities())
            {
                var review = context.CmoAuditReviews.FirstOrDefault(r => r.CandidateId == message.CandidateID && r.MessageId == message.ID);
                if (review != null)
                {
                    // update or delete existing row
                    if (isReview)
                    {
                        review.ReviewNumber = message.AuditReviewNumber.Value;
                    }
                    else
                    {
                        // always delete row if not audit review, but return true only if there is no longer a review number
                        context.DeleteObject(review);
                    }
                }
                else if (isReview)
                {
                    // no audit review entries were found, so try to add a new one if applicable
                    context.AddToCmoAuditReviews(Data.CmoAuditReview.CreateCmoAuditReview(message.CandidateID, message.ID, message.AuditReviewNumber.Value));
                }
                try
                {
                    int updates = context.SaveChanges();
                    return(isReview ? updates > 0 : !hasNumber);
                }
                catch (OptimisticConcurrencyException)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 29
0
        public void SendForAsyncTest()
        {
            string     cid        = "811";
            int        usersCount = 5;
            string     email      = "*****@*****.**";
            CmoMessage message    = new CmoMessage(cid, 1)
            {
                Title    = "Unit Test Title",
                Body     = "Body for unit test",
                PostDate = DateTime.Now,
                Category = new CmoCategory(1)
                {
                    Name = "Test Category"
                }
            };
            LoadCandidateEventHandler loadCandidate = (string id) =>
            {
                return(new Candidate(id)
                {
                    FirstName = "CFB", LastName = "Installation"
                });
            };
            var recipients = from i in Enumerable.Range(1, usersCount)
                             select new CPUser("testuser" + i)
            {
                Cid         = cid,
                DisplayName = "Test User " + i,
                Email       = email,
                Enabled     = true,
                SourceType  = EntityType.Generic
            };

            CPProviders.SettingsProvider = new MockSettingsProvider();
            bool expected = true;
            bool actual;
            Func <CmoMessage, LoadCandidateEventHandler, IEnumerable <CPUser>, bool> caller = CmoPostedMessageNotice.SendFor;
            IAsyncResult result = caller.BeginInvoke(message, loadCandidate, recipients, null, null);

            actual = caller.EndInvoke(result);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 30
0
        public void SendForTest()
        {
            string     cid           = "811";
            int        usersCount    = 5;
            string     googleAccount = "simoncwu";
            CmoMessage message       = new CmoMessage(cid, 1)
            {
                Title    = "Unit Test Title",
                Body     = "Body for unit test",
                PostDate = DateTime.Now,
                Category = new CmoCategory(1)
                {
                    Name = "Test Category"
                }
            };
            LoadCandidateEventHandler loadCandidate = (string id) =>
            {
                System.Threading.Thread.Sleep(10000);
                return(new Candidate(id)
                {
                    FirstName = "CFB", LastName = "Installation"
                });
            };
            var recipients = from i in Enumerable.Range(1, usersCount)
                             select new CPUser("testuser" + i)
            {
                Cid         = cid,
                DisplayName = "Test User " + i,
                Email       = googleAccount + "+caccess" + i + "@gmail.com",
                Enabled     = true,
                SourceType  = EntityType.Generic
            };

            CPProviders.SettingsProvider = new MockSettingsProvider();
            bool expected = true;
            bool actual;

            actual = CmoPostedMessageNotice.SendFor(message, loadCandidate, recipients);
            Assert.AreEqual(expected, actual);
        }