internal RouteWorkflowTask( RouteRequest routeRequest, IRouteEntryRegistry routeEntryRegistry, IRouteAuthorizationManager routeAuthorizationManager, IRouterService routerService, ILogger logger) { _routeRequest = routeRequest; _routeEntryRegistry = routeEntryRegistry; _routeAuthorizationManager = routeAuthorizationManager; _routerService = routerService; _logger = logger .ForContext(SerilogConstants.Serilog_SourceContext_Name, nameof(RouteWorkflowTask)) .ForContext("Uri", Uri) .ForContext("ViewportName", ViewportOptions.ToString()) .ForContext("InitData", InitData) .ForContext("RouterServiceId", _routerService.RouterServiceId) .ForContext("RoutingWorkflowId", RoutingWorkflowId); }
internal async Task <RouteResult> GoAsync() { var initDataIsNull = InitData != null ? " with init data" : " without init data"; using var timer = PerformanceTimer.Start(_logger, $"Routing operation to {Uri} in Viewport {ViewportOptions.ToString() + initDataIsNull}"); try { RouteEntryOption = RouteWorkflow.GetRouteEntry(_logger, _routeEntryRegistry, Uri); timer.Checkpoint("Route entry retrieved."); var routeResult = await RouteEntryOption.Match( some : async routeEntry => { //Check authorization var routeContext = new RoutingContext(routeEntry, _routeRequest); var authorized = await RouteWorkflow.CheckRouteAuthorizationAsync( _logger, _routeAuthorizationManager, routeContext); timer.Checkpoint("Route auth checked."); if (!authorized) { return(new RouteResult(RouteResultStatusCode.Unauthorized)); } //Can deactivate current var canDeactivate = await RouteWorkflow.CanDeactivateCurrentRouteAsync( _logger, _routerService, ViewportOptions, Uri, InitData); timer.Checkpoint("CanDeactivate checked."); if (!canDeactivate) { return(new RouteResult(RouteResultStatusCode.CanDeactiveFailed)); } //Activate new route var canActivate = await RouteWorkflow.CanActivateNewRouteAsync(_logger); timer.Checkpoint("Activate checked."); if (!canActivate) { return(new RouteResult(RouteResultStatusCode.CanActivateFailed)); } //Get ViewModel Controller = RouteWorkflow.CreateViewModel(_logger, routeEntry); timer.Checkpoint("Viewmodel created"); await RouteWorkflow.InitViewModel(_logger, InitData, Controller); timer.Checkpoint("Viewmodel inited."); //Get View View = RouteWorkflow.CreateView(_logger, routeEntry); timer.Checkpoint("View created."); RouteWorkflow.AssignDataContext(_logger, View, Controller); //IViewAware context if (Controller is IViewAware viewAware) { RouteWorkflow.AssignViewToViewModel(_logger, View, viewAware); timer.Checkpoint("ViewModel is view aware, so view assigned to view model"); } //Add View to UI var routeResult = RouteWorkflow.AddViewToUi(_logger, _routerService, this, View); timer.Checkpoint("View added to UI.K"); return(routeResult); }, none : async() => new RouteResult(RouteResultStatusCode.RouteNotFound)); FinishedTime = DateTime.UtcNow; return(routeResult); } catch (Exception e) { _logger.Error(e, "Exception during RouteWorkflowTask.Go() method."); throw; } }