Esempio n. 1
0
        private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
        {
            IDictionary<string, object> d = value as IDictionary<string, object>;
            if (d != null)
            {
                foreach (KeyValuePair<string, object> entry in d)
                {
                    AddToBackingStore(backingStore, MakePropertyKey(prefix, entry.Key), entry.Value);
                }
                return;
            }

            IList l = value as IList;
            if (l != null)
            {
                for (int i = 0; i < l.Count; i++)
                {
                    AddToBackingStore(backingStore, MakeArrayKey(prefix, i), l[i]);
                }
                return;
            }

            // primitive
            backingStore.Add(prefix, value);
        }
Esempio n. 2
0
        private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
        {
            if (!string.IsNullOrEmpty(prefix))
            {
                backingStore.Add(prefix, value);
            }

            var d = value as IDictionary <string, object>;

            if (d != null)
            {
                foreach (var entry in d)
                {
                    AddToBackingStore(backingStore, MakePropertyKey(prefix, entry.Key), entry.Value);
                }
                return;
            }

            var l = value as IList;

            if (l != null)
            {
                for (int i = 0; i < l.Count; i++)
                {
                    AddToBackingStore(backingStore, MakeArrayKey(prefix, i), l[i]);
                }
                return;
            }

            // primitive
            //backingStore.Add(prefix, value);
        }
        private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
        {
            IDictionary <string, object> d = value as IDictionary <string, object>;

            if (d != null)
            {
                foreach (KeyValuePair <string, object> entry in d)
                {
                    AddToBackingStore(backingStore, MakePropertyKey(prefix, entry.Key), entry.Value);
                }
                return;
            }

            IList l = value as IList;

            if (l != null)
            {
                for (int i = 0; i < l.Count; i++)
                {
                    AddToBackingStore(backingStore, MakeArrayKey(prefix, i), l[i]);
                }
                return;
            }

            // primitive
            backingStore.Add(prefix, value);
        }
Esempio n. 4
0
        private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
        {
            IDictionary <string, object> dictionary = value as IDictionary <string, object>;

            if (dictionary != null)
            {
                foreach (KeyValuePair <string, object> pair in dictionary)
                {
                    string newPrefix = MakePropertyKey(prefix, pair.Key);
                    AddToBackingStore(backingStore, newPrefix, pair.Value);
                }
            }
            else
            {
                IList list = value as IList;
                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        AddToBackingStore(backingStore, MakeArrayKey(prefix, i), list[i]);
                    }
                }
                else
                {
                    backingStore.Add(prefix, value);
                }
            }
        }
Esempio n. 5
0
        public override IValueProvider GetValueProvider(ControllerContext controllerContext)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException(nameof(controllerContext));
            }
            if (!controllerContext.HttpContext.Request.ContentType.
                StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            var reader   = new StreamReader(controllerContext.HttpContext.Request.InputStream);
            var bodyText = reader.ReadToEnd();

            if (string.IsNullOrEmpty(bodyText))
            {
                // no JSON data
                return(null);
            }
            var backingStore        = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            var backingStoreWrapper = new EntryLimitedDictionary(backingStore);

            AddToBackingStore(backingStoreWrapper, string.Empty,
                              bodyText.StartsWith("[")
                    ? JArray.Parse(bodyText) as JContainer
                    : JObject.Parse(bodyText));
            return(new DictionaryValueProvider <object>(backingStore, CultureInfo.CurrentCulture));
        }
    private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
    {
        IDictionary <string, object> strs = value as IDictionary <string, object>;

        if (strs != null)
        {
            foreach (KeyValuePair <string, object> keyValuePair in strs)
            {
                CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakePropertyKey(prefix, keyValuePair.Key), keyValuePair.Value);
            }

            return;
        }

        IList lists = value as IList;

        if (lists == null)
        {
            backingStore.Add(prefix, value);
            return;
        }

        for (int i = 0; i < lists.Count; i++)
        {
            CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakeArrayKey(prefix, i), lists[i]);
        }
    }
Esempio n. 7
0
        private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
        {
            switch (value)
            {
            case IDictionary <string, object> d:
            {
                foreach (var entry in d)
                {
                    AddToBackingStore(backingStore, MakePropertyKey(prefix, entry.Key), entry.Value);
                }
                return;
            }

            case IList l:
            {
                for (var i = 0; i < l.Count; i++)
                {
                    AddToBackingStore(backingStore, MakeArrayKey(prefix, i), l[i]);
                }
                return;
            }

            default:
                backingStore.Add(prefix, value);
                break;
            }
        }
 private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
 {
     IDictionary<string, object> dictionary = value as IDictionary<string, object>;
     if (dictionary != null)
     {
         foreach (KeyValuePair<string, object> pair in dictionary)
         {
             string newPrefix = MakePropertyKey(prefix, pair.Key);
             AddToBackingStore(backingStore, newPrefix, pair.Value);
         }
     }
     else
     {
         IList list = value as IList;
         if (list != null)
         {
             for (int i = 0; i < list.Count; i++)
             {
                 AddToBackingStore(backingStore, MakeArrayKey(prefix, i), list[i]);
             }
         }
         else
         {
             backingStore.Add(prefix, value);
         }
     }
 }
        public override IValueProvider GetValueProvider(ControllerContext controllerContext)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException("controllerContext");
            }
            if (!controllerContext.HttpContext.Request.ContentType.
                StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var jsonString  = string.Empty;
            var requestJson = string.Empty;

            using (var reader = new StreamReader(controllerContext.HttpContext.Request.InputStream))
            {
                requestJson = reader.ReadToEnd();
            }

            if (string.IsNullOrEmpty(requestJson))
            {
                return(null);
            }
            int count = 0;

            if (requestJson.Contains("secret") && requestJson.Contains("encryption"))//加密请求
            {
                jsonString = GetDecryptPost(requestJson, ref count);
            }
            else
            {
                jsonString = requestJson;//非加密请求
            }

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            try
            {
                object jsonData = serializer.DeserializeObject(jsonString);
                Dictionary <string, object> backingStore        = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
                EntryLimitedDictionary      backingStoreWrapper = new EntryLimitedDictionary(backingStore);
                AddToBackingStore(backingStoreWrapper, String.Empty, jsonData);
                return(new DictionaryValueProvider <object>(backingStore, CultureInfo.CurrentCulture));
            }
            catch (Exception ex)
            {
                throw new Exception(Utils.RsaError);
            }
        }
 public override IValueProvider GetValueProvider(ControllerContext controllerContext)
 {
     if (controllerContext == null)
     {
         throw new ArgumentNullException("controllerContext");
     }
     object deserializedObject = GetDeserializedObject(controllerContext);
     if (deserializedObject == null)
     {
         return null;
     }
     Dictionary<string, object> innerDictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
     EntryLimitedDictionary backingStore = new EntryLimitedDictionary(innerDictionary);
     AddToBackingStore(backingStore, string.Empty, deserializedObject);
     return new DictionaryValueProvider<object>(innerDictionary, CultureInfo.CurrentCulture);
 }
Esempio n. 11
0
        public override IValueProvider GetValueProvider(ControllerContext controllerContext)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException("controllerContext");
            }
            object deserializedObject = GetDeserializedObject(controllerContext);

            if (deserializedObject == null)
            {
                return(null);
            }
            Dictionary <string, object> innerDictionary = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            EntryLimitedDictionary      backingStore    = new EntryLimitedDictionary(innerDictionary);

            AddToBackingStore(backingStore, string.Empty, deserializedObject);
            return(new DictionaryValueProvider <object>(innerDictionary, CultureInfo.CurrentCulture));
        }
Esempio n. 12
0
        private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, JToken value)
        {
            if (value.Type == JTokenType.Null)
            {
                return;
            }
            var d = value as JObject;

            if (d != null)
            {
                foreach (var v in d)
                {
                    AddToBackingStore(backingStore, MakePropertyKey(prefix, v.Key), v.Value);
                }
                return;
            }
            var l = value as JArray;

            if (l != null)
            {
                if (l.Count == 0)
                {
                    //解决空数组被解析成null的问题
                    backingStore.Add(prefix, new object[0]);
                }
                else
                {
                    for (var i = 0; i < l.Count; i++)
                    {
                        AddToBackingStore(backingStore, MakeArrayKey(prefix, i), l[i]);
                    }

                    /*var i = 0;
                     * foreach (var v in l)
                     * {
                     *  AddToBackingStore(backingStore, MakeArrayKey(prefix, i), v);
                     *  i++;
                     * }*/
                }
                return;
            }
            backingStore.Add(prefix, value.ToString());
        }
Esempio n. 13
0
        public override IValueProvider GetValueProvider(ControllerContext controllerContext)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException("controllerContext");
            }

            var jsonData = GetDeserializedObject(controllerContext);

            if (jsonData == null)
            {
                return(null);
            }

            var backingStore        = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            var backingStoreWrapper = new EntryLimitedDictionary(backingStore);

            AddToBackingStore(backingStoreWrapper, String.Empty, jsonData);
            return(new TraceJsonValueProvider <object>(backingStore, CultureInfo.CurrentCulture));
        }
        private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
        {
            if (value is IDictionary <string, object> d)
            {
                foreach (var entry in d)
                {
                    AddToBackingStore(backingStore, MakePropertyKey(prefix, entry.Key), entry.Value);
                }

                return;
            }

            if (value is IList l)
            {
                for (var i = 0; i < l.Count; i++)
                {
                    AddToBackingStore(backingStore, MakeArrayKey(prefix, i), l[i]);
                }

                return;
            }

            backingStore.Add(prefix, value);
        }