/// <summary> /// Get page model data object. /// </summary> public PageModelData GetPageModelData(string urlPath, Localization localization, bool addIncludes) { try { PageModelRequest request = new PageModelRequest { Path = urlPath, CmUriScheme = localization.CmUriScheme, PublicationId = int.Parse(localization.Id), PageInclusion = addIncludes ? PageInclusion.INCLUDE : PageInclusion.EXCLUDE, Binder = _binder }; ModelServiceResponse <PageModelData> response = _modelServiceClient.PerformRequest <PageModelData>(request); if (response.Response != null) { response.Response.SerializationHashCode = response.Hashcode; } return(response.Response); } catch (ModelServiceException e) { Log.Error("{0} returned an unexpected response for URL '{1}':\n{2} ", ModelServiceName, _modelServiceClient.ModelServiceBaseUri, e.Message); throw new DxaException($"{ModelServiceName} returned an unexpected response.", e); } catch (ItemNotFoundException) { return(null); } }
public string GetContent(string uri, string templateUri = "") { LoggerService.Debug(">>DD4T.Providers.DxaModelService::GetContent({0})", LoggingCategory.Performance, uri); LoggerService.Debug(">>DD4T.Providers.DxaModelService::GetContent({0})", LoggingCategory.Performance, uri); TcmUri tcmUri = new TcmUri(uri); TcmUri templateTcmUri = new TcmUri(templateUri); EntityModelRequest request = new EntityModelRequest { PublicationId = PublicationId, DataModelType = DataModelType.DD4T, DcpType = DcpType.HIGHEST_PRIORITY, ComponentId = tcmUri.ItemId }; if (!string.IsNullOrEmpty(templateUri)) { request.TemplateId = templateTcmUri.ItemId; } try { var response = ModelServiceClient.PerformRequest <IDictionary <string, object> >(request); return(response.Response["Content"] as string); } catch { } return(null); }
/// <summary> /// Gets the raw string (xml) from the broker db by URL /// </summary> /// <param name="Url">URL of the page</param> /// <returns>String with page xml or empty string if no page was found</returns> public string GetContentByUrl(string url) { LoggerService.Debug(">>DD4T.Providers.DxaModelService::GetContentByUrl({0})", LoggingCategory.Performance, url); string content = null; PageModelRequest req = new PageModelRequest { PublicationId = PublicationId, DataModelType = DataModelType.DD4T, PageInclusion = PageInclusion.INCLUDE, Path = url }; try { content = ModelServiceClient.PerformRequest(req).Response; } catch { } // LoggerService.Debug(">>DD4T.Providers.DxaModelService::GetContentByUrl({0}) returns {1}", LoggingCategory.Performance, url, content); return(content); }
/// <summary> /// Gets the raw string (xml) from the broker db by URI /// </summary> /// <param name="Url">TCM URI of the page</param> /// <returns>String with page xml or empty string if no page was found</returns> public string GetContentByUri(string tcmUri) { LoggerService.Debug(">>DD4T.Providers.DxaModelService::GetContentByUri({0})", LoggingCategory.Performance, tcmUri); string content = null; TcmUri tcm = new TcmUri(tcmUri); PageMetaFactory metaFactory = GetPageMetaFactory(tcm.PublicationId); PageModelRequest req = new PageModelRequest { PublicationId = tcm.PublicationId, DataModelType = DataModelType.DD4T, PageInclusion = PageInclusion.INCLUDE, Path = metaFactory.GetMeta(tcm.ItemId).UrlPath }; try { content = ModelServiceClient.PerformRequest(req).Response; } catch { } // LoggerService.Debug(">>DD4T.Providers.DxaModelService::GetContentByUrl({0}) returns {1}", LoggingCategory.Performance, tcmUri, content); return(content); }