project nimbus

37
Lim Cheng Lei Microsoft Student Partners Singapore Data and Services Marketplace for Innovators

Upload: limchenglei

Post on 03-Jul-2015

409 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Project Nimbus

Lim Cheng Lei

Microsoft Student Partners Singapore

Data and Services Marketplace for Innovators

Page 2: Project Nimbus

What is Project Nimbus?

Page 3: 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

Page 4: Project Nimbus

Behind Project Nimbus Architecture

Easy access to data services

Existing Service

Data Service in Project Nimbus

Deliver to End Users

Page 5: Project Nimbus

Project Nimbus Architecture

Existing ServiceData services built in Project Nimbus

Applications used by End Users (Consumers)

Page 6: Project Nimbus

Project Nimbus Architecture

Data information from Content Providers

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

Page 7: Project Nimbus

Sample Application Architecture

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

http://<yourapp>.com

Show Near By

Hungry Go

Where

Cinema Online

Page 8: Project Nimbus

Getting Started

Page 9: Project Nimbus

3 Steps to Use

Developing on Project Nimbus

Get access to Project Nimbus

Call the Web Service

Start Developing

Page 10: Project Nimbus

Get access to Project Nimbus

Project Nimbus Credentials

Page 11: Project Nimbus

How do I get access?

• Email us: [email protected]

– Account Key[Request from Project Nimbus]

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

eg. 00000000000000000000000000000001

Page 12: Project Nimbus

Call the Web Service

Project Nimbus Data Service

Page 13: Project Nimbus

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

Page 14: Project Nimbus

Start Developing

Mesh with Project Nimbus

Page 15: Project Nimbus

Mesh the data services

Innovate Applications

Page 16: Project Nimbus

Getting Started with C#

Page 17: Project Nimbus

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";

Page 18: Project Nimbus

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;

}

Page 19: Project Nimbus

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

Page 20: Project Nimbus

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

Page 21: Project Nimbus

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)

Page 22: Project Nimbus

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());

}

Page 23: Project Nimbus

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();

}

Page 24: Project Nimbus

Getting Started with Silverlight

Page 25: Project Nimbus

Why Silverlight?

Page 26: Project Nimbus

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

Page 27: Project Nimbus

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);

}

Page 28: Project Nimbus

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>();

Page 29: Project Nimbus

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) { }

});

}

Page 30: Project Nimbus

Getting Started with Java

Page 31: Project Nimbus

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();

}

Page 32: Project Nimbus

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()));

Page 33: Project Nimbus

Calling the Web Service II

String line = null;

StringBuilder strBuilder = new StringBuilder();

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

strBuilder.append(line);

System.out.println(line);

}

}

Page 34: Project Nimbus

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;

}

Page 35: Project Nimbus
Page 36: Project Nimbus

www.projectnimbus.org

Page 37: Project Nimbus

innovativesingapore.comtwitter.com/innovativesg