-
16 Nov 2009 11:39 AM #121
I can probably do it either way - because I'm catching all errors in a common controller class and altering them before sending them along. I could probably manage it so that I change them over to DirectExceptions.
However, the reason I want to catch on ALL errors is that, typically, the user would get a 500 page if a server error occurs. With a full AJAX app, these requests could just "disappear" from the user's point of view. (you see it in firebug just fine, but the user would see nothing) By having ALL exceptions get sent through, I can show the user that their attempt failed and collect more information.
D
-
17 Nov 2009 4:00 PM #122
Another suggestion:
Below are some changes to the RequestDataConvertor that will allow it to pass in arrays from the JS back to the methods. Arrays get converted into a List<object> type. There might be an easy way to cast this List<object> to a List<int> or a List<string> inside the Direct library, but I haven't taken a stab at it yet.
Code:internal class RequestDataConverter : JsonConverter { public override object ReadJson(JsonReader reader, Type objectType, JsonSerializer serializer) { var data = new List<object>(); var dataArray = JToken.ReadFrom(reader); if (!dataArray.HasValues) return null; foreach (JToken dataItem in dataArray) { if (dataItem is JObject) { data.Add(dataItem); } else if (dataItem is JValue) { data.Add((dataItem as JValue).Value); } else if (dataItem is JArray) { data.Add(ConvertJArray(dataItem as JArray)); } else { throw new ArgumentException("Arguments of this type are not supported."); } } return data.ToArray(); } private List<object> ConvertJArray(JArray item) { List<object> output = new List<object>(); foreach (JToken dataItem in item.AsJEnumerable()) { if (dataItem is JObject) { output.Add(dataItem); } else if (dataItem is JValue) { output.Add((dataItem as JValue).Value); } else if (dataItem is JArray) { output.Add(this.ConvertJArray(dataItem as JArray)); } else { throw new ArgumentException("Arguments of this type are not supported."); } } return output; } public override bool CanConvert(Type objectType) { return true; } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { throw new NotImplementedException(); } }
-
17 Nov 2009 6:29 PM #123
Passing one-dimensional arrays from JS to the methods on the server is already supported in version 0.7. What you have added is support for multi-dimensional arrays, but it isn't complete. Similar changes have to be made to DirectMethodInvoker class. But do you think it's worth the effort? Personally I don't. I mean, it is such an extreme use case, that I don't think anyone will ever need it. Besides, if you find yourself passing multi-dimensional arrays, chances are you're doing something wrong and should revisit the code.
There is no way in C# to simply cast List of one type to List of another type, it doesn't work. It can only be done to each individual item in a loop and requires an additional List of target type.There might be an easy way to cast this List<object> to a List<int> or a List<string>Eugene
Ext.Direct for ASP.NET MVC
-
17 Nov 2009 8:57 PM #124
First, what other changes? This code is working fine afaik, my arrays are making it to the backend just fine.
Second, apologies, I didn't look in .7 yet, mainly because I've been moving ahead with my development and had already forked for the error data requirement. I will take a look.
Third, what effort? This took about 10 minutes and was running. I expected to be able to send an array of values back from some custom front end code, your .6 code didn't support it and instead threw errors, so I added it.
Fourth, I don't have a case for multidimensional arrays either, but I also haven't written every app that will ever be needed. It's a part of json, and as a developer using the library I would at the minimum be confused why I can't send valid json through. And again it's basically zero work to implement with json.net, just break out a loop and it can be arrays all the way down if someone needs it. (actually array stores use md arrays so it's not entirely out of the realm of possibilty that someone, at some time, may need one too,)
Finally re the list coversion, no there isn't a simple one line way to do it, but there is a call that will call out to other functions for the conversion, that could likely use reflection to properly cast the list. I might figure it out at some point, but since I don't need it right this second, it's not high on my list. It, again, was merely a suggestion of another helper to expand the library and make it more user friendly.
Anyway sorry about not checking 0.7, I'll just keep my suggestions and code to myself. Thanks for the base code, I'll just add on what I need from here since I apparently have such amazingly custom needs.
-
18 Nov 2009 7:51 AM #125
v0.7 is doing everything you need including passing arrays
Except global exception handling that you asked for earlier. I will be releasing v0.7.0.1 soon with a few bug fixes and optimizations.Eugene
Ext.Direct for ASP.NET MVC
-
24 Nov 2009 10:34 PM #126
Ext.Direct.Mvc v0.8 is released.
I have decided to bump the version number to 0.8 because of the number of changes.
The download link is in the first post of this thread.
Changes:Important!Code:* Added: All exceptions now return to the client as a direct response with type "exception" so they can be handled globally by listenening to the "exception" event. * Added: New boolean configuration option called "debug" (optional, default to false). When an exception occures on the server and this option is set to true, the exception response contains a property called "where" with full stack trace. This option should never be set to true in production environment because of security concerns. * Exception response can also contain a property called "exceptionData" with additional user-defined information about the exception. It is set from Exception.Data. To read about Exception.Data and how to set it see http://msdn.microsoft.com/en-us/libr...tion.data.aspx * Changed: Direct() method signatures. Converters are now passed as params array as opposed to List<JsonConverter> as it was done before. * Added: Easy way to return a custom server-side events to the client. To do that simply return the result of one of the DirectEvent() overloaded methods from you action and listen to your event on the client as described in the documentation to Ext.Direct class in "Server side events" section: http://www.extjs.com/deploy/dev/docs/?class=Ext.Direct * Removed: DirectException class. * Misc: Bug fixes, better code organization.
Ext.Direct.Mvc is now licensed under the terms of the GNU Lesser General Public License version 3. A copy of the license can be found in the copying.txt and copying_lesser.txt files included in the distribution. A few people asked for it so here you go.
@Dave.Sanders
I was thinking a lot about your suggestions regarding exception handling and came to a conclusion that it makes total sense in an AJAX app, so I went ahead and implemented everything you asked for. The reason I chose the name "exceptionData" for the property that contains additional data about the exception is because Ext.Direct treats "data" property in the same way as the "result" property, i.e. as a valid returned data. I find it odd, but it is the fact. Anyways, thanks for your suggestions.Eugene
Ext.Direct for ASP.NET MVC
-
25 Nov 2009 4:37 AM #127
Gzip
Gzip
Great work.
I haven't had the time to test the new 0.8 version. But I think it's a great step forwards.
I have another request (or is it already implemented?).
Would it be possible to use gzip if possible to let IIS gzip the generated Javascript dynamicly?
Ofcourse only when gzip is possible. To be checked in the field Request.Headers["Accept-Encoding"].
Another idea. Would it be possible to give the direct proxyclasses in javascript a namespace?Code:HttpResponse Response = HttpContext.Current.Response; string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"]; if (AcceptEncoding.Contains("gzip")) { Response.Filter = new System.IO.Compression.GZipStream(Response.Filter, System.IO.Compression.CompressionMode.Compress); Response.AppendHeader("Content-Encoding", "gzip"); } else { Response.Filter = new System.IO.Compression.DeflateStream(Response.Filter, System.IO.Compression.CompressionMode.Compress); Response.AppendHeader("Content-Encoding", "deflate"); }
I have a
In Javascript this will can be called by:Code:PumpsController: DirectController { //Action ActionResult GetById(int id) { return Direct(data); } }
I try to have everything programmed in ExtJS in useful namespaces.Code:Pumps.Get(id, new function(response)...);
Would it be possible to set a global namespace in the config and/ or set a namespace for a controller through an attribute class?
Just an idea, let me know what you think.Code:Morion.Controllers.Product.Pumps.Get(id, new function(response)...);
Last edited by veenvliet.morion; 25 Nov 2009 at 8:02 AM. Reason: Added another brilliant idea ;)
-
25 Nov 2009 11:43 AM #128
Hi veenvliet.morion,
Thanks for the ideas. I will think about gziping. I do like the idea of being able to overwrite method names, I'll see what I can do about it.
Regarding the namespaces, however, Ext.Direct supports only one namespace for all your direct actions. It creates client-side stubs from a API configuration object of a very strict structure, and there is nothing I can do about it. In my implementation you specify the namespace in the web.config.Eugene
Ext.Direct for ASP.NET MVC
-
26 Nov 2009 12:26 AM #129
Hi,
Thanks for your reaction (by the way, this is my business/ premium account. In private I'm maxigroovy
)
The Gzip is only a matter of adding the header to the response. IIS will take care of the rest.
Renaming methods can also be a bless when having the same method name with different arguments (like you can change the webmethod name in a webservice with the same purpose).
You mean it can be done set the namespace in the web.config?
Code:<ext.direct providerName="Morion.REMOTING_API" apiUrl="DirectApi.ashx" routerUrl="DirectRouter.ashx" assembly="TESTClient" dateFormat="JavaScript"/>
-
26 Nov 2009 1:34 PM #130
Eugene
Ext.Direct for ASP.NET MVC


Reply With Quote