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);
    }
Beispiel #2
0
        public string[] GetOrCreateGoogleGroups(int amount)
        {
            var groupCache = new GoogleGroupCache(Components.GoogleApiOperationExecutor);

            groupCache.Fill();

            var existingGroupNames = new HashSet <string> (groupCache.Groups.Select(g => g.Title), StringComparer.InvariantCultureIgnoreCase);

            while (existingGroupNames.Count < amount)
            {
                string groupName = "Group";
                for (var groupSuffix = 1; existingGroupNames.Contains(groupName); groupName = $"Group {groupSuffix++}")
                {
                    ;
                }

                existingGroupNames.Add(groupName);
                groupCache.GetOrCreateGroup(groupName);
            }

            return(existingGroupNames.Take(amount).ToArray());
        }