Great tool.
I got it working with the LiveGrid store (based the Bufferstore on the DirectStore).
I wanted to save changed value in the store through a JsonWriter to the update api of the directstore (bufferedstore).
When I saved 1 item, everything was okay. But when I wanted to save more than one changed record from the store I got an array.
JArray was not supported.
I made an implementation but I'm really not sure if it is up to your standard, for me it works in my proof of concept. But it's not yet in production state. So if anyone has any comments, improvements or what ever, feel free.
I created a .patch file (with usage of subversion) against the 0.6.4 version.
Code:
Index: DirectMethodInvoker.cs
===================================================================
--- DirectMethodInvoker.cs (revision 4)
+++ DirectMethodInvoker.cs (working copy)
@@ -1,6 +1,7 @@
?using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Reflection;
using System.Web.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -23,10 +24,33 @@
string key = parameterDescriptors[i].ParameterName;
object rawValue = data[i];
- if (rawValue is JObject && parameterDescriptors[i].ParameterType != typeof(JObject)) {
- rawValue = JsonConvert.DeserializeObject(rawValue.ToString(), parameterDescriptors[i].ParameterType);
+ if (rawValue is List<object> && parameterDescriptors[i].ParameterType.BaseType == typeof(Array))
+ {
+ List<object> tempRawArray = rawValue as List<object>;
+ for( int j = 0; j < tempRawArray.Count; j++)
+ {
+ //If is array then get the type of the non array type
+ if (tempRawArray[j] is JObject && parameterDescriptors[i].ParameterType != typeof(JObject))
+ {
+ Assembly assembly = Assembly.GetAssembly(parameterDescriptors[i].ParameterType);
+ Type type = assembly.GetType(parameterDescriptors[i].ParameterType.FullName.Replace("[]",""));
+ tempRawArray[j] = JsonConvert.DeserializeObject(tempRawArray[j].ToString(), type);
+ }
+ }
+ rawValue = tempRawArray.ToArray();
}
+ else if (rawValue is JObject && parameterDescriptors[i].ParameterType != typeof(JObject))
+ {
+ Type type = parameterDescriptors[i].ParameterType;
+ if (type.BaseType == typeof(Array))
+ {
+ Assembly assembly = Assembly.GetAssembly(type);
+ type = assembly.GetType(parameterDescriptors[i].ParameterType.FullName.Replace("[]",""));
+ }
+ rawValue = JsonConvert.DeserializeObject(rawValue.ToString(), type);
+ }
+
string attemptedValue = Convert.ToString(rawValue, invariantCulture);
valueProvider.Add(key, new ValueProviderResult(rawValue, attemptedValue, invariantCulture));
}
Index: RequestDataConverter.cs
===================================================================
--- RequestDataConverter.cs (revision 4)
+++ RequestDataConverter.cs (working copy)
@@ -13,12 +13,34 @@
if (!dataArray.HasValues) return null;
- foreach (JToken dataItem in dataArray) {
- if (dataItem is JObject) {
+ foreach (JToken dataItem in dataArray)
+ {
+ if (dataItem is JObject)
+ {
data.Add(dataItem);
- } else if (dataItem is JValue) {
+ }
+ else if (dataItem is JValue)
+ {
data.Add((dataItem as JValue).Value);
- } else {
+ }
+ else if (dataItem is JArray)
+ {
+ List<object> listObjects = new List<object>();
+ foreach (JToken arrayDataItem in (dataItem as JArray))
+ {
+ if (arrayDataItem is JObject)
+ {
+ listObjects.Add(arrayDataItem);
+ }
+ else if (arrayDataItem is JValue)
+ {
+ listObjects.Add((arrayDataItem as JValue).Value);
+ }
+ }
+ data.Add(listObjects);
+ }
+ else
+ {
throw new ArgumentException("Arguments of this type are not supported.");
}
}
Now I can have an update action like this, supporting arrays.
Code:
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update(int[] ids, WebModelContainerStatus[] records)
{
if (Request.IsAjaxRequest())
{