Tagarchief: silverlight

What I wanted to create was an app that parsed an html site. This because this specific site doesn’t has an official api, so I needed to work around this :mrgreen:

First of all, I needed to get back “into programming”, the last time I’ve programmed was like ages ago ^^ So, back into c#, jej :mrgreen:

After some googling I learned that silverlight in .net worked with an asynchronous call for internet-activities. This ofcourse because a cellular network connection is slow, and you don’t want to stall the GUI.

The method to do this is by using a class called “WebRequest”.
The method is started by using “BeginGetRequestStream“, which starts the fetch in another thread besides the GUI.
When the data is downloaded a callback function is called, so you need to create this as well…

This resulted in some code like the one below:

private void login(string username, string password) {
//the url where we want to go, here no postdata is specified, because the site only uses the postdata in the url
string url = "" + username + "&password=" + password + "&new_language=english&submit=login";

//the initation of a request to a webpage
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
//something for cookies between different httprequests, later more
//webrequest are handled syncronous, on completion the callback is called
IAsyncResult result = (IAsyncResult)request.BeginGetResponse(new AsyncCallback(GetStatusesCallBack), request);

//callback thread
private void GetStatusesCallBack(IAsyncResult result)
string returnValue;
//get the state of the request
var request = (HttpWebRequest)result.AsyncState;
//if completed, put respons in variable
var response = request.EndGetResponse(result);
using (var stream = response.GetResponseStream())
//a streamreader to put the html in a string
using (var reader = new StreamReader(stream))
returnValue = reader.ReadToEnd();
//a third function to update the gui :-)

For my application I needed a method to store some information (email and password). Appearantly each application is given 1MB of datastorage in a database on your phone. More info on this site:

//calling the default constructor
private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
//add a mail of a user to the windows phone database
appSettings.Add("email", "");
//to retrieve data from this db
tbResults.Text = (string)appSettings["email"];

I ran into an issue, because I used 2 different WebRequest because I need to fetch 2 different pages (1 to login, a second to get the information from). But when getting the 2nd page, the login was already gone. Probably a cookie issue. So I ran into this site which solved my problem.

//first we define a cookie container: a context where our cookies are stored:
private CookieContainer cookies = new CookieContainer();
//in the first request we recall this container
//and again in the second request we recall the same container

Then, my second application I wanted to download an image from a website. After some googling found the following method to work:

//just to easy, placing an uri as an image source
Uri uri = new Uri("http://locationofimage.jpg", UriKind.Absolute)
image1.Source = new BitmapImage(uri);

And to create a nice and simple overview I wanted to use the default windows “listbox”, but I didn’t know how to use it. Thankfully this website helped me out:

One of the best initiatives Microsoft has created for us, poor students, is the platform called DreamSpark

For the people that are not familiar with it: it offers a lot of ide’s and tools, and even some full featured os’ses so you can start develop within a couple of hours, read: visual studio, windows server, sql server, windows embedded, etc… And all of this is for free if you are a student. NIIIIICE šŸ˜Ž

Anyway, when you want to develop something for Windows Phone, you get the emulator. But eventually, you want to test your app on a real world device (at least, I want that šŸ˜€ ).
The privilege of placing your app in the appstore, and thus being able to test this on a physical device, is reserved for developers who pay $99… And for students, when you register via DreamSpark… NIIICE again! šŸ˜Ž

Because you are getting a spot in the marketplace for free, you have to be authenticated. This authentication process is done by geotrust, a third party doing Microsoft’s work šŸ˜›

The process exisits out of 3 steps

  1. creating an application in visual studio and debugging using the emulator
  2. uploading your app to the app hub
  3. getting authenticated by geotrust

And you’re ready to go šŸ˜Ž

Currently, IĀ  passed the authentication process from geotrust by scanning my Belgian ID and e-mailing this towards geotrust. (A couple of stupid errors came trough, like for example “mendel alias” is not my real name of-course… šŸ˜€ , but the guys are geotrust where wonderful, thx again if you’re reading this!)

So, from now on, I’m an official WindowsPhone developer! Lol ^^

First app in the marketplace (still needs to be approved) is a check tool (like for example the mobilevikings tool) for the download statistics of my ISP: Dommel.

We’ll see how everything turns out in the future šŸ˜Ž

Yes, I’ve bought an Windows Phone device šŸ˜ˆ

And you can of course use it to call people, browse the internet and listen to some music…

But the real geek starts developing ofcourse šŸ˜Ž

I already have some idea’s for “funny/cool/useful?” programs, let’s name some of them (maybe someone can steal my ideas and make it in a REAL useful application)

  1. a dommel download meter, to see how much broadband you have left
  2. an application that shows the traffic camera’s of the flemish traffic control, perhaps with the location of the speed control?
  3. a wifi scanner that has the functionality of for example inssider

But first, getting back into programming
Second, getting back into .net-programming šŸ˜†

Maybe I’ll post some code snippets here šŸ˜‰

Wish me luck!