Ejemplo n.º 1
0
        /// <summary>
        /// Decode the given stream into a collection of parts.
        /// </summary>
        /// <returns></returns>
        public ITransmissionPartCollection Decode(string name, Stream stream, string mimeType, string id = null)
        {
            ParameterCheck.ParameterRequired(stream, "stream");
            ParameterCheck.StringRequiredAndNotWhitespace(mimeType, "mimeType");

            var transmissionPartCollection = new TransmissionPartCollection();

            try {
                int nextContentId = 1;

                var mime = new Mime(stream);
                Console.WriteLine("Parts " + mime.NumParts);
                logger.DebugFormat("Parts {0}", mime.NumParts);

                for (int partIndex = 0; partIndex < mime.NumParts; partIndex++)
                {
                    Mime   mimePart  = mime.GetPart(partIndex);
                    string contentId = mimePart.GetHeaderField("Content-id");
                    if (contentId.Trim().Length == 0)
                    {
                        var sb = new StringBuilder();
                        sb.Append("OAIPART_"); //TODO determine better name for mime part than OAIPART_
                        sb.Append(DateTime.Now.Ticks.ToString());
                        sb.Append("_");
                        sb.Append(nextContentId.ToString());
                        contentId = sb.ToString();
                        nextContentId++;
                    }

                    string contentType = mimePart.ContentType;

                    //content type may contain ;char-encoding.  Strip it off if found.
                    if (contentType != null)
                    {
                        contentType = contentType.NormalizeContentType();
                    }

                    //TODO We need better way to get a BodyStream from a MimePart.
                    transmissionPartCollection.Add(transmissionPartFactory.CreateTransmissionPart(name,
                                                                                                  new MemoryStream(mimePart.GetBodyBinary()),
                                                                                                  contentType, contentId));
                }
            }
            catch (Exception err) {
                logger.Error(Messages.MimeEncoding_Decode_GeneralDecodingError, err);
                throw new JdfException(Messages.MimeEncoding_Decode_GeneralDecodingError, err);
            }

            if (transmissionPartCollection.Count == 0)
            {
                logger.Error(Messages.MimeEncoding_Decode_NoMessagePartsToDecode);
                throw new JdfException(Messages.MimeEncoding_Decode_NoMessagePartsToDecode);
            }

            return(transmissionPartCollection);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Decode the given stream into a collection of parts.
        /// </summary>
        /// <returns></returns>
        public ITransmissionPartCollection Decode(string name, Stream stream, string mimeType, string id = null)
        {
            ParameterCheck.ParameterRequired(stream, "stream");
            ParameterCheck.StringRequiredAndNotWhitespace(mimeType, "mimeType");

            var transmissionPartCollection = new TransmissionPartCollection();

            transmissionPartCollection.Add(transmissionPartFactory.CreateTransmissionPart(name, stream, mimeType, id));
            return(transmissionPartCollection);
        }
        /// <summary>
        /// Add a JDF that will be sent with this submit queue entry.
        /// </summary>
        /// <param name="ticket"></param>
        /// <returns></returns>
        public SubmitQueueEntryCommandAttributeBuilder Ticket(Ticket ticket)
        {
            ParameterCheck.ParameterRequired(ticket, "ticket");

            var part = transmissionPartFactory.CreateTransmissionPart("Ticket", ticket);

            ParentJmfNode.Message.AddRelatedPart(part);
            var name = Globals.JdfName("QueueSubmissionParams"); //TODO once params are generated, move to use the constant.

            //http://www.faqs.org/rfcs/rfc2387.html
            AddNode(name).With().Attribute("URL", string.Format("cid:{0}", part.Id));
            return(this);
        }