project nimbus

Post on 03-Jul-2015

409 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Lim Cheng Lei

Microsoft Student Partners Singapore

Data and Services Marketplace for Innovators

What is Project Nimbus?

Datasets Available

Project Nimbus

Cinema Online

Hungry Go Where

Land Transport Authority

National Library Board

National Environment Agency

Singapore Tourism Board

Sing Post

Show Near By

Urban Redevelopment Authority

Behind Project Nimbus Architecture

Easy access to data services

Existing Service

Data Service in Project Nimbus

Deliver to End Users

Project Nimbus Architecture

Existing ServiceData services built in Project Nimbus

Applications used by End Users (Consumers)

Project Nimbus Architecture

Data information from Content Providers

Web Service – http://api.projectnimbus.org/yourodataservice.svc/

Sample Application Architecture

http://api.projectnimbus.org/yourodataservice.svc/

http://<yourapp>.com

Show Near By

Hungry Go

Where

Cinema Online

Getting Started

3 Steps to Use

Developing on Project Nimbus

Get access to Project Nimbus

Call the Web Service

Start Developing

Get access to Project Nimbus

Project Nimbus Credentials

How do I get access?

• Email us: projectnimbus@live.com.sg

– Account Key[Request from Project Nimbus]

–Unique User ID[Generate your own 32 characters GUID]

eg. 00000000000000000000000000000001

Call the Web Service

Project Nimbus Data Service

Querying Data Service

• http://api.projectnimbus.org/tool.aspx– http://api.projectnimbus.org/coodataservice.svc/MovieSet

– http://api.projectnimbus.org/snbodataservice.svc/ATMSet

http://api.projectnimbus.org/coodataservice.svc/

XML Data of available properties

(ODATA Format)

$metadata

Start Developing

Mesh with Project Nimbus

Mesh the data services

Innovate Applications

Getting Started with C#

Calling the Web Service I

public List<MovieEntry> GetMovieFromNimbusCO()

{

WebRequest wr =HttpWebRequest.Create("http://api.projectnimbus.org/coodataservice.svc/MovieSet?");

wr.Headers.Add("AccountKey", "YourAccountKeyHere");

wr.Headers.Add("UniqueUserID", Guid.NewGuid().ToString());

wr.Method = "GET";

WebResponse res = wr.GetResponse();

string resStr = new System.IO.StreamReader(res.GetResponseStream()).ReadToEnd();

XNamespace atomNS = "http://www.w3.org/2005/Atom";

XNamespace dNS = "http://schemas.microsoft.com/ado/2007/08/dataservices";

XNamespace mNS = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";

Calling the Web Service II

List<MovieEntry> results =

(from item in XElement.Parse(resStr).Descendants(atomNS + "entry")

let movie = item.Element(atomNS + "content").Element(mNS +"properties")

select new MovieEntry() {

MovieID = movie.Element(dNS +"MovieID").Value,

Name = movie.Element(dNS +"Name").Value,

ReleaseDate = movie.Element(dNS + "ReleaseDate").Value,

Classification = movie.Element(dNS + "Classification").Value }).ToList();

return results;

}

What are proxy classes?

• Individual class files for each datasets of the data services

• Easier for developers to call the datasets from the data services without much effort

• Pre-generated proxy classes

– Developers do not need to code anything

Why should I use proxy classes?

• Simplifies coding process

• .NET to process all the consummation of data back end

• 5 lines of code

– Able to select specific data to display

• Using LINQ to query data services

How can I use it?

• ADO.NET Data Services v1.5 CTP2

• Add Reference > Browse Tab > C:\Program Files\ADO.NET Data Services V1.5 CTP2\bin\Microsoft.Data.Services.Client.dll

• Import in the relevant *Proxy.cs class file into your project (For example, SNBProxy.cs)

Calling the Web Service I (Using LINQ)

protected void Page_Load(object sender, EventArgs e)

{

SNBModel.SNBEntities snbEntities = new SNBModel.SNBEntities(newUri("http://api.projectnimbus.org/snbodataservice.svc/"));

snbEntities.SendingRequest += ModifyRequest;

GridView1.AutoGenerateColumns = true;

GridView1.DataSource = snbEntities.ATMSet.ToArray();

GridView1.DataBind();

}

private static void ModifyRequest(object sender, SendingRequestEventArgs e)

{

e.Request.Headers.Add("AccountKey", “YourAccountKeyHere");

e.Request.Headers.Add("UniqueUserID", Guid.NewGuid().ToString());

}

Calling the Web Service II (Using LINQ)

protected void Page_Load(object sender, EventArgs e)

{

SNBModel.SNBEntities snbEntities = new SNBModel.SNBEntities(newUri("http://api.projectnimbus.org/snbodataservice.svc/"));

snbEntities.SendingRequest += ModifyRequest;

GridView1.AutoGenerateColumns = true;

GridView1.DataSource = snbEntities.ATMSet.ToArray();

GridView1.DataSource = (from c in snbEntities.ATMSet

select new { c.Name, c.Latitude, c.Longitude }).ToArray();

GridView1.DataBind();

}

Getting Started with Silverlight

Why Silverlight?

What do I need?

• ADO.NET Data Services for Silverlight 3 CTP 3

• Add Reference > Browse Tab > C:\Program Files\ADO.NET Data Services for Silverlight 3 CTP 3\System.Data.Services.Client.dll

Calling the Web Service I

DataServiceCollection<SNBModel.ATM> atms;

public MainPage()

{

InitializeComponent();

SNBModel.SNBEntities snbEntities = new SNBModel.SNBEntities (newUri("http://api.projectnimbus.org/snbodataservice.svc/"));

snbEntities.SendingRequest += ModifyRequest;

DataServiceQuery<SNBModel.ATM> query = snbEntities.ATMSet;

try

{

// Begin the query execution.

query.BeginExecute(OnATMSQueryComplete, query);

}

Calling the Web Service II

private void OnATMSQueryComplete(IAsyncResult result)

{

// Use the Dispatcher to ensure that the asynchronous call returns in the correct thread.

Dispatcher.BeginInvoke(() =>

{

// Get the original query back from the result.

DataServiceQuery<SNBModel.ATM> query = result.AsyncState as DataServiceQuery<SNBModel.ATM>;

try

{

List<SNBModel.ATM> returnedATMs = new List<SNBModel.ATM>();

Calling the Web Service III

foreach (var atm in (query.EndExecute(result)))

{

returnedATMs.Add(atm);

}

if (returnedATMs != null)

{

DataGrid1.ItemsSource = returnedATMs;

DataGrid1.DataContext = returnedATMs;

DataGrid1.UpdateLayout();

}

} catch(DataServiceQueryException) { }

});

}

Getting Started with Java

Parsing the Atom Feed

public static String getStringBetween(String src, String start, String end) {

StringBuilder sb = new StringBuilder();

int startIdx = src.indexOf(start) + start.length();

int endIdx = src.indexOf(end);

while(startIdx < endIdx){

sb.append(“” + String.valueOf(src.charAt(startIdx)));

startIdx++;

}

return sb.toString();

}

Calling the Web Service I

public ArrayList<ATM> getATMS() {

atmList = new ArrayList<ATM>();

try {

URL _url = new URL(“http://api.projectnimbus.org/snbodataservice.svc/ATMSet?”);

URLConnection _urlConn = _url.openConnection();

_urlConn.setRequestProperty(“accept”, “*/*”);

_urlConn.addRequestProperty(“AccountKey”, “YourAccountKeyHere”);

_urlConn.addRequestProperty(“UniqueUserID”, “YourUniqueUserID”);

BufferedReader br = new BufferedReader(new InputStreamReader(_urlConn.getInputStream()));

Calling the Web Service II

String line = null;

StringBuilder strBuilder = new StringBuilder();

while ((line = br.readLine()) != null) {

strBuilder.append(line);

System.out.println(line);

}

}

Calling the Web Service III

String[] IProperties = strBuilder.toString().split("<m:properties>");

for (String str : IProperties) {

ATM atm = new ATM();

atm.setName(Utils.getStringBetween(str, “<d:Name>”, “</d:Name>”));

atm.setRoad(Utils.getStringBetween(str, “<d:Road>”, “</d:Road>”));

atm.setPostal(Utils.getStringBetween(str, “<d:Postal>”, “</d:Postal>”));

atmList.add(atm);

}

} catch(...) { }

return atmList;

}

www.projectnimbus.org

innovativesingapore.comtwitter.com/innovativesg

top related