Ejemplo n.º 1
0
        private static IEnumerable <SubmitMessage> CreateSubmitMessageObjects(SubmitMessageViewModel submitInfo)
        {
            string CreatePayloadId(PayloadInfoViewModel payloadInfo, string messageId)
            {
                string name = Path.GetFileNameWithoutExtension(payloadInfo.FileName);

                if (submitInfo.NumberOfSubmitMessages > 1)
                {
                    return($"{messageId}.{name}");
                }

                return(name);
            }

            for (int i = 0; i < submitInfo.NumberOfSubmitMessages; i++)
            {
                var submitMessage = new SubmitMessage {
                    MessageInfo = { MessageId = $"{Guid.NewGuid().ToString()}@{Environment.MachineName}" }
                };
                submitMessage.Collaboration.AgreementRef.PModeId = submitInfo.SendingPMode.Id;

                var originalSenderProperty = new MessageProperty("originalSender",
                                                                 submitInfo.SendingPMode.MessagePackaging.PartyInfo.FromParty.PartyIds.First().Id);

                var finalRecipientProperty = new MessageProperty("finalRecipient",
                                                                 submitInfo.SendingPMode.MessagePackaging.PartyInfo.ToParty.PartyIds.First().Id);

                submitMessage.MessageProperties = new[] { originalSenderProperty, finalRecipientProperty };

                var payloads = new List <Payload>();

                foreach (var payloadInfo in submitInfo.PayloadInformation)
                {
                    var messagePayload = new Payload
                    {
                        Id       = CreatePayloadId(payloadInfo, submitMessage.MessageInfo.MessageId),
                        Location = $"file:///{payloadInfo.FileName}",
                        MimeType = MimeMapping.GetMimeMapping(Path.GetFileName(payloadInfo.FileName))
                    };

                    if (messagePayload.MimeType.Equals("text/xml", StringComparison.OrdinalIgnoreCase))
                    {
                        messagePayload.MimeType = "application/xml";
                    }

                    if (payloadInfo.IncludeSEDPartType)
                    {
                        messagePayload.PayloadProperties = new[] { new PayloadProperty("PartType")
                                                                   {
                                                                       Value = "SED"
                                                                   }, };
                    }

                    payloads.Add(messagePayload);
                }

                submitMessage.Payloads = payloads.ToArray();

                yield return(submitMessage);
            }
        }
Ejemplo n.º 2
0
        public static void CreateSubmitMessages(SubmitMessageViewModel submitInfo)
        {
            var submitMessages = CreateSubmitMessageObjects(submitInfo);

            SubmitMessags(submitMessages, submitInfo.SubmitLocation);
        }