Esempio n. 1
0
        public StatisticsSummaryResponse GetStatistics(DateTime from, DateTime to)
        {
            var completeUrl = _statisticsSummaryUrl
                              + "?apiKey=" + HttpUtility.UrlEncode(_apiKey)
                              + "&client=" + CodeStamp
                              + "&from=" + from.ToString(new CultureInfo("da-DK"))
                              + "&to=" + to.ToString(new CultureInfo("da-DK"));
            var webClient      = new WebClient();
            var responseString = webClient.DownloadString(completeUrl);
            int errorCode;

            if (int.TryParse(responseString, out errorCode))
            {
                throw new StatisticsSummaryException(errorCode);
            }

            return(StatisticsSummaryResponse.Parse(xml: responseString));
        }
Esempio n. 2
0
        public static StatisticsSummaryResponse Parse(string xml)
        {
            var doc            = XDocument.Parse(xml);
            var result         = new StatisticsSummaryResponse();
            var summaryElement = doc.Root.XPathSelectElement("./summary");

            result.From = DateTime.Parse(summaryElement.Attribute(XName.Get("from")).Value, new CultureInfo("da-DK"));
            result.To   = DateTime.Parse(summaryElement.Attribute(XName.Get("to")).Value, new CultureInfo("da-DK"));

            var messageElement = summaryElement.XPathSelectElement("./messages");

            result.Messages = new MessagesInfo();
            result.Messages.TotalMessageCount = int.Parse(messageElement.Attribute(XName.Get("messagecount")).Value);
            result.Messages.TotalSmsCount     = int.Parse(messageElement.Attribute(XName.Get("smscount")).Value);
            foreach (var statusElement in messageElement.XPathSelectElements("./status"))
            {
                var status = new StatusLine();
                status.MessageCount = int.Parse(statusElement.Attribute(XName.Get("messagecount")).Value);
                status.SmsCount     = int.Parse(statusElement.Attribute(XName.Get("smscount")).Value);
                status.StatusCode   = int.Parse(statusElement.Attribute(XName.Get("code")).Value);
                result.Messages.Statuses.Add(status);
            }
            return(result);
        }