Hybrid View

  1. #1
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,120
    Vote Rating
    508
    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 Ext.Direct .NET Router

    Ext.Direct .NET Router


    Here's my implementation of a .NET router. After seeing some of the others I've modified my original implementation a bit.

    Attached is both the source for the router and a small sample project to demonstrate the functionality.

    http://extjs.com/playpen/router/Router-1.0.zip

    UPDATED ON 24th FEB

    1. Setting up the Api Handler
    The API describes which methods are made available to the client. In the .NET version, this is implemented as an ASHX handler. The handler instances a provider object and passes in
    a) The name of the provider
    b) The url of the handler for this provider
    c) An assembly containing the methods for this provider

    Upon calling the configure method, reflection is used to find all classes with a DirectActionAttribute. From here, any methods marked with either a DirectMethodAttribute or a DirectFormMethodAttribute will be included in the generated API. A simple caching class has been provided. It is recommended you use this to save generating the API on each call to the handler.

    2. The rest

    Simply setup your handler ASHX, in this case I've called it DirectHandler.ashx. From here, all we need to do is pass the appropriate provider and the HttpRequest to our processor and it will return a result.

    NB: Any form methods will only be passed a single parameter, which is the HttpRequest object. Any other parameters are ignored.


    Comments/questions/improvements welcome.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  2. #2
    Sencha User
    Join Date
    Dec 2008
    Location
    Mainz
    Posts
    241
    Vote Rating
    1
    crp_spaeth is on a distinguished road

      0  

    Default


    Cool! I just gave it a short look... A few more nice ideas! Since I have followed the last .net thread, I am working on a similar implementation too! So I am counting 3 yet...
    I have just started an Open Source Project and commited the code from "shibubh" with a small change in the router it self today... What do you think about merging our ideas together?

    Two things i got on my list for the shibubh's current Implementation:

    - Pack things to a Dll so you dont need to add those aspx files to an existing Project
    http://msdn.microsoft.com/en-us/libr...ssrequest.aspx
    (makes it possible to add the proxy and router handler via web.config)

    - Use JSON.NET for de- and -serialization see: http://www.codeplex.com/Json
    Thinking about restrict to the use of Static classes or even support them. (This is importent cause of performance issues in big applications)



    So As i have Seen so far your version solves the second point nicely... But what do you think about the first one?


    regards

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

      0  

    Default


    This is great! Thanks so much, Evan.

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,120
    Vote Rating
    508
    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


    RE:

    1) You need to do some configuration to get this working, for example, passing in the assembly. I guess you could do that with a config file, however my .NET is rather rusty.

    Would you have me include the core stuff in the Ext.Direct dll and then have the user extend the ashx?

    2) As you mentioned, it's using JSON.NET internally.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  5. #5
    Ext User shibubh's Avatar
    Join Date
    Jul 2007
    Location
    Lamahi,Dang Nepal
    Posts
    449
    Vote Rating
    -2
    shibubh is on a distinguished road

      0  

    Default


    hi evant,
    thanks for sharing. Cool stuff. i just loved it. i love the you way code it.
    Shibu Bhattarai

    Use JavaScript beautifier to beautify you code http://jsbeautifier.org/

    Code Conventions http://javascript.crockford.com/code.html

    ExtJS Core Manual http://extjs.com/products/extcore/manual/

  6. #6
    Sencha User boolean's Avatar
    Join Date
    Aug 2007
    Location
    china beijing
    Posts
    22
    Vote Rating
    0
    boolean is on a distinguished road

      0  

    Thumbs up


    good work, good idea
    this is something like ajaxpro,but it's better then ajaxpro.
    we can paste the client extjs and the server side c# method with it.

  7. #7
    Ext User
    Join Date
    Mar 2008
    Posts
    2
    Vote Rating
    0
    alekdigital is on a distinguished road

      0  

    Default Modofications

    Modofications


    That was great!

    But the issue is if you have tons of pages in one assembly that need lots of Ajax function for different purposes, it renders all methods to every page while it might not be needed, so I made some modification (in sample application not Library), hope that helps:

    Instead of including ApiHandler.ashx as a script block, I used it as a helper class like this:

    public static void Register(Page page) {

    DirectProviderCache cache = DirectProviderCache.GetInstance();
    DirectProvider provider;

    string hash = GetHashKey(page);
    string key = "Ext.app.REMOTING_API." + hash;

    //After being configured, the provider should be cached.
    if (!cache.ContainsKey(key)) {
    provider = new DirectProvider("Ext.app.REMOTING_API", "/DirectHandler.ashx?hash=" + hash);
    provider.Configure(new object[] { page });
    cache.Add(key, provider);
    }
    else {
    provider = cache[key];
    }

    string script = provider.ToString();
    page.ClientScript.RegisterClientScriptBlock(page.GetType(), "ApiHandler", script, true);
    }


    private static string GetHashKey(Object o) {
    return o.GetType().GetHashCode().ToString();
    }

    The every page that needs this functionality has to call:

    ApiHandler.Register(this);
    In the Load event.

    As this register every page in different Cache key reference I needed to do an alter in Directhandler as well:

    public void ProcessRequest(HttpContext context)
    {
    string key = "Ext.app.REMOTING_API." + context.Request.QueryString["hash"];

    DirectProvider provider = DirectProviderCache.GetInstance()[key];
    context.Response.ContentType = DirectHandlerContentType;
    context.Response.Write(DirectProcessor.Execute(provider, context.Request));
    }
    By moving these two lines:

    Ext.ns('Ext.app');
    Ext.Direct.addProvider(Ext.app.REMOTING_API);
    Inside of Ext.onReady method in default.aspx page, every thing is ready to go to use functions that are defined in pages. So every page has access to it's own functions only, that help organizing methods.

    Note: When registering an action, it gets name of page's type, that returns 'default_aspx' instead of Default, so I had to call:
    default_aspx.Echo(.....);

    Alek.



    PS: adding provider can be moved to Register function in helper class like this:
    string script = provider.ToString();
    script += @"
    Ext.ns('Ext.app');
    Ext.Direct.addProvider(Ext.app.REMOTING_API);";

    page.ClientScript.RegisterClientScriptBlock(page.GetType(), "ApiHandler", script, true);
    So in the page there is no need to register the provider, and it will be ready on load.

    Alek.
    Last edited by alekdigital; 14 May 2009 at 5:41 AM. Reason: Move addProvider ro Register Function

  8. #8
    Ext User
    Join Date
    Mar 2008
    Posts
    125
    Vote Rating
    0
    thomson is on a distinguished road

      0  

    Default


    Can somebody let me know which is the latest Router Version?

    Thanks in Advance
    Thomson

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

      0  

    Default


    Latest "official" code is in post #1 (the 0.6 version)

    My latest code with the additions I've mentioned in this thread, which I don't believe the Ext team has had time to evaluate and include, are in this message:

    http://extjs.com/forum/showthread.ph...222#post366222

    Or on my site at:

    http://vulgrin.com/DavesExtDirectBranch.zip

    because someone had a problem unzipping the version I uploaded.

    I would have started a new thread for my "branch" but the changes aren't all that different and I'd rather they just get included in the original code. There was talk about setting up a google code for it, and if someone at Ext wants to do that then I'll happily seed it with my latest copy to eliminate confusion.

    D

  10. #10
    Ext User
    Join Date
    Mar 2008
    Posts
    125
    Vote Rating
    0
    thomson is on a distinguished road

      0  

    Default


    Hello All,
    I have tried using the router version 6 i have tried calling a function using Ext.Direct

    In firebug i can see there is a post happening to the handler and immediately i am getting the

    uncaught exception: Ext.data.DataProxy: DataProxy attempted to execute an API-action but found an undefined url / function. Please review your Proxy url/api-configuration.

    I am loading the store using the following code

    Code:
    var mystore = new Ext.data.DirectStore({
        paramsAsHash: false,
        root: 'Rows',
        api: {
            load: MyApp.Sample.GetOrder('labelle')
        },
        //directFn: ,
        idProperty: 'id',
        autoLoad: true,
        fields: [
                        { name: 'id' },
                        { name: 'name' }
                   
    
                ],
    
        listeners: {
            load: function(s, records) {
                Ext.MessageBox.alert("Information", "Loaded " + records.length + " records");
            },
            beforeload: function(t, params) {
                Ext.MessageBox.alert(t);
            },
            exception: function(current, action, rs, params) {
                Ext.MessageBox.alert(action);
    
            }
        }
    });
    
    var grid = new Ext.grid.GridPanel({
                store:mystore,
                 cm: new Ext.grid.ColumnModel([
                                new Ext.grid.RowNumberer(),
                                { header: "+/-", width: 120, sortable: true, dataIndex: 'id' },
                                { header: "Sel", width: 70, sortable: true, dataIndex: 'name' },
                                  
                               ]),
    
                viewConfig: {
                    forceFit: true
                }      
    
            });
    The Response will be having a Result attribute which having my json, How do i tell the reader to take only that

    Thanks in Advance

    Thomson

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar