Beispiel #1
0
        private string ConvertArgumentsToJson(IDictionary <string, object> arguments)
        {
            try
            {
                if (CollectionExtensions.IsNullOrEmpty(arguments))
                {
                    return("{}");
                }

                var dictionary = new Dictionary <string, object>();

                foreach (var argument in arguments)
                {
                    if (argument.Value != null && _configuration.IgnoredTypes.Any(t => t.IsInstanceOfType(argument.Value)))
                    {
                        dictionary[argument.Key] = null;
                    }
                    else
                    {
                        var typeConvert =
                            _configuration.TypeConverts.FirstOrDefault(t => t.Key.IsInstanceOfType(argument.Value));

                        dictionary[argument.Key] = typeConvert.Key == null ? argument.Value :
                                                   typeConvert.Value(argument.Value);
                    }
                }

                return(_auditSerializer.Serialize(dictionary));
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.ToString(), ex);
                return("{}");
            }
        }
Beispiel #2
0
        private string ConvertLocalizedArgumentsToJson(IDictionary <Tuple <string, IEnumerable <Attribute> >, object> arguments)
        {
            try
            {
                if (CollectionExtensions.IsNullOrEmpty(arguments))
                {
                    return("{}");
                }

                var dictionary = new Dictionary <string, object>();

                foreach (var argument in arguments)
                {
                    var key = ((LocalizedDescriptionAttribute)argument.Key.Item2.FirstOrDefault(i =>
                                                                                                i is LocalizedDescriptionAttribute))?.Name;
                    var value = argument.Value;
                    if (key == null)
                    {
                        continue;
                    }
                    if (argument.Value != null && _configuration.IgnoredTypes.Any(t => t.IsInstanceOfType(argument.Value)))
                    {
                        dictionary[key] = null;
                    }
                    else
                    {
                        var typeConvert =
                            _configuration.TypeConverts.FirstOrDefault(t => t.Key.IsInstanceOfType(argument.Value));

                        dictionary[key] = typeConvert.Key == null ? value :
                                          typeConvert.Value(value);
                    }
                }

                return(_localizedSerializer.Serialize(dictionary));
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.ToString(), ex);
                return("{}");
            }
        }