public object GetDashboard(string section)
        {
            DashboardHelpers.EnsureCurrentUserCulture();

            // Initialize a new list for the tabs
            List <DashboardTab> tabs = new List <DashboardTab>();

            // Iterate through each of the added plugins
            foreach (IDashboardPlugin plugin in DashboardContext.Current.Plugins)
            {
                try {
                    plugin.GetDashboard(section, tabs);
                } catch (Exception ex) {
                    LogHelper.Error <DashboardController>("Plugin of type " + plugin.GetType() + " has failed for GetDashboard()", ex);
                }
            }

            // Update the "Id" and "IsActive" properties
            int i = 0;

            foreach (DashboardTab tab in tabs)
            {
                tab.IsActive = (i == 0);
                tab.Id       = i++;
            }

            // Return the list and let JSON.net do the magic
            return(tabs);
        }
        public object GetSiteData(int siteId, string period, bool cache = true)
        {
            DashboardHelpers.EnsureCurrentUserCulture();

            try {
                // Get the site
                IDashboardSite site = DashboardContext.Current.GetSiteById(siteId);
                if (site == null)
                {
                    throw new DashboardException(HttpStatusCode.NotFound, "Site ikke fundet", "Et site det angivne ID blev ikke fundet");
                }

                // Get analytics information
                IAnalyticsSite analytics = site as IAnalyticsSite;
                if (analytics == null || !analytics.HasAnalytics)
                {
                    throw new DashboardException(HttpStatusCode.InternalServerError, "Analytics", "Det valgte side understøtter eller er ikke konfigureret til visning af statistik fra Google Analytics");
                }

                // Build the query
                DataQuery query = DataQuery.GetFromPeriod(analytics, period, cache);
                query.Type = DataQueryType.Site;

                // Generate the response object
                DataResponse res = query.GetResponse();

                // Return a nice JSON response
                return(JsonMetaResponse.GetSuccess(res));
            } catch (DashboardException ex) {
                return(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Title + ": " + ex.Message));
            } catch (Exception ex) {
                return(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, "Oopsie (" + ex.GetType() + "): " + ex.Message, ex.StackTrace.Split('\n')));
            }
        }
        public object GetPageData(int siteId, int pageId, string period, bool cache = true)
        {
            DashboardHelpers.EnsureCurrentUserCulture();

            try {
                // Look for the site with the specified ID
                IDashboardSite site = DashboardContext.Current.GetSiteById(siteId);
                if (site == null)
                {
                    throw new DashboardException(HttpStatusCode.NotFound, "Site ikke fundet", "Et site det angivne ID blev ikke fundet");
                }

                // Attempt to cast the site to an Analytics site
                IAnalyticsSite analytics = site as IAnalyticsSite;
                if (analytics == null || !analytics.HasAnalytics)
                {
                    throw new DashboardException(HttpStatusCode.InternalServerError, "Analytics", "Det valgte side understøtter eller er ikke konfigureret til visning af statistik fra Google Analytics");
                }

                // Get the published content of the page
                IPublishedContent content = UmbracoContext.ContentCache.GetById(pageId);

                // Build the query
                DataQuery query = DataQuery.GetFromPeriod(analytics, period, cache);
                query.Type   = DataQueryType.Page;
                query.PageId = content.Id;

                // Set the URL for the query. The protocol and domain is stripped so we only have the path
                query.PageUrl = Regex.Replace(content.Url, "^http(s|)://[a-z0-9-.]+/", "/");

                // Google Analytics sees the same URL with and without a trailing slash as two different pages, so we should tell the query to check both
                string pageUrlTrimmed = query.PageUrl.TrimEnd('/');
                string pageUrlSlashed = pageUrlTrimmed + '/';
                query.PageUrls = String.IsNullOrEmpty(pageUrlTrimmed) ? new[] { pageUrlSlashed } : new[] { pageUrlTrimmed, pageUrlSlashed };

                // Generate the response object
                DataResponse res = query.GetResponse();

                // Return a nice JSON response
                return(JsonMetaResponse.GetSuccess(res));
            } catch (DashboardException ex) {
                return(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Title + ": " + ex.Message));
            } catch (Exception ex) {
                return(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, "Oopsie (" + ex.GetType() + "): " + ex.Message, ex.StackTrace.Split('\n')));
            }
        }