private async Task GetConfig()
        {
            var configList = await OcelotService.GetAllConfig();

            if (configList.status.code == ResultCode.Success)
            {
                configList.custom.ForEach(x =>
                {
                    ConfigItems.Add(new SelectedItem
                    {
                        Text   = x.ConfigName,
                        Value  = x.Id.ToString(),
                        Active = x.IsEnable.Value
                    });
                });
            }
        }
        protected async Task <QueryData <RoutesDto> > OnQueryAsync(QueryPageOptions options)
        {
            var result = await OcelotService.GetRoutePageList(new RoutesQueryDto
            {
                CurrentPage    = options.PageIndex,
                PageSize       = options.PageItems,
                OcelotConfigId = SelectedConfigId,
            });

            if (result.status.code == ResultCode.Success)
            {
                return(new QueryData <RoutesDto>
                {
                    Items = result.custom.Data,
                    TotalCount = result.custom.TotalCount,
                    IsSorted = false,
                    IsFiltered = false
                });
            }
            return(null);
        }
        protected async Task <bool> OnDelete(IEnumerable <RoutesDto> dto)
        {
            var model = dto.FirstOrDefault();

            if (model != null)
            {
                var result = await OcelotService.DelteRoute(model.Id.Value);

                if (result.status.code == ResultCode.Success)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
        private async Task OnSave()
        {
            ResultModel <string> result = new ResultModel <string>();

            if (RoutesEditDto.Id == null)
            {
                RoutesEditDto.OcelotConfigGuid      = (param as RoutesDto).OcelotConfigGuid;
                RoutesEditDto.LoadBalancerOption    = LoadBalancerOptionEditDto;
                RoutesEditDto.AuthenticationOptions = AuthenticationOptionsEditDto;
                result = await OcelotService.CreateRoute(RoutesEditDto);
            }
            else
            {
                RoutesEditDto.OcelotConfigGuid      = (param as RoutesDto).OcelotConfigGuid;
                RoutesEditDto.LoadBalancerOption    = LoadBalancerOptionEditDto;
                RoutesEditDto.AuthenticationOptions = AuthenticationOptionsEditDto;
                result = await OcelotService.UpdateRoute(RoutesEditDto);
            }
            if (result.status.code == ResultCode.Success)
            {
                OnClose?.Invoke();
                await ToastService.Show(new ToastOption()
                {
                    Title   = "保存成功",
                    Content = "保存成功,4 秒后自动关闭"
                });
            }
            else
            {
                await ToastService.Show(new ToastOption()
                {
                    Title    = "保存失败",
                    Content  = $"保存失败,{result.status.text}",
                    Category = ToastCategory.Error
                });
            }
            await Task.CompletedTask;
        }
예제 #5
0
        protected override async Task OnInitializedAsync()
        {
            if (param != null)
            {
                var model = param as RoutesDto;
                if (model.Id != null)
                {
                    var result = await OcelotService.GetRouteById(model.Id.Value);

                    if (result.status.code == ResultCode.Success)
                    {
                        var routesDto = result.custom;
                        RoutesEditDto.Id = routesDto.Id;
                        RoutesEditDto.DownstreamPathTemplate = routesDto.DownstreamPathTemplate;
                        RoutesEditDto.UpstreamPathTemplate   = routesDto.UpstreamPathTemplate;
                        RoutesEditDto.RouteIsCaseSensitive   = routesDto.RouteIsCaseSensitive.Value;
                        RoutesEditDto.DownstreamScheme       = routesDto.DownstreamScheme;
                        LoadBalancerOptionEditDto            = new LoadBalancerOptionEditDto
                        {
                            Id         = routesDto.LoadBalancerOption.Id,
                            Type       = routesDto.LoadBalancerOption.Type,
                            RoutesGuid = routesDto.LoadBalancerOption.RoutesGuid
                        };
                        AuthenticationOptionsEditDto = new AuthenticationOptionsEditDto
                        {
                            Id = routesDto.AuthenticationOptions.Id,
                            AuthenticationProviderKey = routesDto.AuthenticationOptions.AuthenticationProviderKey,
                            RoutesGuid = routesDto.AuthenticationOptions.Id
                        };

                        routesDto.DownstreamHostAndPorts.ForEach(x =>
                        {
                            RoutesEditDto.DownstreamHostAndPorts.Add(new DownstreamHostAndPortsEditDto
                            {
                                Id         = x.Id,
                                Host       = x.Host,
                                Port       = x.Port,
                                RoutesGuid = x.RoutesGuid
                            });
                        });

                        routesDto.UpstreamHttpMethods.ForEach(x =>
                        {
                            RoutesEditDto.UpstreamHttpMethods.Add(new UpstreamHttpMethodsEditDto
                            {
                                Id         = x.Id,
                                Method     = x.Method,
                                RoutesGuid = x.RoutesGuid
                            });
                        });
                    }
                    else
                    {
                        await ToastService.Show(new ToastOption()
                        {
                            Title    = "获取数据失败",
                            Content  = $"获取数据失败,{result.status.text}",
                            Category = ToastCategory.Error
                        });
                    }
                }
            }
            await base.OnInitializedAsync();
        }