Download Source and Example :
Most of you must have heard about Astoria. Read More about it here , if you haven't already :Microsoft Codename "Astoria".The Astoria Team Blog :
It's a "Database in the cloud", your db is hosted on the Web and you access it via REST -style URIs.I have written a ControlExtender that helps one retrieve data and post data to a db on Astoria using JavaScript.The Extender encapsulates its own Server-Side handler so that you don't have to write a Server-Side proxy to avoid Making Cross-Domain Requests from the Client browser.
The way it would work is :Client Browser =====> Server-Side handler ===> Astoria Servers
When the Client Script tries to download the data from the Astoria Servers, the following process is followed
What does the Extender NOT do ?
The Extender does NOT Support the following Scenarios
Events Supported by the Extender:
Subscribing to the Events of the Astoria Data Source Extender :
The BehaviorID of the Extender added on the page is : "asBehavior"
//Subscribing to the dataReady event $find("asBehavior").add_dataReady( dataReadyHandler ); //Subscribing to the dataDownloadBegins event $find("asBehavior").add_dataDownloadBegins(<functionName>); //Subscribing to the dataDownloadEnds event $find("asBehavior").add_dataDownloadEnds(<functionName>); //Subscribing to the dataDownloadError event $find("asBehavior").add_dataDownloadError(dwError);
//The dataReady Event handler function dataReadyHandler(sender,eventArgs) { alert("The Data returned is :: "+eventArgs.get_data()); }
//The dataDownloadError Event handler function dwError(sender,eventArgs) { Sys.Debug.trace("error Code ::"+eventArgs.get_error().ErrorCode); Sys.Debug.trace("error Message ::"+eventArgs.get_error().ErrorMessage); }
Attributes Supported by the Extender
Usage Examples
$find("asBehavior").get_currentPageIndex();$find("asBehavior").set_currentPageIndex(2);
//Retrieve the Table 'Categories' from the 'NorthWind' Database $find("asBehavior").set_dbURI("http://astoria.sandbox.live.com/northwind/northwind.rse"); $find("asBehavior").set_query("/Categories");
$find("asBehavior").set_dataFormat("json"); $find("asBehavior").set_pageSize(10);
Methods Supported by the Extender
Bind the data to the client :$find("asBehavior").DataBind() Move to a Specific page of data ://Move to the 3rd page $find("asBehavior").set_currentPageIndex( 2 ); $find("asBehavior").DataBind(); Move to the Next page$find("asBehavior").set_currentPageIndex( $find("asBehavior").get_currentPageIndex() + 1 ); $find("asBehavior").DataBind(); Move to the Previous page$find("asBehavior").set_currentPageIndex( $find("asBehavior").get_currentPageIndex() - 1 ); $find("asBehavior").DataBind();
Bind the data to the client :
$find("asBehavior").DataBind()
Move to a Specific page of data :
//Move to the 3rd page $find("asBehavior").set_currentPageIndex( 2 ); $find("asBehavior").DataBind();
Move to the Next page
$find("asBehavior").set_currentPageIndex( $find("asBehavior").get_currentPageIndex() + 1 ); $find("asBehavior").DataBind();
Move to the Previous page
$find("asBehavior").set_currentPageIndex( $find("asBehavior").get_currentPageIndex() - 1 ); $find("asBehavior").DataBind();
Markup Way of doing the above
<Raj:AstoriaDSExtender runat="server" ID="asbehaviorPnl" BehaviorID="asBehavior" TargetControlID="btnAstoria" DatabaseURI="http://astoria.sandbox.live.com/northwind/northwind.rse" DataFormat="json" StartPageIndex="0" PageSize="1" Query="/Categories" ExpandRecord="Products" OnClientDataDownloadError="dwError" OnClientDataReady="endDownload" ErrorPanelId="divContainsErrorInfo" />
Setting up your project to use the Astoria ExtenderWeb.Config :1. Register the Handler for the ExtenderAdd the Below line to the <httpHandlers> Section of your web.config.<add path="*.astoria" verb="*" type="AstoriaExtenders.AstoriaHandler"/>
2. The Tag Prefix for the ExtendersAdd this line to the <controls> Section of the <Pages> Section in web.config<add tagPrefix="Raj" namespace="AstoriaExtenders" assembly="AstoriaExtenders"/>
3. Set up the proxy so that the Web Server can talk to the Astoria Servers.<system.net> <defaultProxy> <proxy usesystemdefault="False" proxyaddress=http://proxyServerName bypassonlocal="True"/> </defaultProxy> </system.net>
PingBack from http://www.soundpages.net/computers/?p=3494
Good one Phani!!!
PhaniRajuYN posted a very interesting post about Astoria DataSource Extender. (You can read my Getting