Ext


Go Back   Ext JS Forums > Ext General Forums > Ext: Examples and Extras

Reply
 
Thread Tools
  #1  
Old 09-13-2007, 10:51 AM
Teflon Teflon is offline
Ext User
 
Join Date: Mar 2007
Posts: 74
Teflon is on a distinguished road
Talking [2.0] Write Ext code in C# with ExtJS/ASP.NET/Script#

I really love Ext but coding in javascript just gives me the chills. So I went out and found a way to use my favorite js library (Ext) and my favorite programming language (C#) at the same time. By using a project called Script# I am able to write C# code and have it converted into javascript, similar to GWT. Building on that, Script# also allows you to code against external APIs, but you need to create the types, methods, properties, etc. for everything in the javascript library. So what I did was write a little console app that parses all of the ExtJS source files extracting out the script comments and writing C# files for each class. The end result is a programmable C# API to access all of the Ext objects and I threw in a couple new things to make life a little easier.

Since the entire API is generated, I haven't been able to check every piece of code to make sure nothing is missing, but from what I can tell all of it should be there. The only thing that doesn't work and I have to spend some time to figure out is the methods on Function objects such as createDelegate, defer, etc. Script# includes a createDelegate method but not a defer method. Another feature I want to get done is to create types for each classes constructor config objects so you can get intellisense on the config parameter.

Here is a demo page I put online, this was written entirely in c# code.
It's just the Products in the Northwind DB (Note: This app still uses Ext 1.1.1, I'll update it one day)
http://ext.ordereze.net/scriptsharp/products.aspx

Here's a link to download the complete demo project
http://extsharp.googlecode.com
- The only requirement to run this project locally is to download and install Script# from here and VS2005 of course

And here's the source code for the javascript parser that creates the Ext API
http://extsharp.googlecode.com

UPDATE - 9/14/07
A few things to be aware of when working with this api
  • Since C#/Script# does not allow for classes to be named the same as namespaces, I had to rename a few classes. They are Ext, Toolbar, DomHelper, UpdateManager, SplitBar. These classes have been renamed to {name}Class where {name} is the name of the original class (i.e. Ext becomes ExtClass in Script#).
  • In addition to that, the first thing you need to do before you use any Ext code is run the statement below. This method just tells the browser that the class Ext.ExtClass points to the Ext class
    ScriptSharpAdapter.init();
  • I kept running into a problem where Script# wouldn't compile the code and the reason always was that I was accessing classes using the fully qualified name. (i.e. new Ext.form.TextField()) all you need to do to fix this is to add a using statement for the namespace (using Ext.form;) and then changed the code to be (new TextField())

UPDATE - 9/16/07
I've put all source code and downloads on the GoogleCode project website
http://extsharp.googlecode.com
I'll be making updates to the svn repository over there
The change log can be viewed there as well
http://extsharp.googlecode.com/svn/trunk/CHANGELOG.txt

UPDATE - 10/3/07
This API has been converted to work with the ExtJS 2.0 alpha release. I want to create some samples using it before packaging it up for a release though. Expect an update within the next few days.

UPDATE - 12/5/07
Updated ExtSharp to parse ExtJS v2.0 Final. Zipped up the parser and the samples.

Intellisense


Method Signatures with param info


Method Overloads for varying params


Method Overloads for unlimited param functions
I currently have max 15 overloads, but more can be created by just changing a number in the converter project


Compile-time error checking


Events list with usage info


Delegates for all events


Intellisense for config options
Reply With Quote
  #2  
Old 09-13-2007, 11:46 AM
harley.333's Avatar
harley.333 harley.333 is offline
Ext User
 
Join Date: Mar 2007
Posts: 261
harley.333 is on a distinguished road
Thumbs up

Awesome - please keep up posted on your progress!
Reply With Quote
  #3  
Old 09-13-2007, 11:50 AM
mdissel mdissel is offline
Ext JS Premium Member
 
Join Date: Mar 2007
Location: NL
Posts: 525
mdissel is on a distinguished road
Default

Really great initiative!! If you need any help, just let us know! and keep us posted on updates....

Thanks

Marco
Reply With Quote
  #4  
Old 09-13-2007, 02:20 PM
yaip's Avatar
yaip yaip is offline
Ext User
 
Join Date: Sep 2007
Posts: 6
yaip is on a distinguished road
Default What about VB

Script# seems to be for C# developer only. Anything for VB guys?
Reply With Quote
  #5  
Old 09-13-2007, 02:23 PM
Teflon Teflon is offline
Ext User
 
Join Date: Mar 2007
Posts: 74
Teflon is on a distinguished road
Default

Yeah Script# is only C#, there isn't anything for VB as far as I know.
Reply With Quote
  #6  
Old 09-13-2007, 02:46 PM
J.C. Bize's Avatar
J.C. Bize J.C. Bize is offline
Ext JS - Development Team
 
Join Date: May 2007
Location: Phoenix, AZ
Posts: 171
J.C. Bize is on a distinguished road
Default

Looks really promising, looking forward to your progress
Reply With Quote
  #7  
Old 09-13-2007, 04:57 PM
mdissel mdissel is offline
Ext JS Premium Member
 
Join Date: Mar 2007
Location: NL
Posts: 525
mdissel is on a distinguished road
Default

I started to play with this and got it compiled... It seems you're using a older version of script# (0.4.2 is latest version), but after changing the references all works fine..

It seems that the SP "GetProductsPagedAndSorted" is missing in the database..

(it seems that resharper doesn't handle the checkbox "do not reference mscorlib.dll" ...

Thanks

Marco
Reply With Quote
  #8  
Old 09-13-2007, 05:37 PM
Teflon Teflon is offline
Ext User
 
Join Date: Mar 2007
Posts: 74
Teflon is on a distinguished road
Default

1. I upgraded to Script# v0.4.2 and fixed the references in the zip file above

2. I verified that the sproc "GetProductsPagedAndSorted" is in the db. Here it is if you don't want to download the whole thing again:

CREATE PROCEDURE dbo.GetProductsPagedAndSorted 

(
    @
sortExpression nvarchar(100),
    @
startRowIndex int,
    @
maximumRows int
)
AS

-- 
Make sure a @sortExpression is specified
IF LEN(@sortExpression) = 0
    SET 
@sortExpression 'ProductID'

-- Issue query
DECLARE @sql nvarchar(4000)
SET @sql 'SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued, CategoryName, SupplierName
            FROM (SELECT ProductID, ProductName, p.SupplierID, p.CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued,
                  c.CategoryName, s.CompanyName AS SupplierName, 
                   ROW_NUMBER() OVER (ORDER BY ' 
+ @sortExpression ') AS RowRank
            FROM Products AS p
                    INNER JOIN Categories AS c ON
                        c.CategoryID = p.CategoryID
                    INNER JOIN Suppliers AS s ON
                        s.SupplierID = p.SupplierID) AS ProductsWithRowNumbers
            WHERE     RowRank > ' 
CONVERT(nvarchar(10), @startRowIndex) + 
                
' AND RowRank <= (' CONVERT(nvarchar(10), @startRowIndex) + ' + ' 
                
CONVERT(nvarchar(10), @maximumRows) + ')'

-- Execute the SQL query
EXEC sp_executesql 
@sql 
3. Yes, Resharper doesn't play nice with Script#. I've learned to ignore the "Anbiguous reference" error.

Thanks so much for your comments. I'm glad I'm not the only person who has an interest in this.
Reply With Quote
  #9  
Old 09-13-2007, 08:18 PM
harley.333's Avatar
harley.333 harley.333 is offline
Ext User
 
Join Date: Mar 2007
Posts: 261
harley.333 is on a distinguished road
Talking

I remember seeing Script# about a month ago and thinking it was pretty fantastic. But the very next day, I saw a blog about Microsoft's DLR (Dynamic Language Runtime). Which promises to make techniques like Script# a thing of the past.

But honestly Teflon, I'm very happy you took the initiative, and I'm going to give your code a try. I find JavaScript just as easy to write as C# or VB.Net, but having a compiler check for typos and type safety makes my job that much easier.

Again, thanks a ton!
Reply With Quote
  #10  
Old 09-14-2007, 08:48 AM
rodiniz's Avatar
rodiniz rodiniz is offline
Ext User
 
Join Date: Mar 2007
Location: Rio de Janeiro, Brazil
Posts: 276
rodiniz is on a distinguished road
Send a message via MSN to rodiniz
Default

Nice job.. I thought about doing this, but its a lot of C# code to write
Well done.
__________________
ExtJsExtender Controls
http://www.extendersamples.qsh.eu
My Blog
http://rodiniz.blogspot.com
Reply With Quote
Reply

Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT -5. The time now is 09:37 PM.

© 2006-2009 Ext, LLC
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.