/// <summary> /// Construct a request log message. /// </summary> /// <param name="message"> /// The log message. /// </param> /// <param name="success"> /// The success. /// </param> /// <returns> /// A formatted string ready for logging. /// </returns> protected string ConstructLog(string message = null, bool success = true) { var credentials = this.RequestUtils.Context.AuthenticatedCredentials; var request = this.Context.Request; var requestMessage = string.Format( "[{0}][{1}]{2}", request.Method, this.RequestPath, !string.IsNullOrWhiteSpace(message) ? string.Format(" : {0}", message) : string.Empty); return(LoggerUtils.GetLogMessage(credentials.Person, request.UserHostAddress, success, requestMessage)); }
/// <summary> /// Retrieves the <see cref="PersonRole"/> connected to this person. /// </summary> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="person"> /// The <see cref="AuthenticationPerson"/> to resolve permission for. /// </param> /// <returns> /// The <see cref="PersonRole"/> of the specified <see cref="AuthenticationPerson"/>. /// </returns> private PersonRole GetPersonRole(NpgsqlTransaction transaction, AuthenticationPerson person) { if (person.Role == null) { return(null); } try { return(this.PersonRoleDao.Read(transaction, "SiteDirectory", new List <Guid> { (Guid)person.Role }).SingleOrDefault()); } catch (Exception ex) { Logger.Error(ex, LoggerUtils.GetLogMessage(person, string.Empty, false, "There was an error while retrieving the person roles from the backtier")); return(null); } }
/// <summary> /// Application startup hook. /// </summary> /// <param name="container"> /// The inversion of control container. /// </param> /// <param name="pipelines"> /// The pipelines. /// </param> protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines) { var sw = Stopwatch.StartNew(); Logger.Info("Initiate Application Startup"); Logger.Debug("Configurating CDP4 Authentication"); // No registrations should be performed in here, however you may resolve things that are needed during application startup. var cdp4WebServiceAuthentication = container.Resolve <ICDP4WebServiceAuthentication>(); // hook up the basic authentication cdp4WebServiceAuthentication.Enable( pipelines, new CDP4WebServiceAuthenticationConfiguration(container.Resolve <IUserValidator>(), Realm), new[] { SiteDirectoryRoute, EngineeringModelRoute }); // hook up the on error handler Logger.Debug("Setting up on error pipeline"); pipelines.OnError += (ctx, ex) => { // log any uncatched errors var subject = ctx.CurrentUser is Credentials credentials ? credentials.Person : null; var headerInforProvider = container.Resolve <IHeaderInfoProvider>(); var requestMessage = $"[{ctx.Request.Method}][{ctx.Request.Url.Path}{ctx.Request.Url.Query}]"; Logger.Fatal(ex, LoggerUtils.GetLogMessage(subject, ctx.Request.UserHostAddress, false, requestMessage)); var errorResponse = new JsonResponse($"exception:{ex.Message}", new DefaultJsonSerializer()); headerInforProvider.RegisterResponseHeaders(errorResponse); return(errorResponse.WithStatusCode(HttpStatusCode.InternalServerError)); }; Logger.Debug("Setting view-location conventions"); // clear all view location conventions (to save on irrelevant locations being visited) and supply the Views convention to use this.Conventions.ViewLocationConventions.Clear(); this.Conventions.ViewLocationConventions.Add((viewName, model, context) => $"Views/{viewName}"); // add the folder for the static content containing the compiled app this.Conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("assets")); MigrationEngine.MigrateAllAtStartUp(); Logger.Info($"Application Startup Finished in {sw.ElapsedMilliseconds} [ms]"); }
/// <summary> /// Application startup hook. /// </summary> /// <param name="container"> /// The inversion of control container. /// </param> /// <param name="pipelines"> /// The pipelines. /// </param> protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines) { // No registrations should be performed in here, however you may resolve things that are needed during application startup. var cdp4WebServiceAuthentication = container.Resolve <ICDP4WebServiceAuthentication>(); // hook up the basic authentication cdp4WebServiceAuthentication.Enable( pipelines, new CDP4WebServiceAuthenticationConfiguration(container.Resolve <IUserValidator>(), Realm), new[] { SiteDirectoryRoute, EngineeringModelRoute }); // hook up the on error handler pipelines.OnError += (ctx, ex) => { // log any uncatched errors var credentials = ctx.CurrentUser as Credentials; var subject = credentials != null ? credentials.Person : null; var headerInforProvider = container.Resolve <IHeaderInfoProvider>(); var requestMessage = string.Format( "[{0}][{1}{2}]", ctx.Request.Method, ctx.Request.Url.Path, ctx.Request.Url.Query); Logger.Fatal(ex, LoggerUtils.GetLogMessage(subject, ctx.Request.UserHostAddress, false, requestMessage)); var errorResponse = new JsonResponse(string.Format("exception:{0}", ex.Message), new DefaultJsonSerializer()); headerInforProvider.RegisterResponseHeaders(errorResponse); return(errorResponse.WithStatusCode(HttpStatusCode.InternalServerError)); }; // clear all view location conventions (to save on irrelevant locations being visited) and supply the Views convention to use this.Conventions.ViewLocationConventions.Clear(); this.Conventions.ViewLocationConventions.Add( (viewName, model, context) => string.Format("Views/{0}", viewName)); // add the folder for the static content containing the compiled app this.Conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("assets")); }