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

      0  

    Default


    Also, I've just added a Name property to the attributes. So, you can alias methods / actions in your code. (I can see this as being very useful if someone were switching between platforms and you didn't want to / couldn't rename all of your methods to match.)

    So, you would declare an action like:

    [DirectAction("user")]
    public class UserController
    {
    [DirectMethod("getUser")]
    public string GetUserById(int Id)
    {...}
    }

    and your client side method would be user.getUser instead of UserController.GetUserById

  2. #42
    Sencha User Gunmen's Avatar
    Join Date
    Jul 2007
    Posts
    305
    Vote Rating
    0
    Gunmen is on a distinguished road

      0  

    Post


    @durlabh: I think this thread must continue as intended, namely a central thread for comments, questions, and improvements regarding Evan's Ext.Direct .NET Router. I appreciate your ExtJs related initiatives but please do not use this thread as a 'promotional platform' for your version.

    @Dave.Sanders: Name property is a good suggestion.

  3. #43
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,167
    Vote Rating
    674
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Dave, I like your ideas, however make sure you've got the latest version (first post of this thread).
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

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

      0  

    Default


    Ok, I've attached my version of the code. I looked around at the latest version, but I think the differences were things that I had modified in my code (in a slightly different way.) If I missed something, please let me know and I'll update my code.

    Some highlights: (any line numbers are from my code)

    1. I've done a little bit of cleaning up in the logic of DirectProcessor around line 58 just to make it more concise.

    2. I've changed out how the JSON is created by using the DefaultValueHandling property on JsonSerializerSettings. (See this thread here on JSON.Net board - it was a feature I implemented, then James modified a year or so ago.) This, combined with [DefaultValue] attributes added to JsonResponse makes the JSON more concise. If an event is sent back, then you don't get the other unnecessary null fields. (DirectProcessor line 60 and attributes in DirectResponse)

    3. I've added DirectEvent, which can be passed back by an action/method to invoke a clientside event in Ext.Direct.

    4. I've modified DirectResponse to recognize an exception or an event and to send different response types down to the client. (DirectResponse line 14)

    5. I've modified DirectProcessor.ProcessRequest to be able to handle the return of a List<object> from the method, and to create a List<DirectResponse> that it passes back to be serialized. This allows events AND data to be sent down to the client at the same time. (Though caution has to be taken due to how events are ran by Ext.Direct.) (DirectProcessor line 77)

    6. I've modified ProcessRequest to catch and handle exceptions. Instead of just handing DirectExceptions like your code does, I handle ALL exceptions, but I've wrapped the try catch in a Preprocessor directive so that the IDE will still catch on errors while in debug mode. You can put it in Release mode to have the errors sent only to the client. (This needs finished to not send down callstack when in Release mode.) (DirectProcessor Line 72)

    I think that's it, but you can see why it was easier to just attach my code instead of trying to describe patches. Take a look and let me know what's good / bad. I'd be happy to help integrate these into your code, or vice versa.

    Cheers
    D

    UPDATED: Code files removed. LATEST CODE IS IN THIS POST

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

      0  

    Default


    UPDATE: Attached a new version of the code, there was a slight bug in finding actions / methods by the name you give to the attribute. Which was a feature I forgot to mention:

    7. You can abstract the name of the action / method used in the client side away from the server side by specifying a name property when using the DirectAction or DirectMethod attributes. example:

    [DirectAction("myAction")]
    public class YourAction
    {
    [DirectMethod("myMethod")]
    public string YourMethod
    }

    would map the clientside myAction.myMethod() to the server side YourAction.YourMethod(). Useful if you really do decide to change your server back end, or having naming conflicts between client side objects and server side objects. I personally use it so that I can name all of my Direct Action classes as "ObjectController" without having to call "ObjectController" on the clientside.

    anyway, the previous post had a bug, so I'm updating the code in that post to fix the bug.

  6. #46
    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 have another version of the library now that will pass back the "enableBuffer" property on methods that I propose in this other thread.

    I don't want to post it up yet because I don't want to muddy the waters between official ext and the ux I'm using for adding this feature to Ext.Direct. But if someone wants it, let me know. The change is pretty straight forward, just add a new property to DirectMethod called enable buffering, and make it render to the json, then use it when you use the DirectMethod attribute when needed.

    I would also suggest adding "enableBuffer" at the Provider level so that it conforms with the Ext.Direct interface.

  7. #47
    Sencha Premium Member
    Join Date
    Jun 2008
    Posts
    51
    Vote Rating
    1
    mbajema is on a distinguished road

      0  

    Exclamation Direct methods not working with directFn & baseParams

    Direct methods not working with directFn & baseParams


    I am using the Router 0.6 and can get it to work by calling a Direct method from my Javascript code, but when I try to use it to populate a combobox specifying a directFn and baseParams, request.Data in DirectProcessor.ProcessRequest ends up looking like this:

    {object[1]}
    [0]: {object}

    I get the following error:
    Error occurred while calling Direct method: Object of type 'System.Object' cannot be converted to type 'System.String'

    It doesn't seem to matter what I put in the baseParams--I'd like to send more than one parameter. Can anyone help me?
    Mark Bajema
    Youth Mentoring Software from Innovative Mentoring

  8. #48
    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 actually haven't tried the Direct Data store stuff yet, or even really looked at it but:

    1. Can we see some code showing how you are calling it and
    2. Can we see what is being sent to the server, via Firebug

    Then maybe I'll have an idea. I should be getting to trying the data store stuff here in the next day or so.

    Dave

  9. #49
    Sencha Premium Member
    Join Date
    Jun 2008
    Posts
    51
    Vote Rating
    1
    mbajema is on a distinguished road

      0  

    Default


    It seems that with the directFn approach, it sends the parameters as a JSON object, so the problem can be reproduced by simply passing a JSON object to a Direct method. For example:
    Code:
    var config = {
         param1: 'test1',
         param2: 2
    };
    
    MyApp.MyDirectMethod(config, function(e, result) {
         alert(Ext.util.JSON.encode(result.result));
    });
    The problem is with the deserialization here:
    Code:
    JsonConvert.DeserializeObject<DirectRequest>(json)
    It deserializes the JSON object into an {object}, but I'm not sure how to cast that into something usable.

    I just tried using durlabh's alternate Ext.Direct .Net implementation (http://extjs.com/forum/showthread.php?t=75311) which uses Microsoft's JavaScript serialization. It deserializes the JSON object into an object that can be cast into a Dictionary<string, object> type.
    Mark Bajema
    Youth Mentoring Software from Innovative Mentoring

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

      0  

    Default


    Ah, for anything that I need to send a JSON object to the server, I encode it first:
    Code:
    Ext.encode(myJSONObject);
    Then it gets sent up as a string to the server.

    In my current case, I am deserializing the string into a dictionary:

    Code:
    JsonConvert.DeserializeObject<Dictionary<string, string>>(FormData.ToString())
    With "FormData" being the result of the Ext.encode.

    That said - this won't handle cases where the object contains objects, etc.