Ejemplo n.º 1
0
        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="source"></param>
        public Message(Message source) {
            ParameterCheck.ParameterRequired(source, "source");

            if (source.Root != null) {
                Add(new XElement(source.Root));
            }
        }
        /// <summary>
        /// Construct a part from a message
        /// </summary>
        /// <param name="message"></param>
        /// <param name="name"></param>
        /// <param name="id"></param>
        public MessageTransmissionPart(Message message, string name, string id = null) {
            ParameterCheck.ParameterRequired(message, "message");
            ParameterCheck.StringRequiredAndNotWhitespace(name, "name");

            InitalizeProperties(message, name, id);
        }
        /// <summary>
        /// Initialize the properties.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="name"></param>
        /// <param name="id"></param>
        public void InitalizeProperties(Message message, string name, string id) {
            if (string.IsNullOrWhiteSpace(id)) {
                id = string.Format("P_{0}", UniqueGenerator.MakeUnique());
            }

            Name = name;
            MimeType = message.MimeType();
            Id = id;
            Message = message;
        }
        /// <summary>
        /// Creates a transmission part based on a Message.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="message"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ITransmissionPart CreateTransmissionPart(string name, Message message, string id = null) {
            var transmissionPart = ConstructConfiguredTransmissionPart(MimeTypeHelper.JmfMimeType);
            if (transmissionPart is IMessageTransmissionPart) {
                ((IMessageTransmissionPart)transmissionPart).InitalizeProperties(message, name, id);
            }
            else {
                var tempStream = new TempFileStream();
                message.Save(tempStream);
                transmissionPart.Initialize(name, tempStream, MimeTypeHelper.JmfMimeType, id);
            }

            return transmissionPart;
        }
        /// <summary>
        /// Create a message from a document.
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">If the document has
        /// a root element that is not a JMF element.</exception>
        public static Message ToMessage(this XDocument document) {
            ParameterCheck.ParameterRequired(document, "document");
            if (document.Root != null) {
                document.Root.ThrowExceptionIfNotJmfElement();
            }

            var message = new Message();
            if (document.Root != null) {
                message.Add(document.Root);
            }

            return message;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Create a message.
 /// </summary>
 /// <returns></returns>
 public static JmfNodeBuilder Create() {
     var message = new Message();
     return new JmfNodeBuilder(message);
 }
        internal void MapMessageUrls(Message message, IDictionary<string, string> urlMapping) {
            // Access the URL in the QueueSubmissionParams or ResubmissionParams of each Command element in the JMF.
            foreach (var command in message.Root.SelectJDFDescendants(Element.Command)) {
                bool toProcess = false;

                var commandType = command.GetAttributeValueOrNull("Type");

                IEnumerable<XElement> submissionParams = null;

                if (commandType == Command.SubmitQueueEntry) {
                    submissionParams = command.SelectJDFDescendants(Element.QueueSubmissionParams);
                    if (submissionParams.Count() == 0) {
                        throw new JdfException(FluentJdf.Resources.Messages.QueueSubmissionParamsAreRequiredInSubmitQueueEntry);
                    }
                    else {
                        toProcess = true;
                    }
                }
                if (commandType == Command.ResubmitQueueEntry) {
                    submissionParams = command.SelectJDFDescendants(Element.ResubmissionParams);
                    if (submissionParams.Count() == 0) {
                        throw new JdfException(FluentJdf.Resources.Messages.ReSubmissionParamsAreRequiredInResubmitQueueEntry);
                    }
                    else {
                        toProcess = true;
                    }
                }
                if (toProcess) {
                    string jdfUrl = submissionParams.First().GetAttributeValueOrNull("URL").ToString().ToLower();
                    string newUrl = urlMapping.FirstOrDefault(item => item.Key.Equals(jdfUrl, StringComparison.OrdinalIgnoreCase)).Value;
                    if (newUrl != null) {
                        submissionParams.First().AddOrReplaceAttribute(new XAttribute("URL", (new Uri(newUrl)).AbsoluteUri));
                    }
                }
            }
        }