protected async Task OnEdit(RoutesDto dto)
        {
            var option = new DialogOption()
            {
                Title       = "编辑路由",
                Size        = Size.ExtraLarge,
                BodyContext = dto
            };

            option.BodyTemplate = DynamicComponent.CreateComponent <RouteForm>(new KeyValuePair <string, object>[]
            {
                new KeyValuePair <string, object>(nameof(RouteForm.OnClose), new Action(async() => { await Table.QueryAsync(); option.Dialog?.Close(); }))
            }).Render();
            await DialogService.Show(option);
        }
예제 #2
0
        public async Task <ResultModel> GetRouteById(Guid id)
        {
            try
            {
                var route = await _userDatabaseContext.Routes.Where(x => x.Id == id)
                            .Include(x => x.AuthenticationOptions)
                            .Include(x => x.DownstreamHostAndPorts)
                            .Include(x => x.LoadBalancerOption)
                            .Include(x => x.UpstreamHttpMethods)
                            .FirstOrDefaultAsync();

                if (route == null)
                {
                    return(new ResultModel(ResultCode.Fail, "没有对应路由"));
                }
                var routeDto = new RoutesDto
                {
                    Id = route.Id,
                    DownstreamPathTemplate = route.DownstreamPathTemplate,
                    DownstreamScheme       = route.DownstreamScheme,
                    UpstreamPathTemplate   = route.UpstreamPathTemplate,
                    RouteIsCaseSensitive   = route.RouteIsCaseSensitive
                };

                if (route.LoadBalancerOption != null)
                {
                    routeDto.LoadBalancerOption = new LoadBalancerOptionDto
                    {
                        Id         = route.LoadBalancerOption.Id,
                        Type       = route.LoadBalancerOption.Type,
                        RoutesGuid = route.Id
                    };
                }

                if (route.AuthenticationOptions != null)
                {
                    routeDto.AuthenticationOptions = new AuthenticationOptionsDto
                    {
                        Id = route.AuthenticationOptions.Id,
                        AuthenticationProviderKey = route.AuthenticationOptions.AuthenticationProviderKey,
                        RoutesGuid = route.Id
                    };
                }

                route.DownstreamHostAndPorts.ForEach(x =>
                {
                    routeDto.DownstreamHostAndPorts.Add(new DownstreamHostAndPortsDto
                    {
                        Id         = x.Id,
                        Host       = x.Host,
                        Port       = x.Port,
                        RoutesGuid = x.RoutesGuid
                    });
                });

                route.UpstreamHttpMethods.ForEach(x =>
                {
                    routeDto.UpstreamHttpMethods.Add(new UpstreamHttpMethodsDto
                    {
                        Id         = x.Id,
                        Method     = x.Method,
                        RoutesGuid = x.RoutesGuid
                    });
                });
                return(new ResultModel(ResultCode.Success, routeDto));
            }
            catch (Exception ex)
            {
                return(new ResultModel(ResultCode.Fail, ex.Message));
            }
        }