/// <summary>
 /// Gets a list of all web properties of the specified account.
 /// </summary>
 /// <param name="accountId">The ID of the parent account.</param>
 /// <param name="maxResults">The maximum number of results per page (default is 1000).</param>
 /// <param name="startIndex">The start index (default is 1).</param>
 public AnalyticsWebPropertiesResponse GetWebProperties(string accountId, int maxResults = 0, int startIndex = 0)
 {
     return(AnalyticsWebPropertiesResponse.ParseJson(Service.Client.Analytics.GetWebProperties(accountId, maxResults, startIndex)));
 }
예제 #2
0
        public static AnalyticsCachedUser GetFromResponses(AnalyticsUserConfiguration user, AnalyticsAccountsResponse response1, AnalyticsWebPropertiesResponse response2, AnalyticsProfilesResponse response3)
        {
            Dictionary <string, List <AnalyticsWebProperty> > webProperties = new Dictionary <string, List <AnalyticsWebProperty> >();
            Dictionary <string, List <AnalyticsProfile> >     profiles      = new Dictionary <string, List <AnalyticsProfile> >();

            // Add the web properties to a dictionary for faster lookups
            foreach (AnalyticsWebProperty webProperty in response2.Body.Items)
            {
                List <AnalyticsWebProperty> list;
                if (!webProperties.TryGetValue(webProperty.AccountId, out list))
                {
                    webProperties.Add(webProperty.AccountId, list = new List <AnalyticsWebProperty>());
                }
                list.Add(webProperty);
            }

            // Add the profiles to a dictionary for faster lookups
            foreach (AnalyticsProfile profile in response3.Body.Items)
            {
                List <AnalyticsProfile> list;
                if (!profiles.TryGetValue(profile.WebPropertyId, out list))
                {
                    profiles.Add(profile.WebPropertyId, list = new List <AnalyticsProfile>());
                }
                list.Add(profile);
            }



            AnalyticsCachedUser cachedUser = new AnalyticsCachedUser {
                Id = user.Id
            };


            List <AnalyticsCachedAccount> cachedAccounts = new List <AnalyticsCachedAccount>();

            foreach (AnalyticsAccount account in response1.Body.Items)
            {
                List <AnalyticsCachedWebProperty> list11 = new List <AnalyticsCachedWebProperty>();

                List <AnalyticsWebProperty> list1;
                if (!webProperties.TryGetValue(account.Id, out list1))
                {
                    list1 = new List <AnalyticsWebProperty>();
                }

                AnalyticsCachedAccount ca = new AnalyticsCachedAccount {
                    User    = null,
                    Id      = account.Id,
                    Name    = account.Name,
                    Created = account.JsonObject.GetString("created"),
                    Updated = account.JsonObject.GetString("updated")
                };

                foreach (AnalyticsWebProperty webProperty in list1)
                {
                    List <AnalyticsProfile> list2;
                    if (!profiles.TryGetValue(webProperty.Id, out list2))
                    {
                        list2 = new List <AnalyticsProfile>();
                    }

                    AnalyticsCachedWebProperty cwp = new AnalyticsCachedWebProperty {
                        Id         = webProperty.Id,
                        Name       = webProperty.Name,
                        WebsiteUrl = webProperty.WebsiteUrl,
                        Created    = webProperty.Created.ToString("r"),
                        Updated    = webProperty.Updated.ToString("r")
                    };

                    cwp.Profiles = list2.Select(profile => new AnalyticsCachedProfile {
                        WebProperty = cwp,
                        Id          = profile.Id,
                        Name        = profile.Name,
                        Currency    = profile.Currency,
                        Timezone    = profile.Timezone,
                        WebsiteUrl  = profile.WebsiteUrl,
                        Type        = profile.Type,
                        Created     = profile.JsonObject.GetString("created"),
                        Updated     = profile.JsonObject.GetString("updated")
                    }).ToArray();

                    list11.Add(cwp);
                }

                ca.WebProperties = list11.ToArray();

                cachedAccounts.Add(ca);
            }

            cachedUser.Accounts = cachedAccounts.ToArray();

            return(cachedUser);
        }