示例#1
0
 private void ExtractHeaders(HttpRequestMessage httpClient)
 {
     if (Headers == null || !Headers.Any())
     {
         return;
     }
     try
     {
         foreach (var header in Headers)
         {
             if (header.Key == "Content-Type" && httpClient.Content != null)
             {
                 // 如果时上传文件则不自动设置
                 if (httpClient.Content is HttpMultipartFormDataContent)
                 {
                     continue;
                 }
                 httpClient.Content.Headers.ContentType = new HttpMediaTypeHeaderValue(header.Value);
             }
             else
             {
                 httpClient.Headers.TryAppendWithoutValidation(header.Key, header.Value);
             }
         }
     }
     catch (ArgumentException ex)
     {
         Log.Info(ex.Message);
     }
 }
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine("{");

            if (Args?.Any() ?? false)
            {
                sb
                .AppendLine("Args: {")
                .AppendLine(DictToString(Args))
                .AppendLine("}");
            }

            if (Headers?.Any() ?? false)
            {
                sb
                .AppendLine("Headers: {")
                .AppendLine(DictToString(Headers))
                .AppendLine("}");
            }

            if (Url != null)
            {
                sb.AppendLine($"\tUrl: {Url}");
            }

            sb.AppendLine("}");

            return(sb.ToString());
        }
示例#3
0
        /// <summary>
        ///     Validates the properties of this instance, and returns a list of validation errors.
        /// </summary>
        /// <returns>The list with validation errors, or an empty list, when this instance is valid.</returns>
        public IEnumerable <ValidationError> GetValidationErrors()
        {
            var errors = new List <ValidationError>();

            if (KeyId == KeyId.Empty)
            {
                errors.Add(new ValidationError(nameof(KeyId), $"The signing settings do not specify a valid {nameof(KeyId)}."));
            }
            if (SignatureAlgorithm == null)
            {
                errors.Add(new ValidationError(nameof(SignatureAlgorithm), $"The signing settings do not specify a valid {nameof(SignatureAlgorithm)}."));
            }
            if (SignatureAlgorithm != null && !SupportedSignatureAlgorithmNames.Contains(SignatureAlgorithm.Name, StringComparer.OrdinalIgnoreCase))
            {
                errors.Add(new ValidationError(nameof(SignatureAlgorithm), $"The specified signature algorithm ({SignatureAlgorithm.Name}) is not supported."));
            }
            if (Expires <= TimeSpan.Zero)
            {
                errors.Add(new ValidationError(nameof(Expires), $"The signing settings do not specify a valid value for {nameof(Expires)}."));
            }
            if (string.IsNullOrEmpty(AuthorizationScheme))
            {
                errors.Add(new ValidationError(nameof(AuthorizationScheme), $"The signing settings do not specify a valid value for {nameof(AuthorizationScheme)}."));
            }
            if (Headers == null)
            {
                errors.Add(new ValidationError(nameof(Headers), $"{nameof(Headers)} cannot be unspecified (null)."));
            }
            if (Headers != null && !Headers.Any())
            {
                errors.Add(new ValidationError(nameof(Headers), $"{nameof(Headers)} cannot be unspecified empty."));
            }
            return(errors);
        }
        /// <summary>
        /// Write the report to the provided stream.
        /// </summary>
        /// <param name="stream">The stream to which to write.</param>
        /// <returns>A task representing the asyncronous operation.</returns>
        public override async Task SaveAsync(Stream stream)
        {
            if (stream?.CanWrite ?? false)
            {
                if (Headers.Any())
                {
                    await WriteLineToStreamAsync(stream, string.Join(Configuration.Delimiter, Headers)).ConfigureAwait(false);
                }

                foreach (IDictionary <string, string> line in Lines)
                {
                    List <string> lineItems = new();

                    foreach (var header in Headers)
                    {
                        if (line.ContainsKey(header))
                        {
                            lineItems.Add(line[header]);
                        }
                        else
                        {
                            lineItems.Add(string.Empty);
                        }
                    }
                    await WriteLineToStreamAsync(stream, string.Join(Configuration.Delimiter, lineItems)).ConfigureAwait(false);
                }

                await stream.FlushAsync().ConfigureAwait(false);
            }
        }
示例#5
0
        public override async Task SetParametersAsync(ParameterView parameters)
        {
            await base.SetParametersAsync(parameters);

            if (parameters.GetValueOrDefault <object>(nameof(DataSource)) != null)
            {
                rows     = (DataSource as IEnumerable).Cast <object>().ToList();
                DataType = DataSource.GetType().GetGenericArguments()[0];
                if (AutoGenerateColumns && !headerInitilized)
                {
                    headerInitilized = true;
                    DataType.GetProperties().Where(p => !IgnoreProperties.Contains(p.Name)).Reverse().ToList().ForEach(property =>
                    {
                        if (Headers.Any(x => x.Property?.Name == property.Name))
                        {
                            return;
                        }
                        var attrs        = property.GetCustomAttributes(true);
                        var columnConfig = attrs.OfType <TableColumnAttribute>().FirstOrDefault() ?? new TableColumnAttribute()
                        {
                            Text = property.Name
                        };

                        Headers.Insert(0, new TableHeader()
                        {
                            Eval = row =>
                            {
                                var value = property.GetValue(row);
                                if (string.IsNullOrWhiteSpace(columnConfig.Format))
                                {
                                    return(value);
                                }
                                if (value == null)
                                {
                                    return(null);
                                }

                                try
                                {
                                    return(Convert.ToDateTime(value).ToString(columnConfig.Format));
                                }
                                catch (InvalidCastException)
                                {
                                    throw new BlazuiException("仅日期列支持 Format 参数");
                                }
                            },
                            IsCheckBox = property.PropertyType == typeof(bool) || Nullable.GetUnderlyingType(property.PropertyType) == typeof(bool),
                            Property   = property,
                            Text       = columnConfig.Text,
                            Width      = columnConfig.Width
                        });
                    }
                                                                                                                       );
                }
                SelectedRows = new HashSet <object>();
                chkAll?.MarkAsRequireRender();
                ResetSelectAllStatus();
            }
        }
示例#6
0
        public HttpRequestMessage BuildHttpRequestMessage(HttpHandlerOptions httpHandlerOptions, HttpMethod httpMethod, object?content)
        {
            var requestUri = !PathSegments.Any()
                ? httpHandlerOptions.RequestUri
                : new Uri(httpHandlerOptions.RequestUri, String.Join('/', PathSegments));



            if (QueryParameters.Any())
            {
                var qb = new QueryBuilder();
                if (!String.IsNullOrWhiteSpace(requestUri.Query))
                {
                    var query = QueryHelpers.ParseQuery(requestUri.Query);
                    foreach (var kv in query)
                    {
                        qb.Add(kv.Key, kv.Value.ToArray());
                    }
                }
                foreach (var kv in QueryParameters)
                {
                    qb.Add(kv.Key, kv.Value.ToArray());
                }

                var uriBuilder = new UriBuilder(requestUri);
                uriBuilder.Query = qb.ToQueryString().ToString();

                requestUri = uriBuilder.Uri;
            }



            var message = new HttpRequestMessage(httpMethod, requestUri);

            if (content != null)
            {
                message.Content = CreateHttpContent(content);
            }

            if (Headers.Any())
            {
                foreach (var kv in Headers)
                {
                    if (message.Headers.Contains(kv.Key))
                    {
                        message.Headers.Remove(kv.Key);
                    }
                    message.Headers.Add(kv.Key, kv.Value);
                }
            }


            if (!String.IsNullOrWhiteSpace(ContentType) && message.Content != null)
            {
                message.Content.Headers.ContentType = new MediaTypeHeaderValue(ContentType);
            }

            return(message);
        }
示例#7
0
        public override string ToString()
        {
            var r = Request;
            var h = Headers.Any() ? $"\r\n{string.Join("\r\n", Headers)}" : "";
            var b = string.IsNullOrWhiteSpace(Body) ? "" : $"\r\n{Body}";

            return(r + h + b);
        }
示例#8
0
 internal void SetEmptyValuesToNull()
 {
     Headers = Headers.Any() ? Headers : null;
     if (MatchingRules != null)
     {
         MatchingRules.SetEmptyValuesToNull();
     }
 }
示例#9
0
        public string MakeRequest(string parameters)
        {
            var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);

            request.Method        = Method.ToString();
            request.ContentLength = 0;
            request.ContentType   = ContentType;
            request.KeepAlive     = false;
            request.Timeout       = System.Threading.Timeout.Infinite;

            if (UserName != null && Password != null)
            {
                SetBasicAuth(request, UserName, Password);
            }

            if (Headers != null && Headers.Any())
            {
                foreach (var h in Headers)
                {
                    request.Headers.Add(h.Key, h.Value);
                }
            }

            if (!string.IsNullOrEmpty(PostData) && Method == HttpVerb.POST)
            {
                var encoding = new UTF8Encoding();
                var bytes    = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);
                request.ContentLength = bytes.Length;

                using (var writeStream = request.GetRequestStream())
                {
                    writeStream.Write(bytes, 0, bytes.Length);
                }
            }

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                var responseValue = string.Empty;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
                    throw new ApplicationException(message);
                }

                using (var responseStream = response.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (var reader = new StreamReader(responseStream))
                        {
                            responseValue = reader.ReadToEnd();
                        }
                    }
                }
                return(responseValue);
            }
        }
 /// <summary>
 /// Add a header required for making the request
 /// </summary>
 /// <param name="key">key or name of the header</param>
 /// <param name="value">value of the header</param>
 /// <returns></returns>
 public virtual TestApiRequest AddHeader(string key, string value)
 {
     if (Headers.Any(tHead => tHead.Key.EqualsIgnoreCase(key)))
     {
         Headers.Remove(Headers.First(tHead => tHead.Key.EqualsIgnoreCase(key)));
     }
     Headers.Add(new TestApiHeader(key, value));
     return(this);
 }
示例#11
0
 public bool TryGetHeaderField <T>(string name, out T field) where T : HeaderField
 {
     if (Headers.Any(x => x.Name.ToLower() == name.ToLower()))
     {
         field = GetHeaderField <T>(name);
         return(true);
     }
     field = null;
     return(false);
 }
示例#12
0
        public override string ToString()
        {
            var httpMethodText = HttpMethod?.ToString() ?? NoValue;

            var headers = Headers != null &&
                          Headers.Any()
                              ? " " + string.Join(":", Headers.Select(x => $"{x.Key}|{string.Join(",", x.Value)}"))
                              : "";

            return($"{httpMethodText} {RequestUri}{(HttpContent != null ? $" body/content: {_httpContentSerialized}" : "")}{headers}");
        }
示例#13
0
        public void Serialize(JsonWriter writer)
        {
            writer.WritePropertyName(Code);

            writer.WriteStartObject();

            if (!string.IsNullOrWhiteSpace(Description))
            {
                writer.WritePropertyName("description");
                writer.WriteValue(Description);
            }
            else
            {
                writer.WritePropertyName("description");
                writer.WriteValue("not available");
            }

            if (Schema != null)
            {
                writer.WritePropertyName("schema");
                writer.WriteStartObject();
                Schema.Serialize(writer);
                writer.WriteEndObject();
            }

            if (Example != null)
            {
                writer.WritePropertyName("examples");
                writer.WriteStartObject();
                writer.WritePropertyName(Example.MimeType);
                writer.WriteRawValue(Example.Content);
                writer.WriteEndObject();
            }

            if (Headers != null && Headers.Any())
            {
                writer.WritePropertyName("headers");

                writer.WriteStartObject();

                foreach (var header in Headers)
                {
                    writer.WritePropertyName(header);
                    writer.WriteStartObject();
                    writer.WritePropertyName("type");
                    writer.WriteValue("string");
                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
 /// <summary>
 /// Creates and sets the SOAPAction header using the supplied method name
 /// </summary>
 /// <param name="soapAction">The method name that is the target of the invocation</param>
 private void SetSOAPAction(string soapAction)
 {
     if (Headers.Any(x => x.Key == "SOAPAction"))
     {
         Headers["SOAPAction"] = $@"https://test.heartlandpaymentservices.net/BillingDataManagement/v3/BillingDataManagementService/IBillingDataManagementService/{soapAction}";
     }
     else
     {
         Headers.Add("SOAPAction", $@"https://test.heartlandpaymentservices.net/BillingDataManagement/v3/BillingDataManagementService/IBillingDataManagementService/{soapAction}");
     }
 }
示例#15
0
        public ISwaggerGenerator AddRequiredHeader(string name, string suggestedValue)
        {
            if (Headers.Any(x => x.Name == name))
            {
                ((List <RequiredHeader>)Headers).RemoveAll(x => x.Name == name);
            }

            Headers.Add(new RequiredHeader {
                Name = name, SuggestedValue = suggestedValue
            });
            return(this);
        }
        /// <inheritdoc />
        public void Validate(string errorLocation, string propertyPath = "")
        {
            FulcrumValidate.IsNotNullOrWhiteSpace(Method, nameof(Method), errorLocation);
            FulcrumValidate.IsNotNullOrWhiteSpace(EncodedUrl, nameof(EncodedUrl), errorLocation);
            FulcrumValidate.IsTrue(IsValidUri(EncodedUrl), errorLocation, $"{propertyPath}.{nameof(EncodedUrl)} is not a valid URL.");
            FulcrumValidate.IsTrue(HttpMethodExists(), errorLocation, $"{Method} is not a valid HttpMethod");
            if (BodyAsString != null)
            {
                FulcrumValidate.IsTrue(JsonHelper.TryDeserializeObject(BodyAsString, out JToken _), errorLocation,
                                       $"{propertyPath}.{nameof(BodyAsString)} must be JSON.");
            }
            ValidateHeaders();

            bool HttpMethodExists()
            {
                var propertyInfo = typeof(System.Net.Http.HttpMethod).GetProperty(Method,
                                                                                  BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public);

                return(propertyInfo != null);
            }

            bool IsValidUri(string url)
            {
                var result = Uri.TryCreate(url, UriKind.Absolute, out var uri) &&
                             (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps);

                return(result);
            }

            void ValidateHeaders()
            {
                if (Headers != null && Headers.Any())
                {
                    var index = 0;
                    foreach (var header in Headers)
                    {
                        index++;
                        FulcrumValidate.IsNotNullOrWhiteSpace(header.Key, "ignore", errorLocation,
                                                              $"Header {index} in {propertyPath}.{nameof(Headers)} had an empty key.");
                        FulcrumValidate.IsTrue(!header.Key.StartsWith("Content-"), errorLocation,
                                               $"Header {header.Key} is not allowed, as it is a content header.");
                        FulcrumValidate.IsNotNullOrWhiteSpace(header.Value.ToString(), "ignore", errorLocation,
                                                              $"Header {header.Key} had an empty value.");
                        FulcrumValidate.IsTrue(header.Value.Any(), errorLocation,
                                               $"Header {header.Key} had no values.");
                        FulcrumValidate.IsTrue(!header.Value.Any(string.IsNullOrWhiteSpace), errorLocation,
                                               $"Header {header.Key} had an empty value.");
                    }
                }
            }
        }
	public override string ToString()
	{
	    StringBuilder request = new StringBuilder();
	    request.Append($"{Method} {Url} {Constants.HttpOneProtocolFragment}");
	    request.Append(Environment.NewLine);
	    if (Headers.Any()) request.Append(Headers.ToString());
	    if (Cookies.Any())
	    {
		request.Append(Constants.CookieRequestHeaderKey);
		request.Append($": {Cookies.ToString()}");
	    }
	    request.Append(Environment.NewLine);
	    return request.ToString();
	}
        public override string ToString()
        {
            StringBuilder request = new StringBuilder();

            if (Headers.Any())
            {
                request.Append(Headers.ToString() + Environment.NewLine);
            }
            if (Cookies.Any())
            {
                request.Append(Constants.CookieRequestHeaderKey);
                request.Append($": {Cookies.ToString()}{Environment.NewLine}");
            }
            return(request.ToString());
        }
示例#19
0
 private void ExtractHeaders(HttpRequestMessage httpClient)
 {
     if (Headers != null && Headers.Any())
     {
         foreach (var header in Headers)
         {
             if (header.Key == "Content-Type" && httpClient.Content != null)
             {
                 httpClient.Content.Headers.ContentType = new MediaTypeHeaderValue(header.Value);
             }
             else
             {
                 httpClient.Headers.TryAddWithoutValidation(header.Key, header.Value);
             }
         }
     }
 }
示例#20
0
        public override async Task SetParametersAsync(ParameterView parameters)
        {
            await base.SetParametersAsync(parameters);

            if (parameters.GetValueOrDefault <object>(nameof(DataSource)) != null)
            {
                rows     = (DataSource as IEnumerable).Cast <object>().ToList();
                DataType = DataSource.GetType().GetGenericArguments()[0];
                if (AutoGenerateColumns && !headerInitilized)
                {
                    headerInitilized = true;
                    DataType.GetProperties().Where(p => !IgnoreProperties.Contains(p.Name)).Reverse().ToList().ForEach(property =>
                    {
                        if (Headers.Any(x => x.Property?.Name == property.Name))
                        {
                            return;
                        }
                        var attrs = property.GetCustomAttributes(true);
                        var text  = attrs.OfType <DisplayAttribute>().FirstOrDefault()?.Name;
                        if (string.IsNullOrWhiteSpace(text))
                        {
                            text = attrs.OfType <DescriptionAttribute>().FirstOrDefault()?.Description;
                        }
                        var width = attrs.OfType <WidthAttribute>().FirstOrDefault()?.Width;
                        Headers.Insert(0, new TableHeader()
                        {
                            Eval = row =>
                            {
                                return(property.GetValue(row));
                            },
                            IsCheckBox = property.PropertyType == typeof(bool) || Nullable.GetUnderlyingType(property.PropertyType) == typeof(bool),
                            Property   = property,
                            Text       = text ?? property.Name,
                            Width      = width
                        });
                    }
                                                                                                                       );
                }
                chkAll?.MarkAsRequireRender();
                ResetSelectAllStatus();
            }
        }
        public override string ToString()
        {
            StringBuilder response = new StringBuilder();

            response.Append(GlobalConstants.HttpOneProtocolFragment);
            response.Append($" {(int)StatusCode} {StatusCode}{Environment.NewLine}");
            if (Headers.Any())
            {
                response.Append(Headers.ToString() + Environment.NewLine);
            }
            if (Cookies.Any())
            {
                response.Append(GlobalConstants.CookieResponseHeaderKey);
                response.Append($": {Cookies.ToString()}{Environment.NewLine}");
            }
            if (Content.Length > 0)
            {
                response.Append(Environment.NewLine);
            }
            return(response.ToString());
        }
        public override string ToString()
        {
            StringBuilder response = new StringBuilder();

            response.Append(Constants.HttpOneProtocolFragment);
            string statusText = Enumerator.ToTextOrDefault(StatusCode.GetType(), StatusCode);

            response.Append($" {statusText}");
            response.Append(Environment.NewLine);
            if (Headers.Any())
            {
                response.Append(Headers.ToString());
            }
            if (Cookies.Any())
            {
                response.Append(Constants.CookieResponseHeaderKey);
                response.Append($": {Cookies.ToString()}");
            }
            response.Append(Environment.NewLine);
            return(response.ToString());
        }
示例#23
0
        /// <summary>
        ///     Validates the properties of this instance, and returns a list of validation errors.
        /// </summary>
        /// <returns>The list with validation errors, or an empty list, when this instance is valid.</returns>
        public IEnumerable <ValidationError> GetValidationErrors()
        {
            var errors = new List <ValidationError>();

            if (KeyId == KeyId.Empty)
            {
                errors.Add(new ValidationError(nameof(KeyId), $"The {nameof(Signature)} do not specify a valid {nameof(KeyId)}."));
            }
            if (string.IsNullOrEmpty(String))
            {
                errors.Add(new ValidationError(nameof(String), $"The {nameof(Signature)} do not specify a valid signature {nameof(String)}."));
            }
            if (Headers == null)
            {
                errors.Add(new ValidationError(nameof(Headers), $"{nameof(Headers)} cannot be unspecified (null)."));
            }
            if (Headers != null && !Headers.Any())
            {
                errors.Add(new ValidationError(nameof(Headers), $"{nameof(Headers)} cannot be unspecified empty."));
            }
            return(errors);
        }
        private void SetHttpRequestHeaders(HttpRequestMessage message)
        {
            message.Headers?.Clear();

            if (Headers != null && Headers.Any())
            {
                foreach (var header in Headers)
                {
                    message.Headers.Add(header.Key, header.Value);
                }
            }

            if (!message.Headers.Accept.Any(x => x.MediaType == AcceptHeader))
            {
                message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(AcceptHeader));
            }

            if (!message.Headers.AcceptEncoding.Any(x => x.Value == "gzip"))
            {
                message.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
            }
        }
示例#25
0
        private void SendHeaders()
        {
            if (_HeadersSent)
            {
                throw new IOException("Headers already sent.");
            }

            _Response.ContentLength64   = ContentLength;
            _Response.StatusCode        = StatusCode;
            _Response.StatusDescription = GetStatusDescription(StatusCode);
            _Response.SendChunked       = ChunkedTransfer;
            _Response.ContentType       = ContentType;

            if (Headers != null && Headers.Count > 0)
            {
                foreach (KeyValuePair <string, string> header in Headers)
                {
                    if (String.IsNullOrEmpty(header.Key))
                    {
                        continue;
                    }
                    _Response.AddHeader(header.Key, header.Value);
                }
            }

            if (_Settings.Headers != null)
            {
                foreach (KeyValuePair <string, string> header in _Settings.Headers)
                {
                    if (!Headers.Any(h => h.Key.ToLower().Equals(header.Key.ToLower())))
                    {
                        _Response.AddHeader(header.Key, header.Value);
                    }
                }
            }

            _HeadersSent = true;
        }
示例#26
0
 internal void SetEmptyValuesToNull()
 {
     Headers = Headers.Any() ? Headers : null;
     Query   = string.IsNullOrWhiteSpace(Query) ? null : Query;
 }
示例#27
0
 internal void SetEmptyValuesToNull()
 {
     Headers = Headers.Any() ? Headers : null;
     Query   = Query.Any() ? Query : null;
 }
示例#28
0
 /// <summary>
 /// 判断是否存在指定的头
 /// </summary>
 /// <param name="name"> </param>
 /// <returns> </returns>
 public bool HasHeader(string name) => Headers.Any(it => string.Equals(it.Key, name, StringComparison.OrdinalIgnoreCase));
示例#29
0
        private void InitilizeHeaders()
        {
            if (AutoGenerateColumns && !headerInitilized)
            {
                headerInitilized = true;
                DataType.GetProperties().Where(p => !IgnoreProperties.Contains(p.Name)).Reverse().ToList().ForEach(property =>
                {
                    if (Headers.Any(x => x.Property?.Name == property.Name))
                    {
                        return;
                    }
                    var attrs = property.GetCustomAttributes(true);
                    if (attrs.OfType <TableIgnoreAttribute>().Any())
                    {
                        Headers.Add(new TableHeader()
                        {
                            Ignore   = true,
                            Property = property
                        });
                        return;
                    }
                    var columnConfig = attrs.OfType <TableColumnAttribute>().FirstOrDefault() ?? new TableColumnAttribute()
                    {
                        Text = property.Name
                    };

                    if (columnConfig.Ignore)
                    {
                        Headers.Add(new TableHeader()
                        {
                            Ignore   = true,
                            Property = property
                        });
                        return;
                    }
                    var editorConfig = attrs.OfType <EditorGeneratorAttribute>().FirstOrDefault() ?? new EditorGeneratorAttribute()
                    {
                        Control = typeof(BInput <string>)
                    };

                    var formConfig     = attrs.OfType <FormControlAttribute>().FirstOrDefault();
                    var propertyConfig = attrs.OfType <PropertyAttribute>().FirstOrDefault();

                    var tableHeader = new TableHeader()
                    {
                        EvalRaw = row =>
                        {
                            object value = property.GetValue(row);
                            return(value);
                        },
                        SortNo     = columnConfig.SortNo,
                        IsCheckBox = property.PropertyType == typeof(bool) || Nullable.GetUnderlyingType(property.PropertyType) == typeof(bool),
                        Property   = property,
                        Text       = columnConfig.Text,
                        Width      = columnConfig.Width,
                        IsEditable = columnConfig.IsEditable
                    };
                    tableHeader.Eval = displayRender.CreateRenderFactory(tableHeader).CreateRender(tableHeader);
                    if (IsEditable && columnConfig.IsEditable)
                    {
                        InitilizeHeaderEditor(property, editorConfig, tableHeader);
                    }
                    Headers.Insert(0, tableHeader);
                }
                                                                                                                   );
                if (IsEditable)
                {
                    CreateOperationColumn();
                }
                chkAll?.MarkAsRequireRender();
                ResetSelectAllStatus();
            }
            else if (!AutoGenerateColumns && !headerInitilized && Headers.Any())
            {
                headerInitilized = true;
                foreach (var header in Headers)
                {
                    if (!CanEdit(header))
                    {
                        continue;
                    }
                    InitilizeHeaderEditor(header.Property, header.Property.GetCustomAttribute <EditorGeneratorAttribute>() ?? new EditorGeneratorAttribute(), header);
                }
                CreateOperationColumn();
                Refresh();
            }
        }
示例#30
0
 internal void SetEmptyValuesToNull()
 {
     Headers       = Headers.Any() ? Headers : null;
     MatchingRules = MatchingRules.Any() ? MatchingRules : null;
 }