Example #1
0
        public static T GetValue <T>(this ExtendedDataDictionary extendedData, string key)
        {
            if (!extendedData.ContainsKey(key))
            {
                throw new KeyNotFoundException(String.Format("Key \"{0}\" not found in the dictionary.", key));
            }

            object data = extendedData[key];

            if (data is T)
            {
                return((T)data);
            }

            if (data is string)
            {
                try {
                    return(JsonConvert.DeserializeObject <T>((string)data));
                } catch {}
            }

            try {
                return(data.ToType <T>());
            } catch {}

            return(default(T));
        }
 public void SetUp()
 {
     dictionary = new Dictionary <string, string> {
         { "key", "value" }
     };
     extendedDataObj = new ExtendedDataDictionary(dictionary);
 }
Example #3
0
 public Parameter() {
     ExtendedData = new ExtendedDataDictionary();
     GenericArguments = new GenericArguments();
 }
Example #4
0
 public Module() {
     ExtendedData = new ExtendedDataDictionary();
 }
Example #5
0
 public RequestInfo() {
     ExtendedData = new ExtendedDataDictionary();
     Cookies = new Dictionary<string, string>();
     QueryString = new Dictionary<string, string>();
 }
 public EnvironmentInfo() {
     ExtendedData = new ExtendedDataDictionary();
 }
Example #7
0
 public Person(string name)
 {
     Name         = name;
     ExtendedData = new ExtendedDataDictionary();
 }
Example #8
0
 public ErrorInfo()
 {
     ExtendedData = new ExtendedDataDictionary();
     StackTrace = new StackFrameCollection();
 }
Example #9
0
 public Person(string name) {
     Name = name;
     ExtendedData = new ExtendedDataDictionary();
 }
Example #10
0
 public Method()
 {
     ExtendedData = new ExtendedDataDictionary();
     GenericArguments = new GenericArguments();
     Parameters = new ParameterCollection();
 }
Example #11
0
        internal static void SerializeExtendedDataObjectsToStrings(IConfigurationAndLogAccessor accessor, string id, ExtendedDataDictionary extendedData)
        {
            if (extendedData == null)
            {
                return;
            }

            // pre-serialize extended data objects so that we won't fail if we can't serialize them
            // also this allows us to log the exact one that caused an issue.
            var keys = new List <string>(extendedData.Keys);

            foreach (string key in keys)
            {
                if (key.AnyWildcardMatches(accessor.Configuration.DataExclusions, true))
                {
                    continue;
                }

                object data = extendedData[key];
                if (data is string)
                {
                    continue;
                }

                try {
                    extendedData[key] = ModelSerializer.Current.SerializeToString(data, excludedPropertyNames: accessor.Configuration.DataExclusions);
                } catch (Exception ex) {
                    accessor.Log.FormattedError(typeof(QueueManager), ex, "Unable to serialize extended data entry for '{0}' with key '{1}': {2}", id, key, ex.Message);
                    extendedData[key] = String.Format("Unable to serialize extended data key \"{0}\" of type \"{1}\". {2}", key, extendedData[key].GetType(), ex);
                }
            }
        }
Example #12
0
        internal static void SerializeExtendedDataObjectsToStrings(IConfigurationAndLogAccessor accessor, string id, ExtendedDataDictionary extendedData) {
            if (extendedData == null)
                return;

            // pre-serialize extended data objects so that we won't fail if we can't serialize them
            // also this allows us to log the exact one that caused an issue.
            var keys = new List<string>(extendedData.Keys);
            foreach (string key in keys) {
                if (key.AnyWildcardMatches(accessor.Configuration.DataExclusions, true))
                    continue;

                object data = extendedData[key];
                if (data is string)
                    continue;

                try {
                    extendedData[key] = ModelSerializer.Current.SerializeToString(data, excludedPropertyNames: accessor.Configuration.DataExclusions);
                } catch (Exception ex) {
                    accessor.Log.FormattedError(typeof(QueueManager), ex, "Unable to serialize extended data entry for '{0}' with key '{1}': {2}", id, key, ex.Message);
                    extendedData[key] = String.Format("Unable to serialize extended data key \"{0}\" of type \"{1}\". {2}", key, extendedData[key].GetType(), ex);
                }
            }
        }