Exemple #1
0
        public void FixtureSetup()
        {
            HttpClientMock = MockRepository.GenerateMock <IHttpClient>();
            Client         = new RestBroadcastClient(HttpClientMock);

            ExpectedQueryBroadcastData = new CfQueryBroadcastData(500, 0, 1);

            ExpectedContactBatch = new CfContactBatch(1, "contactBatch", CfBatchStatus.Active, 2, DateTime.Now, 10, 15);

            var contactBatchArray = new CfContactBatch[1];

            contactBatchArray[0] = ExpectedContactBatch;

            ExpectedContactBatchQueryResult = new CfContactBatchQueryResult(10, contactBatchArray);

            var resource = new ResourceList();
            var array    = new ContactBatch[1];

            array[0]              = ContactBatchMapper.ToSoapContactBatch(ExpectedContactBatchQueryResult.ContactBatch[0]);
            resource.Resource     = array;
            resource.TotalResults = 1;

            var        serializer = new XmlSerializer(typeof(ResourceList));
            TextWriter writer     = new StringWriter();

            serializer.Serialize(writer, resource);

            HttpClientMock
            .Stub(j => j.Send(Arg <string> .Is.Equal(String.Format("/broadcast/{0}/batch",
                                                                   ExpectedQueryBroadcastData.BroadcastId)),
                              Arg <HttpMethod> .Is.Equal(HttpMethod.Get),
                              Arg <object> .Is.Anything))
            .Return(writer.ToString());
        }
        public async Task <List <string> > getContacts()
        {
            List <string> listResults        = new List <string>();
            ContactStore  store              = null;
            IReadOnlyList <ContactList> list = null;
            ContactReader reader             = null;
            ContactBatch  batch              = null;

            // *** This RequestStoreAsync() call is where the exception is thrown. All the cases below have the same issue. ***
            //store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadWrite);
            //store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);
            store = await ContactManager.RequestStoreAsync();

            list = await store.FindContactListsAsync();

            foreach (ContactList contactList in list)
            {
                reader = contactList.GetContactReader();
                batch  = await reader.ReadBatchAsync();

                foreach (Contact contact in batch.Contacts)
                {
                    string fullname = contact.FullName; //+ ", " + contact.Name;// + ", " + contact.Emails.First().Address;
                    listResults.Add(fullname);
                    DisplayContact dc = new DisplayContact(contact);
                    vDisplayContact.Add(dc);
                }
            }
            return(listResults);
        }
 internal static CfContactBatch FromSoapContactBatch(ContactBatch source)
 {
     if (source == null)
     {
         return(null);
     }
     return(new CfContactBatch(source.id, source.Name, EnumeratedMapper.EnumFromSoapEnumerated <CfBatchStatus>(source.Status.ToString()),
                               source.BroadcastId, source.Created, source.Size, source.Remaining));
 }
Exemple #4
0
        private string GetBatchName()
        {
            string       batchName;
            var          rand    = new Random();
            ContactBatch batch   = new ContactBatch();
            var          newRand = rand.Next(100);

            batchName = batch.BatchName = "Upload - " + newRand;

            return(batchName);
        }
Exemple #5
0
        async Task <ObservableCollection <Contact> > GetContactsAsync()
        {
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            //find contact list
            ContactList contactlist = await store.CreateContactListAsync(Windows.ApplicationModel.Package.Current.DisplayName); //problem if it already exists

            ContactReader contactreader = contactlist.GetContactReader();
            ContactBatch  contactbatch  = await contactreader.ReadBatchAsync();

            return(new ObservableCollection <Contact>(contactbatch.Contacts)); // store.FindContactsAsync()
        }
Exemple #6
0
        /// <summary>
        /// Update displayed contacts.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private async Task DisplayContactsFromReaderAsync(ContactReader reader)
        {
            Contacts.Clear();
            ContactBatch contactBatch = await reader.ReadBatchAsync();

            while (contactBatch.Contacts.Count != 0 &&
                   contactBatch.Status == ContactBatchStatus.Success)
            {
                foreach (Contact c in contactBatch.Contacts)
                {
                    Contacts.Add(new ContactViewModel(c));
                }
                contactBatch = await reader.ReadBatchAsync();
            }
        }
Exemple #7
0
        public ActionResult ContactsTable()
        {
            DateTime myDateTime       = DateTime.Now;
            string   sqlformattedDate = myDateTime.ToString("yyyy-MM-dd hh:mm:ss.fff");
            string   batchName        = GetBatchName();
            //Creating a new Batch object
            ContactBatch batch = new ContactBatch();

            batch.BatchName   = batchName;
            batch.CreatedBy   = "System";
            batch.DateCreated = Convert.ToDateTime(sqlformattedDate);

            //calling the post to ContactBatch table--
            int batchID = ContactDB.GetBatchID(batch);

            List <ContactVM> contacts = new List <ContactVM>();

            contacts = (List <ContactVM>)Session["Upload"];
            ContactDB.PostToDatabase(contacts, batchID);
            return(View(contacts));
        }
        public ActionResult CreateContact()
        {
            //DateTime myDateTime = DateTime.Now;
            //string sqlformattedDate = myDateTime.ToString("yyyy-MM-dd hh:mm:ss.fff");

            var batchName = getBatchName();

            ContactBatch batch = new ContactBatch
            {
                BatchName   = batchName,
                CreatedBy   = "System",
                DateCreated = DateTime.Now
                              //DateCreated = Convert.ToDateTime(sqlformattedDate)
            };
            int batchId = ContactBatchDB.GetBatchID(batch);
            List <ContactVM> contacts = new List <ContactVM>();

            contacts = (List <ContactVM>)Session["Upload"];
            ContactDb.PostToDatabase(contacts, batchId);
            return(View(contacts));
        }
Exemple #9
0
        /// <summary>
        /// Displays the items from the contact store in the contacts view.
        /// </summary>
        /// <param name="reader">Contact store reader</param>
        /// <param name="isGroup">
        /// Boolean to decide if to show the list in a group or a flat list
        /// Groups is shown by default and search
        /// Flast list is shown during search
        /// </param>
        private async Task DisplayContactsFromReaderAsync(ContactReader reader, bool isGroup)
        {
            contactItems.Clear();
            ContactBatch contactBatch = await reader.ReadBatchAsync();

            if (contactBatch.Contacts.Count == 0)
            {
                Debug.WriteLine("Contact store empty");
                ContactsStatusText = "We couldn't find any contacts.";
                ShowContactListStatusText();
                return;
            }

            while (contactBatch.Contacts.Count != 0)
            {
                //should batch add to avoid triggering callbacks
                foreach (Contact c in contactBatch.Contacts)
                {
                    ContactItem contactToAdd = new ContactItem(c.Id, c.DisplayName);
                    contactToAdd.SetImageAsync(c.Thumbnail);
                    contactItems.Add(contactToAdd);
                }
                contactBatch = await reader.ReadBatchAsync();
            }

            if (isGroup)
            {
                GroupsOfContacts = alphaGroupSorting(contactItems);
                ShowContactGroup();
            }
            else
            {
                ListOfContacts = contactItems;
                ShowContactList();
            }
            return;
        }
    private async Task <IReadOnlyList <Contact> > ListContactsAsync()
    {
        ContactStore store = await Store();

        if (store != null)
        {
            ContactList list = await GetAsync();

            if (list != null)
            {
                ContactReader reader = list.GetContactReader();
                if (reader != null)
                {
                    ContactBatch batch = await reader.ReadBatchAsync();

                    if (batch != null)
                    {
                        return(batch.Contacts);
                    }
                }
            }
        }
        return(null);
    }
Exemple #11
0
        private async Task DisplayContactsFromReaderAsync(ContactReader reader, bool isGroup)
        {
            contactItems.Clear();
            ContactBatch contactBatch = await reader.ReadBatchAsync();

            if (contactBatch.Contacts.Count == 0)
            {
                return;
            }

            while (contactBatch.Contacts.Count != 0)
            {
                foreach (Contact c in contactBatch.Contacts)
                {
                    if (c.Phones.Count > 0 || c.Emails.Count > 0)
                    {
                        ContactItem contactToAdd = new ContactItem(c.Id, c.DisplayName);
                        contactToAdd.ContactEmails = c.Emails;
                        contactToAdd.ContactPhones = c.Phones;
                        contactToAdd.SetImageAsync(c.Thumbnail);
                        contactItems.Add(contactToAdd);
                    }
                }
                contactBatch = await reader.ReadBatchAsync();
            }

            if (isGroup)
            {
                groupsOfContacts = alphaGroupSorting(contactItems);
            }
            else
            {
                _contactsList = contactItems;
            }
            return;
        }
 public ContactBatchQueryResult(long totalResults, ContactBatch[] contactBatch)
 {
     TotalResults = totalResults;
     ContactBatch = contactBatch;
 }