private static void SetJsonConfig(JsConfigScope scope) { // Assume all dates are UTC dates scope.DateHandler = CurrentDateHandler; scope.AssumeUtc = true; scope.AlwaysUseUtc = true; }
public ConfigScope() { scope = JsConfig.With(dateHandler: DateHandler.UnixTime, propertyConvention: PropertyConvention.Lenient, emitLowercaseUnderscoreNames: true); holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy; QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded; }
private static void WithinJsonScope(Action action) { using (JsConfigScope config = JsConfig.BeginScope()) { SetJsonConfig(config); action(); } }
public ConfigurationScope() { _jsConfigScope = JsConfig.BeginScope(); _jsConfigScope.DateHandler = JsonDateHandler.ISO8601; _jsConfigScope.EmitCamelCaseNames = true; // serialize guids with dashes JsConfig <Guid> .SerializeFn = guid => guid.ToString("D"); }
public ConfigScope() { scope = JsConfig.With(new ServiceStack.Text.Config { DateHandler = DateHandler.UnixTime, PropertyConvention = PropertyConvention.Lenient, TextCase = TextCase.SnakeCase, }); holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy; QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded; }
public ConfigScope() { scope = JsConfig.With(new ServiceStack.Text.Config { DateHandler = DateHandler.UnixTime, PropertyConvention = PropertyConvention.Lenient, EmitLowercaseUnderscoreNames = true }); holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy; QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded; }
private void SetPropertyConvention(JsConfigScope scope) { var assembly = Assembly.GetAssembly(typeof(JsConfig)); var jsConfig = assembly.GetType("ServiceStack.Text.JsConfig"); var conventionEnum = assembly.GetType("ServiceStack.Text.JsonPropertyConvention") ?? assembly.GetType("ServiceStack.Text.PropertyConvention"); var propertyConvention = jsConfig.GetProperty("PropertyConvention"); var lenient = conventionEnum.GetField("Lenient"); var enumValue = Enum.ToObject(conventionEnum, (int)lenient.GetValue(conventionEnum)); propertyConvention.SetValue(scope, enumValue, null); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigScope"/> class. /// </summary> public ConfigScope() { var config = Config.Defaults; config.DateHandler = DateHandler.UnixTime; config.PropertyConvention = PropertyConvention.Lenient; config.TextCase = TextCase.SnakeCase; config.TreatEnumAsInteger = false; config.ExcludeTypeInfo = true; JsConfig <RotessaProcessDate> .SerializeFn = date => date.ToString(); this.jsConfigScope = JsConfig.With(config); this.holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy; QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded; }
public ConfigScope() { bool? convertObjectTypesIntoStringDictionary = new bool?(); bool? tryToParsePrimitiveTypeValues = new bool?(); bool? tryToParseNumericType = new bool?(); ParseAsType? parsePrimitiveFloatingPointTypes = new ParseAsType?(); ParseAsType? parsePrimitiveIntegerTypes = new ParseAsType?(); bool? excludeDefaultValues = new bool?(); bool? includeNullValues = new bool?(); bool? includeNullValuesInDictionaries = new bool?(); bool? includeDefaultEnums = new bool?(); bool? excludeTypeInfo = new bool?(); bool? includeTypeInfo = new bool?(); DateHandler? nullable1 = new DateHandler?(DateHandler.UnixTime); PropertyConvention?nullable2 = new PropertyConvention?(PropertyConvention.Lenient); bool? nullable3 = new bool?(true); bool? emitCamelCaseNames = new bool?(false); bool? emitLowercaseUnderscoreNames = nullable3; DateHandler? dateHandler = nullable1; TimeSpanHandler? timeSpanHandler = new TimeSpanHandler?(); PropertyConvention?propertyConvention = nullable2; bool? preferInterfaces = new bool?(); bool? throwOnDeserializationError = new bool?(); // ISSUE: variable of the null type // ISSUE: variable of the null type // ISSUE: variable of the null type bool?treatEnumAsInteger = new bool?(); bool?skipDateTimeConversion = new bool?(); bool?alwaysUseUtc = new bool?(); bool?assumeUtc = new bool?(); bool?appendUtcOffset = new bool?(); bool?escapeUnicode = new bool?(); bool?includePublicFields = new bool?(); int? maxDepth = new int?(); // ISSUE: variable of the null type // ISSUE: variable of the null type this.jsConfigScope = JsConfig.With(convertObjectTypesIntoStringDictionary, tryToParsePrimitiveTypeValues, tryToParseNumericType, parsePrimitiveFloatingPointTypes, parsePrimitiveIntegerTypes, excludeDefaultValues, includeNullValues, includeNullValuesInDictionaries, includeDefaultEnums, excludeTypeInfo, includeTypeInfo, emitCamelCaseNames, emitLowercaseUnderscoreNames, dateHandler, timeSpanHandler, propertyConvention, preferInterfaces, throwOnDeserializationError, (string)null, null, (Func <Type, string>)null, (Func <string, Type>)null, treatEnumAsInteger, skipDateTimeConversion, alwaysUseUtc, assumeUtc, appendUtcOffset, escapeUnicode, includePublicFields, maxDepth, (EmptyCtorFactoryDelegate)null, (string[])null); this.holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy; QueryStringSerializer.ComplexTypeStrategy = new WriteComplexTypeDelegate(QueryStringStrategy.FormUrlEncoded); }
/// <summary> /// /// </summary> /// <param name="config"></param> /// <param name="scope"></param> /// <returns></returns> public static JsConfigScope CreateScope(string config, JsConfigScope scope = null) { if (string.IsNullOrEmpty(config)) { return(scope); } scope ??= BeginScope(); var items = config.Split(','); foreach (var item in items) { var parts = item.SplitOnFirst(':'); var key = parts[0].ToLower(); var value = parts.Length == 2 ? parts[1].ToLower() : null; var boolValue = parts.Length == 1 || value != "false" && value != "0"; switch (key) { case "cotisd": case "convertobjecttypesintostringdictionary": scope.ConvertObjectTypesIntoStringDictionary = boolValue; break; case "ttpptv": case "trytoparseprimitivetypevalues": scope.TryToParsePrimitiveTypeValues = boolValue; break; case "ttpnt": case "trytoparsenumerictype": scope.TryToParseNumericType = boolValue; break; case "edv": case "excludedefaultvalues": scope.ExcludeDefaultValues = boolValue; break; case "inv": case "includenullvalues": scope.IncludeNullValues = boolValue; break; case "invid": case "includenullvaluesindictionaries": scope.IncludeNullValuesInDictionaries = boolValue; break; case "ide": case "includedefaultenums": scope.IncludeDefaultEnums = boolValue; break; case "eti": case "excludetypeinfo": scope.ExcludeTypeInfo = boolValue; break; case "iti": case "includetypeinfo": scope.IncludeTypeInfo = boolValue; break; case "i": case "pp": //pretty-print case "indent": scope.Indent = boolValue; break; case "eccn": case "emitcamelcasenames": scope.TextCase = boolValue ? TextCase.CamelCase : scope.TextCase; break; case "elun": case "emitlowercaseunderscorenames": scope.TextCase = boolValue ? TextCase.SnakeCase : scope.TextCase; break; case "pi": case "preferinterfaces": scope.PreferInterfaces = boolValue; break; case "tode": case "throwondeserializationerror": case "toe": case "throwonerror": scope.ThrowOnError = boolValue; break; case "teai": case "treatenumasinteger": scope.TreatEnumAsInteger = boolValue; break; case "sdtc": case "skipdatetimeconversion": scope.SkipDateTimeConversion = boolValue; break; case "auu": case "alwaysuseutc": scope.AlwaysUseUtc = boolValue; break; case "au": case "assumeutc": scope.AssumeUtc = boolValue; break; case "auo": case "appendutcoffset": scope.AppendUtcOffset = boolValue; break; case "ipf": case "includepublicfields": scope.IncludePublicFields = boolValue; break; case "dh": case "datehandler": switch (value) { case "timestampoffset": case "to": scope.DateHandler = DateHandler.TimestampOffset; break; case "dcjsc": case "dcjscompatible": scope.DateHandler = DateHandler.DCJSCompatible; break; case "iso8601": scope.DateHandler = DateHandler.ISO8601; break; case "iso8601do": case "iso8601dateonly": scope.DateHandler = DateHandler.ISO8601DateOnly; break; case "iso8601dt": case "iso8601datetime": scope.DateHandler = DateHandler.ISO8601DateTime; break; case "rfc1123": scope.DateHandler = DateHandler.RFC1123; break; case "ut": case "unixtime": scope.DateHandler = DateHandler.UnixTime; break; case "utm": case "unixtimems": scope.DateHandler = DateHandler.UnixTimeMs; break; } break; case "tsh": case "timespanhandler": switch (value) { case "df": case "durationformat": scope.TimeSpanHandler = TimeSpanHandler.DurationFormat; break; case "sf": case "standardformat": scope.TimeSpanHandler = TimeSpanHandler.StandardFormat; break; } break; case "pc": case "propertyconvention": switch (value) { case "l": case "lenient": scope.PropertyConvention = PropertyConvention.Lenient; break; case "s": case "strict": scope.PropertyConvention = PropertyConvention.Strict; break; } break; case "tc": case "textcase": switch (value) { case "d": case "default": scope.TextCase = TextCase.Default; break; case "pc": case "pascalcase": scope.TextCase = TextCase.PascalCase; break; case "cc": case "camelcase": scope.TextCase = TextCase.CamelCase; break; case "sc": case "snakecase": scope.TextCase = TextCase.SnakeCase; break; } break; } } return(scope); }
public NullableConfigScope(Func <Money?, string> serializer, JsConfigScope scope = null) { _scope = scope; JsConfig <Money?> .RawSerializeFn = serializer; }
public NullableConfigScope(Func <string, Money?> deSerializer, JsConfigScope scope = null) { _scope = scope; JsConfig <Money?> .RawDeserializeFn = deSerializer; }
public ConfigScope(Func <Money, string> serializer, JsConfigScope scope = null) { _scope = scope; JsConfig <Money> .RawSerializeFn = serializer; }
public void SetJsConfigSettings(JsConfigScope scope) { scope.DateHandler = JsonDateHandler.ISO8601; scope.EmitCamelCaseNames = true; }
public void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName) { if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) { return; } List <KeyValuePair <string, object> > configInfo = new List <KeyValuePair <string, object> >(); if (AppHostBase.Instance != null) { configInfo.Add(new KeyValuePair <string, object>("StartUpTime", AppHostBase.Instance.StartUpTime)); } if (AppHostHttpListenerBase.Instance != null) { configInfo.Add(new KeyValuePair <string, object>("StartUpTime", AppHostHttpListenerBase.Instance.StartUpTime)); } configInfo.Add(new KeyValuePair <string, object>("AppId", ServiceUtils.AppId)); configInfo.Add(new KeyValuePair <string, object>("IPv4", ServiceUtils.HostIP)); configInfo.Add(new KeyValuePair <string, object>("MachineName", ServiceUtils.MachineName)); configInfo.Add(new KeyValuePair <string, object>("SOA.CurrentEnv", EnvironmentUtility.CurrentEnv)); var metadata = EndpointHost.MetadataMap[httpReq.ServicePath]; configInfo.Add(new KeyValuePair <string, object>("SOA.ServiceName", metadata.ServiceName)); configInfo.Add(new KeyValuePair <string, object>("SOA.ServiceNamespace", metadata.ServiceNamespace)); configInfo.Add(new KeyValuePair <string, object>("SOA.ServiceTestSubEnv", metadata.ServiceTestSubEnv ?? "null")); configInfo.Add(new KeyValuePair <string, object>( ServiceMetadata.DefaultLogErrorWithRequestInfoSettingKey, metadata.LogErrorWithRequestInfo)); configInfo.Add(new KeyValuePair <string, object>( ServiceMetadata.DefaultLogCommonRequestInfoSettingKey, metadata.LogCommonRequestInfo)); configInfo.Add(new KeyValuePair <string, object>( ServiceMetadata.DefaultLogH5HeadExtensionDataSettingKey, metadata.LogH5HeadExtensionData)); bool circuitBreakerForceClosed = metadata.CircuitBreakerForceClosed; configInfo.Add(new KeyValuePair <string, object>(ServiceMetadata.DefaultCircuitBreakerForceClosedSettingKey, circuitBreakerForceClosed)); Dictionary <string, double> timeoutMap = new Dictionary <string, double>(); foreach (Operation operation in metadata.Operations) { timeoutMap.Add(operation.Name, operation.HystrixCommand.GetExecutionTimeout().TotalMilliseconds); } configInfo.Add(new KeyValuePair <string, object>(ServiceMetadata.DefaultOperationTimeoutMapSettingKey, timeoutMap)); configInfo.Add(new KeyValuePair <string, object>( ServiceMetadata.DefaultUseChunkedTransferEncodingSettingKey, metadata.UseChunkedTransferEncoding)); configInfo.Add(new KeyValuePair <string, object>("SOA.FxConfigWebServiceUtils.Enabled", AntFxConfigWebServiceUtils.Enabled)); configInfo.Add(new KeyValuePair <string, object>("SOA.FxConfigWebServiceUtils.ApiUrl", AntFxConfigWebServiceUtils.ConfigWebServiceApiUrl)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MinGlobalDefaultTimeout", HystrixCommandHelper.MinGlobalDefaultCircuitBreakerTimeoutSetting.TotalMilliseconds.ToString())); configInfo.Add(new KeyValuePair <string, object>( "SOA.GlobalDefaultTimeout", HystrixCommandHelper.GlobalDefaultCircuitBreakerTimeoutSetting.HasValue ? HystrixCommandHelper.GlobalDefaultCircuitBreakerTimeoutSetting.Value.TotalMilliseconds.ToString() : null)); configInfo.Add(new KeyValuePair <string, object>( "SOA.FrameworkDefaultTimeout", HystrixPropertiesCommandDefault.DefaultExecutionIsolationThreadTimeout.TotalMilliseconds.ToString())); configInfo.Add(new KeyValuePair <string, object>( "SOA.FrameworkDefaultConnectionMaxRequestCount", ServiceMetadata.FrameworkDefaultConnectionMaxRequestCount)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MinConnectionMaxRequestCount", ServiceMetadata.MinConnectionMaxRequestCount)); configInfo.Add(new KeyValuePair <string, object>( "SOA.CheckConnectionMaxRequestCount", metadata.CheckConnectionMaxRequestCount)); configInfo.Add(new KeyValuePair <string, object>( "SOA.ConnectionMaxRequestCount", metadata.ConnectionMaxRequestCount)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MessageLogConfig.RequestLogMaxSize", MessageLogConfig.RequestLogMaxSize)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MessageLogConfig.ResponseLogMaxSize", MessageLogConfig.ResponseLogMaxSize)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MessageLogConfig.FrameworkDefalut.Test", MessageLogConfig.FrameworkDefalutMessageLogConfigOfTestEnv)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MessageLogConfig.FrameworkDefalut.Uat", MessageLogConfig.FrameworkDefalutMessageLogConfigOfUatEnv)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MessageLogConfig.FrameworkDefalut.Prod", MessageLogConfig.FrameworkDefalutMessageLogConfigOfProdEnv)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MessageLogConfig.FrameworkDefalut.Null", MessageLogConfig.FrameworkDefalutMessageLogConfigOfNullEnv)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MessageLogConfig.FrameworkDefault.Current", MessageLogConfig.CurrentFrameworkDefaultMessageLogConfig)); configInfo.Add(new KeyValuePair <string, object>( "SOA.MessageLogConfig.Service", metadata.ServiceMessageLogConfig)); var operationMessageConfigs = from operation in metadata.Operations select new { operation.Name, operation.OperationMessageLogConfig, }; configInfo.Add(new KeyValuePair <string, object>( "SOA.MessageLogConfig.Operation", operationMessageConfigs)); configInfo.Add(new KeyValuePair <string, object>( "SOA.DeserializeRequestUseMemoryStream", metadata.DeserializeRequestUseMemoryStream)); configInfo.Add(new KeyValuePair <string, object>( "SOA.LogPopulateExceptionAsWarning", ReflectionUtils.LogPopulateExceptionAsWarning)); foreach (IHasConfigInfo configInfoOwner in ConfigInfoOwners) { configInfo.AddRange(configInfoOwner.GetConfigInfo(httpReq.ServicePath)); } using (JsConfigScope scope = JsConfig.BeginScope()) { scope.ExcludeTypeInfo = true; scope.DateHandler = JsonDateHandler.LongDateTime; httpRes.ContentType = "application/json"; httpRes.Write(WrappedJsonSerializer.Instance.SerializeToString(configInfo)); } }