protected virtual IRepository CreateRepository(string connectionString)
        {
            log4net.ElasticSearch.Models.Uri.Init(RollingIndexNameDateFormat, IndexTypeName);

            var overrides = fieldNameOverrides.ToDictionary(x => x.Original, x => x.Replacement);
            var resolver  = new CustomDataContractResolver
            {
                FieldNameChanges  = overrides,
                FieldValueReplica = fieldValueReplicas,
            };

            return(Repository.Create(connectionString, resolver));
        }
        public static string ToJson <T>(this T self, CustomDataContractResolver resolver)
        {
            var json = JsonConvert.SerializeObject(self, new JsonSerializerSettings {
                ContractResolver = resolver
            });

            if (resolver.FieldValueReplica != null && resolver.FieldValueReplica.Count > 0)
            {
                resolver.FieldValueReplica.ForEach(x =>
                {
                    var originalValue = self.GetType().GetProperty(x.Original)?.GetValue(self, null);
                    var obj           = JsonConvert.DeserializeObject <ExpandoObject>(json) as IDictionary <string, Object>;
                    obj.Add(x.Replica, originalValue);
                    json = JsonConvert.SerializeObject(obj);
                });
            }

            return(json);
        }
Exemplo n.º 3
0
 public static IRepository Create(string connectionString, CustomDataContractResolver resolver)
 {
     return(Create(connectionString, new HttpClient(resolver)));
 }