Tuesday 20 September 2011

Play sound with Windows Phone 7 SIlverlight App -

Hi all,

There's a time that I've used the Emulator for my dev purpose. One of my apps played a mp3 file, the file has been hard-coded for keeping the thing simple.
Today, I deployed it on my windows phone 7 device, and guess what ?!!! any sound played..., but it perfectly works on the emulator.
First,I think that it is a frequency and rate of the file which is not supported by my phone.So, I've moved the file via Zune on the phone and it can play the song.
What's the matter. I'm sure that my code is correct, but it must be something wrong somewhere.


In the MainPage.xaml, I've used the MediaElement like this :

<MediaElement x:Name="media" AutoPlay="True"  ></MediaElement>

And I the main Page, I've added those two lines after the InitializeComponent method

media.Source = new Uri("Audio/song1.mp3", UriKind.Relative);
media.Play();

When debuging using the device, the screen main application appears but I dont hear any song...

I don't see what's wrong... it becomes boring I've said. So decided to shutdown my PC, unplug the USB cable.... and guess what ???!!!!!  the song is being played ....

Finally, I found the solution... BEFORE TESTING ANY APPS, DISCONNECT FIRST THE USB CABLE

Thursday 15 September 2011

Windows Developer Preview Release of "Windows 8"

Hi all,

As you may know, today is released the Windows Developer Preview Release of "Windows 8", with VS2011 Preview!!!!!  packaged only for x64 at writing


Tomorrow, the new  NET Framework 4.5 Developer Preview will be available too.

So wish you a nice download and a nice preview.


Sunday 11 September 2011

Windows phone 7 tips - Please check that the Zune software is running and that Zune's sync partnership with your phone has been established

Hi all,

I write this article to help some of you when unlocking your windows phone 7 for development purposes.

Why do I write it ?
The reason is that I've spend  a lot of time when I've done it, to resolve the trouble about this process. For some of you, it may be passed for the first time, at the first attempt , but for the others, it was a nightmare... a very very black nightmare ever seen :)

What do you need to unlock the phone ?
- A windows phone 7 device :) A Samsung I8700 Omnia 7 in this article.
- Zune at www.zune.net
- Windows Phone Developer Tools at http://create.msdn.com/en-us/home/getting_started
- Visual studio (optionally for testing deployment to a device)
- An appHub account (with some fees :) ) or if your region is not available for an appHub account, you can subscribe onto your regional center. For example, I live in Mauritius, this country is outside of the global appHub, so I need to subcribe on Yallaapps to unlock my device.

Each of them are available for download.


First of all, install visual studio, the Zune (take care of this installation, read below) and finally the Windows Phone Developer Tools.

Zune install is one of the tricky part of the process. Don't plug your phone during this installation.
Once the install is finished, Zune looks for an available upgrade for the OS. ( Don't accept it, instead "Install later"), it is very important otherwise it will break all futures steps.
Your phone is now plug to your PC. In Zune Go to Settings :


Name your device :

Click OK to save your modification.

At this time, we're ready to register your phone.

Go to Start > Programs > Windows Phone Developer Tools > Windows Phone Developer Registration. Keep phone plugged and Zune running.

It will ask you to enter your account that has been activated on appHubs or others ( for me that was Yallaapps).

Normally, if everything goes well, it will display :


Troubleshoots :
- Error communicating with the developer portal. Please set the correct date and time on the phone, check the Internet connection and try again later ( ErrorCode:0x64) : if you have this error, set the same time on both side ( pc and phone ). Try to have the same time even in seconds unit.
- Please check that the Zune software is running and that Zune's sync partnership with your phone has been established : if you have this error and have checked that your phone is plugged on the pc and Zune is correctly running, do the following :
Go to setting, click update :

This problem is due to an incompatibility between the Zune version and the firmware update. You've certainly done an upgrade before. The restore point is the one that has keeped an image of your last firmware. In major case, the factory setting firmware is the one that is intact. I my case, I've done an upgrade just after I've bought the phone ;) . A hard reset doesn't work.

Before a restore, may be you must backup all your data on the phone. Installed apps will be lost after.

Don't worry to do a restore ;). During the restore operation, my laptop crashed and had rebooted. It was a nightmare for  me, what happened if it will not resume the process ??? The phone screen displayed a dramatic information aaaaaahhhhhhh. But be sure, it was not a problem. Restart Zune and plug your phone, it will redo all the processes from the beginning.


Once your phone is restored, redo the registration process. Normally, the process will be ok.


But that's not all.


You can now upgrade your firmware and your device remains unlocked!!!

If you do a hard reset, the phone will be locked, you need to do the same process registration . May be, you need to restore the factory version for that. 


For any problem on this process , you can post here, i'll reply you as soon as I can.


If this article was helpful for you, please click on one advertisement link on the blog page ;)

Tuesday 6 September 2011

Windows vista temp folder cleaning

Don't forget to check periodically the folder C:\Users\[USER]\AppData\Local\Temp

Mine costs me 4.92 Go of 160 Go.

SHIFT + DELETE

K2 Blackpearl integration - invoking external WCF Service from K2 Blackpearl process - Part2 - English Version

After reading my first post about K2, we know how to use and how to choose outcome automatically from code behind of the activity. As we've seen, we've called an external DataSource and used it to build our business rules.
In this part, I'll show you how a way to integrate a WCF client inside the K2 project. The client will then communicate with any DataSource in your organization, keeping the K2 process highly decoupled to the Business Organisation. 

For example, I've already worked on project that uses datas from Dynamic CRM 4.0 and used them to make a decision on the K2 process.

Study case :

Suppose that your organization exposes a large webservice that is shared with all business units. Not a matter how they are made, you will only consume them by calling the method of your need.
Remember our code in the previous article :

 public void Main(Project_fd73bddd345e4782bbb4cb51bef68a2e.EventItemContext_04bac391a41e42aea8272dd6e8848693 K2)
        {
            //We will put our code here

        int dataFromAnExternalDataSource =     wcfServiceClient.GetDecisionCode();

        switch (dataFromAnExternalDataSource)
            {
                case 1: //will choose the first decision

                    K2.ActivityInstanceDestination.ActivityInstance.DataFields[systemOutCome].Value = decision1 ;
                    break;
                case 2: //will choose the second decision
                    K2.ActivityInstanceDestination.ActivityInstance.DataFields[systemOutCome].Value = decision2 ;
                    break;
                case 3: //will choose the third decision
                    K2.ActivityInstanceDestination.ActivityInstance.DataFields[systemOutCome].Value = decision3 ;
                    break;
                default:
                    break;
            }
        }
the wcfServiceClient.GetDecisionCode() is the line that we'll focus. It calls the GetDecisionCode() of a WCF webservice in our organization. wcfServiceClient is an instatiation of our wcf service client.

To build the client class:

1 - create a C# class library in visual studio.
2 - Add a service reference to the solution. Point to the Webservice URL of your organization
3 - At this time, Visual studio generate automatically the client class of the web service, update your web.config and the client is ready to query the service. But wait... that's not all.
    We have only setup our local environment to map the webservice. But the client will be used inside the K2 process. So any web.config updated, no libraries generated on the K2 server yet.
    The thing becomes more complicated as expected.
    Fortunately, we can configure the client by code to setup information about the server as URL, binding protocols and so for.
4- In the Class1 (created when we have created our visual studio library solution), let's put the code :

public static class Class1
    {
        public static Devenva.Service1Client GetsServiceReference(string serviceUrl)
        {
            BasicHttpBinding binding = new BasicHttpBinding();
            EndpointAddress address = new EndpointAddress(serviceUrl);    
        //you can put here more configuration about the service,
        //you must set the binding.Name property of WCF service, or the     //MessageEncoding ( by default is text)
        //You can see more example and a lot of way to do this on the book MCTS //Self-Paced Training Kit (Exam 70-503) : Microsoft .NET
        //Framework 3.5, Chapter 4 : Consuming Services      

            Devenva.Service1Client client = new Service1Client(binding, address);           
            return client;
        }
    }
}
Devenva.Service1Client is the Type of the reference that we have setup earlier.
   
5- Now, compile your solution and copy the generated dll to another location than bin/Debug. Why ? we'll use it with our K2 server and therefore it will be locked by this process and you can not recompile the solution again.

6- Go to the K2 IDE, click the project reference icon


7 - Click Add on the Project Reference window

8 - In the Add references, click browse to and choose the location of your dll.

9- Once the dll is added, on the Manage Project Reference, check if the Copy Local is checked for the dll. It will copy the dll into database once the process is deployed.

10 - We can now access all methods by instantiating first a reference to the service :

Devenva.Service1Client clt = Devenva.Class1.GetReference("url_of_your_service");


The codes becomes

public void Main(Project_fd73bddd345e4782bbb4cb51bef68a2e.EventItemContext_04bac391a41e42aea8272dd6e8848693 K2)
        {
            //instatiate the wcf proxy object
        Devenva.Service1Client wcfServiceClient = Devenva.Class1.GetReference("url_of_service");

        //the proxy will handle all WCF OperationContract
        //I can improve by stocking the url_of_service into a process datafield when the process begins.

        int dataFromAnExternalDataSource =     wcfServiceClient.GetDecisionCode();

        switch (dataFromAnExternalDataSource)
            {
                case 1: //will choose the first decision

                    K2.ActivityInstanceDestination.ActivityInstance.DataFields[systemOutCome].Value = decision1 ;
                    break;
                case 2: //will choose the second decision
                    K2.ActivityInstanceDestination.ActivityInstance.DataFields[systemOutCome].Value = decision2 ;
                    break;
                case 3: //will choose the third decision
                    K2.ActivityInstanceDestination.ActivityInstance.DataFields[systemOutCome].Value = decision3 ;
                    break;
                default:
                    break;
            }
        }

As you see, we have used WCF to allow our K2 process to communicate with the rest of your organization. In that manner, we can change data from external datasources without changing any data in our k2 process. I've used this way to design a process where K2 is only used to route the flow through the workflow tree. We can also remove datafields and use instead WCF OperationContract

In those 2 articles I've show you how to :
    - setup an activity system that decides which outcome should be choose depending on the value returned from an external datasource, this was done in the K2 code behind.
    - add a WCF Proxy library into the K2 solution, the proxy allow the K2 process to communicate with the rest of the world.


Cons/On. : it's up to you, all the following are my personal view

For the process design, K2 recommends the use of SmartObject. SmartObject allows a highly decoupled implementation of the process and the data used by the process. But personally, I think that building a SmartObject from scratch is more time consuming. The reasons are : needs of implementing extra modules, configuring ServiceBroker, deploying Process + SmartObject Service, need access to the K2 server... or instead configuring via the API....
One drawback is when there several developpers work on the same K2 process and code a common methods exposed by the SmartObject. As you know, we configure through the ServiceBroker the url of the service that should be contacted by the K2 SmartObject. Imagine that Developper A modify localy a SmartObject ClientList() method on his visual studio. Developper B also works on the Same method. What's happen ? The method that is invoked is the one that is located at the service declared in the ServiceBroker. So at least one of the Developper A orB will haven't their modification to be available for test. Only one can be invoked.
This is not the case with the method exposed before. By defining the "url_of_service" inside a process dataField, each developer can specify his own service URL (exposed via IIS on the local dev machine) , do their modifications on their local dev environment, and the K2 server process will contact the right service. So several developers can use an unique K2 server, deploy only one process, and can test their works independently.

Hope that it will help you.

Don't hesitate to mail me if you have another point of view.

If this article was helpful for you, please click on one advertisement link on the blog page ;) 

K2 Blackpearl - dynamically set activity outcome from code behind - Part1 - English Version

In this article, I will show you how to set an activity outcomes programmatically.

When the business requirements grow, it's is more easy for developers to manage directly the business logic from the code behind instead of trying to manage it from the IDE.

This article also shows a different way to communicate with a third party datasource, from the K2 process as the SmartObject does, but it will not use SmartObject.

Study case (simplified for the lab) :

Let's suppose that the SYSTEM IS ABLE TO MAKE AUTOMATICALLY A DECISION under specific conditions. This type of activity doesn't require any Destination User but is used only for making decision with input parameters received from an external datasource.

Step 1 :

Create an activity and add a Default Server Event (Code) from the toolbox. Name the activity "System"




Step 2 :

Create a datafield on the activity "System". Select the activity system and do as shown


1 - Select K2 ObjectBrowser
2 - Select the Process/Activity Data icon
3- Select the Activity System, right click and Add

You are going to add a new Data Fields on this activity. When a Datafield is created on an activity, it becomes a property of this activity and is only accessible inside this activity.

Fill the DataField form like the following


Notice that I've set the category to Outcomes.

Step 3 :

Create  OutCome lines on System Activity as many as there's outcomes the activity can take.
To do it, drag a Default line to the System activity


In this article, I create 3 default lines on the System activity. The activity should be like that :
Step 4 :

We need to configure each line to have their own outcomes rules.

Right click the first arrow line, and fill the Line General properties  like :


On the Line General properties Line Rule tab  :


 1 - Select the Line Rule Option
 2 - Click Add
 3 - Click the Browse
 4 - Go to the SystemOutCome datafield, drag and drop it to the First Variable input.
 5 - On comparison operator, choose =
 6 - Set the Second Variable input to the string "Decision 1" (without quotes)
 7 - Click finish

Then click OK. You should have :


Repeat the same steps with the 2 others lines, but change the Decision 1 to Decision 2 or Decision 3.

You should have something like this :

Note : In the real world, you should connect each of those lines to other activities into your K2 process diagram. In this labs, we focus only on the System activity.

Step 5 :

Configure the code behind of the ServerEvent. We'll set our business rule there. To do it :

Right click on the ServeEvent component > View Code > Event Item. It will open the code behind

namespace ExtenderProject_fd73bddd345e4782bbb4cb51bef68a2e
{
    public partial class EventItem_04bac391a41e42aea8272dd6e8848693 : ICodeExtender<hostContext>
    {
        public void Main(Project_fd73bddd345e4782bbb4cb51bef68a2e.EventItemContext_04bac391a41e42aea8272dd6e8848693 K2)
        {
            //We will put our code here
        }
    }
}

Your code is not exactly the same.

Generally when using this approach, the body of the Main method should be a condition switch based on inputs that will used to decide where to dispatch the process, an update method is also expected to perform some business before leaving the activity.

First of all, I will set some const variables that will be used in our code

namespace ExtenderProject_fd73bddd345e4782bbb4cb51bef68a2e
{   
   
    private const string decision1 = "Decision 1";
    private const string decision2 = "Decision 2";
    private const string decision3 = "Decision 3";

    public partial class EventItem_04bac391a41e42aea8272dd6e8848693 : ICodeExtender<hostContext>
    {
        public void Main(Project_fd73bddd345e4782bbb4cb51bef68a2e.EventItemContext_04bac391a41e42aea8272dd6e8848693 K2)
        {
            //We will put our code here
        }
    }
}
Now I need to make the business body of function. To keep thing simply, I only show the general structure of the process

namespace ExtenderProject_fd73bddd345e4782bbb4cb51bef68a2e
{   
   
    private const string decision1 = "Decision 1";
    private const string decision2 = "Decision 2";
    private const string decision3 = "Decision 3";
    private const string systemOutCome = "SystemOutCome";
   
    public partial class EventItem_04bac391a41e42aea8272dd6e8848693 : ICodeExtender<hostContext>
    {
        public void Main(Project_fd73bddd345e4782bbb4cb51bef68a2e.EventItemContext_04bac391a41e42aea8272dd6e8848693 K2)
        {
            //We will put our code here

        int dataFromAnExternalDataSource =     wcfServiceClient.GetDecisionCode(); // get data from an external datasource, described later

        switch (dataFromAnExternalDataSource)
            {
                case 1: //will choose the first decision
                //you can add here some business method that update some entities on the external server
                //wcfServiceClient.UpdateCustomerList();
                    K2.ActivityInstanceDestination.ActivityInstance.DataFields[systemOutCome].Value = decision1 ;
                    break;
                case 2: //will choose the second decision
                    K2.ActivityInstanceDestination.ActivityInstance.DataFields[systemOutCome].Value = decision2 ;
                    break;
                case 3: //will choose the third decision
                    K2.ActivityInstanceDestination.ActivityInstance.DataFields[systemOutCome].Value = decision3 ;
                    break;
                default:
                    break;
            }
        }
    }
}

We will see in the part 2 of this article that we can remove the datafield SystemOutCome and replace it by an OperationContract exposed by a WCF, having a String as return value.

The activity "System" is now ready to take automatically decision depending on the value provided by the external dataSource.

We notice that we haven't include  any embedded methods in the K2 process but have deferred it to a reference of a WCF service instance wcfServiceClient that will retrieve the data through the GetDecisionCode() operationContract. In that manner, we avoid to keep this value into a DataField and make a highly decoupled communication between K2 and other DataSource in our organization.

How to do it ? Read the second part of the article

If this article was helpful for you, please click on one advertisement link on the blog page ;)