예제 #1
0
 internal static RequestFile ToRequestFile(ViestitMessageFile file)
 {
     return(new RequestFile
     {
         Size = file.Size,
         Base64Content = file.Content,
         FileMimeType = file.ContentType,
         Name = file.Name
     });
 }
예제 #2
0
        /// <summary>
        /// Sends printable messages to customers through suomi.fi/viestit -service.
        /// Throws ClientFaultException in case of this Client working improperly.
        /// Throws custom Keha.SuomiFiViestitHub.Client.Exceptions on returned error codes.
        /// </summary>
        /// <param name="msgList">Messages are given as a list of ViestitMessages</param>
        /// <returns>Returns the StateCode of the handled message along with supplementing information</returns>
        public async Task <List <SentMessageStatus> > SendPrintableMessageToViestit(List <PrintableViestitMessage> msgList)
        {
            msgList.ForEach((msg) =>
            {
                Validator.ValidateObject(msg, new ValidationContext(msg), true);
                Validator.ValidateObject(msg.Address, new ValidationContext(msg.Address)); // TODO: Is this required?
            });

            var reqList = new List <Task <LahetaViestiResponse> >();

            foreach (PrintableViestitMessage msg in msgList)
            {
                var req = new LahetaViestiRequest
                {
                    CustomerId = msg.SocialSecurityNumber,
                    Files      = new List <RequestFile>()
                    {
                        ViestitMessageFile.ToRequestFile(msg.File)
                    },
                    Id                   = msg.Id,
                    MsgId                = msg.MsgId,
                    Topic                = msg.Topic,
                    SenderName           = msg.SenderName,
                    Text                 = msg.Text,
                    RecipientName        = msg.Address.RecipientName,
                    StreetAddress        = msg.Address.StreetAddress,
                    PostalCode           = msg.Address.PostalCode,
                    City                 = msg.Address.City,
                    CountryCode          = msg.Address.CountryCode,
                    PrintingProvider     = msg.PrintingProvider,
                    SendAlsoAsPrinted    = msg.SendAlsoAsPrinted,
                    UsePrinting          = !msg.TestingOnlyDoNotSendPrinted,
                    ReadConfirmation     = msg.ReadConfirmation,
                    ReceivedConfirmation = msg.ReceivedConfirmation
                };
                InitRequest(req);
                reqList.Add(HubApi.SendPrintableMessageToViestit.Post(_client, req));
            }

            var data = new List <LahetaViestiResponse>(await Task.WhenAll(reqList));

            return(data.ConvertAll((response) =>
                                   new SentMessageStatus
            {
                StateCode = response.StateCode.ToMessageStateCode(),
                StateDescription = response.StateCodeDescription,
                Id = response.MessageId,
            }));
        }