Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
 public void SetUp()
 {
     dictionary = new Dictionary <string, string> {
         { "key", "value" }
     };
     extendedDataObj = new ExtendedDataDictionary(dictionary);
 }
Ejemplo n.º 3
0
 public Parameter() {
     ExtendedData = new ExtendedDataDictionary();
     GenericArguments = new GenericArguments();
 }
Ejemplo n.º 4
0
 public Module() {
     ExtendedData = new ExtendedDataDictionary();
 }
Ejemplo n.º 5
0
 public RequestInfo() {
     ExtendedData = new ExtendedDataDictionary();
     Cookies = new Dictionary<string, string>();
     QueryString = new Dictionary<string, string>();
 }
Ejemplo n.º 6
0
 public EnvironmentInfo() {
     ExtendedData = new ExtendedDataDictionary();
 }
Ejemplo n.º 7
0
 public Person(string name)
 {
     Name         = name;
     ExtendedData = new ExtendedDataDictionary();
 }
Ejemplo n.º 8
0
 public ErrorInfo()
 {
     ExtendedData = new ExtendedDataDictionary();
     StackTrace = new StackFrameCollection();
 }
Ejemplo n.º 9
0
 public Person(string name) {
     Name = name;
     ExtendedData = new ExtendedDataDictionary();
 }
Ejemplo n.º 10
0
 public Method()
 {
     ExtendedData = new ExtendedDataDictionary();
     GenericArguments = new GenericArguments();
     Parameters = new ParameterCollection();
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
                }
            }
        }