コード例 #1
0
ファイル: Message.cs プロジェクト: OnpointOnDemand/fluentjdf
        /// <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));
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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;
        }
コード例 #4
0
        /// <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;
        }
コード例 #5
0
        /// <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;
        }
コード例 #6
0
ファイル: Message.cs プロジェクト: OnpointOnDemand/fluentjdf
 /// <summary>
 /// Create a message.
 /// </summary>
 /// <returns></returns>
 public static JmfNodeBuilder Create() {
     var message = new Message();
     return new JmfNodeBuilder(message);
 }
コード例 #7
0
        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));
                    }
                }
            }
        }