public GoogleContactContext(GoogleGroupCache groupCache, IGoogleContactCache contactCache) { if (groupCache == null) { throw new ArgumentNullException(nameof(groupCache)); } if (contactCache == null) { throw new ArgumentNullException(nameof(contactCache)); } GroupCache = groupCache; ContactCache = contactCache; }
public async Task <IGoogleContactContext> Create() { return(await Task.Run(() => { var googleGroupCache = new GoogleGroupCache(_apiOperationExecutor); googleGroupCache.Fill(); var googleContactCache = new GoogleContactCache(_apiOperationExecutor, _contactIdComparer, _userName, _chunkSize); googleContactCache.Fill(googleGroupCache.DefaultGroupIdOrNull); var context = new GoogleContactContext( googleGroupCache, googleContactCache); return context; })); }
public GoogleContactContext(GoogleGroupCache groupCache, IGoogleApiOperationExecutor apiOperationExecutor, IEqualityComparer <string> contactIdComparer, string userName) { if (groupCache == null) { throw new ArgumentNullException(nameof(groupCache)); } if (apiOperationExecutor == null) { throw new ArgumentNullException(nameof(apiOperationExecutor)); } if (contactIdComparer == null) { throw new ArgumentNullException(nameof(contactIdComparer)); } if (String.IsNullOrEmpty(userName)) { throw new ArgumentException("Argument is null or empty", nameof(userName)); } GroupCache = groupCache; _apiOperationExecutor = apiOperationExecutor; _userName = userName; _contactsById = new Dictionary <string, Contact> (contactIdComparer); }
private static void AssignGroupsToContacts(IEnumerable <GoogleContactWrapper> contacts, GoogleGroupCache groupCache) { foreach (var contactWrapper in contacts) { contactWrapper.Contact.GroupMembership.Clear(); groupCache.AddDefaultGroupToContact(contactWrapper.Contact); foreach (var groupName in contactWrapper.Groups) { var group = groupCache.GetOrCreateGroup(groupName); if (!groupCache.IsDefaultGroup(group)) { contactWrapper.Contact.GroupMembership.Add(new GroupMembership() { HRef = group.Id }); } } } }