/// <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;
        }
示例#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();

            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);
        }
示例#3
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);
        }
        public static List<FluentJdf.Transmission.FileTransmissionItem> GetFileTransmissionItem(string encoderId) {
            var message = GetMessage();

            string name = string.Format("JMF{0}", Infrastructure.Core.Helpers.MimeTypeHelper.JmfExtension);
            var transmissionPartCollection = new TransmissionPartCollection();
            transmissionPartCollection.Add(new MessageTransmissionPart(message, name));
            transmissionPartCollection.AddRange(message.AdditionalParts);

            var encoder = FluentJdf.Configuration.FluentJdfLibrary.Settings.EncodingSettings.FileTransmitterEncoders
               .FirstOrDefault(item => item.Value.Id.Equals(encoderId, StringComparison.OrdinalIgnoreCase)).Value;

            return encoder.PrepareTransmission(transmissionPartCollection, new TransmissionPartFactory(), new EncodingFactory(), new TransmissionLogger()).OrderBy(item => item.Order).ToList();
        }
示例#5
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;
        }
示例#6
0
        /// <summary>
        /// Transmit this ticket to the given url.
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public IJmfResult Transmit(Uri url) {
            try {
                //todo: add packaging options

                string name = string.Format("JMF{0}", MimeTypeHelper.JmfExtension);
                using (var transmissionPartCollection = new TransmissionPartCollection()) {
                    transmissionPartCollection.Add(new MessageTransmissionPart(this, name));
                    transmissionPartCollection.AddRange(additionalParts);
                    return transmitterFactory.GetTransmitterForUrl(url).Transmit(url, transmissionPartCollection);
                }
            }
            catch (Exception err) {
                logger.Error(string.Format(Messages.Ticket_Transmit_Failed, url), err);
                throw;
            }
        }