Beispiel #1
0
        internal static Wrappers.SendSMSResp.response ProcessSendSMS(Wrappers.SendSMSReq.request request)
        {
            Wrappers.SendSMSResp.response resp = new Wrappers.SendSMSResp.response();
            List <XElement> elements           = new List <XElement>();

            foreach (var destination in request.phone_to)
            {
                string sessionKey = sh.GetSessionKey(request.login, request.pwd, request.originator.FirstOrDefault(source => source.num_message == destination.num_message)
                                                     .TypedValue);
                resp.method = "SendSMS";
                string[] sentMessages;
                bool     isError = false;
                try
                {
                    sentMessages = service.SendSms(
                        sessionKey: sessionKey,
                        addresses: new[] { destination.TypedValue },
                        messageId: null,
                        distibutionId: null,
                        message: request.message.FirstOrDefault(
                            mess => mess.num_message == destination.num_message
                            ).TypedValue,
                        transliterate: false,
                        transliterateSpecified: false,
                        deliveryTime: null,
                        deliveryTimeSpecified: false,
                        validalityPeriod: null)
                                   .Select(message => message.Id).ToArray();
                }
                catch (Exception ex)
                {
                    sentMessages = new[] {
                        ex.Message.Split(new string[] { "--->" }, StringSplitOptions.RemoveEmptyEntries)
                        .LastOrDefault()
                        .Trim()
                        .RemoveUnredableSymbols()
                        .Unidecode()
                    };
                    isError = true;
                }
                for (int i = 1; i <= sentMessages.Length; ++i)
                {
                    if (!isError)
                    {
                        elements.Add(new Wrappers.SendSMSResp.response.smsLocalType()
                        {
                            num_message = destination.num_message,
                            parts       = (uint)sentMessages.Length,
                            part_no     = (uint)i,
                            id          = sentMessages[i - 1]
                        }.Untyped);
                    }
                    else
                    {
                        XElement element = new XElement(@"msg");
                        element.Add(
                            new XAttribute(@"num_message", destination.num_message),
                            sentMessages[i - 1]
                            );
                        elements.Add(element);
                    }
                }
            }
            elements.ForEach(resp.Untyped.Add);
            return(resp);
        }