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 GetRedirectsForMedia(int contentId) { try { // Get a reference to the media item IMedia media = ApplicationContext.Services.MediaService.GetById(contentId); // Trigger an exception if the media item couldn't be found if (media == null) { throw new RedirectsException(HttpStatusCode.NotFound, Localize("redirects/errorMediaNoRedirects")); } // Generate the response return(JsonMetaResponse.GetSuccess(new { media = new { id = media.Id, name = media.Name }, redirects = Repository.GetRedirectsByMediaId(contentId) })); } catch (RedirectsException ex) { // Generate the error response return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message))); } }
public object GetRedirectsForContent(int contentId) { try { // Get a reference to the content item IContent content = Current.Services.ContentService.GetById(contentId); // Trigger an exception if the content item couldn't be found if (content == null) { throw new RedirectsException(HttpStatusCode.NotFound, Localize("redirects/errorContentNoRedirects")); } // Generate the response return(JsonMetaResponse.GetSuccess(new { content = new { id = content.Id, name = content.Name }, redirects = _redirects.GetRedirectsByContentId(contentId) })); } catch (RedirectsException ex) { // Generate the error response return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message))); } }
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'))); } }
public object GetRedirectsForMedia(int contentId) { IMedia media = ApplicationContext.Services.MediaService.GetById(contentId); if (media == null) { throw new RedirectsException(HttpStatusCode.NotFound, "A media item with the specified ID could not be found."); } try { return(JsonMetaResponse.GetSuccess(new { media = new { id = media.Id, name = media.Name }, redirects = Repository.GetRedirectsByMediaId(contentId) })); } catch (RedirectsException ex) { return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message))); } }
public object Search(int siteid, string keywords = "", int offset = 0, int limit = 10) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (!siteid.IsExistingNode()) { return(Request.CreateResponse(JsonMetaResponse.GetError("siteid is not valid"))); } int total = 0; int pageTotal = 0; int jobTotal = 0; int employeeTotal = 0; try { #region Normal Search SearchOptions initialSo = new SearchOptions { Text = keywords, RootIds = new int[] { siteid }, DocumentTypes = new string[] { Constants.SkyConstants.DocumentTypes.SubPage, Constants.SkyConstants.DocumentTypes.FrontPage }, // add your own doctypes Fields = { FieldList = new List <Field> { Field.GetFieldOption("nodeName_lci", 15, null), Field.GetFieldOption("title_lci", 15, null), Field.GetFieldOption("teaser_lci", 15, null), Field.GetFieldOption(Constants.SkyConstants.Properties.ContentGrid, null, null), // add more fields to search here } }, Order = new Order { OrderType = OrderType.Score }, Limit = limit, Offset = offset, Debug = HttpContext.Current.IsDebuggingEnabled }; List <IPublishedContent> results = SkybrudSearch.SearchDocuments( out pageTotal, initialSo ).ToList(); #endregion // create response body List <SiteSearchResult> returnResults = results.Select(x => SiteSearchResult.GetFromContent(x)).ToList(); JsonMetaResponse response = JsonMetaResponse.GetSuccess(returnResults.Take(limit)); total = pageTotal + jobTotal + employeeTotal; response.SetPagination(new JsonPagination { Total = total, Limit = limit, Offset = offset }); //Set groups JObject obj = JObject.FromObject(response); return(obj); } catch (Exception ex) { Error error = new Error("Der skete en fejl på serveren"); LogHelper.Error <SiteController>(error.ToString(), ex); return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, error.Message, error))); } }
public object Search(int contextId, string keywords = "", int offset = 0, int limit = 10, string year = "") { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (!contextId.IsExistingNode()) { return(Request.CreateResponse(JsonMetaResponse.GetError("contextId is not a valid Umbraco-node"))); } List <IPublishedContent> results; int total; try { SpecificFields fields = new SpecificFields { Fields = new List <ISpecificField> { new SpecificField { FieldName = "year", SearchTerms = new [] { year } } } }; SearchOptions initialSo = new SearchOptions { Text = keywords, DocumentTypes = new string[] { Constants.SkyConstants.DocumentTypes.NewsPage }, RootIds = new int[] { contextId }, Fields = { FieldList = new List <Field> { Field.GetFieldOption("nodeName_lci", 15, null), Field.GetFieldOption("titel_lci", 15, null), Field.GetFieldOption("teaser_lci", 15, null), Field.GetFieldOption(Constants.SkyConstants.Properties.ContentGrid, null, null) } }, Order = new Order() { FieldName = string.Format("{0}_range", Constants.SkyConstants.Properties.ContentDate), OrderDirection = OrderDirection.Descending, OrderType = OrderType.String }, DateRange = new DateRange() { FieldName = Constants.SkyConstants.Properties.ContentDate, End = DateTime.MaxValue, Start = DateTime.MinValue.AddDays(1) }, Limit = limit, Offset = offset, Debug = HttpContext.Current.IsDebuggingEnabled }; if (!string.IsNullOrEmpty(year)) { initialSo.SpecificFields = fields; } results = Skybrud.Umbraco.Search.SkybrudSearch.SearchDocuments( out total, initialSo ).ToList(); } catch (Exception ex) { Error error = new Error("Der skete en fejl på serveren"); LogHelper.Error <NewsController>(error.ToString(), ex); return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, error.Message, error))); } var returnResults = results.Select(x => NewsSearchResult.GetFromContent(x)); JsonMetaResponse response = JsonMetaResponse.GetSuccess(returnResults); response.SetPagination(new JsonPagination { Total = total, Limit = limit, Offset = offset }); return(Request.CreateResponse(response)); }