Sergiy Baydachnyy

Blog about technologies

Archive for the ‘Windows 10’ Category

How to manage AllJoyn devices in C#: LIFX Color 1000 Example

with one comment

In the previous video we discussed, how to onboard an AllJoyn device using Visual Studio, C# and Windows 10 AllJoyn features (How to onboard AllJoyn devices in C#: LIFX Color 1000 Example).

Today, I am going to show, how we can start working with an “onboarded” AllJoyn device.

https://channel9.msdn.com/Series/Internet-of-Things-micro-boards-for-beginners/How-to-work-with-AllJoyn-devices-in-C-LIFX-Color-1000-example/player

Written by Sergiy Baydachnyy

06/06/2016 at 7:06 PM

Posted in IoT, Visual Studio, Windows 10

Tagged with

How to onboard AllJoyn devices in C#: LIFX Color 1000 Example

leave a comment »

I already published some articles about AllJoyn, ZigBee/Z-Wave bridges and bulbs. You can find all my previous posts using these links:

Smart bulbs or how to be lazier (part 1)

Smart bulbs or how to be lazier (part 2)

Smart bulbs or how to be lazier (part 3): AllJoyn client

Smart bulbs or how to be lazier (part 4): IoT Hub

 

But today I got a chance to play with a truly AllJoyn device – LIFX Color 1000 bulb. And the first task that I had to solve is how to onboard the bulb to my local network. More information about the task you can find watching this video:

https://channel9.msdn.com/Series/Internet-of-Things-micro-boards-for-beginners/How-to-onboard-AllJoyn-devices-in-C-LIFX-Color-1000-example/player

Written by Sergiy Baydachnyy

05/20/2016 at 9:29 PM

Posted in IoT, Universal Applications, Windows 10

Tagged with

Developing Windows 10 applications with C# (the first 3 modules)

with 3 comments

Once I published my book about Windows 10 development, several people told me that developers don’t read paper books anymore. Looks like it’s true. At least, I can see that I sold Kindle edition books in three times more compare to paperback version. That’s why I decided to record a video training about Windows 10 development. Not sure if people like it but I can train my English at least. The first three modules are available on Channel9:

Module 1: What is the Universal Windows Platform?

Module 2: Introduction to XAML

Module 3: Layouts

Written by Sergiy Baydachnyy

02/28/2016 at 3:07 AM

UWP: Profiling and debugging tools in Visual Studio 2015

leave a comment »

I have already published a post about Live Visual Tree but Visual Studio 2015 has lots of different tools which allow you to tune your application on Universal Windows Platform. Let’s make an overview of some of these tools.

But before the start, just make sure that you switch the Enable Diagnostic Tools while debugging and PerfTip while debugging in the Debugging options. These tools should be enabled by default but it’s better to know how to disable/enable them:

clip_image001

Ok. Let’s talk about particular features, and I would like to start with the performance tips. Thanks to this feature you can use the breakpoints and debug mode to know exactly how much time has elapsed since the last breakpoint:

clip_image003

If you want to see this information for each line in your code you simply need to use debugger to go step by step through the code. But if you need to understand elapsed time for any of the blocks then you just need to set two breakpoints at the beginning and at the end of the block. So, using the performance tips you can easily locate problems with performance.

You can see that Visual Studio displays this information as tips and you can easily click these tips to navigate to Diagnostic Tools window, which is the second important tool which you can use together with performance tips:

clip_image005

Diagnostic Tools contains three sections. The first one shows events like information about exceptions, even if exception is caught; messages from output window which are generated by the Debug class; IntelliTrace events related to threads, assemblies etc. The next two sections show CPU utilization and usage of memory at runtime but you can easily pause the debugger and select any timeframe in order to check events and memory and CPU usage.

Additionally, you can take a snapshot of memory at any time during debugging of the application and check the number of references for each object, amount of memory etc.

clip_image007

The next set of tools you can find if you execute Start diagnostic tools without debugging… command.

clip_image009

These tools allow to collect information during runtime. Because these tools collect all information not in the debug mode, these data has better quality but you cannot check it in real time. Instead, the tools collect information about application until you stop them. Once they are stopped, the report abound the collected metrics is generated and you can analyze the data using dashboard.

clip_image011

Among all tools I would like to recommend Application Timeline. Thanks to this tool you can find problems with rendering and review the most critical parts of your application.

Written by Sergiy Baydachnyy

10/01/2015 at 8:23 PM

Visual Studio Tools for Unity

leave a comment »

Lots of developers use Visual Studio like the default code editor for Unity engine for many years and looks like, since Visual Studio 2015 release, integration between both products are stronger than before. Since Unity3D 5.2, Visual Studio Community Edition 2015 is the default Unity3D code editor for developers on Windows.

First of all, both tools have cross-product installations. If you have fresh PC with Visual Studio 2015 installed you can find that New Project dialog contains a new category there – Game. You cannot use this category to create new projects because there are just links to some popular gaming frameworks including Unity.

clip_image002

Selecting Install Unity, Visual Studio will help you to install Unity and Visual Studio Tools for Unity:

clip_image004

In case of Unity installer, integration even much better: users can select and install Visual Studio Community Edition directly from Unity installer:

clip_image006

Pay special attention that starting with Visual Studio Community Edition announcement, game developers can use all important Visual Studio features for free including extensions (plug-ins) and debug features. If you want to download VS Community Edition separately, you can do it visiting https://www.visualstudio.com/ web site.

Visual Studio Community Edition has some licensing limitations. For example, you can use it for small teams only (up to 5 people) but if you work in a big company you can use Professional or Enterprise version of Visual Studio. In this case Unity installer will recognize existing version of Visual Studio and propose to install Visual Studio Tools for Unity only that is a bridge between Unity and Visual Studio 2015:

clip_image008

So, using Unity installer or Visual Studio, it’s really hard to miss installation opportunity for Microsoft Visual Studio Tools for Unity. Let’s see how to use the tools themselves.

The good news that Unity3D 5.2 has native support for Visual Studio Tools. So, you should not add any packages or something like before. So, you simply need to create a new project or open existing one. To make sure that Visual Studio is the default editor you can call Edit->Preferences menu item and open Unity Preferences window that contains information about external tools including script editor:

clip_image010

On this step you can start working with your Unity project, create scripts in C#, objects, assets etc. Once you want to open the project in Visual Studio you simply need to use Open in C# menu item.

clip_image011

It’s easy to do and Unity will open your project in Visual Studio. Let’s look at some important features that you can use there.

First of all you can use Unity Project Explorer (Shift+Alt+E):

clip_image013

This window is similar to Project window in Unity and can present project’s files in the same way. So, if you need to find some files very quickly you can use the same way like in Unity. Unity Project Explorer and Solution Explorer show project’s files in different ways. Especially you can see that difference for large projects.

The next two windows allows you to override MonoBehaviour class methods very quickly. You can use Ctrl+Shift+Q combinations to call Quick MonoBehaviours window. Just start typing name of the method and the window will help to select the right one:

clip_image015

The second window you can call using Ctrl+Shift+M combination:

clip_image017

Using MonoBehaviour wizard you can generate several method stubs at once.

Two more features of Visual Studio Tools for Unity is supporting shaders editing and integration with Unity output. Thanks to the first feature you can see coloring syntaxes and formatting features if you are working with shaders in Visual Studio. The second feature allows you to see Unity errors and warnings in Visual Studio error window.

Finally, the most important feature there is Debugging. You can connect to Unity Debugger using Debug -> Attach Unity Debugger menu item. Select Unity Instance window will show available Unity instances and you can select any of them:

clip_image019

Or you can simply click Attach to Unity button on Standard toolbar.

clip_image020

Once Visual Studio is connected, you can open Unity editor and use Play/Stop features. Of course, Visual Studio supports breakpoints, allows to evaluate expressions and variables and other debugging features.

Written by Sergiy Baydachnyy

10/01/2015 at 8:19 PM

State triggers and Blend

leave a comment »

At last, Windows 10 is released and today developers have access to Visual Studio 2015 and Windows 10 SDK. I have already published some posts about Universal Windows Platform and Visual Studio 2015, and I promise lots of topics about it over next months; but today I want to drag your attention to Microsoft Blend 2015 tool which is included to Visual Studio installation.

Looks like Microsoft continues to invest in Blend and the latest release contains lots of new features. Today I want to talk about visual states editor new features.

In order to see the new features just create a new project in Blend and select MainPage.xaml in Solution Explorer. Once you do this, Objects and Timeline window will show structure of the page. Usually, when we create visual states we work with main container such as Grid. So, in order to create several visual states it’s better to select the root Grid element in Object and Timeline and States windows to start editing visual states.

Blend allows you to edit visual states without coding at all. With the help of the States window you can create as many states as needed, and once you select a state, Blend switches editor to Record mode (Ctrl+R). In this mode you can change properties of any user controls and all these changes will be included to the selected state automatically. So, I propose to create just one state using Add State button in States window and select the main grid to change some properties. For example, you can change Opacity and Visibility using Properties window.

clip_image002

If you open XAML document you can find the following code there:

<VisualState x:Name="Normal"> <VisualState.Setters> <Setter Target="grid.(UIElement.Opacity)" Value="0.5"/> <Setter Target="grid.(UIElement.Visibility)" Value="Collapsed"/> </VisualState.Setters> </VisualState>

So, you can see that Blend editor is fully integrated with the new approach that Universal Windows Platform implements thanks to Setter elements.

If you want to use the old approach or animate your properties from one state to another, you can continue to use the timeline and Blend will use animation instead of setters.

One more feature of Universal Windows Platform is state triggers, which allow you to move interface from one state to another without coding at all. UWP supports just AdaptiveTrigger but you can create your own triggers. Let’s see, how to use triggers in Blend.

I propose to add a class to the project which will have just one property but this class should be inherited from StateTriggerBase:

class MyTrigger: StateTriggerBase { public int State { get; set; } }

Of course, this class doesn’t have any sense because it does not have any logic inside but it’s enough to show it in Blend. Just recompile the application because Blend will look at assemblies.

Let’s try to apply the created trigger to one of the states using the States window. Pay attention that this window contains new button called edit adaptive triggers:

clip_image003

Just click the button for any state and Blend will show a dialog, which allows to select available triggers for the project:

clip_image005

Just select our trigger and Blend will allow you to initialize all public properties there (we have just one):

clip_image007

Enter any value there and click OK. Blend will generate the following code:

<VisualState.StateTriggers> <Code:MyTrigger State="10"/> </VisualState.StateTriggers>

Therefore, if you want to create a real adaptive interface and need to create lots of states and use many triggers, Microsoft Blend is the best tool for that.

Written by Sergiy Baydachnyy

09/07/2015 at 9:20 PM

UWP: New features of Launcher class

leave a comment »

In this post I want to discuss how to establish communications between Universal Windows Platform applications. It was a problem since Windows 8 because each application is running in its own sandbox without access to data of other applications. Of course, Windows 8.x supports several ways to invoke external applications and pass data to them. For example you could use share charm or use Launcher class. But all these methods have some disadvantages. Let’s look at Launcher class.

In Windows 8.x Launcher class allows to launch external applications based on Uri. The most common protocol for Uri is http and you can use it to launch browser but applications can register their own protocols for own needs. For example, in Windows 10 to invoke Settings window you can use ms-settings protocol and create Uri for Launcher class based on it:

await Launcher.LaunchUriAsync(new Uri("ms-settings:"));

You can see that in order to launch external application you should call LaunchUriAsync method which doesn’t allow to pass anything except Uri. If you need to pass some parameters to external application, you could use the same approach as for http protocol: get parameters in Uri. But if you need to pass file as a parameter you cannot make it using LaunchUriAsync. Frankly speaking, Launcher class supports LaunchFileAsync method but that method supports StorageFile as a parameter. So, you can not pass several files and you can not combine both methods (launch application using Uri and pass file at the same time). Even in order to pass file to a(??) third-party application it is required to register extensions of accepted files. Additionally, LaunchUriAsync and LaunchFileAsync don’t allow to control which application should be launched. If several applications register the same extension, user needs to select an application from the list. Finally, there was no way to understand if an application is launched and how to get some result back.

Let’s summarize all disadvantages, which Launcher class has in Windows 8.x:

· Allows to pass Uri or file using two different methods without a way to combine them;

· Doesn’t allow to pass several files;

· System might ask user to select an application from the list;

· There is no way to know if an external application is launched;

· There is no way to get response from an external application;

But in Universal Windows Platform, Microsoft made huge investment to Launcher class and today developers can avoid all mentioned disadvantages. Let’s see which changes were implemented there.

Look at the following code:

LauncherOptions options = new LauncherOptions() { TargetApplicationPackageFamilyName = "Microsoft.MicrosoftEdge_8wekyb3d8bbwe" }; await Launcher.LaunchUriAsync(new Uri("http://www.microsoft.com"), options);

When running this code we asked Launcher to launch an application which has defined application package name. This approach is very useful for corporate systems when you developed for customers more than one application. Using LauncherOptions you can guarantee that system will run exactly the application you need from your bunch of applications. Of course, you need to know the application family name but you can easily to find it using the Store:

clip_image002

Additionally, you can use FindUriSchemeHandlersAsync method of Launcher class to get information about all packages which accept the selected schema:

var res = await Launcher.FindUriSchemeHandlersAsync("http");

This method returns an array which contains all needed information including package name:

clip_image003

Of course, if package doesn’t exist in the system, LaunchUriAsync method will return false and you can ask users to install an additional application.

Launcher class contains one more method, QueryUriSupportAsync, which allows to get information if selected Uri is supported in the system:

var res = await Launcher.QueryUriSupportAsync(new Uri("http://www.microsoft.com"), LaunchQuerySupportType.Uri);

This method doesn’t return any information about external applications but allows to check if you can run an application using a passed Uri. And what is more important, this method allows to check result using package family name and even to understand if external application can return a response.

I would like to note that you can use the same bunch of methods for open files using external applications: LaunchFileAsync, FindFileHandlersAsync, QueryFileSupportAsync. Of course, these methods don’t resolve the problem with multiply files but UWP brings an opportunity to use LaunchUriAsync method for passing several files (references) as parameters. Let’s see how to implement it.

The idea is in using of SharedStorageAccessManager class. Thanks to this class you can share files between applications using tokens.

var token=SharedStorageAccessManager.AddFile(myfile);

Because token is a string, you can use it as a parameter in Uri. So, you should not pass any IStorageFile objects or anything special – just the same Uri. And it is possible to create as many tokens as needed.

External application can redeem tokens and get access to IStorageFile objects:

string myFileToken = queryStrings.GetFirstValueByName("GpxFile"); if (!string.IsNullOrEmpty(myFileToken)) { StorageFile file=await SharedStorageAccessManager.RedeemTokenForFileAsync(myFileToken)); }

Once the token is redeemed nobody can redeem the token once again. But the token may live for 14 days. So, if the application discovers a problem with launching of an external application, there is a way to delete token from the list using RemoveFile method.

Of course, in case of file token it’s easy to include tokens to Uri but you can pass any serializable objects what you want. In order to do it you can use ValueSet class , which is a dictionary of serializable objects. Developers can use it to pass tokens as well but it’s possible to pass anything:

ValueSet v = new ValueSet(); v.Add("token1", token); var f = await Launcher.LaunchUriAsync(myUri, options, v);

Finally, Launcher class allows to launch Uri for results. Imagine an application for making a payment. You can use this application as external method to make payments inside your own application but you need to get information from external one if payment is processed and, probably, some information to check if payment is received. In Windows 10 you can implement it using LaunchUriForResultsAsync method. This method has the same parameter list like LaunchUriAsync but it returns LaunchUriResult object instead of bool and you can use this object to see status and get results if launch was succeeded.

var result = await Windows.System.Launcher.LaunchUriForResultsAsync(myUri, options, inputData); if (result.Status == LaunchUriStatus.Success) { ValueSet theValues = result.Result; //do something here }

Therefore, all Windows 8.x problems with Launcher class are gone and today you have a great way to make communications between different applications.

Written by Sergiy Baydachnyy

09/03/2015 at 9:22 PM