public void BuildHtmlBodyStep_AndPlainText(string text)
        {
            var body        = new ContentBody().WithHtml("<tag>something</tag>");
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildHtmlBodyStep(
                    MailerMessage.Create().WithBody(body), body);
            var stepBuilder = contentStep.AndPlainText(text);

            stepBuilder
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildContentStep.BuildBodyStep.BuildBodyCompleteStep>()
            .Which.As <IBuilderContext>()
            .Message.Body
            .As <ContentBody>()
            .Should().BeEquivalentTo
            (
                new ContentBody
            {
                HtmlContent      = "<tag>something</tag>",
                PlainTextContent = text
            },
                config => config
                .Including(b => b.HtmlContent)
                .Including(b => b.PlainTextContent));
        }
Пример #2
0
        //
        // GET: /ContentDetails/Edit/5

        public ActionResult Edit(int id)
        {
            ContentBody contentbody = db.ContentBodies.Single(c => c.Id == id);

            ViewBag.ContentSection_ID = new SelectList(db.ContentSections, "Id", "Header", contentbody.ContentSection_ID);
            return(View(contentbody));
        }
Пример #3
0
        /// <summary>
        /// Determines the total length of the multipart content (content length of
        /// individual parts plus that of extra elements required to delimit the parts
        /// from one another).
        /// </summary>
        /// <remarks>
        /// Determines the total length of the multipart content (content length of
        /// individual parts plus that of extra elements required to delimit the parts
        /// from one another). If any of the @{link BodyPart}s contained in this object
        /// is of a streaming entity of unknown length the total length is also unknown.
        /// <p/>
        /// This method buffers only a small amount of data in order to determine the
        /// total length of the entire entity. The content of individual parts is not
        /// buffered.
        /// </remarks>
        /// <returns>
        /// total length of the multipart entity if known, <code>-1</code>
        /// otherwise.
        /// </returns>
        public virtual long GetTotalLength()
        {
            long contentLen = 0;

            foreach (FormBodyPart part in this.parts)
            {
                ContentBody body = part.GetBody();
                long        len  = body.GetContentLength();
                if (len >= 0)
                {
                    contentLen += len;
                }
                else
                {
                    return(-1);
                }
            }
            ByteArrayOutputStream @out = new ByteArrayOutputStream();

            try
            {
                DoWriteTo(this.mode, @out, false);
                byte[] extra = @out.ToByteArray();
                return(contentLen + extra.Length);
            }
            catch (IOException)
            {
                // Should never happen
                return(-1);
            }
        }
        public void MessageContentBodyReceived(ushort channelId, ContentBody contentBody)
        {
            UnprocessedMessage msg = (UnprocessedMessage)_channelId2UnprocessedMsgMap[channelId];

            if (msg == null)
            {
                throw new AMQException("Error: received content body without having received a BasicDeliver frame first");
            }
            if (msg.ContentHeader == null)
            {
                _channelId2UnprocessedMsgMap.Remove(channelId);
                throw new AMQException("Error: received content body without having received a ContentHeader frame first");
            }
            try
            {
                msg.ReceiveBody(contentBody);
            }
            catch (UnexpectedBodyReceivedException e)
            {
                _channelId2UnprocessedMsgMap.Remove(channelId);
                throw e;
            }
            if (msg.IsAllBodyDataReceived())
            {
                DeliverMessageToAMQSession(channelId, msg);
            }
        }
        public void BuildTextBody_AndHtml(string html)
        {
            var body        = new ContentBody().WithPlainText("some text");
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildTextBodyStep(
                    MailerMessage.Create().WithBody(body), body);
            var stepBuilder = contentStep.AndHtml(html);

            stepBuilder
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildContentStep.BuildBodyStep.BuildBodyCompleteStep>()
            .Which.As <IBuilderContext>()
            .Message.Body
            .As <ContentBody>()
            .ShouldBeEquivalentTo
            (
                new ContentBody
            {
                HtmlContent      = html,
                PlainTextContent = "some text"
            },
                config => config
                .Including(b => b.HtmlContent)
                .Including(b => b.PlainTextContent));
        }
Пример #6
0
        public SigningEnvelope <T> DecryptSignature(string signedContent, string signatory)
        {
            var decryptedSingature  = cryptoService.DecryptSignature(signedContent, signatory);
            var deserializedContent = JsonConvert.DeserializeObject <T>(decryptedSingature?.Body?.Content);

            var body = new ContentBody <T>();

            if (decryptedSingature?.Body != null)
            {
                body.Content        = deserializedContent;
                body.Version        = decryptedSingature.Body.Version;
                body.CreateDateTime = decryptedSingature.Body.CreateDateTime;
                body.EmailAddress   = decryptedSingature.Body.EmailAddress;
                body.IpAddress      = decryptedSingature.Body.IpAddress;
                body.Signatory      = decryptedSingature.Body.Signatory;
            }

            var mappedSignature = new SigningEnvelope <T>
            {
                Header = decryptedSingature?.Header,
                Body   = body
            };

            return(mappedSignature);
        }
Пример #7
0
        public ActionResult Create(ContentBody contentbody)
        {
            if (ModelState.IsValid)
            {
                db.ContentBodies.Attach(contentbody);
                db.ObjectStateManager.ChangeObjectState(contentbody, EntityState.Added);

                if (contentbody.Promote == "Y")
                {
                    UpdatePromotedArticle(contentbody.Id);
                }
                else
                {
                    contentbody.Promote = "N";
                    UpdatePromotedArticle(5); // article 5 is the dfault
                }

                db.SaveChanges();
            }
            ContentSection contentSection = db.ContentSections.Single(c => c.Id == contentbody.ContentSection_ID);

            ViewBag.SectionTitle = contentSection.Header;
            ViewData.Model       = db.ContentBodies.Where(c => c.ContentSection_ID == contentbody.ContentSection_ID).ToList();
            return(RedirectToAction("../ContentMaintenance/GetSectionItems/" + contentbody.ContentSection_ID));
        }
Пример #8
0
        public ActionResult DeleteConfirmed(int id)
        {
            ContentBody contentbody = db.ContentBodies.Single(c => c.Id == id);

            db.ContentBodies.DeleteObject(contentbody);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void ReceiveBody(ContentBody body)
 {
     Bodies.Add(body);
     if (body.Payload != null)
     {
         _bytesReceived += (uint)body.Payload.Remaining;
     }
 }
        private void SendImpl(string exchangeName, string routingKey, AbstractQmsMessage message, DeliveryMode deliveryMode, int priority, uint timeToLive, bool mandatory, bool immediate)
        {
            // todo: handle session access ticket
            AMQFrame publishFrame = BasicPublishBody.CreateAMQFrame(
                _channel.ChannelId, 0, exchangeName,
                routingKey, mandatory, immediate
                );

            // fix message properties
            if (!_disableTimestamps)
            {
                message.Timestamp = DateTime.UtcNow.Ticks;
                if (timeToLive != 0)
                {
                    message.Expiration = message.Timestamp + timeToLive;
                }
            }
            else
            {
                message.Expiration = 0;
            }
            message.DeliveryMode = deliveryMode;
            message.Priority     = (byte)priority;

            ByteBuffer payload       = message.Data;
            int        payloadLength = payload.Limit;

            ContentBody[] contentBodies = CreateContentBodies(payload);
            AMQFrame[]    frames        = new AMQFrame[2 + contentBodies.Length];
            for (int i = 0; i < contentBodies.Length; i++)
            {
                frames[2 + i] = ContentBody.CreateAMQFrame(_channelId, contentBodies[i]);
            }
            if (contentBodies.Length > 0 && _logger.IsDebugEnabled)
            {
                _logger.Debug(string.Format("Sending content body frames to {{exchangeName={0} routingKey={1}}}", exchangeName, routingKey));
            }

            // weight argument of zero indicates no child content headers, just bodies
            AMQFrame contentHeaderFrame = ContentHeaderBody.CreateAMQFrame(
                _channelId, AmqChannel.BASIC_CONTENT_TYPE, 0,
                message.ContentHeaderProperties, (uint)payloadLength
                );

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug(string.Format("Sending content header frame to  {{exchangeName={0} routingKey={1}}}", exchangeName, routingKey));
            }

            frames[0] = publishFrame;
            frames[1] = contentHeaderFrame;
            CompositeAMQDataBlock compositeFrame = new CompositeAMQDataBlock(frames);

            lock (_channel.Connection.FailoverMutex)
            {
                _channel.Connection.ProtocolWriter.Write(compositeFrame);
            }
        }
        /// <summary>
        ///     Gets the MIME entity the content body.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="message">The message.</param>
        /// <param name="cbody">The cbody.</param>
        /// <returns>BodyBuilder.</returns>
        public static BodyBuilder GetMimeEntityForContentBody(this BodyBuilder builder, DeliveryItem message,
                                                              ContentBody cbody)
        {
            if (cbody != null)
            {
                builder.TextBody = message.ProcessSubstitutions(cbody.PlainTextContent);
                builder.HtmlBody = message.ProcessSubstitutions(cbody.HtmlContent);
            }

            return(builder);
        }
        public void BuildTextBody_And()
        {
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildTextBodyStep(MailerMessage.Create(),
                                                                                    ContentBody.Create());

            contentStep.And
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildPostContentStep>();
        }
 public virtual bool IsRepeatable()
 {
     foreach (FormBodyPart part in this.multipart.GetBodyParts())
     {
         ContentBody body = part.GetBody();
         if (body.GetContentLength() < 0)
         {
             return(false);
         }
     }
     return(true);
 }
 public ActionResult Index(int id = 13)
 {
     try
     {
         ContentBody contentbody = db.ContentBodies.Single(c => c.Id == id);
         return(View(contentbody));
     }
     catch
     {
         return(View());
     }
 }
Пример #15
0
 public ActionResult Index(string pagename = "SEOdefault")
 {
     try
     {
         ContentBody contentbody = db.ContentBodies.Single(c => c.SEOUrl.ToLower() == pagename.ToLower());
         return(View("Index", contentbody));
     }
     catch
     {
         ContentBody contentbody = db.ContentBodies.Single(c => c.SEOUrl == "SEOdefault");
         return(View("Index", contentbody));
     }
 }
Пример #16
0
        protected internal virtual void GenerateContentDisp(ContentBody body)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append("attachment");
            if (body.GetFilename() != null)
            {
                buffer.Append("; filename=\"");
                buffer.Append(body.GetFilename());
                buffer.Append("\"");
            }
            AddField(MIME.ContentDisposition, buffer.ToString());
        }
Пример #17
0
        protected internal virtual void GenerateContentType(ContentBody body)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append(body.GetMimeType());
            // MimeType cannot be null
            if (body.GetCharset() != null)
            {
                // charset may legitimately be null
                buffer.Append("; charset=");
                buffer.Append(body.GetCharset());
            }
            AddField(MIME.ContentType, buffer.ToString());
        }
Пример #18
0
        public ActionResult UpdateSort()
        {
            int         bodyId       = Convert.ToInt32(Request.Form["section"]);
            int         sortPosition = Convert.ToInt32(Request.Form["position"]);
            ContentBody contentBody  = db.ContentBodies.Single(c => c.Id == bodyId);

            contentBody.SortOrder = sortPosition;
            db.SaveChanges();

            ContentSection contentSection = db.ContentSections.Single(con => con.Id == contentBody.ContentSection_ID);

            ViewBag.SectionTitle = contentSection.Header;
            ViewData.Model       = db.ContentBodies.Where(cb => cb.ContentSection_ID == contentSection.Id).OrderBy(s => s.SortOrder).ToList();
            return(View("SectionItems"));
        }
Пример #19
0
        public static PageItem GetPageByFriendlyUrl(string friendlyUrl)
        {
            NESTV1Entities db = new NESTV1Entities();

            PageItem page = null;

            ContentBody contentbody = db.ContentBodies.Single(c => c.SEOUrl == friendlyUrl);

            page                = new PageItem();
            page.PageId         = (int)contentbody.Id;
            page.ControllerName = "Contribute";
            page.FriendlyUrl    = contentbody.SEOUrl;


            return(page);
        }
Пример #20
0
 public FormBodyPart(string name, ContentBody body) : base()
 {
     if (name == null)
     {
         throw new ArgumentException("Name may not be null");
     }
     if (body == null)
     {
         throw new ArgumentException("Body may not be null");
     }
     this.name   = name;
     this.body   = body;
     this.header = new Header();
     GenerateContentDisp(body);
     GenerateContentType(body);
     GenerateTransferEncoding(body);
 }
Пример #21
0
		public FormBodyPart(string name, ContentBody body) : base()
		{
			if (name == null)
			{
				throw new ArgumentException("Name may not be null");
			}
			if (body == null)
			{
				throw new ArgumentException("Body may not be null");
			}
			this.name = name;
			this.body = body;
			this.header = new Header();
			GenerateContentDisp(body);
			GenerateContentType(body);
			GenerateTransferEncoding(body);
		}
        public void BuildHtmlBodyStep_Build()
        {
            var body        = new ContentBody().WithHtml("<tag>something</tag>");
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildHtmlBodyStep(
                    MailerMessage.Create().WithBody(body), body);
            var message = contentStep.Build();

            message
            .Should()
            .NotBeNull()
            .And.BeOfType <MailerMessage>()
            .Which.Body.As <ContentBody>()
            .HtmlContent
            .Should()
            .NotBeNullOrEmpty()
            .And.Be("<tag>something</tag>");
        }
        public void BuildTextBody_Build()
        {
            var body        = new ContentBody().WithPlainText("some text");
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildTextBodyStep(
                    MailerMessage.Create().WithBody(body), body);

            var message = contentStep.Build();

            message
            .Should()
            .NotBeNull()
            .And.BeOfType <MailerMessage>()
            .Which.Body.As <ContentBody>()
            .PlainTextContent
            .Should()
            .NotBeNullOrEmpty()
            .And.Be("some text");
        }
        /// <summary>
        /// Create content bodies. This will split a large message into numerous bodies depending on the negotiated
        /// maximum frame size.
        /// </summary>
        /// <param name="payload"></param>
        /// <returns>return the array of content bodies</returns>
        private ContentBody[] CreateContentBodies(ByteBuffer payload)
        {
            if (payload == null)
            {
                return(null);
            }
            else if (payload.Remaining == 0)
            {
                return(new ContentBody[0]);
            }
            // we substract one from the total frame maximum size to account for the end of frame marker in a body frame
            // (0xCE byte).
            int framePayloadMax = (int)(_channel.Connection.MaximumFrameSize - 1);
            int frameCount      = CalculateContentBodyFrames(payload);

            ContentBody[] bodies = new ContentBody[frameCount];
            for (int i = 0; i < frameCount; i++)
            {
                int length = (payload.Remaining >= framePayloadMax)
               ? framePayloadMax : payload.Remaining;
                bodies[i] = new ContentBody(payload, (uint)length);
            }
            return(bodies);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="BuildBodyStep" /> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public BuildBodyStep(MailerMessage context) : base(context)
 {
     Body         = new ContentBody();
     Context.Body = Body;
 }
Пример #26
0
		protected internal virtual void GenerateContentDisp(ContentBody body)
		{
			StringBuilder buffer = new StringBuilder();
			buffer.Append("attachment");
			if (body.GetFilename() != null)
			{
				buffer.Append("; filename=\"");
				buffer.Append(body.GetFilename());
				buffer.Append("\"");
			}
			AddField(MIME.ContentDisposition, buffer.ToString());
		}
Пример #27
0
		protected internal virtual void GenerateContentType(ContentBody body)
		{
			StringBuilder buffer = new StringBuilder();
			buffer.Append(body.GetMimeType());
			// MimeType cannot be null
			if (body.GetCharset() != null)
			{
				// charset may legitimately be null
				buffer.Append("; charset=");
				buffer.Append(body.GetCharset());
			}
			AddField(MIME.ContentType, buffer.ToString());
		}
Пример #28
0
		protected internal virtual void GenerateTransferEncoding(ContentBody body)
		{
			AddField(MIME.ContentTransferEnc, body.GetTransferEncoding());
		}
Пример #29
0
        public ActionResult Details(int id)
        {
            ContentBody contentbody = db.ContentBodies.Single(c => c.Id == id);

            return(View(contentbody));
        }
 public virtual void AddPart(string name, ContentBody contentBody)
 {
     AddPart(new FormBodyPart(name, contentBody));
 }
Пример #31
0
		public virtual void AddPart(string name, ContentBody contentBody)
		{
			AddPart(new FormBodyPart(name, contentBody));
		}
 /// <summary>
 ///     Adds a plain text email body.
 /// </summary>
 /// <param name="body">The body.</param>
 /// <param name="text">The text.</param>
 /// <returns>ContentBody.</returns>
 public static ContentBody WithPlainText(this ContentBody body, string text)
 {
     body.PlainTextContent = text;
     return(body);
 }
Пример #33
0
 protected internal virtual void GenerateTransferEncoding(ContentBody body)
 {
     AddField(MIME.ContentTransferEnc, body.GetTransferEncoding());
 }
 /// <summary>
 ///     Adds an HTML email body.
 /// </summary>
 /// <param name="body">The body.</param>
 /// <param name="html">The HTML.</param>
 /// <returns>ContentBody.</returns>
 public static ContentBody WithHtml(this ContentBody body, string html)
 {
     body.HtmlContent = html;
     return(body);
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="BuildTextBodyStep" /> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="body">The body.</param>
 public BuildTextBodyStep(MailerMessage context, ContentBody body) : base(context, body)
 {
 }