public IGXWebApiCacheAttribute() : base() { var sitePath = CMSPageFactory.GetSitePath(); Settings settings = Settings.Get(new FileInfo(Path.Combine(sitePath, "settings/settings.xml"))); TriggerFile = Path.Combine(sitePath, settings.GetSetting <string>("RuntimeCache", "TriggerFile")); }
static CmsRoute() { if (string.IsNullOrWhiteSpace(_SitePath)) { _SitePath = CMSPageFactory.GetDefaultSitePath(); } _PageFactory = new CMSPageFactory(_SitePath); initControlleSummeries(); }
public PageModel GetPage(string pageUrl = "/") { //System.Diagnostics.Debugger.Launch(); if (!pageUrl.StartsWith("/") && !pageUrl.IsXId()) { pageUrl = $"/{pageUrl}"; } string sitePath = CmsRoute.GetSitePath(); var context = new HttpContextWrapper(HttpContext.Current); HttpRequestBase _request = context.Request; CMSPageFactory pageFactory = new CMSPageFactory(sitePath); ICMSPage page; if (!pageUrl.IsXId()) { page = pageFactory.GetPageByPath(_request, pageUrl) as ICMSPage; } else { page = pageFactory.GetPage(_request, pageUrl) as ICMSPage; } if (page == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "this item does not exist")); } Request.Properties[IGXWebApiCacheAttribute.NAVS_CACHED_PROP_NAME] = (page as CMSPageRequest).NavigationUsingCacheContent; var eleExceptions = new ElementModel().ElementExceptionList; var attrExceptions = new ElementModel().AttributeExceptionList; var pageModel = new PageModel() { Attributes = page .Attributes() .Where(pageAttrs => !attrExceptions.Contains(pageAttrs.AttributeName)) .ToDictionary(pageAttrs => pageAttrs.AttributeName, pageAttrs => pageAttrs.Value), Elements = page .Elements() .Select(e => new ElementModel(e)).Where(e => !eleExceptions.Contains(e.Name)) }; pageModel.Attributes.Add("TestTime", System.DateTime.Now.ToString()); return(pageModel); }
public override void OnActionExecuting(HttpActionContext actionContext) { var sitePath = CMSPageFactory.GetSitePath(); Settings settings = Settings.Get(new FileInfo(Path.Combine(sitePath, "settings/settings.xml"))); var path = actionContext.Request.RequestUri.LocalPath.ToLowerInvariant(); ObjectCache cache = MemoryCache.Default; var cachedContentObject = cache.Get($"{MEM_CACHE_PREFIX}{path}"); if (cachedContentObject != null) { if (cachedContentObject is string cachedContent) { var response = actionContext.Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(cachedContent); actionContext.Response = response; return; } } IGXPageLevelCache pageLevelCache = IGXPageLevelCache.Get(TriggerFile); PageCache pageCache = pageLevelCache.GetPageCacheSettings(path); UseCache = settings.GetSetting <bool>("RuntimeCache", "UseRuntimeCache") && pageCache != null && pageCache.Cache; if (!UseCache) { Duration = 0; } else { int durationSettings = pageCache.CacheTime > 0 ? pageCache.CacheTime : settings.GetSetting <int>("RuntimeCache", "ExpireTime"); Duration = durationSettings; } base.OnActionExecuting(actionContext); }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); _SitePath = CmsRoute.GetSitePath(); _DTSitePath = ConfigurationManager.AppSettings["DesignTimeAssetsLocation"] .ToNullOrEmptyHelper() .Return(_SitePath); _AllowTfrm = ConfigurationManager.AppSettings["EnableTFRMParameter"].ToNullHelper().Branch( str => str.Trim().ToLowerInvariant() == "true", () => true); _LegacyTransformation = ConfigurationManager.AppSettings["LegacyRendering"].ToNullHelper() .Branch( str => str.Trim().ToLowerInvariant() != "false", () => true); _UseTempStylesheetsLocation = ConfigurationManager.AppSettings["UseTempStylesheetsLocation"].ToNullHelper().Branch(str => str.Trim().ToLowerInvariant() != "false", () => true); _IsDesignTime = Reference.Reference.IsDesignTime(_SitePath); try { //page factory is a cheap object to construct, since both surl map and ssmap are cached most time _PageFactory = CMSPageFactoryHelper.GetPageFactory(_IsDesignTime, _SitePath, requestContext, _LegacyTransformation, out _IsDTAuthenticated) as CMSPageFactory; } catch (Ingeniux.CMS.Exceptions.LicensingException e) { if (e.Expired) { _InvalidPageResult = new XmlResult( new XElement("TrialLicenseExpired", new XAttribute("ExpirationDateUTC", e.ExpirationDate.ToIso8601DateString(true)), new XElement("IngeniuxSupport", new XAttribute("Phone", "1.877.299.8900"), new XAttribute("Email", "*****@*****.**"), new XAttribute("Portal", "http://support.ingeniux.com/")))); } else { _InvalidPageResult = new XmlResult( new XElement("InvalidCMSLicense", new XElement("IngeniuxSupport", new XAttribute("Phone", "1.877.299.8900"), new XAttribute("Email", "*****@*****.**"), new XAttribute("Portal", "http://support.ingeniux.com/")))); } } if (_InvalidPageResult == null) { if (_PageFactory.CacheSiteControls) { // only set site control schemas when list is not empty string[] siteControlSchemas = ConfigurationManager.AppSettings["SiteControlSchemas"].ToNullHelper().Branch <string[]>( str => str.Split(';').Select( s => s.Trim()).Where( s => s != "").ToArray(), () => new string[] { }); if (siteControlSchemas.Length > 0) { _PageFactory.SiteControlSchemas = siteControlSchemas; } } _PageFactory.LocalExportsIncludeLinks = ConfigurationManager.AppSettings["LocalExportsIncludeLinks"].ToNullHelper().Branch <bool>( str => str.Trim().ToLowerInvariant() == "true", () => true); //move page getting to here so it can be used to OnActionExecuting try { _CMSPageRoutingRequest = _PageFactory.GetPage(Request, false); } catch (DesignTimeInvalidPageIDException exp) { //this message is exclusive to design time and need to present a special page _InvalidPageResult = new XmlResult(new XElement("DynamicPreviewError", exp.Message)); } } if (_CMSPageRoutingRequest != null && string.IsNullOrWhiteSpace(_CMSPageRoutingRequest.RemaingPath)) { HttpContext.Items["PageRequest"] = _CMSPageRoutingRequest; } }
public override RouteData GetRouteData(HttpContextBase httpContext) { if (string.IsNullOrWhiteSpace(_BaseController)) { _BaseController = ConfigurationManager.AppSettings["BaseControllerName"] .ToNullOrEmptyHelper() .Return(DEFAULT_CONTROLLER_NAME); } ICMSRequest pageRequest = null; RouteData data = null; string action = defaultAction; string controller = _BaseController; string appPath = httpContext.Request.ApplicationPath; if (appPath == "/") { appPath = string.Empty; } string relativePath = httpContext.Request.Path.Substring(appPath.Length).ToLowerInvariant(); if (relativePath.StartsWith("/igxdtpreview")) { pageRequest = _PageFactory.GetPreviewPage(httpContext.Request, true); // because the preview does not get a url, but rather an id and xml, // it is not possible to look for other actions based on the URL action = "Preview"; locateController(pageRequest, ref controller); data = createRouteData(action, controller); } if (relativePath.StartsWith("/igxdynamicpreview") || _PageFactory == null) { action = "DynamicPreview"; try { CMS.IContentStore contentStore = CMSPageFactoryHelper.GetPreviewContentStore(httpContext.Request.RequestContext, _SitePath); CMS.IReadonlyUser currentUser = CMSPageFactoryHelper.GetPreviewCurrentUser(contentStore, httpContext.Request.RequestContext, httpContext.Session); _PageFactory = new DocumentPreviewPageFactory(contentStore, currentUser, _SitePath); _PageFactory.CacheSiteControls = false; pageRequest = _PageFactory.GetDynamicPreviewPage(httpContext.Request, true, true); // because the preview does not get a url, but rather an id and xml, // it is not possible to look for other actions based on the URL locateController(pageRequest, ref controller); } catch { controller = "CMSPageDefault"; } data = createRouteData(action, controller); } else { //only need the schema data, not the whole page ICMSRoutingRequest routingRequest = _PageFactory.GetPage(httpContext.Request, true); if (routingRequest != null && routingRequest.CMSRequest != null && routingRequest.CMSRequest.Exists) { pageRequest = routingRequest.CMSRequest; if (pageRequest != null) { //use default controller for routing request if (pageRequest is CMSPageRedirectRequest) { data = createRouteData(defaultAction, controller); } else { var matchingController = locateController(pageRequest, ref controller); if (!string.IsNullOrEmpty(routingRequest.RemaingPath.Trim('/'))) { //use the first section of the remaining path as action, this is arbitrary. string actionInPath = routingRequest.RemaingPath.Trim('/').SubstringBefore("/"); //if the controller doesn't have this action, use default action action = matchingController.ToNullHelper() .Propagate( c => c.ActionNames .Where(an => an.ToLowerInvariant() == actionInPath.ToLowerInvariant()) .FirstOrDefault()) .Return(defaultAction); //get the remaining path in the controller action itself } else { action = defaultAction; } data = createRouteData(action, controller); } } else { data = createRouteData(defaultAction, controller); } } else { data = createRouteData(defaultAction, controller); } } return(data); }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); _SitePath = ConfigurationManager.AppSettings["PageFilesLocation"]; if (string.IsNullOrWhiteSpace(_SitePath)) { _SitePath = requestContext.HttpContext.Server.MapPath("~/App_Data/site"); } _DTSitePath = ConfigurationManager.AppSettings["DesignTimeAssetsLocation"] .ToNullOrEmptyHelper() .Return(_SitePath); _AllowTfrm = ConfigurationManager.AppSettings["EnableTFRMParameter"].ToNullHelper().Branch( str => str.Trim().ToLowerInvariant() == "true", () => true); _LegacyTransformation = ConfigurationManager.AppSettings["LegacyRendering"].ToNullHelper() .Branch( str => str.Trim().ToLowerInvariant() != "false", () => true); _UseTempStylesheetsLocation = ConfigurationManager.AppSettings["UseTempStylesheetsLocation"].ToNullHelper().Branch(str => str.Trim().ToLowerInvariant() != "false", () => true); _IsDesignTime = Reference.Reference.IsDesignTime(_SitePath); if (_IsDesignTime) { //if design time, check if authenticated already. //we will use the parent dt site cookie string authCookie = requestContext.HttpContext.Request.Cookies["IGXAuth"] .ToNullHelper() .Propagate( c => c.Value) .Return(null); _IsDTAuthenticated = !string.IsNullOrWhiteSpace(authCookie); } //page factory is a cheap object to construct, since both surl map and ssmap are cached most time _PageFactory = new CMSPageFactory(_SitePath, !_LegacyTransformation); _PageFactory.CacheSiteControls = ConfigurationManager.AppSettings["CacheSiteControls"].ToNullHelper().Branch <bool>( str => str.Trim().ToLowerInvariant() == "true", () => true); if (_PageFactory.CacheSiteControls) { // only set site control schemas when list is not empty string[] siteControlSchemas = ConfigurationManager.AppSettings["SiteControlSchemas"].ToNullHelper().Branch <string[]>( str => str.Split(';').Select( s => s.Trim()).Where( s => s != "").ToArray(), () => new string[] { }); if (siteControlSchemas.Length > 0) { _PageFactory.SiteControlSchemas = siteControlSchemas; } } _PageFactory.LocalExportsIncludeLinks = ConfigurationManager.AppSettings["LocalExportsIncludeLinks"].ToNullHelper().Branch <bool>( str => str.Trim().ToLowerInvariant() == "true", () => true); }
public static string GetSitePath() { return(CMSPageFactory.GetSitePath()); }
static CmsRoute() { _PageFactory = new CMSPageFactory(_SitePath); initControlleSummeries(); }