/// <summary> /// Get meta title. /// </summary> /// <param name="page"></param> /// <returns></returns> public static string GetMetaTitle(this Site site, WcmsAppContext appctx, string title) { string metaTitle = (appctx?.Region?.StringValue != null) ? Framework.String.RemoveAccents(title) /*+ ((ForAllRegion == true) ? "@" : "")*/ + " - " + appctx.Region.StringValue.ToLower() : Framework.String.RemoveAccents(title) /*+ ((ForAllRegion == true) ? "@" : "")*/; return(Framework.String.reSize(metaTitle, 83)?.Replace("...", string.Empty)); }
///// <summary> ///// Get post groups. ///// </summary> ///// <param name="post"></param> ///// <returns></returns> //public static ICollection<Models.Claim> GetGroups(this Post post) //{ // return post?.PostClaims?.Where(s => s.Type == ClaimType.Group).Cast<Models.Claim>()?.ToList(); //} ///// <summary> ///// Get post regions. ///// </summary> ///// <param name="post"></param> ///// <returns></returns> //public static ICollection<PostClaim> GetRegions(this Post post) //{ // return post?.PostClaims?.Where(s => s.Type == ClaimType.Region)?.ToList(); //} /// <summary> /// Get post regions as string. /// </summary> /// <param name="post"></param> /// <returns></returns> public static string GetRegionsAsString(this Post post, WcmsAppContext appctx) { string asString = string.Empty; List <int> ids = new List <int>(); ICollection <PostRegion> postRegions = null; # if !DENORMALIZE if ((postRegions = post?.PostRegions) != null)
/// <summary> /// Get meta description. /// </summary> /// <param name="page"></param> /// <returns></returns> public static string GetMetaDescription(this Site site, WcmsAppContext appctx, string title) { string metaDescription = (appctx?.Region?.StringValue != null) ? $"{title?.ToLower()} - {appctx?.Region.StringValue?.ToLower()}" : title?.ToLower(); return(Framework.String.reSize(metaDescription, 83).Replace("...", string.Empty)); }
/// <summary> /// Get user cover path. /// </summary> /// <param name="user"></param> /// <param name="appctx"></param> /// <returns></returns> public static string GetCoverPath(this ApplicationUser user, WcmsAppContext appctx) { if (user?.Cover == null) { return(null); } return((user.Cover.StartsWith("http:") == true) ? null : user.GetFilePath(appctx, $"cover{user.Cover}")); }
/// <summary> /// Get meta keyword. /// </summary> /// <param name="page"></param> /// <returns></returns> public static string GetMetaKeywords(this Site site, WcmsAppContext appctx, string title) { string keyword = appctx.Module?.LongName?.ToLower() + ", "; if (appctx?.Region?.StringValue != null) { keyword += appctx.Region.StringValue.ToLower() + ", "; } keyword += Framework.String.AsKeyWord(title); return(keyword); }
/// <summary> /// Call next middleware. /// </summary> /// <param name="appContext"></param> /// <param name="perfMsg1"></param> /// <param name="perfMsg2"></param> /// <param name="context"></param> /// <returns></returns> private async Task _NextMiddleWare(WcmsAppContext appContext, string perfMsg1, string perfMsg2, HttpContext context) { // Trace performance... appContext?.AddPerfLog(perfMsg1); { // Call next middleware... await _next(context); } // Trace performance... appContext?.AddPerfLog(perfMsg2); }
/// <summary> /// Page authorization handler constructor. /// </summary> /// <param name="appContext"></param> /// <param name="perfProvider"></param> /// <param name="loggerFactory"></param> public PageAuthorizationHandler(WcmsAppContext appContext, PerformanceProvider perfProvider, ILoggerFactory loggerFactory) { _AppContext = appContext; _PerfProvider = perfProvider; // Trace... if (LogDisabled == false) { _Log = loggerFactory?.CreateLogger("Authorization" /*typeof(PageAuthorizationHandler).FullName*/); } }
/// <summary> /// Site authorization handler constructor. /// </summary> /// <param name="signInManager"></param> /// <param name="userManager"></param> /// <param name="perfProvider"></param> /// <param name="loggerFactory"></param> public SiteAuthorizationHandler(WcmsAppContext appContext, PerformanceProvider perfProvider, ILoggerFactory loggerFactory) { _AppContext = appContext; _PerfProvider = perfProvider; // Trace... if (LogDisabled == false) { _Log = loggerFactory?.CreateLogger("Authorization" /*typeof(SiteAuthorizationHandler).FullName*/); } //_Log?.LogInformation("SiteAuthorizationHandler allocated."); }
/// <summary> /// Get user file path. /// </summary> /// <param name="user"></param> /// <param name="appctx"></param> /// <param name="fileName"></param> /// <returns></returns> public static string GetFilePath(this ApplicationUser user, WcmsAppContext appctx, string fileName) { string fileUrl = null; if (user.SiteId == 0 || user.SiteId != (appctx?.Site?.Id ?? 0) || (fileUrl = user.GetFileUrl(fileName)) == null) { return(null); } IFileInfo filInf = appctx?.HostingEnvironment?.WebRootFileProvider?.GetFileInfo($"/{appctx.Site.Id}/{fileUrl}"); appctx?.Log?.LogDebug("GetFilePath: {0} to {1}", fileName, filInf?.PhysicalPath); return(filInf?.PhysicalPath); }
/// <summary> /// Init user folder. /// </summary> /// <param name="user"></param> /// <param name="appctx"></param> public static bool InitDirectory(this ApplicationUser user, WcmsAppContext appctx) { string userPath = null; if ((userPath = user.GetRootPath(appctx)) == null) { appctx?.Log?.LogDebug("userPath=null"); return(false); } appctx?.Log?.LogDebug("userPath={0}", userPath); if (Directory.Exists(userPath) == false) { Directory.CreateDirectory(userPath); } return(true); }
/// <summary> /// Get user groups. /// </summary> /// <param name="user"></param> /// <param name="appctx"></param> /// <returns></returns> public static ICollection <UserGroup> UserGroups(this ApplicationUser user, WcmsAppContext appctx) { ICollection <SiteClaim> claims = null; ICollection <UserGroup> groups = new List <UserGroup>(); if ((claims = appctx?.Site?.GetGroups()) != null) { foreach (SiteClaim claim in claims) { if (claim.Id == user.Group1 || claim.Id == user.Group2 || claim.Id == user.Group3 || claim.Id == user.Group4 || claim.Id == user.Group5 || claim.Id == user.Group6 || claim.Id == user.Group7 || claim.Id == user.Group8 || claim.Id == user.Group9 || claim.Id == user.Group10) { groups.Add(new UserGroup { GroupId = claim.Id, User = user }); } } } return(groups); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task RouteAsync(RouteContext context) { ModuleController modCtrl = null; WcmsAppContext appContext = null; var sw = new Stopwatch(); sw.Start(); //_log?.LogDebug("==============================================================="); // Checking.... if (context == null) { throw new Exception("Route failed: Invalid context!!!"); } try { // Manage case where a lib file not found match to a MVC route... if (context.HttpContext.Request.Path.Value.StartsWith(CRoute.RouteStaticFile_Lib) == true) { // This lib file is missing, so return a 404 error status code... context.HttpContext.Response.StatusCode = 404; return; } // Get the application context... if ((appContext = _GetAppContext(context)) == null) { throw new Exception("Route failed: Invalid app context!!!"); } // For diagnostics and link-generation purposes, routing should include // a list of IRoute instances that lead to the ultimate destination. // It's the responsibility of each IRouter to add the 'next' before calling it. context.RouteData.Routers.Add(_next); // Initialize the application context... if (await appContext.InitRouteAsync(context) == false) { throw new Exception($"Route failed: Route initilisation failed for {context.HttpContext.Request.Path.Value}!!!"); } // Get controller and action... string controller = (string)context.RouteData.Values["controller"]; if (controller != null && controller != "Error") { // Mvc and not WebApi... string action = (string)context.RouteData.Values["action"]; // Customize the route based on the page (must be done before // the customization based on the module... if (controller == "Page" && appContext.Page != null) { _log?.LogDebug("Page {0}: controller={1}, action={2}.", appContext.Page.Id, appContext.Page.Controller, appContext.Page.Action); // Overwrite controller page and action based on the retrieved page... context.RouteData.Values.Remove("controller"); context.RouteData.Values.Add("controller", controller = appContext.Page.Controller); context.RouteData.Values.Remove("action"); context.RouteData.Values.Add("action", action = appContext.Page.Action); // Check if we have to load a post for the page... IEnumerable <PageClaim> claims = null; if ((claims = appContext.Page.GetClaims(PageClaimType.FilterPostId)) != null) { foreach (PageClaim claim in claims) { await appContext.LoadPost(claim?.Value?.ToString()); break; } } } // Get site module... if (appContext.Module == null) { throw new Exception("Route failed: No module found for the site!!!"); } // Save the module to route data... context.RouteData.Values.Add("module", appContext.Module); // Get module controller... string lowerController = controller.ToLower(); if (controller != null && appContext.Module.Controllers.ContainsKey(lowerController) == true && (modCtrl = appContext.Module.Controllers[lowerController]) != null) { // Trace... _log?.LogDebug("Module controller: {0}: ControllerAndView={1}, HaveLayout={2}.", modCtrl?.Name, modCtrl?.HaveControllerAndView ?? false, modCtrl?.HaveLayout ?? false); // Save the module controller to route data... context.RouteData.Values.Add("moduleController", modCtrl); } // Update the context with the module and controller... appContext.InitModule(context, modCtrl); // Customize the route based on the module... if (modCtrl != null && modCtrl.HaveControllerAndView == true) { if (appContext.Module.UseArea == true) { // Area customization... context.RouteData.Values.Remove("area"); context.RouteData.Values.Add("area", appContext.Module.Name /*.ToLower()*/); _log?.LogDebug("Route overwrited: {0}\\{1}\\{2}", appContext.Module.Name, controller, action); } else { // Controller name customization... context.RouteData.Values.Remove("controller"); context.RouteData.Values.Add("controller", appContext.Module.Name + controller); _log?.LogDebug("Route overwrited: {0}{1}\\{2}", appContext.Module.Name, controller, action); } } // Save the context to route data... context.RouteData.Values.Add("appcontext", appContext); } // Process duration... long routeDuration = sw.ElapsedMilliseconds; _log?.LogInformation("Route handling for \"{0}\" processed in {1} milliseconds.", context?.HttpContext?.Request?.Path.Value?.ToString(), routeDuration); // Execute the next route handler... await _next.RouteAsync(context); // Process %... long routeDuration2 = sw.ElapsedMilliseconds; _log?.LogInformation("Route handling for \"{0}\" took {1}% of the process ({2} milliseconds).", context?.HttpContext?.Request?.Path.Value?.ToString(), (routeDuration2 == 0) ? 0 : ((routeDuration * 100) / routeDuration2), routeDuration2); } finally { } //catch(Exception e) //{ // if (appContext != null) // appContext.Exception = e.Message; // throw e; //} }
public AuthMessageSender(WcmsAppContext context) { _Context = context; _logger = context?.LoggerFactory?.CreateLogger <AuthMessageSender>(); }
/// <summary> /// Stop the middleware chain. /// </summary> /// <param name="appContext"></param> /// <param name="perfMsg1"></param> /// <param name="context"></param> private void _StopChain(WcmsAppContext appContext, string perfMsg1, HttpContext context) { // Trace performance... appContext?.AddPerfLog(perfMsg1); }
/// <summary> /// Get user root path. /// </summary> /// <param name="user"></param> /// <param name="appctx"></param> /// <returns></returns> public static string GetRootPath(this ApplicationUser user, WcmsAppContext appctx) { return(user?.GetFilePath(appctx, string.Empty)); }
/// <summary> /// Get site root path. /// </summary> /// <param name=""></param> /// <param name="fileName"></param> /// <returns></returns> public static string GetRootPath(this Site site, WcmsAppContext appctx) { IFileInfo filInf = appctx?.HostingEnvironment?.WebRootFileProvider?.GetFileInfo($"/{site.Id}"); return(filInf?.PhysicalPath); }
/// <summary> /// Page provider constructor. /// </summary> /// <param name="appContext"></param> public PageProvider(WcmsAppContext appContext) : base(appContext) { }
/// <summary> /// Get user regions. /// </summary> /// <param name="user"></param> /// <param name="appctx"></param> /// <returns></returns> public static ICollection <UserRegion> UserRegions(this ApplicationUser user, WcmsAppContext appctx) { ICollection <SiteClaim> claims = null; ICollection <UserRegion> regions = new List <UserRegion>(); if ((claims = appctx?.Site?.GetRegions()) != null) { foreach (SiteClaim claim in claims) { if (user.Region1 == 0 || claim.Id == user.Region1 || claim.Id == user.Region2 || claim.Id == user.Region3 || claim.Id == user.Region4 || claim.Id == user.Region5 || claim.Id == user.Region6 || claim.Id == user.Region7 || claim.Id == user.Region8 || claim.Id == user.Region9 || claim.Id == user.Region10) { regions.Add(new UserRegion { RegionId = claim.Id, User = user }); } } } return(regions); }