コード例 #1
0
        /////////////////////////////////////////////////////////////////////////////


        /////////////////////////////////////////////////////////////////////
        /// <summary>runs an basic auth test against the groups feed test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GroupsModelTest()
        {
            Tracing.TraceMsg("Entering GroupsModelTest");


            RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord);

            rs.AutoPaging = true;
            ContactsRequest cr = new ContactsRequest(rs);

            Feed <Group> fg = cr.GetGroups();

            Group newGroup = new Group();

            newGroup.Title = "Private Data";

            Group insertedGroup = cr.Insert(fg, newGroup);

            Group g2 = new Group();

            g2.Title = "Another private Group";

            Group insertedGroup2 = cr.Insert(fg, g2);

            // now insert a new contact that belongs to that group
            Feed <Contact> fc = cr.GetContacts();
            Contact        c  = new Contact();

            c.AtomEntry = ObjectModelHelper.CreateContactEntry(1);

            GroupMembership member = new GroupMembership();

            member.HRef = insertedGroup.Id;


            GroupMembership member2 = new GroupMembership();

            member2.HRef = insertedGroup2.Id;

            Contact insertedEntry = cr.Insert(fc, c);

            // now change the group membership
            insertedEntry.GroupMembership.Add(member);
            insertedEntry.GroupMembership.Add(member2);
            Contact currentEntry = cr.Update(insertedEntry);

            Assert.IsTrue(currentEntry.GroupMembership.Count == 2, "The entry should be in 2 groups");

            currentEntry.GroupMembership.Clear();
            currentEntry = cr.Update(currentEntry);
            Assert.IsTrue(currentEntry.GroupMembership.Count == 0, "The entry should not be in a group");

            cr.Delete(currentEntry);
            cr.Delete(insertedGroup);
            cr.Delete(insertedGroup2);
        }
コード例 #2
0
        public void InsertExtendedPropertyContactsTest()
        {
            Tracing.TraceMsg("Entering InsertExtendedPropertyContactsTest");

            DeleteAllContacts();

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord);

            rs.AutoPaging = true;

            FeedQuery query = new FeedQuery();

            query.Uri = new Uri(CreateUri(this.resourcePath + "contactsextendedprop.xml"));



            ContactsRequest cr = new ContactsRequest(rs);

            Feed <Contact> f = cr.Get <Contact>(query);

            Contact newEntry = null;

            foreach (Contact c in f.Entries)
            {
                ExtendedProperty e = c.ExtendedProperties[0];
                Assert.IsTrue(e != null);
                newEntry = c;
            }

            f = cr.GetContacts();

            Contact createdEntry = cr.Insert <Contact>(f, newEntry);

            cr.Delete(createdEntry);
        }
コード例 #3
0
        /// <summary>
        /// Creates a Contact group/label in Google Contacts. This is only used on the first
        /// sync where we need to create the new group/label
        /// </summary>
        /// <param name="creds">credentials with valid token/refresh token</param>
        /// <returns></returns>
        static string CreateContactGroup(UserCredential creds)
        {
            ContactsRequest cr = BuildContactsRequest(creds);

            try
            {
                RefreshToken(creds, out bool success);
                if (!success)
                {
                    return("");
                }

                Group newGroup = new Group();
                newGroup.Title = Constants.GroupName;

                Group createdGroup = cr.Insert(new Uri("https://www.google.com/m8/feeds/groups/default/full"),
                                               newGroup);

                logger.Info("Created group: " + Constants.GroupName + ", Group Atom Id: " + createdGroup.Id);
                Thread.Sleep(10000); //okay hack, but apparrently we need to give Google a few secs to get their ducks in a row.
                return(createdGroup.Id);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error creating group " + Constants.GroupName);
                return("");
            }
        }
コード例 #4
0
        private void CreateContact(ContactsRequest cr, Contact contact)
        {
            var newEntry = new global::Google.Contacts.Contact
            {
                Name = new Name()
                {
                    FullName   = contact.FirstName + contact.LastName,
                    GivenName  = contact.FirstName,
                    FamilyName = contact.LastName,
                }
            };

            // Set the contact's name.

            // Set the contact's e-mail addresses.
            newEntry.Emails.Add(new EMail()
            {
                Primary = true,
                Rel     = ContactsRelationships.IsHome,
                Address = contact.EmailAddress
            });
            // Set the contact's phone numbers.
            newEntry.Phonenumbers.Add(new PhoneNumber()
            {
                Primary = true,
                Rel     = ContactsRelationships.IsWork,
                Value   = contact.PhoneNumber
            });
            // Insert the contact.
            Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));

            global::Google.Contacts.Contact createdEntry = cr.Insert(feedUri, newEntry);
            //return createdEntry;
        }
コード例 #5
0
        //Create Shared Contact
        public static Contact CreateContacttest(ContactsRequest cr)
        {
            Contact newEntry = new Contact();

            // Set the contact's name.
            newEntry.Name = new Name()
            {
                FullName   = "Ice Cold005",
                GivenName  = "Ice",
                FamilyName = "Cold005"
            };
            newEntry.Content = "Notes";
            // Set the contact's e-mail addresses.
            newEntry.Emails.Add(new EMail()
            {
                Primary = true,
                Rel     = ContactsRelationships.IsWork,
                Address = "*****@*****.**"
            });
            //Insert the contact
            Uri     feedUri      = new Uri(ContactsQuery.CreateContactsUri("test.com"));
            Contact createdEntry = cr.Insert(feedUri, newEntry);

            Console.WriteLine("New Contact created successfully with ContactID = " + createdEntry.Id);
            return(createdEntry);
        }
コード例 #6
0
ファイル: oauthtest.cs プロジェクト: zngduong/google-gdata
        public void OAuth2LeggedContactsTest()
        {
            Tracing.TraceMsg("Entering OAuth2LeggedContactsTest");

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.oAuthConsumerKey,
                                                     this.oAuthConsumerSecret, this.oAuthUser, this.oAuthDomain);

            ContactsRequest cr = new ContactsRequest(rs);

            Feed <Contact> f = cr.GetContacts();

            // modify one
            foreach (Contact c in f.Entries)
            {
                c.Title = "new title";
                cr.Update(c);
                break;
            }

            Contact entry = new Contact();

            entry.AtomEntry            = ObjectModelHelper.CreateContactEntry(1);
            entry.PrimaryEmail.Address = "*****@*****.**";
            Contact e = cr.Insert(f, entry);

            cr.Delete(e);
        }
コード例 #7
0
        public async Task <bool> SynchContact(ContactsRequest cr, string Name, string Email)
        {
            try
            {
                Contact newEntry = new Contact();
                newEntry.Name = new Name()
                {
                    FullName = Name
                };

                newEntry.Emails.Add(new EMail()
                {
                    Primary = true,
                    Rel     = ContactsRelationships.IsWork,
                    Address = Email
                });

                newEntry.IMs.Add(new IMAddress()
                {
                    Primary  = true,
                    Rel      = ContactsRelationships.IsWork,
                    Protocol = ContactsProtocols.IsGoogleTalk,
                });

                Uri     feedUri      = new Uri(ContactsQuery.CreateContactsUri("default"));
                Contact createdEntry = cr.Insert(feedUri, newEntry);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #8
0
 private Group CreateContactGroup(ContactsRequest request, string name)
 {
     return(request.Insert(new Uri(GoogleSyncSettings.ContactGroupScope), new Group()
     {
         Title = name
     }));
 }
コード例 #9
0
ファイル: oauthtest.cs プロジェクト: zngduong/google-gdata
        public void OAuth2LeggedModelContactsBatchInsertTest()
        {
            const int numberOfInserts = 10;

            Tracing.TraceMsg("Entering OAuth2LeggedModelContactsBatchInsertTest");

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.oAuthConsumerKey,
                                                     this.oAuthConsumerSecret, this.oAuthUser, this.oAuthDomain);

            ContactsTestSuite.DeleteAllContacts(rs);
            rs.AutoPaging = true;

            ContactsRequest cr            = new ContactsRequest(rs);
            Feed <Contact>  f             = cr.GetContacts();
            int             originalCount = f.TotalResults;

            PhoneNumber    p        = null;
            List <Contact> inserted = new List <Contact>();

            if (f != null)
            {
                Assert.IsTrue(f.Entries != null, "the contacts needs entries");

                for (int i = 0; i < numberOfInserts; i++)
                {
                    Contact entry = new Contact();
                    entry.AtomEntry            = ObjectModelHelper.CreateContactEntry(i);
                    entry.PrimaryEmail.Address = "joe" + i.ToString() + "@doe.com";
                    p = entry.PrimaryPhonenumber;
                    inserted.Add(cr.Insert(f, entry));
                }
            }

            List <Contact> list = new List <Contact>();

            f = cr.GetContacts();
            foreach (Contact e in f.Entries)
            {
                list.Add(e);
            }

            Assert.AreEqual(numberOfInserts, inserted.Count);

            // now delete them again
            ContactsTestSuite.DeleteList(inserted, cr, new Uri(f.AtomFeed.Batch));
        }
コード例 #10
0
 public void CreateContactFromOutlook(ContactItem oContact)
 {
     try
     {
         LogInfo("Creating contact from Outlook");
         Contact         gContact = new Contact();
         ContactsRequest cr       = new ContactsRequest(rs);
         Uri             feedUri  = new Uri(ContactsQuery.CreateContactsUri("default"));
         UpdateContactDataFromOutlook(oContact, gContact);
         cr.Insert(feedUri, gContact);
         LogInfo("Contact created");
     }
     catch (System.Exception ex)
     {
         LogError(ex.Message);
         LogDebug(ex.StackTrace.ToString());
     }
 }
コード例 #11
0
        public void TestTheGoogleWay()
        {
            try {
                RequestSettings rs = new RequestSettings("GContactSync", GoogleContactDownloader.TestUser, GoogleContactDownloader.TestPass);
                ContactsRequest cr = new ContactsRequest(rs);

                Google.Contacts.Contact entry = new Google.Contacts.Contact();
                entry.Name          = new Name();
                entry.Name.FullName = "John Doe";
                entry.Emails.Add(new EMail("*****@*****.**", ContactsRelationships.IsOther));
                Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
                cr.Insert(feedUri, entry);
            }
            //catch (GDataRequestException ex) {
            //    throw ex;
            //}
            catch (System.Exception ex) {
                throw ex;
            }
        }
コード例 #12
0
ファイル: GContact.cs プロジェクト: nodet/GContactSync
 public override void Update()
 {
     try
     {
         ContactsRequest cr = new ContactsRequest(_rs);
         if (_alreadyExistsOnGoogle)
         {
             //System.Windows.Forms.MessageBox.Show("Updating " + this.ToString() + " on Google");
             cr.Update(_item);
         }
         else
         {
             //System.Windows.Forms.MessageBox.Show("Inserting " + this.ToString() + " into Google");
             Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
             cr.Insert(feedUri, _item);
         }
     }
     catch (GDataRequestException ex)
     {
         System.Windows.Forms.MessageBox.Show("GDataRequestException while saving data for " + this.ToString() + ": " + ex.ResponseString);
     }
 }
コード例 #13
0
ファイル: clsGoogle.cs プロジェクト: hafsjold/snvrepos
        private static void addMedlem(string p_navn, string p_email)
        {
            Contact newContact = new Contact();

            newContact.Title = p_navn;

            EMail primaryEmail = new EMail(p_email);

            primaryEmail.Primary = true;
            primaryEmail.Rel     = ContactsRelationships.IsHome;
            newContact.Emails.Add(primaryEmail);

            GroupMembership gm = new GroupMembership();

            gm.HRef = HRefMedlem;
            newContact.GroupMembership.Add(gm);



            Uri     feedUri        = new Uri(ContactsQuery.CreateContactsUri("default"));
            Contact createdContact = cr.Insert(feedUri, newContact);
        }
コード例 #14
0
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, inserts a new contact</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void ModelPhotoTest()
        {
            Tracing.TraceMsg("Entering ModelPhotoTest");

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord);

            rs.AutoPaging = true;

            ContactsRequest cr = new ContactsRequest(rs);

            Feed <Contact> f = cr.GetContacts();

            Contact e = null;

            if (f != null)
            {
                Contact entry = new Contact();
                entry.AtomEntry            = ObjectModelHelper.CreateContactEntry(1);
                entry.PrimaryEmail.Address = "*****@*****.**";
                e = cr.Insert(f, entry);
            }
            Assert.IsTrue(e != null, "we should have a contact here");

            Stream s = cr.GetPhoto(e);

            Assert.IsTrue(s == null, "There should be no photo yet");


            using (FileStream fs = new FileStream(this.resourcePath + "contactphoto.jpg", System.IO.FileMode.Open))
            {
                cr.SetPhoto(e, fs);
            }

            // now delete the guy, which requires us to reload him from the server first, as the photo change operation
            // changes the etag off the entry
            e = cr.Retrieve(e);
            cr.Delete(e);
        }
コード例 #15
0
        public async Task <ViewModels.Contact> AddContact(ViewModels.Contact contact)
        {
            var cSvc = new ContactsService("F3Test").Credentials;

            var rs = new RequestSettings("F3Test", Token.AccessToken);

            // AutoPaging results in automatic paging in order to retrieve all contacts
            rs.AutoPaging = true;
            var cr = new ContactsRequest(rs);

            var newEntry = new Contact
            {
                Name = new Name()
                {
                    FullName   = string.Format("{0} {1}", contact.FirstName, contact.LastName),
                    GivenName  = contact.FirstName,
                    FamilyName = contact.LastName,
                }
            };

            // Set the contact's name.
            // Set the contact's e-mail addresses.
            newEntry.Emails.Add(new EMail
            {
                Primary = true,
                Rel     = ContactsRelationships.IsHome,
                Address = contact.Email
            });

            // Insert the contact.
            var feedUri      = new Uri(ContactsQuery.CreateContactsUri("default"));
            var createdEntry = cr.Insert(feedUri, newEntry);

            contact.Id = createdEntry.Id;
            return(contact);
        }
コード例 #16
0
        /// <summary>
        /// 创建Google Contact
        /// </summary>
        private void CreateGoogleContact(GoogleContactSyncData contactData, ContactsRequest contactRequest, Group defaultContactGroup)
        {
            global::Google.Contacts.Contact contact = null;
            bool success = false;

            try
            {
                //设置联系人默认分组
                contactData.Contact.GroupMembership.Add(new GroupMembership()
                {
                    HRef = defaultContactGroup.Id
                });
                //调用API新增联系人
                contact = contactRequest.Insert(new Uri(GoogleSyncSettings.ContactScope), contactData.Contact);
                _logger.InfoFormat("新增Google联系人#{0}|{1}|{2}", contact.Id, contactData.Subject, _account.ID);
                success = true;
            }
            catch (Exception ex)
            {
                _logger.Error("CreateGoogleContact has exception.", ex);
            }

            if (success)
            {
                //更新联系人最后更新时间,确保与Google Contact的最后更新时间一致
                UpdateContactLastUpdateTime(int.Parse(contactData.SyncId), contact.Updated.ToLocalTime());

                //创建同步信息
                SyncInfo syncInfo = new SyncInfo();
                syncInfo.AccountId    = _account.ID;
                syncInfo.LocalDataId  = contactData.SyncId;
                syncInfo.SyncDataId   = contact.Id;
                syncInfo.SyncDataType = contactData.SyncType;
                InsertSyncInfo(syncInfo);
            }
        }
コード例 #17
0
        public void OAuth2LeggedContactsTest() {
            Tracing.TraceMsg("Entering OAuth2LeggedContactsTest");

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.oAuthConsumerKey,
                this.oAuthConsumerSecret, this.oAuthUser, this.oAuthDomain);

            ContactsRequest cr = new ContactsRequest(rs);

            Feed<Contact> f = cr.GetContacts();

            // modify one
            foreach (Contact c in f.Entries) {
                c.Title = "new title";
                cr.Update(c);
                break;
            }

            Contact entry = new Contact();
            entry.AtomEntry = ObjectModelHelper.CreateContactEntry(1);
            entry.PrimaryEmail.Address = "*****@*****.**";
            Contact e = cr.Insert(f, entry);

            cr.Delete(e);
        }
コード例 #18
0
ファイル: GContact.cs プロジェクト: KrishPS/GContactSync
 public override void Update()
 {
     try
     {
         ContactsRequest cr = new ContactsRequest(_rs);
         if (_alreadyExistsOnGoogle)
         {
             //System.Windows.Forms.MessageBox.Show("Updating " + this.ToString() + " on Google");
             cr.Update(_item);
         }
         else
         {
             //System.Windows.Forms.MessageBox.Show("Inserting " + this.ToString() + " into Google");
             Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
             cr.Insert(feedUri, _item);
         }
     }
     catch (GDataRequestException ex)
     {
         System.Windows.Forms.MessageBox.Show("GDataRequestException while saving data for " + this.ToString() + ": " + ex.ResponseString);
     }
 }
コード例 #19
0
 public void CreateContactFromOutlook(ContactItem oContact)
 {
     try
     {
         LogInfo("Creating contact from Outlook");
         Contact gContact = new Contact();
         ContactsRequest cr = new ContactsRequest(rs);
         Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
         UpdateContactDataFromOutlook(oContact, gContact);
         cr.Insert(feedUri, gContact);
         LogInfo("Contact created");
     }
     catch (System.Exception ex)
     {
         LogError(ex.Message);
         LogDebug(ex.StackTrace.ToString());
     }
 }
コード例 #20
0
        /// <summary>
        /// 创建Google Contact
        /// </summary>
        private void CreateGoogleContact(GoogleContactSyncData contactData, ContactsRequest contactRequest, Group defaultContactGroup)
        {
            global::Google.Contacts.Contact contact = null;
            bool success = false;

            try
            {
                //设置联系人默认分组
                contactData.Contact.GroupMembership.Add(new GroupMembership() { HRef = defaultContactGroup.Id });
                //调用API新增联系人
                contact = contactRequest.Insert(new Uri(GoogleSyncSettings.ContactScope), contactData.Contact);
                _logger.InfoFormat("新增Google联系人#{0}|{1}|{2}", contact.Id, contactData.Subject, _account.ID);
                success = true;
            }
            catch (Exception ex)
            {
                _logger.Error("CreateGoogleContact has exception.", ex);
            }

            if (success)
            {
                //更新联系人最后更新时间,确保与Google Contact的最后更新时间一致
                UpdateContactLastUpdateTime(int.Parse(contactData.SyncId), contact.Updated.ToLocalTime());

                //创建同步信息
                SyncInfo syncInfo = new SyncInfo();
                syncInfo.AccountId = _account.ID;
                syncInfo.LocalDataId = contactData.SyncId;
                syncInfo.SyncDataId = contact.Id;
                syncInfo.SyncDataType = contactData.SyncType;
                InsertSyncInfo(syncInfo);
            }
        }
コード例 #21
0
        public Google.Contacts.Contact CreateContact(contacts item)
        {
            Google.Contacts.Contact newEntry = new Google.Contacts.Contact();

            // ----- NAME -----
            newEntry.Name = new Name()
            {
                FullName       = item.Name.FullName,
                NamePrefix     = item.Name.Prefix,
                GivenName      = item.Name.Firstname,
                AdditionalName = item.Name.AdditionalName,
                FamilyName     = item.Name.Surname,
                NameSuffix     = item.Name.Suffix,
                //FamilyNamePhonetics = ,
                //AdditionalNamePhonetics = ,
                //FamilyNamePhonetics = ,
            };

            // ----- EMAIL -----
            foreach (var email in item.Email)
            {
                newEntry.Emails.Add(new EMail()
                {
                    Primary = email.Primary,
                    Rel     = email.Desc,        // ContactsRelationships.IsHome,
                    Address = email.Value
                });
            }

            // ----- PHONE -----
            foreach (var phone in item.Phone)
            {
                newEntry.Phonenumbers.Add(new PhoneNumber()
                {
                    Primary = phone.Primary,
                    Rel     = phone.Desc,        // ContactsRelationships.IsWork,
                    Value   = phone.Value
                });
            }

            // ----- Organization -----

            // ----- ADDRESS -----
            foreach (var address in item.Address)
            {
                newEntry.PostalAddresses.Add(new StructuredPostalAddress()
                {
                    Rel              = address.Tag, // ContactsRelationships.IsWork,
                    Primary          = address.Primary,
                    Street           = address.Street,
                    City             = address.City,
                    Region           = address.Region,
                    Postcode         = address.ZipCode,
                    Country          = address.Country,
                    FormattedAddress = address.Street + ", " + address.City + ", " + address.Region + ", " + address.Country + ", " + address.ZipCode
                });
            }

            // ----- BIRTHDATE -----


            // ----- DATES -----

            // ----- WEBSITES -----

            // ----- IM -----
            foreach (var im in item.IM)
            {
                newEntry.IMs.Add(new IMAddress()
                {
                    Address = im.Value,
                    Primary = im.Primary,
                    //Rel = //ContactsRelationships.IsHome,
                    Protocol = im.Desc, // ContactsProtocols.IsGoogleTalk,
                });
            }


            // ----- RELATIONS -----

            // ----- NOTE -----
            newEntry.Content = item.Note;

            // ----- google ID -----

            // ----- GROUP -----



            // Insert the contact.
            Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));

            Google.Contacts.Contact createdEntry = cr.Insert(feedUri, newEntry);
            Console.WriteLine("Contact's ID: " + createdEntry.Id);
            return(createdEntry);
        }
コード例 #22
0
        public void OAuth2LeggedModelContactsBatchInsertTest()
        {
            const int numberOfInserts = 37;

            Tracing.TraceMsg("Entering OAuth2LeggedModelContactsBatchInsertTest");


            RequestSettings rs = new RequestSettings(this.ApplicationName, this.oAuthConsumerKey, this.oAuthConsumerSecret,
                                                     this.oAuthUser, this.oAuthDomain);

            ContactsTestSuite.DeleteAllContacts(rs);

            rs.AutoPaging = true;

            ContactsRequest cr = new ContactsRequest(rs);

            Feed <Contact> f = cr.GetContacts();

            int originalCount = f.TotalResults;

            PhoneNumber    p        = null;
            List <Contact> inserted = new List <Contact>();

            if (f != null)
            {
                Assert.IsTrue(f.Entries != null, "the contacts needs entries");

                for (int i = 0; i < numberOfInserts; i++)
                {
                    Contact entry = new Contact();
                    entry.AtomEntry            = ObjectModelHelper.CreateContactEntry(i);
                    entry.PrimaryEmail.Address = "joe" + i.ToString() + "@doe.com";
                    p = entry.PrimaryPhonenumber;
                    inserted.Add(cr.Insert(f, entry));
                }
            }


            List <Contact> list = new List <Contact>();

            f = cr.GetContacts();
            foreach (Contact e in f.Entries)
            {
                list.Add(e);
            }

            if (inserted.Count > 0)
            {
                int iVer = numberOfInserts;
                // let's find those guys
                for (int i = 0; i < inserted.Count; i++)
                {
                    Contact test = inserted[i];
                    foreach (Contact e in list)
                    {
                        if (e.Id == test.Id)
                        {
                            iVer--;
                            // verify we got the phonenumber back....
                            Assert.IsTrue(e.PrimaryPhonenumber != null, "They should have a primary phonenumber");
                            Assert.AreEqual(e.PrimaryPhonenumber.Value, p.Value, "They should be identical");
                        }
                    }
                }

                Assert.IsTrue(iVer == 0, "The new entries should all be part of the feed now, " + iVer + " left over");
            }

            // now delete them again
            ContactsTestSuite.DeleteList(inserted, cr, new Uri(f.AtomFeed.Batch));

            // now make sure they are gone
            if (inserted.Count > 0)
            {
                f = cr.GetContacts();
                Assert.IsTrue(f.TotalResults == originalCount, "The count should be correct as well");
                foreach (Contact e in f.Entries)
                {
                    // let's find those guys, we should not find ANY
                    for (int i = 0; i < inserted.Count; i++)
                    {
                        Contact test = inserted[i] as Contact;
                        Assert.IsTrue(e.Id != test.Id, "The new entries should all be deleted now");
                    }
                }
            }
        }
コード例 #23
0
        public void CreateNewContact()
        {
            string gmailUsername;
            string syncProfile;

            LoadSettings(out gmailUsername, out syncProfile);

            ContactsRequest service;

            var scopes = new List <string>();

            //Contacts-Scope
            scopes.Add("https://www.google.com/m8/feeds");
            //Calendar-Scope
            scopes.Add(CalendarService.Scope.Calendar);

            UserCredential credential;

            byte[] jsonSecrets = Properties.Resources.client_secrets;

            using (var stream = new MemoryStream(jsonSecrets))
            {
                FileDataStore fDS = new FileDataStore(Logger.AuthFolder, true);

                GoogleClientSecrets clientSecrets = GoogleClientSecrets.Load(stream);

                credential = GCSMOAuth2WebAuthorizationBroker.AuthorizeAsync(
                    clientSecrets.Secrets,
                    scopes.ToArray(),
                    gmailUsername,
                    CancellationToken.None,
                    fDS).
                             Result;

                OAuth2Parameters parameters = new OAuth2Parameters
                {
                    ClientId     = clientSecrets.Secrets.ClientId,
                    ClientSecret = clientSecrets.Secrets.ClientSecret,

                    // Note: AccessToken is valid only for 60 minutes
                    AccessToken  = credential.Token.AccessToken,
                    RefreshToken = credential.Token.RefreshToken
                };

                RequestSettings settings = new RequestSettings("GoContactSyncMod", parameters);

                service = new ContactsRequest(settings);
            }

            #region Delete previously created test contact.
            ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
            query.NumberToRetrieve = 500;

            Feed <Contact> feed = service.Get <Contact>(query);

            Logger.Log("Loaded Google contacts", EventType.Information);

            foreach (Contact entry in feed.Entries)
            {
                if (entry.PrimaryEmail != null && entry.PrimaryEmail.Address == "*****@*****.**")
                {
                    service.Delete(entry);
                    Logger.Log("Deleted Google contact", EventType.Information);
                    //break;
                }
            }
            #endregion

            Contact newEntry = new Contact();
            newEntry.Title = "John Doe";

            EMail primaryEmail = new EMail("*****@*****.**");
            primaryEmail.Primary = true;
            primaryEmail.Rel     = ContactsRelationships.IsWork;
            newEntry.Emails.Add(primaryEmail);

            PhoneNumber phoneNumber = new PhoneNumber("555-555-5551");
            phoneNumber.Primary = true;
            phoneNumber.Rel     = ContactsRelationships.IsMobile;
            newEntry.Phonenumbers.Add(phoneNumber);

            StructuredPostalAddress postalAddress = new StructuredPostalAddress();
            postalAddress.Street  = "123 somewhere lane";
            postalAddress.Primary = true;
            postalAddress.Rel     = ContactsRelationships.IsHome;
            newEntry.PostalAddresses.Add(postalAddress);

            newEntry.Content = "Who is this guy?";

            Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));

            Contact createdEntry = service.Insert(feedUri, newEntry);

            Logger.Log("Created Google contact", EventType.Information);

            Assert.IsNotNull(createdEntry.ContactEntry.Id.Uri);

            Contact updatedEntry = service.Update(createdEntry);

            Logger.Log("Updated Google contact", EventType.Information);

            //delete test contacts
            service.Delete(createdEntry);

            Logger.Log("Deleted Google contact", EventType.Information);
        }
コード例 #24
0
        public void CreateNewContact()
        {
            string gmailUsername;
            string syncProfile;
            GoogleAPITests.LoadSettings(out gmailUsername, out syncProfile);

            ContactsRequest service;

            var scopes = new List<string>();
            //Contacts-Scope
            scopes.Add("https://www.google.com/m8/feeds");
            //Notes-Scope
            scopes.Add("https://docs.google.com/feeds/");
            //scopes.Add("https://docs.googleusercontent.com/");
            //scopes.Add("https://spreadsheets.google.com/feeds/");
            //Calendar-Scope
            //scopes.Add("https://www.googleapis.com/auth/calendar");
            scopes.Add(CalendarService.Scope.Calendar);

            UserCredential credential;
            byte[] jsonSecrets = Properties.Resources.client_secrets;

            using (var stream = new MemoryStream(jsonSecrets))
            {
                FileDataStore fDS = new FileDataStore(Logger.AuthFolder, true);

                GoogleClientSecrets clientSecrets = GoogleClientSecrets.Load(stream);

                credential = GCSMOAuth2WebAuthorizationBroker.AuthorizeAsync(
                                clientSecrets.Secrets,
                                scopes.ToArray(),
                                gmailUsername,
                                CancellationToken.None,
                                fDS).
                                Result;

                OAuth2Parameters parameters = new OAuth2Parameters
                {
                    ClientId = clientSecrets.Secrets.ClientId,
                    ClientSecret = clientSecrets.Secrets.ClientSecret,

                    // Note: AccessToken is valid only for 60 minutes
                    AccessToken = credential.Token.AccessToken,
                    RefreshToken = credential.Token.RefreshToken
                };

                RequestSettings settings = new RequestSettings("GoContactSyncMod", parameters);

                service = new ContactsRequest(settings);
            }

            #region Delete previously created test contact.
            ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
            query.NumberToRetrieve = 500;

            Feed<Contact> feed = service.Get<Contact>(query);

            Logger.Log("Loaded Google contacts", EventType.Information);

            foreach (Contact entry in feed.Entries)
            {
                if (entry.PrimaryEmail != null && entry.PrimaryEmail.Address == "*****@*****.**")
                {
                    service.Delete(entry);
                    Logger.Log("Deleted Google contact", EventType.Information);
                    //break;
                }
            }
            #endregion

            Contact newEntry = new Contact();
            newEntry.Title = "John Doe";

            EMail primaryEmail = new EMail("*****@*****.**");
            primaryEmail.Primary = true;
            primaryEmail.Rel = ContactsRelationships.IsWork;
            newEntry.Emails.Add(primaryEmail);

            PhoneNumber phoneNumber = new PhoneNumber("555-555-5551");
            phoneNumber.Primary = true;
            phoneNumber.Rel = ContactsRelationships.IsMobile;
            newEntry.Phonenumbers.Add(phoneNumber);

            StructuredPostalAddress postalAddress = new StructuredPostalAddress();
            postalAddress.Street = "123 somewhere lane";
            postalAddress.Primary = true;
            postalAddress.Rel = ContactsRelationships.IsHome;
            newEntry.PostalAddresses.Add(postalAddress);

            newEntry.Content = "Who is this guy?";

            Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));

            Contact createdEntry = service.Insert(feedUri, newEntry);

            Logger.Log("Created Google contact", EventType.Information);

            Assert.IsNotNull(createdEntry.ContactEntry.Id.Uri);

            Contact updatedEntry = service.Update(createdEntry);

            Logger.Log("Updated Google contact", EventType.Information);

            //delete test contacts
            service.Delete(createdEntry);

            Logger.Log("Deleted Google contact", EventType.Information);
        }
コード例 #25
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, inserts a new contact</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void ModelUpdateContactsTest()
        {
            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);

            Feed<Contact> f = cr.GetContacts();

            int originalCount = f.TotalResults;

            PhoneNumber p = null;
            List<Contact> inserted = new List<Contact>();

            if (f != null)
            {
                Assert.IsTrue(f.Entries != null, "the contacts needs entries");

                for (int i = 0; i < numberOfInserts; i++)
                {
                    Contact entry = new Contact();
                    entry.AtomEntry = ObjectModelHelper.CreateContactEntry(i);
                    entry.PrimaryEmail.Address = "joe" + i.ToString() + "@doe.com";
                    p = entry.PrimaryPhonenumber;
                    inserted.Add(cr.Insert(f, entry));
                }
            }

            string newTitle = "This is an update to the title";
            f = cr.GetContacts();
            if (inserted.Count > 0)
            {
                int iVer = numberOfInserts;
                // let's find those guys
                foreach (Contact e in f.Entries )
                {
                    for (int i = 0; i < inserted.Count; i++)
                    {
                        Contact test = inserted[i];
                        if (e.Id == test.Id)
                        {
                            iVer--;
                            // verify we got the phonenumber back....
                            Assert.IsTrue(e.PrimaryPhonenumber != null, "They should have a primary phonenumber");
                            Assert.AreEqual(e.PrimaryPhonenumber.Value,p.Value, "They should be identical");
                            e.Title = newTitle;
                            inserted[i] = cr.Update(e);
                        }
                    }
                }

                Assert.IsTrue(iVer == 0, "The new entries should all be part of the feed now, we have " + iVer + " left");
            }

            f = cr.GetContacts();
            if (inserted.Count > 0)
            {
                int iVer = numberOfInserts;
                // let's find those guys
                foreach (Contact e in f.Entries )
                {
                    for (int i = 0; i < inserted.Count; i++)
                    {
                        Contact test = inserted[i];
                        if (e.Id == test.Id)
                        {
                            iVer--;
                            // verify we got the phonenumber back....
                            Assert.IsTrue(e.PrimaryPhonenumber != null, "They should have a primary phonenumber");
                            Assert.AreEqual(e.PrimaryPhonenumber.Value,p.Value, "They should be identical");
                            Assert.AreEqual(e.Title, newTitle, "The title should have been updated");
                        }
                    }
                }
                Assert.IsTrue(iVer == 0, "The new entries should all be part of the feed now, we have: " +  iVer + " now");
            }


            // now delete them again
            DeleteList(inserted, cr, new Uri(f.AtomFeed.Batch));



            // now make sure they are gone
            if (inserted.Count > 0)
            {
                int iVer = inserted.Count;
                f = cr.GetContacts();
                foreach (Contact e in f.Entries)
                {
                    // let's find those guys, we should not find ANY
                    for (int i = 0; i < inserted.Count; i++)
                    {
                        Contact test = inserted[i] as Contact;
                        Assert.IsTrue(e.Id != test.Id, "The new entries should all be deleted now");
                    }
                }
                Assert.IsTrue(f.TotalResults == originalCount, "The count should be correct as well");
            }
        }
コード例 #26
0
        public void TestTheGoogleWay()
        {
            try {
                RequestSettings rs = new RequestSettings("GContactSync", GoogleContactDownloader.TestUser, GoogleContactDownloader.TestPass);
                ContactsRequest cr = new ContactsRequest(rs);

                Google.Contacts.Contact entry = new Google.Contacts.Contact();
                entry.Name = new Name();
                entry.Name.FullName = "John Doe";
                entry.Emails.Add(new EMail("*****@*****.**", ContactsRelationships.IsOther));
                Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
                cr.Insert(feedUri, entry);
            }
            //catch (GDataRequestException ex) {
            //    throw ex;
            //}
            catch  (System.Exception ex) {
                throw ex;
            }
        }
コード例 #27
0
        public void OAuth2LeggedModelContactsBatchInsertTest() {
            const int numberOfInserts = 10;
            Tracing.TraceMsg("Entering OAuth2LeggedModelContactsBatchInsertTest");

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.oAuthConsumerKey,
                this.oAuthConsumerSecret, this.oAuthUser, this.oAuthDomain);

            ContactsTestSuite.DeleteAllContacts(rs);
            rs.AutoPaging = true;

            ContactsRequest cr = new ContactsRequest(rs);
            Feed<Contact> f = cr.GetContacts();
            int originalCount = f.TotalResults;

            PhoneNumber p = null;
            List<Contact> inserted = new List<Contact>();

            if (f != null) {
                Assert.IsTrue(f.Entries != null, "the contacts needs entries");

                for (int i = 0; i < numberOfInserts; i++) {
                    Contact entry = new Contact();
                    entry.AtomEntry = ObjectModelHelper.CreateContactEntry(i);
                    entry.PrimaryEmail.Address = "joe" + i.ToString() + "@doe.com";
                    p = entry.PrimaryPhonenumber;
                    inserted.Add(cr.Insert(f, entry));
                }
            }

            List<Contact> list = new List<Contact>();

            f = cr.GetContacts();
            foreach (Contact e in f.Entries) {
                list.Add(e);
            }

            Assert.AreEqual(numberOfInserts, inserted.Count);

            // now delete them again
            ContactsTestSuite.DeleteList(inserted, cr, new Uri(f.AtomFeed.Batch));
        }
コード例 #28
0
        public void InsertExtendedPropertyContactsTest()
        {
            Tracing.TraceMsg("Entering InsertExtendedPropertyContactsTest");

            DeleteAllContacts();

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord);
            rs.AutoPaging = true;

            FeedQuery query = new FeedQuery();
            query.Uri = new Uri(CreateUri(this.resourcePath + "contactsextendedprop.xml"));

         

            ContactsRequest cr = new ContactsRequest(rs);

            Feed<Contact> f = cr.Get<Contact>(query);

            Contact newEntry = null;

            foreach (Contact c in f.Entries)
            {
                ExtendedProperty e = c.ExtendedProperties[0];
                Assert.IsTrue(e != null);
                newEntry = c;
            }

            f = cr.GetContacts();

            Contact createdEntry = cr.Insert<Contact>(f, newEntry);

            cr.Delete(createdEntry);



   
        }
コード例 #29
0
        public void OAuth2LeggedModelContactsBatchInsertTest()
        {
            const int numberOfInserts = 37;
            Tracing.TraceMsg("Entering OAuth2LeggedModelContactsBatchInsertTest");


            RequestSettings rs = new RequestSettings(this.ApplicationName, this.oAuthConsumerKey, this.oAuthConsumerSecret,
                                               this.oAuthUser, this.oAuthDomain);

            ContactsTestSuite.DeleteAllContacts(rs);
     
            rs.AutoPaging = true;

            ContactsRequest cr = new ContactsRequest(rs);

            Feed<Contact> f = cr.GetContacts();

            int originalCount = f.TotalResults;

            PhoneNumber p = null;
            List<Contact> inserted = new List<Contact>();

            if (f != null)
            {
                Assert.IsTrue(f.Entries != null, "the contacts needs entries");

                for (int i = 0; i < numberOfInserts; i++)
                {
                    Contact entry = new Contact();
                    entry.AtomEntry = ObjectModelHelper.CreateContactEntry(i);
                    entry.PrimaryEmail.Address = "joe" + i.ToString() + "@doe.com";
                    p = entry.PrimaryPhonenumber;
                    inserted.Add(cr.Insert(f, entry));
                }
            }


            List<Contact> list = new List<Contact>();

            f = cr.GetContacts();
            foreach (Contact e in f.Entries)
            {
                list.Add(e);
            }

            if (inserted.Count > 0)
            {
                int iVer = numberOfInserts;
                // let's find those guys
                for (int i = 0; i < inserted.Count; i++)
                {
                    Contact test = inserted[i];
                    foreach (Contact e in list)
                    {
                        if (e.Id == test.Id)
                        {
                            iVer--;
                            // verify we got the phonenumber back....
                            Assert.IsTrue(e.PrimaryPhonenumber != null, "They should have a primary phonenumber");
                            Assert.AreEqual(e.PrimaryPhonenumber.Value, p.Value, "They should be identical");
                        }
                    }
                }

                Assert.IsTrue(iVer == 0, "The new entries should all be part of the feed now, " + iVer + " left over");
            }

            // now delete them again
            ContactsTestSuite.DeleteList(inserted, cr, new Uri(f.AtomFeed.Batch));

            // now make sure they are gone
            if (inserted.Count > 0)
            {
                f = cr.GetContacts();
                Assert.IsTrue(f.TotalResults == originalCount, "The count should be correct as well");
                foreach (Contact e in f.Entries)
                {
                    // let's find those guys, we should not find ANY
                    for (int i = 0; i < inserted.Count; i++)
                    {
                        Contact test = inserted[i] as Contact;
                        Assert.IsTrue(e.Id != test.Id, "The new entries should all be deleted now");
                    }
                }
            }
        }
コード例 #30
0
        //public void AddContact(GooglePlusAccessToken serStatus)
        //{
        //    /*Get Google Contacts From Access Token and Refresh Token*/
        //    string refreshToken = serStatus.refresh_token;
        //    string accessToken = serStatus.access_token;
        //    string scopes = "https://www.google.com/m8/feeds/contacts/default/full/";
        //    OAuth2Parameters oAuthparameters = new OAuth2Parameters()
        //    {
        //        Scope = scopes,
        //        AccessToken = accessToken,
        //        RefreshToken = refreshToken
        //    };

        //    RequestSettings settings = new RequestSettings("<var>YOUR_APPLICATION_NAME</var>", oAuthparameters);
        //    ContactsRequest cr = new ContactsRequest(settings);

        //    Contact newEntry = new Contact();
        //    newEntry.Name = new Name();
        //    newEntry.Name.FullName = "Abhishek k";

        //    newEntry.Emails = new
        //}

        public static Contact CreateContact(ContactsRequest cr)
        {
            Contact newEntry = new Contact();

            // Set the contact's name.
            newEntry.Name = new Name()
            {
                FullName   = "Elizabeth Bennet",
                GivenName  = "Elizabeth",
                FamilyName = "Bennet",
            };
            newEntry.Content = "Notes";
            // Set the contact's e-mail addresses.
            newEntry.Emails.Add(new EMail()
            {
                Primary = true,
                Rel     = ContactsRelationships.IsHome,
                Address = "*****@*****.**"
            });
            newEntry.Emails.Add(new EMail()
            {
                Rel     = ContactsRelationships.IsWork,
                Address = "*****@*****.**"
            });
            // Set the contact's phone numbers.
            newEntry.Phonenumbers.Add(new PhoneNumber()
            {
                Primary = true,
                Rel     = ContactsRelationships.IsWork,
                Value   = "(206)555-1212",
            });
            newEntry.Phonenumbers.Add(new PhoneNumber()
            {
                Rel   = ContactsRelationships.IsHome,
                Value = "(206)555-1213",
            });
            // Set the contact's IM information.
            newEntry.IMs.Add(new IMAddress()
            {
                Primary  = true,
                Rel      = ContactsRelationships.IsHome,
                Protocol = ContactsProtocols.IsGoogleTalk,
            });
            // Set the contact's postal address.
            newEntry.PostalAddresses.Add(new StructuredPostalAddress()
            {
                Rel              = ContactsRelationships.IsWork,
                Primary          = true,
                Street           = "1600 Amphitheatre Pkwy",
                City             = "Mountain View",
                Region           = "CA",
                Postcode         = "94043",
                Country          = "United States",
                FormattedAddress = "1600 Amphitheatre Pkwy Mountain View",
            });
            // Insert the contact.
            Uri     feedUri      = new Uri(ContactsQuery.CreateContactsUri("default"));
            Contact createdEntry = cr.Insert(feedUri, newEntry);

            Console.WriteLine("Contact's ID: " + createdEntry.Id);
            return(createdEntry);
        }
コード例 #31
0
        /////////////////////////////////////////////////////////////////////////////
 

        /////////////////////////////////////////////////////////////////////
        /// <summary>runs an basic auth test against the groups feed test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void GroupsModelTest()
        {
            Tracing.TraceMsg("Entering GroupsModelTest");


            RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord);
            rs.AutoPaging = true; 
            ContactsRequest cr = new ContactsRequest(rs);

            Feed<Group> fg = cr.GetGroups();

            Group newGroup = new Group();
            newGroup.Title = "Private Data";

            Group insertedGroup = cr.Insert(fg, newGroup);

            Group g2 = new Group();
            g2.Title = "Another private Group"; 

            Group insertedGroup2 = cr.Insert(fg, g2); 

            // now insert a new contact that belongs to that group
            Feed<Contact> fc = cr.GetContacts();
            Contact c = new Contact();
            c.AtomEntry = ObjectModelHelper.CreateContactEntry(1);

            GroupMembership member = new GroupMembership();
            member.HRef = insertedGroup.Id; 


            GroupMembership member2 = new GroupMembership();
            member2.HRef = insertedGroup2.Id; 
            
            Contact insertedEntry = cr.Insert(fc, c);

            // now change the group membership
            insertedEntry.GroupMembership.Add(member);
            insertedEntry.GroupMembership.Add(member2);
            Contact currentEntry = cr.Update(insertedEntry);

            Assert.IsTrue(currentEntry.GroupMembership.Count == 2, "The entry should be in 2 groups");

            currentEntry.GroupMembership.Clear();
            currentEntry = cr.Update(currentEntry);
            Assert.IsTrue(currentEntry.GroupMembership.Count == 0, "The entry should not be in a group");

            cr.Delete(currentEntry);
            cr.Delete(insertedGroup);
            cr.Delete(insertedGroup2);

        }
コード例 #32
0
        public void ModelUpdateIfMatchAllContactsTest()
        {
            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);

            Feed <Contact> f = cr.GetContacts();

            int originalCount = f.TotalResults;

            PhoneNumber    p        = null;
            List <Contact> inserted = new List <Contact>();

            if (f != null)
            {
                Assert.IsTrue(f.Entries != null, "the contacts needs entries");

                for (int i = 0; i < numberOfInserts; i++)
                {
                    Contact entry = new Contact();
                    entry.AtomEntry            = ObjectModelHelper.CreateContactEntry(i);
                    entry.PrimaryEmail.Address = "joe" + i.ToString() + "@doe.com";
                    p = entry.PrimaryPhonenumber;
                    inserted.Add(cr.Insert(f, entry));
                }
            }

            string newTitle = "This is an update to the title";

            f = cr.GetContacts();
            if (inserted.Count > 0)
            {
                int iVer = numberOfInserts;
                // let's find those guys
                foreach (Contact e in f.Entries)
                {
                    for (int i = 0; i < inserted.Count; i++)
                    {
                        Contact test = inserted[i];
                        if (e.Id == test.Id)
                        {
                            iVer--;
                            // verify we got the phonenumber back....
                            Assert.IsTrue(e.PrimaryPhonenumber != null, "They should have a primary phonenumber");
                            Assert.AreEqual(e.PrimaryPhonenumber.Value, p.Value, "They should be identical");
                            e.Name.FamilyName = newTitle;
                            e.ETag            = GDataRequestFactory.IfMatchAll;
                            inserted[i]       = cr.Update(e);
                        }
                    }
                }

                Assert.IsTrue(iVer == 0, "The new entries should all be part of the feed now, we have " + iVer + " left");
            }

            f = cr.GetContacts();
            if (inserted.Count > 0)
            {
                int iVer = numberOfInserts;
                // let's find those guys
                foreach (Contact e in f.Entries)
                {
                    for (int i = 0; i < inserted.Count; i++)
                    {
                        Contact test = inserted[i];
                        if (e.Id == test.Id)
                        {
                            iVer--;
                            // verify we got the phonenumber back....
                            Assert.IsTrue(e.PrimaryPhonenumber != null, "They should have a primary phonenumber");
                            Assert.AreEqual(e.PrimaryPhonenumber.Value, p.Value, "They should be identical");
                            Assert.AreEqual(e.Name.FamilyName, newTitle, "The familyname should have been updated");
                        }
                    }
                }
                Assert.IsTrue(iVer == 0, "The new entries should all be part of the feed now, we have: " + iVer + " now");
            }


            // now delete them again
            DeleteList(inserted, cr, new Uri(f.AtomFeed.Batch));



            // now make sure they are gone
            if (inserted.Count > 0)
            {
                int iVer = inserted.Count;
                f = cr.GetContacts();
                foreach (Contact e in f.Entries)
                {
                    // let's find those guys, we should not find ANY
                    for (int i = 0; i < inserted.Count; i++)
                    {
                        Contact test = inserted[i] as Contact;
                        Assert.IsTrue(e.Id != test.Id, "The new entries should all be deleted now");
                    }
                }
                Assert.IsTrue(f.TotalResults == originalCount, "The count should be correct as well");
            }
        }
コード例 #33
0
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, inserts a new contact</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void ModelPhotoTest()
        {
            Tracing.TraceMsg("Entering ModelPhotoTest");

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord);
            rs.AutoPaging = true; 

            ContactsRequest cr = new ContactsRequest(rs);

            Feed<Contact> f = cr.GetContacts();

            Contact e = null;

            if (f != null)
            {
                Contact entry = new Contact();
                entry.AtomEntry = ObjectModelHelper.CreateContactEntry(1);
                entry.PrimaryEmail.Address = "*****@*****.**";
                e = cr.Insert(f, entry);
                
            }
            Assert.IsTrue(e!=null, "we should have a contact here");

            Stream s = cr.GetPhoto(e);

            Assert.IsTrue(s == null, "There should be no photo yet"); 


            using (FileStream fs = new FileStream(this.resourcePath + "contactphoto.jpg", System.IO.FileMode.Open))
            {
                cr.SetPhoto(e, fs); 
            }

            // now delete the guy, which requires us to reload him from the server first, as the photo change operation
            // changes the etag off the entry
            e = cr.Retrieve(e);
            cr.Delete(e);
        }
コード例 #34
0
    //This event controls the submit button for both the add contact modal and the edit contact modal.
    protected void addSubmitButton_Click(object sender, EventArgs e)
    {
        RequestSettings settings = new RequestSettings("ProQuorum Messaging Module", (String)Session["username"], (String)Session["password"]);
        ContactsRequest cr       = new ContactsRequest(settings);

        if (!editContactFlag)   //If we are adding a contact and not editing one.
        {
            Contact newEntry = new Contact();
            // Set the contact's name.
            if (fullName.Text != "")    //make sure the user has put in a full name.
            {
                newEntry.Name = new Name()
                {
                    FullName = fullName.Text
                               //GivenName = "Elizabeth",
                               //FamilyName = "Bennet",
                };
            }
            if (notes.Text != "")
            {
                newEntry.Content = notes.Text;
            }

            // Set the contact's e-mail addresses.
            if (prEmail.Text != "")         //make sure the user has put in a primary email.
            {
                newEntry.Emails.Add(new EMail()
                {
                    Primary = true,
                    Rel     = ContactsRelationships.IsHome,
                    Address = prEmail.Text
                });
            }
            // Set the contact's phone numbers.
            if (homePhone.Text != "")
            {
                newEntry.Phonenumbers.Add(new PhoneNumber()
                {
                    Primary = true,
                    Rel     = ContactsRelationships.IsHome,
                    Value   = homePhone.Text
                });
            }

            /* Set the contact's IM information.
             * newEntry.IMs.Add(new IMAddress()
             * {
             *  Primary = true,
             *  Rel = ContactsRelationships.IsHome,
             *  Protocol = ContactsProtocols.IsGoogleTalk,
             * });*/
            // Set the contact's postal address.
            if (address.Text != "" || city.Text != "" || state.Text != "" || zip.Text != "" || country.Text != "")
            {
                newEntry.PostalAddresses.Add(new StructuredPostalAddress()
                {
                    Rel      = ContactsRelationships.IsWork,
                    Primary  = true,
                    Street   = address.Text,
                    City     = city.Text,
                    Region   = state.Text,
                    Postcode = zip.Text,
                    Country  = country.Text
                               //FormattedAddress = "1600 Amphitheatre Pkwy Mountain View",
                });
            }
            // Insert the contact.
            Uri     feedUri      = new Uri(ContactsQuery.CreateContactsUri("default"));
            Contact createdEntry = cr.Insert(feedUri, newEntry);

            //Update the contacts list box to reflect the new contact as well as the contacts data structures.
            _contacts.Add(newEntry);
            _contactNames.Add(newEntry.Name.FullName);
            //Sort both the lists of contacts in alphabetical order
            _contactNames.Sort();
            _contacts = _contacts.OrderBy(o => o.Name.FullName).ToList();
            ContactsListBox.DataSource = null;      //update the listbox.
            ContactsListBox.DataSource = _contactNames;
            ContactsListBox.DataBind();
            title.Text = "Contact List (" + _contacts.Count.ToString() + " entries)";

            //MessageBox.Show("Contact was successfully added.");
            successOutput.Text = "Contact was successfully added.";
            ClientScript.RegisterStartupScript(GetType(), "Show", "<script> $('#successModal').modal('toggle');</script>");
        }
        else //We are editing a contact.
        {
            try
            {
                //set all of the contacts fields to the new values of the text fields.
                if (fullName.Text.Length > 0)
                {
                    contact.Name.FullName = fullName.Text;
                }
                else
                {
                    contact.Name.FullName = "";
                }

                if (notes.Text.Length > 0)
                {
                    contact.Content = notes.Text;
                }
                else
                {
                    contact.Content = "";
                }

                if (prEmail.Text.Length > 0)
                {
                    contact.PrimaryEmail.Address = prEmail.Text;
                }
                else
                {
                    contact.PrimaryEmail.Address = "";
                }

                if (homePhone.Text.Length > 0)
                {
                    contact.PrimaryPhonenumber.Value = homePhone.Text;
                }
                else
                {
                    contact.PrimaryPhonenumber.Value = "";
                }

                if (address.Text.Length > 0)
                {
                    contact.PrimaryPostalAddress.Street = address.Text;
                }
                else
                {
                    contact.PrimaryPostalAddress.Street = "";
                }

                if (city.Text.Length > 0)
                {
                    contact.PrimaryPostalAddress.City = city.Text;
                }
                else
                {
                    contact.PrimaryPostalAddress.City = "";
                }

                if (state.Text.Length > 0)
                {
                    contact.PrimaryPostalAddress.Region = state.Text;
                }
                else
                {
                    contact.PrimaryPostalAddress.Region = "";
                }

                if (zip.Text.Length > 0)
                {
                    contact.PrimaryPostalAddress.Postcode = zip.Text;
                }
                else
                {
                    contact.PrimaryPostalAddress.Postcode = "";
                }

                if (country.Text.Length > 0)
                {
                    contact.PrimaryPostalAddress.Country = country.Text;
                }
                else
                {
                    contact.PrimaryPostalAddress.Country = "";
                }

                Contact updatedContact = cr.Update(contact);

                //MessageBox.Show("Contact was updated successfully.");
                successOutput.Text = "Contact was updated successfully.";
                ClientScript.RegisterStartupScript(GetType(), "Show", "<script> $('#successModal').modal('toggle');</script>");
            }
            catch (GDataVersionConflictException ex)
            {
                //MessageBox.Show("Etag mismatch. Could not update contact.");
                errorOutput.Text = "Etag mismatch. Could not update contact.";
                ClientScript.RegisterStartupScript(GetType(), "Show", "<script> $('#errorModal').modal('toggle');</script>");
            }
        }
    }