示例#1
0
        /// <summary>
        /// Get a message history based on a YouMailQuery
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task <GetUpdateResult <YouMailHistory[]> > GetMessageHistoryFromQueryAsync(YouMailQuery query)
        {
            GetUpdateResult <YouMailHistory[]> returnValue = null;
            HttpResponseMessage   response = null;
            List <YouMailHistory> callList = new List <YouMailHistory>();
            DateTime lastQueryUpdated      = DateTime.MinValue;
            int      count = 0;

            do
            {
                count = 0;
                string queryString = query.GetQueryString();

                using (response = await YouMailApiAsync(YMST.c_messageBoxHistoryQuery + queryString, null, HttpMethod.Get))
                {
                    var histories = DeserializeObject <YouMailHistories>(response.GetResponseStream());

                    // Get all the call histories where the result is no message left
                    if (histories != null && histories.Histories != null)
                    {
                        var messageQuery = from c in histories.Histories
                                           where c.Result != VoicemailResult.LeftMessage
                                           select c;

                        count = messageQuery.Count();
                        callList.AddRange(messageQuery);
                    }
                    if (lastQueryUpdated == DateTime.MinValue)
                    {
                        var date = response.Headers.Date.ToString();
                        lastQueryUpdated = DateTime.Parse(date);
                    }
                }
                query.Page++;
            } while (count == query.PageLength);

            returnValue = new GetUpdateResult <YouMailHistory[]>(lastQueryUpdated, callList.ToArray());
            return(returnValue);
        }
示例#2
0
        private async Task <GetUpdateResult <YouMailMessage[]> > ExecuteMessageQueryAsync(YouMailQuery query)
        {
            HttpResponseMessage   response = null;
            List <YouMailMessage> list     = new List <YouMailMessage>();
            int count = 0;

            do
            {
                if (query.MaxResults < query.PageLength)
                {
                    query.PageLength = query.MaxResults;
                }
                string queryString = query.GetQueryString();

                using (response = await YouMailApiAsync(YMST.c_messageBoxEntryQuery + queryString, null, HttpMethod.Get))
                {
                    try
                    {
                        YouMailMessages messages = DeserializeObject <YouMailMessages>(response.GetResponseStream());
                        if (messages != null && messages.Messages != null)
                        {
                            count = messages.Messages.Length;
                            list.AddRange(messages.Messages);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                    }
                    query.Offset     += count;
                    query.MaxResults -= count;
                    query.Page++;
                }
            } while (count == query.PageLength && query.MaxResults > 0);

            string date = null;

            date = response.Headers.Date.ToString();

            return(new GetUpdateResult <YouMailMessage[]>(DateTime.Parse(date), list.ToArray()));
        }
示例#3
0
        private async Task <GetUpdateResult <YouMailContact[]> > ExecuteContactQueryAsync(YouMailQuery query)
        {
            HttpResponseMessage   response = null;
            List <YouMailContact> contacts = new List <YouMailContact>();
            DateTime lastQueryUpdated      = DateTime.MinValue;
            int      count = 0;

            do
            {
                count = 0;
                using (response = await YouMailApiAsync(YMST.c_getContacts + query.GetQueryString(), null, HttpMethod.Get))
                {
                    var contactResponse = DeserializeObject <YouMailContactsResponse>(response.GetResponseStream());
                    if (contactResponse != null)
                    {
                        count = contactResponse.Contacts.Length;
                        if (count > 0)
                        {
                            contacts.AddRange(contactResponse.Contacts);
                        }
                    }

                    if (lastQueryUpdated == DateTime.MinValue)
                    {
                        var date = response.Headers.Date.ToString();
                        lastQueryUpdated = DateTime.Parse(date);
                    }
                }
                query.Page++;
            } while (count == query.PageLength);

            return(new GetUpdateResult <YouMailContact[]>(lastQueryUpdated, contacts.ToArray()));
        }