Monthly Archives: October 2012

Developing Windows Store App Part 3: Ćevap Explorer Windows Store App

First of  all, I had great two sessions talking about developing  Windows 8 Line of business App by presenting my main demo Ćevap Explorer. In September I held session in Sarajevo at MSCommunityBH Conference, and yesterday in Belgrade at Sinergija 12.

Now It time to publish whole solution and source code for this app.

In previous two parts I was trying to explain how model data looks like in Ćevap Explorer, and expose it in order to be consumed by Windows 8 Store app.

At the end of the blog post you will find complete source code, but before you start you need to prepare solution for run.

Here is step by step instruction how to achieve this.

1. Unzip downloaded file with solution, and copy folder of database file in your location. Use SQL Server Management Studio and attach the database. The picture below shows where is that folder.

After you attach the Database, you need to change connection string in Rest Service, in order to use the right database.

2. Start VS 2012 as Administrator and open web.config file of RestService. The picture shows my configuration, bu you need to define you own connection string, with right user name.

3. Check is CevapExplorer is you start up project and hit F5. Now you will get this:

4. Use standard Windows 8 Search (Win+Q) to find places with great Ćevap. After you find Item, click on picture to open details about it. If you want to see AppBar in action right click and choose Edit button.

You can download whole solution from this link. I hope you will find some interesting implementation in this demo.


Oktobarski sastanak Bihac .NET UG

Termin sastanka: 31. 10. 2012. 17:00, Tehnički fakultet Bihać

Nakon ljetnje pauze i septembaskih obaveza zakazujemo naredni sastanak Bihac .NET UG. Naime, u srijedu 31. oktobra sastaćemo se na starom mjestu, na Tehničkom fakultetu u Bihaću i održati sastanak na temu razvoja Windows 8 aplikacija. Ovog puta moja malenkost će održati predavanje pod nazivom “Consuming data in Windows 8 Store apps” u narednom tekstu date su detaljne informacije o predavanju.

Tema: Consuming data in Windows 8 Store app / Konzumacija podataka u Windows 8 Store aplikacijama

Level: 300

Predavač: Bahrudin Hrnjica, Microsoft MVP

Opis: Windows 8 Store aplikacije izvršavaju se u izoliranom okruženju kojim upravlja Windows Run-Time. Ova okolina pruža mogućnosti razvoja aplikacija pod nazivom Windows Store app, odnosno novi tip aplikacija koje se vrte na Windows 8 OS. Jedna od karakteristika ovih aplikacija je što su prilagođene za pokretanje na raznim uređajima od notebooka, tableta do PCa, i što mogu da se distribuiraju na Windows Store globalnu prodavnicu Windows 8 aplikacija. Jednistvenost platforme daje i određena ograničenja, a u ovom predavanju ćemo vidjeti na koji način Windows Store aplikacijama obezbijediti podatke iz različitih izvora podataka, a posebno sa SQL Servera. Widnows Store aplikacija nisu u mogućnosti da direktno pristupe Entity Framework ORM maperima, pa smo prisiljeni da koristimo ili ASP.NET Web API ili WCF. Demo primjeri će pokazati kako koristiti HTTPClient klasu za pristup podacima preko pomenutih serverskih tehnolgija. S druge strane na predavanju će biti pokazano kako koristiti SQLite C++-cross-platform biblioteku u Windows Store applikacijama direktno bez korištenja pomenutih Rest i WCF tehnologije. Kroz demo primjere predavanje će dati kompletnu sliku kako Windows Store aplikacija mogu koristiti podatke iz vanjskih izvora bez kojih je teško zamisliti današnju modernu Windows 8 Store aplikaciju.

Na sastanku će biti i nekoliko nagrada na najsretnije i najaktivnije članove. Nagrade su: majica, usb stik, …..

GPdotNET v2 release date is Nov, 04. 2012.

GPdotNET Logo

GPdotNET Logo

I am very happy to announce that GPdotNET v2 will be released at November 4th this year. All planned tests are performed, and it is only left some minor corrections and review of User Manual. When GPdotNET v2 would be released it will be available with ClickOnce instalation, so you can stay up do date with further updates at the same time when it would be released.

The click once instalation will be placed on CodePlex site too, and can be downloaded from Downloads  section of the project site.

There were also some improvement from the last Beta 3 version:

–  Thread creation form background processing was replaced with Task class

– Logo Icon is added to execute file.

– Some minor bugs found while testing  on Fedora 17 and MonoDevelop. I hope GPdotNET will run with no bugs on Fedora 17 too.

– GPdotNET page on my blog is also updated with more informations:

How to convert your old sequential code in to async

There are plenty of ansyc samples over the internet, and most of them are different and not satisfy your requirements. Actually, async pattern depends of its creator, and can be implement on various ways. It is important to understand the async pattern in order to use it. Only on this way, you can stop searching for exact sample you need, and start coding your own async code.  More that year ago, I wrote simple blog post about async pattern (part 1 and part 2) (Bosnian language), and also wrote how to call Entity Framework with async pattern as well.

Today I am going to show you how old synchronous code block convert in to asynchronous. I think it is interesting because async pattern can improve your existing applications on various ways. First of all async pattern can increase responsiveness of  an application, performance, etc.

First of all, create simple Windows Forms sample and implement synchronous code.This will represent our old application, in which we are going to implement new programming paradigm.

1. Create Windows Forms Project, Name it “WinFormsAsyncSample

2. Design your main form (Form1.cs) exactly as picture shows below, and implement events.

As picture shows we have few labels, one text box, one progress bars, and two buttons.

Note: At the end of the blog you can download both versions (nonasync and async) of this sample.

The sample application calculates how many prime numbers exist in range. You need to enter number, press run button. The program starts counting. The progress bars informs user status of counting.

Lets see the implementation of runBtn_Click event:

private void btnRun_Click(object sender, EventArgs e)
    if(!int.TryParse(textBox1.Text,out m_number))
        m_number= 1000000;

    textBox1.Text = m_number.ToString();
    progressBar1.Maximum = m_number;
    progressBar1.Minimum = 0;
    progressBar1.Value = 0;

    //call start calculation

At the beginning of the btnRun_Click we prepare progressBar, and also convert text from textbox in to int type.At the end of the function startConting method is called. Here is the source code of the method:

private void startCounting()
    int counter=0;
    for(int i=2;i<m_number; i++)
        bool retVal= IsPrime(i);
        if (retVal)
            label3.Text = "Result is: " + counter.ToString();

The method is very simple. It iterates from 2 to specified number by calling helper method IsPrime (see source code of the blog post) to check if certain number is prime. Then the method increased the counter variable and tried to update label about current count value.  If  you run the sample and press run button, you can see that the application is not responsive on user input, and represent classic sequential, synchronous single thread application.

Now I am going to show how this implementation can be converted in to async with minimum code changes.We are going to change only startCounting method, other code will remain the same. Explanation is divided in only 3 steps, which is enough to convert our code in to full async pattern.

  • Put async keyword right after public modifier of startCounting method.

Explanation: Every method which implements async patter needs to be decorated with async.

  • Put sequential implementation in to Task action, and wait.

Explanation: With this, you define a Task object which will run the code without blocking main thread. The simplest implementation is the following:

private async void startCalculation()
    var task = new Task(() =>
            int counter = 0;
            for (int i = 2; i < m_number; i++)             {                 bool retVal = IsPrime(i);                 this.Invoke((Action)(()=>
                    if (retVal)
                        label3.Text = "Result is: " + counter.ToString();


    await task;

Now if you run the sample, you have fully asynchronous implementation. Main thread is free and can receive user input. So this is the simplest way how to convert your sync code in to async. This is the case when Task object create another thread in order to execute the code. That’s why we called this.Invoke method in order to set controls properties progressBar.Value and label3.Text. Everything else remain the same as in previous implementation.

  • Create global variable of type CancellationTokenSource and call Cancel method from Cancel Event handler.

Explanation: On this way we can cancel counting at any time.With this case we need to implements extra code in our previous implementation like the following.

private async void RunProces()
    if (m_IsRunning)
    m_IsRunning = true;
    int counter=0;
    if (m_ct != null)
        m_ct = null;
    m_ct = new CancellationTokenSource();

    var task = new Task(() =>
            for (int i = 0; i < m_number; i++)             {                 bool retVal = IsPrime(i);                 this.Invoke((Action)(()=>
                    if (retVal)
                        label3.Text = "Result is: " + counter.ToString();


                if (m_ct.IsCancellationRequested)
                    m_IsRunning = false;
        }, m_ct.Token);

    await task;

With the last code implementation you have full of async patter in yur old application.

In this blog post I have tried to explain as simple as possible the way how you can convert you old sync code in to new async programming pattern.

Source code sample used in this blog post:

On this link you can find sequential version of the sample.

On this link you can find the final solution of async pattern.


How to optimize analityc function in GPdotNET

This is short tutorial how to use GPdotNET in order to find global optimum of analytically defined function.

Let’s take an example of not so simple function. The picture below shows graph of the function. The function has two local minimum in interval from -5 to 5.


Analytic term of the function is: 2b516ec5b2eb31fa2fc2ceed6d96b1e2.


To be sure that we are dealing with the correct result, first we will find the optimum from Wolfram Alpha. The picture below shows global optimum of our function, calculated by Wolfram Alpha.


From the above we see that global minimum can be found for X=-2.93536, and corresponded optimal value is y=-2,377.

So let’s try to find this optimum with GPdotNET v2.

1. Open the GPdotNET and choose New.



2. Select Optimization of Analytic Function radio box

3. Click OK button.

4. Optimization module appears on the screen.


Now we need to define function in analytic form. As we have previously seen in blog post:

5. Select ” +” function from Function combo box and press Add Function button.

6. Click on left outer node

7. Select “/” function and press Add Function button.

8. Select left outer node

9. Select Mul4 function and press Add Function button.

10. For each outer node of Mult4 function add + function, similar like previous.

11. For each left outer node of + function , add Param Name X1 and press Add Param buton.

12. For right node add 4,1,-1,-3 param from left to right.

13. For right node of Mul4 function add 14 param.

14. For right node of / function add 0,5 param.

After you finish you get the following picture:


15. Press Finish button and select Optimize Tab page.

16. Select X1 variable in List View control for defining variable range

17. Enter -10 for min and 15 for maximum and press update button.

18. Select Minimize check box, for minimum.

19. Now we can perform optimization by press Optimize toolbar icon.

20. After very short period of time you get the following picture:


From picture above we can see that we got Xmin=-2,935 and Ymin=-2,9377, exactly as we got when we have performed optimization by Wolfram Alpha.

With GPdotNET v2 you can optimize any analityc function, regladles of number of inut variables.

Dev Camp Developing Windows 8 Store app, Banjaluka 11.10.2012.

U koliko želite da razvijete Windows 8 Store apps, imate jedinstvenu priliku da posjetite Dev Camp i saznate više oko ove nadolazeće tehnologije. Dev Camp u Banjaluci je jedan od stotine Dev Campove koji se održavaju svijeta. Posjetite stranicu i saznajte najbližu lokaciju održavanja kampa . Dev Camp je zamišljen kao cjelodnevno predavanje sa puno demo primjera putem kojih će te više saznati kako razvijati Windows 8 Store aplikacije.

Čast da mogu da najavim Dev Camp u Banjaluci na kojem ću uz Enisa Šahonovica iz Microsoft BiH održati cjelodnevno predavanje oko razvoja Windows 8 Store aplikacija. Agenda predavanja na Dev Campu možete pogledati u narednoj tabeli.

8:30 – 9:00

Registracija učesnika

9:00 – 9:45

Uvod u dizajn Windows 8 aplikacija

Enis Šahinovic, Microsoft DPE,

9:45 – 10:45

Training Lab 1: Razvoj Windows 8 aplikacija

Bahrudin Hrnjica, Microsoft MVP

10:45 – 11:00


11:00 – 12:00

Training Lab 2: Contracts, App bars…

Bahrudin Hrnjica, Microsoft MVP

12:00 – 13:00

Training Lab 3: Settings, Preferences, Tiles, Notifications

Bahrudin Hrnjica, Microsoft MVP

13:00 – 13:45


13:45 – 14:45

Training Lab 4: Windows Store & Deployment

Bahrudin Hrnjica, Microsoft MVP

14:45 – 15:30

Q&A sesija

Još da napomenem da se Dev Camp održava u Hotelu Vidovic u Banjaluci. Početak i registracija učesnika počinje u 8:30.