Exemplo n.º 1
0
        public static string GenerateJsFuncParameterList(ActionApiDescriptionModel action, string ajaxParametersName)
        {
            var methodParamNames = action.Parameters.Select(p => p.NameOnMethod).Distinct().ToList();

            methodParamNames.Add(ajaxParametersName);
            return(methodParamNames.Select(prmName => NormalizeJsVariableName(prmName.ToCamelCase())).JoinAsString(", "));
        }
Exemplo n.º 2
0
        private void AddApiDescriptionToModel(ApiDescription apiDescription, ApplicationApiDescriptionModel model)
        {
            var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType();
            var setting        = FindSetting(controllerType);

            var moduleModel = model.GetOrAddModule(GetRootPath(controllerType, setting));

            var controllerModel = moduleModel.GetOrAddController(controllerType.FullName, CalculateControllerName(controllerType, setting), controllerType, _modelOptions.IgnoredInterfaces);

            var method = apiDescription.ActionDescriptor.GetMethodInfo();

            var uniqueMethodName = GetUniqueActionName(method);

            if (controllerModel.Actions.ContainsKey(uniqueMethodName))
            {
                Logger.LogWarning($"Controller '{controllerModel.ControllerName}' contains more than one action with name '{uniqueMethodName}' for module '{moduleModel.RootPath}'. Ignored: " + method);
                return;
            }

            Logger.LogDebug($"ActionApiDescriptionModel.Create: {controllerModel.ControllerName}.{uniqueMethodName}");
            var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create(
                                                            uniqueMethodName,
                                                            method,
                                                            apiDescription.RelativePath,
                                                            apiDescription.HttpMethod,
                                                            GetSupportedVersions(controllerType, method, setting)
                                                            ));

            AddParameterDescriptionsToModel(actionModel, method, apiDescription);
        }
        private void AddParameterDescriptionsToModel(ActionApiDescriptionModel actionModel, MethodInfo method, ApiDescription apiDescription)
        {
            if (!apiDescription.ParameterDescriptions.Any())
            {
                return;
            }

            var matchedMethodParamNames = ArrayMatcher.Match(
                apiDescription.ParameterDescriptions.Select(p => p.Name).ToArray(),
                method.GetParameters().Select(GetMethodParamName).ToArray()
                );

            for (var i = 0; i < apiDescription.ParameterDescriptions.Count; i++)
            {
                var parameterDescription   = apiDescription.ParameterDescriptions[i];
                var matchedMethodParamName = matchedMethodParamNames.Length > i ?
                                             matchedMethodParamNames[i] :
                                             parameterDescription.Name;

                actionModel.AddParameter(ParameterApiDescriptionModel.Create(
                                             parameterDescription.Name,
                                             matchedMethodParamName,
                                             parameterDescription.Type,
                                             parameterDescription.RouteInfo?.IsOptional ?? false,
                                             parameterDescription.RouteInfo?.DefaultValue,
                                             parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(),
                                             parameterDescription.Source.Id,
                                             parameterDescription.ModelMetadata?.ContainerType != null ?
                                             parameterDescription.ParameterDescriptor?.Name ?? string.Empty :
                                             string.Empty
                                             ));
            }
        }
Exemplo n.º 4
0
        private static HttpContent GenerateFormPostData(ActionApiDescriptionModel action, IReadOnlyDictionary <string, object> methodArguments)
        {
            var parameters = action
                             .Parameters
                             .Where(p => p.BindingSourceId == ParameterBindingSources.Form)
                             .ToArray();

            if (!parameters.Any())
            {
                return(null);
            }

            var postDataBuilder = new StringBuilder();

            var isFirstParam = true;

            foreach (var queryStringParameter in parameters)
            {
                var value = HttpActionParameterHelper.FindParameterValue(methodArguments, queryStringParameter);
                if (value == null)
                {
                    continue;
                }

                postDataBuilder.Append(isFirstParam ? "?" : "&");
                postDataBuilder.Append(queryStringParameter.Name + "=" + System.Net.WebUtility.UrlEncode(value.ToString()));

                isFirstParam = false;
            }

            return(new StringContent(postDataBuilder.ToString(), Encoding.UTF8, MimeTypes.Application.XWwwFormUrlencoded));
        }
    protected virtual Task <HttpContent> GenerateBodyAsync(ActionApiDescriptionModel action, IReadOnlyDictionary <string, object> methodArguments, IJsonSerializer jsonSerializer)
    {
        var parameters = action
                         .Parameters
                         .Where(p => p.BindingSourceId == ParameterBindingSources.Body)
                         .ToArray();

        if (parameters.Length <= 0)
        {
            return(Task.FromResult <HttpContent>(null));
        }

        if (parameters.Length > 1)
        {
            throw new AbpException(
                      $"Only one complex type allowed as argument to a controller action that's binding source is 'Body'. But action on URL: {action.Url} contains more than one!"
                      );
        }

        var value = HttpActionParameterHelper.FindParameterValue(methodArguments, parameters[0]);

        if (value == null)
        {
            return(Task.FromResult <HttpContent>(null));
        }

        return(Task.FromResult <HttpContent>(new StringContent(jsonSerializer.Serialize(value), Encoding.UTF8, MimeTypes.Application.Json)));
    }
        private static string GenerateBody(ActionApiDescriptionModel action, IReadOnlyDictionary <string, object> methodArguments, IJsonSerializer jsonSerializer)
        {
            var parameters = action
                             .Parameters
                             .Where(p => p.BindingSourceId == ParameterBindingSources.Body)
                             .ToArray();

            if (parameters.Length <= 0)
            {
                return(null);
            }

            if (parameters.Length > 1)
            {
                throw new AbpException(
                          $"Only one complex type allowed as argument to a controller action that's binding source is 'Body'. But action on URL: {action.Url} contains more than one!"
                          );
            }

            var value = HttpActionParameterHelper.FindParameterValue(methodArguments, parameters[0]);

            if (value == null)
            {
                return(null);
            }

            return(jsonSerializer.Serialize(value));
        }
Exemplo n.º 7
0
    private static void AddActionScript(StringBuilder script, string controllerName, ActionApiDescriptionModel action, string normalizedActionName)
    {
        var parameterList = ProxyScriptingJsFuncHelper.GenerateJsFuncParameterList(action, "ajaxParams");

        script.AppendLine($"    {controllerName}{ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(normalizedActionName.RemovePostFix("Async").ToCamelCase())} = function({parameterList}) {{");

        var versionParam = action.Parameters.FirstOrDefault(p => p.Name == "apiVersion" && p.BindingSourceId == ParameterBindingSources.Path) ??
                           action.Parameters.FirstOrDefault(p => p.Name == "api-version" && p.BindingSourceId == ParameterBindingSources.Query);

        if (versionParam != null)
        {
            var version = FindBestApiVersion(action);
            script.AppendLine($"      var {ProxyScriptingJsFuncHelper.NormalizeJsVariableName(versionParam.Name)} = '{version}';");
        }

        script.AppendLine("      return abp.ajax($.extend(true, {");

        AddAjaxCallParameters(script, action);

        var ajaxParamsIsFromForm = action.Parameters.Any(x => x.BindingSourceId == ParameterBindingSources.Form);
        var dataType             = action.ReturnValue.Type == ReturnValueApiDescriptionModel.Create(typeof(string)).Type
            ? "{ dataType: 'text' }, "
            : string.Empty;

        script.AppendLine(ajaxParamsIsFromForm
            ? "      }, $.extend(true, {}, " + dataType + "{ contentType: 'application/x-www-form-urlencoded; charset=UTF-8' }, ajaxParams)));"
            : "      }, " + dataType + "ajaxParams));");

        script.AppendLine("    };");
    }
Exemplo n.º 8
0
        protected virtual void AddHeaders(IAbpMethodInvocation invocation, ActionApiDescriptionModel action, HttpRequestMessage requestMessage, ApiVersionInfo apiVersion)
        {
            //API Version
            if (!apiVersion.Version.IsNullOrEmpty())
            {
                //TODO: What about other media types?
                requestMessage.Headers.Add("accept", $"{MimeTypes.Text.Plain}; v={apiVersion.Version}");
                requestMessage.Headers.Add("accept", $"{MimeTypes.Application.Json}; v={apiVersion.Version}");
                requestMessage.Headers.Add("api-version", apiVersion.Version);
            }

            //Header parameters
            var headers = action.Parameters.Where(p => p.BindingSourceId == ParameterBindingSources.Header).ToArray();

            foreach (var headerParameter in headers)
            {
                var value = HttpActionParameterHelper.FindParameterValue(invocation.ArgumentsDictionary, headerParameter);
                if (value != null)
                {
                    requestMessage.Headers.Add(headerParameter.Name, value.ToString());
                }
            }

            //CorrelationId
            requestMessage.Headers.Add(CorrelationIdOptions.HttpHeaderName, CorrelationIdProvider.Get());
        }
Exemplo n.º 9
0
        private void AddApiDescriptionToModel(ApiDescription apiDescription, ApplicationApiDescriptionModel model)
        {
            var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType();
            var setting        = FindSetting(controllerType);

            var moduleModel = model.GetOrAddModule(GetRootPath(controllerType, setting));

            var controllerModel = moduleModel.GetOrAddController(controllerType.FullName, CalculateControllerName(controllerType, setting), controllerType, _modelOptions.IgnoredInterfaces);

            var method = apiDescription.ActionDescriptor.GetMethodInfo();

            var uniqueMethodName = GetUniqueActionName(method);

            if (controllerModel.Actions.ContainsKey(uniqueMethodName))
            {
                Logger.LogWarning($"Controller '{controllerModel.ControllerName}' contains more than one action with name '{uniqueMethodName}' for module '{moduleModel.RootPath}'. Ignored: " + method);
                return;
            }

            var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create(
                                                            uniqueMethodName,
                                                            method,
                                                            apiDescription.RelativePath,
                                                            apiDescription.HttpMethod,
                                                            setting?.ApiVersions.Select(v => v.ToString()).ToList() ?? new List <string>() //TODO: Also get from ApiVersion attributes if available..?
                                                            ));

            AddParameterDescriptionsToModel(actionModel, method, apiDescription);
        }
Exemplo n.º 10
0
        public static string GenerateUrlWithParameters(ActionApiDescriptionModel action)
        {
            //TODO: Can be optimized using StringBuilder?
            var url = ReplacePathVariables(action.Url, action.Parameters);

            url = AddQueryStringParameters(url, action.Parameters);
            return(url);
        }
Exemplo n.º 11
0
        public static string GenerateUrlWithParameters(ActionApiDescriptionModel action, IReadOnlyDictionary <string, object> methodArguments, ApiVersionInfo apiVersion)
        {
            var urlBuilder = new StringBuilder(action.Url);

            ReplacePathVariables(urlBuilder, action.Parameters, methodArguments, apiVersion);
            AddQueryStringParameters(urlBuilder, action.Parameters, methodArguments, apiVersion);

            return(urlBuilder.ToString());
        }
        private void AddApiDescriptionToModel(
            ApiDescription apiDescription,
            ApplicationApiDescriptionModel applicationModel,
            ApplicationApiDescriptionModelRequestDto input)
        {
            var controllerType = apiDescription
                                 .ActionDescriptor
                                 .AsControllerActionDescriptor()
                                 .ControllerTypeInfo;

            var setting = FindSetting(controllerType);

            var moduleModel = applicationModel.GetOrAddModule(
                GetRootPath(controllerType, setting),
                GetRemoteServiceName(controllerType, setting)
                );

            var controllerModel = moduleModel.GetOrAddController(
                controllerType.FullName,
                _options.ControllerNameGenerator(controllerType, setting),
                controllerType,
                _modelOptions.IgnoredInterfaces
                );

            var method = apiDescription.ActionDescriptor.GetMethodInfo();

            var uniqueMethodName = _options.ActionNameGenerator(method);

            if (controllerModel.Actions.ContainsKey(uniqueMethodName))
            {
                Logger.LogWarning(
                    $"Controller '{controllerModel.ControllerName}' contains more than one action with name '{uniqueMethodName}' for module '{moduleModel.RootPath}'. Ignored: " +
                    method);
                return;
            }

            Logger.LogDebug($"ActionApiDescriptionModel.Create: {controllerModel.ControllerName}.{uniqueMethodName}");

            var actionModel = controllerModel.AddAction(
                uniqueMethodName,
                ActionApiDescriptionModel.Create(
                    uniqueMethodName,
                    method,
                    apiDescription.RelativePath,
                    apiDescription.HttpMethod,
                    GetSupportedVersions(controllerType, method, setting)
                    )
                );

            if (input.IncludeTypes)
            {
                AddCustomTypesToModel(applicationModel, method);
            }

            AddParameterDescriptionsToModel(actionModel, method, apiDescription);
        }
Exemplo n.º 13
0
        public static string GenerateJsFuncParameterList(ActionApiDescriptionModel action, string ajaxParametersName)
        {
            var paramsIsFromForm = action.Parameters.Any(x => x.BindingSourceId == ParameterBindingSources.Form);
            var methodParamNames = paramsIsFromForm
                ? action.Parameters.Select(p => p.DescriptorName + p.Name).Distinct().ToList()
                : action.ParametersOnMethod.Select(p => p.Name).Distinct().ToList();

            methodParamNames.Add(ajaxParametersName);
            return(methodParamNames.Select(prmName => NormalizeJsVariableName(prmName.ToCamelCase())).JoinAsString(", "));
        }
Exemplo n.º 14
0
        private ApiVersionInfo GetApiVersionInfo(ActionApiDescriptionModel action)
        {
            var apiVersion = FindBestApiVersion(action);

            //TODO: Make names configurable?
            var versionParam = action.Parameters.FirstOrDefault(p => p.Name == "apiVersion" && p.BindingSourceId == ParameterBindingSources.Path) ??
                               action.Parameters.FirstOrDefault(p => p.Name == "api-version" && p.BindingSourceId == ParameterBindingSources.Query);

            return(new ApiVersionInfo(versionParam?.BindingSourceId, apiVersion));
        }
Exemplo n.º 15
0
 public ClientProxyRequestContext(
     [NotNull] ActionApiDescriptionModel action,
     [NotNull] IReadOnlyDictionary <string, object> arguments,
     [NotNull] Type serviceType)
 {
     ServiceType = serviceType;
     Action      = Check.NotNull(action, nameof(action));
     Arguments   = Check.NotNull(arguments, nameof(arguments));
     ServiceType = Check.NotNull(serviceType, nameof(serviceType));
 }
Exemplo n.º 16
0
    public ActionApiDescriptionModel AddAction(string uniqueName, ActionApiDescriptionModel action)
    {
        if (Actions.ContainsKey(uniqueName))
        {
            throw new AbpException(
                      $"Can not add more than one action with same name to the same controller. Controller: {ControllerName}, Action: {action.Name}."
                      );
        }

        return(Actions[uniqueName] = action);
    }
Exemplo n.º 17
0
 public static string GenerateUrlWithParameters(ActionApiDescriptionModel action)
 {
     // The ASP.NET Core route value provider and query string value provider:
     //  Treat values as invariant culture.
     //  Expect that URLs are culture-invariant.
     using (CultureHelper.Use(CultureInfo.InvariantCulture))
     {
         //TODO: Can be optimized using StringBuilder?
         var url = ReplacePathVariables(action.Url, action.Parameters);
         url = AddQueryStringParameters(url, action.Parameters);
         return(url);
     }
 }
Exemplo n.º 18
0
    public virtual async Task <HttpContent> BuildContentAsync(ActionApiDescriptionModel action, IReadOnlyDictionary <string, object> methodArguments, IJsonSerializer jsonSerializer, ApiVersionInfo apiVersion)
    {
        var body = await GenerateBodyAsync(action, methodArguments, jsonSerializer);

        if (body != null)
        {
            return(body);
        }

        body = await GenerateFormPostDataAsync(action, methodArguments);

        return(body);
    }
Exemplo n.º 19
0
    public Task <string> ConvertAsync(ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, int value)
    {
        if (actionApiDescription.Name == nameof(IRegularTestController.GetObjectandCountAsync))
        {
            if (value <= 0)
            {
                value = 888;
            }
            return(Task.FromResult(value.ToString()));
        }

        return(Task.FromResult <string>(null));
    }
Exemplo n.º 20
0
        public static HttpContent BuildContent(ActionApiDescriptionModel action, IReadOnlyDictionary <string, object> methodArguments, IJsonSerializer jsonSerializer, ApiVersionInfo apiVersion)
        {
            var body = GenerateBody(action, methodArguments, jsonSerializer);

            if (body != null)
            {
                return(body);
            }

            body = GenerateFormPostData(action, methodArguments);

            return(body);
        }
Exemplo n.º 21
0
        public static string GenerateFormPostData(ActionApiDescriptionModel action, int indent = 0)
        {
            var parameters = action
                             .Parameters
                             .Where(p => p.BindingSourceId == ParameterBindingSources.Form)
                             .ToArray();

            if (!parameters.Any())
            {
                return(null);
            }

            return(ProxyScriptingJsFuncHelper.CreateJsObjectLiteral(parameters, indent));
        }
Exemplo n.º 22
0
        private void AddParameterDescriptionsToModel(ActionApiDescriptionModel actionModel, MethodInfo method, ApiDescription apiDescription)
        {
            if (!apiDescription.ParameterDescriptions.Any())
            {
                return;
            }

            var paramInfos = method.GetParameters();

            foreach (var p in paramInfos)
            {
                var name = GetMethodParamName(p);
                actionModel.AddParameter(new ParameterApiDescriptionModel(
                                             name,
                                             name,
                                             p.ParameterType,
                                             p.IsOptional,
                                             p.DefaultValue,
                                             null,
                                             null
                                             )
                                         );
            }

            /*
             * //var matchedMethodParamNames = ArrayMatcher.Match(
             * //    apiDescription.ParameterDescriptions.Select(p => p.Name).ToArray(),
             * //    method.GetParameters().Select(GetMethodParamName).ToArray()
             * //);
             *
             * for (var i = 0; i < apiDescription.ParameterDescriptions.Count; i++)
             * {
             *  var parameterDescription = apiDescription.ParameterDescriptions[i];
             *  //var matchedMethodParamName = matchedMethodParamNames.Length > i
             *  //                                 ? matchedMethodParamNames[i]
             *  //                                 : parameterDescription.Name;
             *
             *  actionModel.AddParameter(new ParameterApiDescriptionModel(
             *          parameterDescription.Name,
             *          "",//matchedMethodParamName,
             *          parameterDescription.Type,
             *          parameterDescription.RouteInfo?.IsOptional ?? false,
             *          parameterDescription.RouteInfo?.DefaultValue,
             *          parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(),
             *          parameterDescription.Source.Id
             *      )
             *  );
             * }
             */
        }
Exemplo n.º 23
0
        public static string GenerateUrlWithParameters(ActionApiDescriptionModel action, IReadOnlyDictionary <string, object> methodArguments, ApiVersionInfo apiVersion)
        {
            // The ASP.NET Core route value provider and query string value provider:
            //  Treat values as invariant culture.
            //  Expect that URLs are culture-invariant.
            using (CultureHelper.Use(CultureInfo.InvariantCulture))
            {
                var urlBuilder = new StringBuilder(action.Url);

                ReplacePathVariables(urlBuilder, action.Parameters, methodArguments, apiVersion);
                AddQueryStringParameters(urlBuilder, action.Parameters, methodArguments, apiVersion);

                return(urlBuilder.ToString());
            }
        }
Exemplo n.º 24
0
        private string FindBestApiVersion(ActionApiDescriptionModel action)
        {
            var configuredVersion = GetConfiguredApiVersion();

            if (action.SupportedVersions.IsNullOrEmpty())
            {
                return(configuredVersion ?? "1.0");
            }

            if (action.SupportedVersions.Contains(configuredVersion))
            {
                return(configuredVersion);
            }

            return(action.SupportedVersions.Last()); //TODO: Ensure to get the latest version!
        }
Exemplo n.º 25
0
    public Task <List <KeyValuePair <string, HttpContent> > > ConvertAsync(ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, List <GetParamsNameValue> values)
    {
        if (values.IsNullOrEmpty())
        {
            return(null);
        }

        var formDataContents = new List <KeyValuePair <string, HttpContent> >();

        for (var i = 0; i < values.Count; i++)
        {
            formDataContents.Add(new KeyValuePair <string, HttpContent>($"NameValues[{i}].Name", new StringContent(values[i].Name, Encoding.UTF8)));
            formDataContents.Add(new KeyValuePair <string, HttpContent>($"NameValues[{i}].Value", new StringContent(values[i].Value, Encoding.UTF8)));
        }

        return(Task.FromResult(formDataContents));
    }
Exemplo n.º 26
0
        public static HttpContent BuildContent(ActionApiDescriptionModel action, IReadOnlyDictionary <string, object> methodArguments, IJsonSerializer jsonSerializer, ApiVersionInfo apiVersion)
        {
            var body = GenerateBody(action, methodArguments, jsonSerializer);

            if (body != null)
            {
                return(new StringContent(body, Encoding.UTF8, "application/json")); //TODO: application/json to a constant
            }

            body = GenerateFormPostData(action, methodArguments);
            if (body != null)
            {
                return(new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded")); //TODO: application/x-www-form-urlencoded to a constant
            }

            return(null);
        }
Exemplo n.º 27
0
        public static HttpContent BuildContent(ActionApiDescriptionModel action, IReadOnlyDictionary <string, object> methodArguments, IJsonSerializer jsonSerializer, ApiVersionInfo apiVersion)
        {
            var body = GenerateBody(action, methodArguments, jsonSerializer);

            if (body != null)
            {
                return(new StringContent(body, Encoding.UTF8, MimeTypes.Application.Json));
            }

            body = GenerateFormPostData(action, methodArguments);
            if (body != null)
            {
                return(new StringContent(body, Encoding.UTF8, MimeTypes.Application.XWwwFormUrlencoded));
            }

            return(null);
        }
Exemplo n.º 28
0
    public Task <string> ConvertAsync(ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, List <GetParamsNameValue> values)
    {
        if (values.IsNullOrEmpty())
        {
            return(null);
        }

        var sb = new StringBuilder();

        for (var i = 0; i < values.Count; i++)
        {
            sb.Append($"NameValues[{i}].Name={values[i].Name}&NameValues[{i}].Value={values[i].Value}&");
        }

        sb.Remove(sb.Length - 1, 1);
        return(Task.FromResult(sb.ToString()));
    }
Exemplo n.º 29
0
        protected virtual void AddHeaders(IAbpMethodInvocation invocation, ActionApiDescriptionModel action, HttpRequestMessage requestMessage, ApiVersionInfo apiVersion)
        {
            //API Version
            if (!apiVersion.Version.IsNullOrEmpty())
            {
                //TODO: What about other media types?
                requestMessage.Headers.Add("accept", $"{MimeTypes.Text.Plain}; v={apiVersion.Version}");
                requestMessage.Headers.Add("accept", $"{MimeTypes.Application.Json}; v={apiVersion.Version}");
                requestMessage.Headers.Add("api-version", apiVersion.Version);
            }

            //Header parameters
            var headers = action.Parameters.Where(p => p.BindingSourceId == ParameterBindingSources.Header).ToArray();

            foreach (var headerParameter in headers)
            {
                var value = HttpActionParameterHelper.FindParameterValue(invocation.ArgumentsDictionary, headerParameter);
                if (value != null)
                {
                    requestMessage.Headers.Add(headerParameter.Name, value.ToString());
                }
            }

            //CorrelationId
            requestMessage.Headers.Add(AbpCorrelationIdOptions.HttpHeaderName, CorrelationIdProvider.Get());

            //TenantId
            if (CurrentTenant.Id.HasValue)
            {
                //TODO: Use AbpAspNetCoreMultiTenancyOptions to get the key
                requestMessage.Headers.Add(TenantResolverConsts.DefaultTenantKey, CurrentTenant.Id.Value.ToString());
            }

            //Culture
            //TODO: Is that the way we want? Couldn't send the culture (not ui culture)
            var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name;

            if (!currentCulture.IsNullOrEmpty())
            {
                requestMessage.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(currentCulture));
            }

            //X-Requested-With
            requestMessage.Headers.Add("X-Requested-With", "XMLHttpRequest");
        }
Exemplo n.º 30
0
        public static string GenerateBody(ActionApiDescriptionModel action)
        {
            var parameters = action
                             .Parameters
                             .Where(p => p.BindingSourceId == ParameterBindingSources.Body)
                             .ToArray();

            if (parameters.Length <= 0)
            {
                return(null);
            }

            if (parameters.Length > 1)
            {
                throw new AbpException(
                          $"Only one complex type allowed as argument to a controller action that's binding source is 'Body'. But {action.Name} ({action.Url}) contains more than one!"
                          );
            }

            return(ProxyScriptingJsFuncHelper.GetParamNameInJsFunc(parameters[0]));
        }