예제 #1
0
        public override async Task ProcessAsync(Auth0ResourceTemplate template)
        {
            using var managementClient = await _managementApiClientFactory.CreateAsync();

            var rule = _converter.Convert(template);

            //todo support proper pagination - how to do this where every api call is different?!
            var getRulesRequest = new GetRulesRequest
            {
                IncludeFields = true, Fields = "name,id"
            };
            var results = managementClient.Rules.GetAllAsync(getRulesRequest, Reporter);

            var matchingRule = await results.FirstOrDefaultAsync(x => string.Equals(x.Name, rule.Name));

            if (matchingRule == null)
            {
                var createRequest = Reflectorisor.CopyMembers <Rule, RuleCreateRequest>(rule);
                await Create(
                    async() => await managementClient.Rules.CreateAsync(createRequest),
                    request => request.Id,
                    rule.Name);
            }
            else
            {
                var updateRequest = Reflectorisor.CopyMembers <Rule, RuleUpdateRequest>(rule);
                await Update(
                    async() => await managementClient.Rules.UpdateAsync(matchingRule.Id, updateRequest),
                    matchingRule.Id,
                    rule.Name
                    );
            }
        }
예제 #2
0
파일: RuleController.cs 프로젝트: adkl/nsi
        /// <summary>
        /// Retrieves all rules from system
        /// </summary>
        /// <returns><see cref="IEnumerable{RuleDomain}"/></returns>
        public IHttpActionResult Get([FromUri] GetRulesRequest request)
        {
            UserDomain user = (UserDomain)ActionContext.Request.Properties["UserDetails"];

            return(Ok(new GetRulesResponse()
            {
                Data = _ruleManipulation.GetAllRules(user, request.FilterCriteria, request.Paging),
                Success = ResponseStatus.Succeeded,
                Paging = request.Paging
            }));
        }
        /// <summary>
        /// 获取转发规则列表
        /// </summary>
        /// <param name="req">参考<see cref="GetRulesRequest"/></param>
        /// <returns>参考<see cref="GetRulesResponse"/>实例</returns>
        public async Task <GetRulesResponse> GetRules(GetRulesRequest req)
        {
            JsonResponseModel <GetRulesResponse> rsp = null;

            try
            {
                var strResp = await this.InternalRequest(req, "GetRules");

                rsp = JsonConvert.DeserializeObject <JsonResponseModel <GetRulesResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
예제 #4
0
        /// <inheritdoc />
        public Task <IPagedList <Rule> > GetAllAsync(GetRulesRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(Connection.GetAsync <IPagedList <Rule> >("rules", null,
                                                            new Dictionary <string, string>
            {
                { "enabled", request.Enabled?.ToString().ToLower() },
                { "fields", request.Fields },
                { "include_fields", request.IncludeFields?.ToString().ToLower() },
                { "stage", request.Stage }
            }, null, new PagedListConverter <Rule>("rules")));
        }
예제 #5
0
        /// <summary>
        /// Retrieves a list of all rules.
        /// </summary>
        /// <param name="request">Specifies criteria to use when querying rules.</param>
        /// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
        /// <returns>An <see cref="IPagedList{Rule}"/> containing the rules requested.</returns>
        public Task <IPagedList <Rule> > GetAllAsync(GetRulesRequest request, PaginationInfo pagination)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (pagination == null)
            {
                throw new ArgumentNullException(nameof(pagination));
            }

            return(Connection.GetAsync <IPagedList <Rule> >(BuildUri("rules",
                                                                     new Dictionary <string, string>
            {
                { "enabled", request.Enabled?.ToString().ToLower() },
                { "fields", request.Fields },
                { "include_fields", request.IncludeFields?.ToString().ToLower() },
                { "stage", request.Stage },
                { "page", pagination.PageNo.ToString() },
                { "per_page", pagination.PerPage.ToString() },
                { "include_totals", pagination.IncludeTotals.ToString().ToLower() }
            }), DefaultHeaders, rulesConverters));
        }
예제 #6
0
        public async Task <List <Rule> > GetRulesAsync(GetRulesRequest request)
        {
            HttpClient client = CreateClient();

            var url = $"{_options.Value.ApiBaseAddress}/nzh/biz/withdrawRuleList?userId={request.UserId}" +
                      $"&offset=0&size=50";

            using (var httpRequest = new HttpRequestMessage(HttpMethod.Get, url))
            {
                httpRequest.Headers.Add("_token_", new List <string>()
                {
                    _options.Value.Token
                });
                httpRequest.Headers.Add("_token_issuer_", new List <string>()
                {
                    "1"
                });

                var httpResponse = await client.SendAsync(httpRequest);

                var body = await httpResponse.Content.ReadAsStringAsync();

                if (!httpResponse.IsSuccessStatusCode)
                {
                    throw new ApiException($"An error occurred: ${body}");
                }

                var result = JsonConvert.DeserializeObject <PodResult <List <Rule> > >(body);
                if (result.HasError)
                {
                    return(new List <Rule>());
                }

                return(result.Result);
            }
        }
 public static IAsyncEnumerable <Rule> GetAllAsync(this RulesClient client, GetRulesRequest request, IReporter reporter = null)
 {
     return(GetAllAsyncInternal(page => client.GetAllAsync(request, page), "rules", reporter));
 }
예제 #8
0
        public IHttpActionResult GetRules([FromUri] GetRulesRequest getRulesRequest)
        {
            var responses = new Responses();

            try
            {
                if (Utility.UserId < 0)
                {
                    return(BadRequest(Utility.INVALID_USER));
                }

                if (getRulesRequest == null)
                {
                    getRulesRequest = new GetRulesRequest();
                }

                if (getRulesRequest.PageSize == null)
                {
                    getRulesRequest.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["PageSize"]);
                }

                var rules = new Rules()
                {
                    RulesId          = getRulesRequest.RulesId,
                    SearchText       = getRulesRequest.SearchText,
                    IsActive         = getRulesRequest.IsActive,
                    PageNumber       = getRulesRequest.PageNumber,
                    PageSize         = Convert.ToInt32(getRulesRequest.PageSize),
                    IsPagingRequired = (getRulesRequest.PageNumber != null) ? true : false,
                    OrderBy          = getRulesRequest.OrderBy,
                    OrderByDirection = getRulesRequest.OrderByDirection
                };
                var ruless = iRules.GetRules(rules);

                var rulesList = new List <GetRulesResponse>();
                foreach (var rulesDetail in ruless)
                {
                    rulesList.Add(new GetRulesResponse()
                    {
                        RulesId         = rulesDetail.RulesId,
                        RulesName       = rulesDetail.RulesName,
                        RulesNo         = rulesDetail.RulesNo,
                        Year            = rulesDetail.Year,
                        PublicationDate = rulesDetail.PublicationDate,
                        IsActive        = Convert.ToBoolean(rulesDetail.IsActive),
                        CreatedBy       = rulesDetail.CreatedBy,
                        TotalPageCount  = rulesDetail.TotalPageCount,
                        TotalRecord     = rulesDetail.TotalRecord
                    });
                }

                responses.Status      = Utility.SUCCESS_STATUS_RESPONSE;
                responses.Description = "Rules retrieved successfully";
                responses.Response    = rulesList;
            }
            catch (Exception ex)
            {
                responses.Status      = Utility.ERROR_STATUS_RESPONSE;
                responses.Description = "Error while retrieving rules.";

                Utility.WriteLog("GetRules", getRulesRequest, "Error while retrieving rules. (RulesAdminController)", ex.ToString());
            }
            return(Ok(responses));
        }