1. #121
    Ext User Dave.Sanders's Avatar
    Join Date
    Mar 2008
    Posts
    131
    Vote Rating
    0
    Dave.Sanders is on a distinguished road

      0  

    Default


    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

  2. #122
    Ext User Dave.Sanders's Avatar
    Join Date
    Mar 2008
    Posts
    131
    Vote Rating
    0
    Dave.Sanders is on a distinguished road

      0  

    Default


    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();
            }
        }

  3. #123
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    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 might be an easy way to cast this List<object> to a List<int> or a List<string>
    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.

  4. #124
    Ext User Dave.Sanders's Avatar
    Join Date
    Mar 2008
    Posts
    131
    Vote Rating
    0
    Dave.Sanders is on a distinguished road

      0  

    Default


    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.

  5. #125
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    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.

  6. #126
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    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:
    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.
    Important!
    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.

  7. #127
    Ext JS Premium Member veenvliet.morion's Avatar
    Join Date
    Oct 2009
    Location
    Netherlands
    Posts
    24
    Vote Rating
    0
    veenvliet.morion is on a distinguished road

      0  

    Lightbulb 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"].

    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");
                    }
    Another idea. Would it be possible to give the direct proxyclasses in javascript a namespace?
    I have a

    Code:
    PumpsController: DirectController
    {
        //Action
        ActionResult GetById(int id)
        {
            return Direct(data);
        }
    }
    In Javascript this will can be called by:
    Code:
    Pumps.Get(id, new function(response)...);
    I try to have everything programmed in ExtJS in useful namespaces.
    Would it be possible to set a global namespace in the config and/ or set a namespace for a controller through an attribute class?

    Code:
    Morion.Controllers.Product.Pumps.Get(id, new function(response)...);
    Just an idea, let me know what you think.
    Last edited by veenvliet.morion; 25 Nov 2009 at 8:02 AM. Reason: Added another brilliant idea ;)

  8. #128
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    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.

  9. #129
    Ext JS Premium Member veenvliet.morion's Avatar
    Join Date
    Oct 2009
    Location
    Netherlands
    Posts
    24
    Vote Rating
    0
    veenvliet.morion is on a distinguished road

      0  

    Default


    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"/>

  10. #130
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    Quote Originally Posted by veenvliet.morion View Post
    Hi,
    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"/>
    Absolutely. Check out the first post of this thread. Configuration section in particular.

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi