internal static void DeleteAllContacts(RequestSettings rs) { rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); Feed <Contact> f = cr.GetContacts(); List <Contact> list = new List <Contact>(); int i = 0; foreach (Contact c in f.Entries) { c.BatchData = new GDataBatchEntryData(); c.BatchData.Id = i.ToString(); c.BatchData.Type = GDataBatchOperationType.delete; i++; list.Add(c); } cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.delete); f = cr.GetContacts(); Assert.IsTrue(f.TotalResults == 0, "Feed should be emtpy now"); }
private void DeleteAllContacts() { RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord); rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); Feed <Contact> f = cr.GetContacts(); List <Contact> list = new List <Contact>(); int i = 0; foreach (Contact c in f.Entries) { c.BatchData = new GDataBatchEntryData(); c.BatchData.Id = i.ToString(); c.BatchData.Type = GDataBatchOperationType.delete; i++; list.Add(c); } cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.insert); f = cr.GetContacts(); Assert.IsTrue(f.TotalResults == 0, "Feed should be emtpy now"); }
///////////////////////////////////////////////////////////////////////////// internal static void DeleteList(List <Contact> list, ContactsRequest cr, Uri batch) { int i = 0; foreach (Contact c in list) { c.BatchData = new GDataBatchEntryData(); c.BatchData.Id = i.ToString(); i++; } cr.Batch(list, batch, GDataBatchOperationType.delete); }
/// <summary> /// Unshare all profiles for the domain /// </summary> public BatchResult UnshareProfiles() { BatchResult result = new BatchResult() { ErrorEntries = new List <Contact>(), }; int index = 0; if (this.profiles == null) { this.GetAllProfiles(); } while (index < this.Profiles.Count) { List <Contact> requestFeed = new List <Contact>(); for (int i = 0; i < this.BatchSize && index < this.Profiles.Count; ++i, ++index) { Contact entry = this.Profiles[index]; entry.ContactEntry.Status = new Status(false); entry.BatchData = new GDataBatchEntryData(GDataBatchOperationType.update); requestFeed.Add(entry); } Feed <Contact> responseFeed = cr.Batch(requestFeed, new Uri("https://www.google.com/m8/feeds/profiles/domain/" + this.domain + "/full/batch"), GDataBatchOperationType.Default); // Check the status of each operation. foreach (Contact entry in responseFeed.Entries) { if (entry.BatchData.Status.Code == 200) { ++result.Success; } else { ++result.Error; result.ErrorEntries.Add(entry); } } } return(result); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs an authentication test, inserts a new contact</summary> ////////////////////////////////////////////////////////////////////// [Test] public void ModelBatchContactsTest() { const int numberOfInserts = 5; Tracing.TraceMsg("Entering ModelInsertContactsTest"); DeleteAllContacts(); RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord); rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); List<Contact> list = new List<Contact>(); Feed<Contact> f = cr.GetContacts(); for (int i = 0; i < numberOfInserts; i++) { Contact entry = new Contact(); entry.AtomEntry = ObjectModelHelper.CreateContactEntry(i); entry.PrimaryEmail.Address = "joe" + i.ToString() + "@doe.com"; GDataBatchEntryData g = new GDataBatchEntryData(); g.Id = i.ToString(); g.Type = GDataBatchOperationType.insert; entry.BatchData = g; list.Add(entry); } Feed<Contact> r = cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.Default); list.Clear(); int iVerify = 0; foreach (Contact c in r.Entries ) { // let's count and update them iVerify++; c.Title = "get a nother one"; c.BatchData.Type = GDataBatchOperationType.update; list.Add(c); } Assert.IsTrue(iVerify == numberOfInserts, "should have gotten 5 inserts"); Feed<Contact> u = cr.Batch(list, new Uri(r.AtomFeed.Batch), GDataBatchOperationType.Default); list.Clear(); iVerify = 0; foreach (Contact c in u.Entries ) { // let's count and update them iVerify++; c.BatchData.Type = GDataBatchOperationType.delete; list.Add(c); } Assert.IsTrue(iVerify == numberOfInserts, "should have gotten 5 updates"); Feed<Contact> d = cr.Batch(list, new Uri(u.AtomFeed.Batch), GDataBatchOperationType.Default); iVerify = 0; foreach (Contact c in d.Entries ) { if (c.BatchData.Status.Code == 200) { // let's count and update them iVerify++; } } Assert.IsTrue(iVerify == numberOfInserts, "should have gotten 5 deletes"); }
///////////////////////////////////////////////////////////////////////////// private void DeleteList(List<Contact> list, ContactsRequest cr, Uri batch) { int i = 0; foreach (Contact c in list) { c.BatchData = new GDataBatchEntryData(); c.BatchData.Id = i.ToString(); i++; } cr.Batch(list, batch, GDataBatchOperationType.delete); }
private void DeleteAllContacts() { RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord); rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); Feed<Contact> f = cr.GetContacts(); List<Contact> list = new List<Contact>(); int i=0; foreach (Contact c in f.Entries) { c.BatchData = new GDataBatchEntryData(); c.BatchData.Id = i.ToString(); c.BatchData.Type = GDataBatchOperationType.delete; i++; list.Add(c); } cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.insert); f = cr.GetContacts(); Assert.IsTrue(f.TotalResults == 0, "Feed should be emtpy now"); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs an authentication test, inserts a new contact</summary> ////////////////////////////////////////////////////////////////////// [Test] public void ModelBatchContactsTest() { const int numberOfInserts = 5; Tracing.TraceMsg("Entering ModelInsertContactsTest"); DeleteAllContacts(); RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord); rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); List <Contact> list = new List <Contact>(); Feed <Contact> f = cr.GetContacts(); for (int i = 0; i < numberOfInserts; i++) { Contact entry = new Contact(); entry.AtomEntry = ObjectModelHelper.CreateContactEntry(i); entry.PrimaryEmail.Address = "joe" + i.ToString() + "@doe.com"; GDataBatchEntryData g = new GDataBatchEntryData(); g.Id = i.ToString(); g.Type = GDataBatchOperationType.insert; entry.BatchData = g; list.Add(entry); } Feed <Contact> r = cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.Default); list.Clear(); int iVerify = 0; foreach (Contact c in r.Entries) { // let's count and update them iVerify++; c.Name.FamilyName = "get a nother one"; c.BatchData.Type = GDataBatchOperationType.update; list.Add(c); } Assert.IsTrue(iVerify == numberOfInserts, "should have gotten 5 inserts"); Feed <Contact> u = cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.Default); list.Clear(); iVerify = 0; foreach (Contact c in u.Entries) { // let's count and update them iVerify++; c.BatchData.Type = GDataBatchOperationType.delete; list.Add(c); } Assert.IsTrue(iVerify == numberOfInserts, "should have gotten 5 updates"); Feed <Contact> d = cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.Default); iVerify = 0; foreach (Contact c in d.Entries) { if (c.BatchData.Status.Code == 200) { // let's count and update them iVerify++; } } Assert.IsTrue(iVerify == numberOfInserts, "should have gotten 5 deletes"); }
internal static void DeleteAllContacts(RequestSettings rs) { rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); Feed<Contact> f = cr.GetContacts(); List<Contact> list = new List<Contact>(); int i=0; foreach (Contact c in f.Entries) { c.BatchData = new GDataBatchEntryData(); c.BatchData.Id = i.ToString(); c.BatchData.Type = GDataBatchOperationType.delete; i++; list.Add(c); } cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.delete); f = cr.GetContacts(); Assert.IsTrue(f.TotalResults == 0, "Feed should be empty now"); }