<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Mim's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/mim/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/mim/feed.xml</link>
    <description>Windows 8 XAML addict ! (... and a little data Inside)</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:19:41 GMT</lastBuildDate>
    <language>fr_FR</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Disponibilité du SDK.NET Microsoft.Graph</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/disponibilite-du-sdk-net-microsoft-graph</link>
      <pubDate>Wed, 06 Apr 2016 14:16:16 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/?p=522</guid>
      <description><![CDATA[Bonjour à tous;
Si vous avez une question, n'hésitez pas à me contacter via twitter :...]]></description>
      <content:encoded><![CDATA[Bonjour à tous;
<pre>Si vous avez une question, n'hésitez pas à me contacter via twitter : <a title="@sebastienpertus" href="https://www.twitter.com/sebastienpertus" target="_blank">@sebastienpertus</a>
Les sources du projet sont disponibles ici : <a title="https://www.github.com/Mimetis/NextMeetingsForGraphSample" href="https://www.github.com/Mimetis/NextMeetingsForGraphSample" target="_blank">https://www.github.com/Mimetis/NextMeetingsForGraphSample</a></pre>
Une annonce passée un peu inaperçu pendant la <strong>//Build 2016</strong>, qui me semble pourtant importante quand vous développez avec Office 365 :
La disponibilité du <strong>SDK Microsoft GRAPH</strong> pour <strong>.NET</strong>, <strong>ANDROID </strong>et <strong>iOS </strong>!

Pour rappel, quand on veut attaquer les données du Graph, on peut aussi bien utiliser directement les API REST, et maintenant donc, les SDK mobiles:

<a href="https://msdnshared.blob.core.windows.net/media/2016/04/MicrosoftGraph-e1459944526418.png"><img class="aligncenter size-medium wp-image-524" src="https://msdnshared.blob.core.windows.net/media/2016/04/MicrosoftGraph-300x177.png" alt="MicrosoftGraph" width="300" height="177" /></a>

Voici quelques pointeurs intéressants sur le sujet :
<ul>
	<li><a title="https://github.com/microsoftgraph" href="https://github.com/microsoftgraph" target="_blank">https://github.com/microsoftgraph</a> : Le nouveau Github utilisé par l'équipe Microsoft Graph.</li>
	<li><a title="https://www.nuget.org/packages/Microsoft.Graph" href="https://www.nuget.org/packages/Microsoft.Graph" target="_blank">https://www.nuget.org/packages/Microsoft.Graph </a>: Le package Nuget du Microsoft.Graph</li>
	<li><a title="https://github.com/OfficeDev/Microsoft-Graph-UWP-Connect-Library" href="https://github.com/OfficeDev/Microsoft-Graph-UWP-Connect-Library" target="_blank">https://github.com/OfficeDev/Microsoft-Graph-UWP-Connect-Library</a> : Un premier exemple utilisant le SDK .NET</li>
</ul>
Le SDK est bien fait. Il permet d'utiliser son propre mécanisme d'authentification.
Evidemment <a title="ADAL" href="https://azure.microsoft.com/fr-fr/documentation/articles/active-directory-authentication-libraries/" target="_blank">ADAL </a>est celui préconisé.

<strong>Sauf que </strong>l'exemple de l'équipe Office Dev se base sur un fournisseur d'authentification personnalisé (donc pas ADAL ...)

Je vous propose de créer une application UWP qui tire parti de ce nouveau SDK, avec quelques APIs classiques et quelques retours d'expériences.

Et biensûr, un fournisseur d'accès basé sur ADAL !
<h2>Application de démonstration</h2>
L'application qui sert de base à notre petite démo est accessible sur mon github ici : <a title="https://www.github.com/Mimetis/NextMeetingsForGraphSample" href="https://www.github.com/Mimetis/NextMeetingsForGraphSample" target="_blank">https://www.github.com/Mimetis/NextMeetingsForGraphSample</a>

C'est une application UWP, qui pourra vous servir de base à d'autres projets :)

<a href="https://msdnshared.blob.core.windows.net/media/2016/04/NextMeeting01.png"><img class="aligncenter size-medium wp-image-533" src="https://msdnshared.blob.core.windows.net/media/2016/04/NextMeeting01-253x300.png" alt="NextMeeting01" width="253" height="300" /></a>
<h2>GraphServiceClient et Authentification</h2>
Une fois le package nuget installé, vous aurez accès à l'objet <strong>GraphServiceClient </strong>qui lors de son instanciation a besoin d'un objet implémentant <strong>IAuthenticationProvider</strong>.

Pour faire simple, le SDK demande juste à remplir le header de votre requête REST avec le jeton d'authentification correct.
Voici une partie de la définition de la classe :

&nbsp;

<script src="https://gist.github.com/Mimetis/1e2ef48e2acc042ce582652dde0584cc.js"></script>Et voici l'interface <strong>IAuthenticationProvider</strong> :<script src="https://gist.github.com/Mimetis/078eef477ebf0f1310d8b0cb286a766e.js"></script>

Pour utiliser ADAL, n'oubliez pas d'ajouter le package nuget ADAL.NET : <a title="https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/" href="https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/" target="_blank">https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/</a>

Voici une <strong>partie</strong> de la classe <strong>AuthenticationHelper</strong> que vous trouverez dans l'application exemple.
Remarquez bien la méthode <strong>AuthenticateRequestAsync</strong> qui est l'implémentation de l'interface <strong>IAuthenticationProvider</strong>.
On s'authentifie et on injecte le jeton d'accès dans l'entête de la requête http provenant du SDK Microsoft.Graph :)

&nbsp;

<script src="https://gist.github.com/Mimetis/6fc8770ccd70e3f52ac4a6f733481ce8.js"></script>

<pre><span style="text-decoration: underline"><strong>Amélioration possible</strong> </span>: ajouter un <strong>CancellationToken</strong> pour gérer les exceptions, ça serait beaucoup mieux qu'afficher une boite de dialogue :o</pre>

Voilà la partie la plus compliquée de l'utilisation du SDK :) Il ne reste plus qu'à appeler les APIs REST via les méthodes du SDK !

<h2>Récupération d'informations</h2>

La plupart du temps, chaque requête REST faisant un GET est plutôt simple. Il existe quelques variantes pour par exemple récupérer une photo ou avoir la liste des évènements de votre calendrier. Voici un exemple d'appel pour récupérer son propre profil :  <script src="https://gist.github.com/Mimetis/2146ddbcc14330cf59fa3499b0e89b0c.js"></script>

Ok, simplissime !
Pour entrer un peu dans le détail, la méthode <strong>Request()</strong> génère la requête qui est exécutée lors de l'appel de <strong>GetAsync().</strong>
La méthode <strong>Request()</strong> peut prendre des paramètres, mais nous verrons cela un peu plus loin

Un cas un peu plus complexe : Récupérer la photo d'un utilisateur.
Par défaut si vous exécuter ce code :

&nbsp;

<script src="https://gist.github.com/Mimetis/aaa8cb74d282980a8aee5408cd461c22.js"></script>Vous récupérez non pas la photo, mais les informations de la photo :) Récupérer le Stream de la photo s'effectue avec la requête REST: <em>//users/{identifier}/photo$value</em> Le SDK Graph gère ce cas et vous propose la propriété Content pour récupérer ce flux. Voici l'exemple de récupération de la photo d'un utilisateur :  <script src="https://gist.github.com/Mimetis/599561429854769a47e044f14802c6a1.js"></script>

Un autre cas un peu particulier, récupérer les évènements à venir de votre calendrier.

La requête REST nécessite absolument de rajouter 2 paramètres (date début et date de fin) dans la requête GET.
Comme on l'a vu précédemment, vous pouvez appelez la méthode Request() avec un tableau de paramètres de type QueryOption.

Voici le code pour récupérer vos prochains évènements sur un mois :

&nbsp;

<script src="https://gist.github.com/Mimetis/eb8a82927e5a12504dc59285c651702b.js"></script>Vous noterez que le résultats de votre requête est paginée. Pensez à vérifier la valeur de la propriété <strong>NextPageRequest</strong> pour savoir si vous devez itérer :)

<h2>Ajout, modification, suppression</h2>

Une fois que vous avez saisi la logique, il est simplissime (again) d'ajouter modifier ou supprimer une entité. Voici le code des méthodes Save et Delete, qui parlent d'elles-mêmes :)

&nbsp;

<script src="https://gist.github.com/Mimetis/55741eb83fb6ebb26764e94062ae9c18.js"></script>

That's all !

<a href="https://msdnshared.blob.core.windows.net/media/2016/04/NextMeeting02.png"><img class="aligncenter size-medium wp-image-544" src="https://msdnshared.blob.core.windows.net/media/2016/04/NextMeeting02-278x300.png" alt="NextMeeting02" width="278" height="300" /></a>

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>VorlonJS plugin for debugging Office Addin</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/vorlonjs-plugin-for-debugging-office-addin</link>
      <pubDate>Thu, 18 Feb 2016 09:03:35 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/2016/02/18/vorlonjs-plugin-for-debugging-office-addin/</guid>
      <description><![CDATA[&#160;     If you have any question about this article, Vorlon.js or Office dev, feel free to...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <blockquote>   <p><i>If you have any question about this article, Vorlon.js or Office dev, feel free to contact me on twitter: <a href="https://twitter.com/sebastienpertus">https://twitter.com/sebastienpertus</a></i></p> </blockquote>  <p>Today I want to share with you my last project.    <br />I developed a plugin for VorlonJS, to be able to debug any Office-Addin, even if you don’t develop with Visual Studio or if you experience some troubles with your addin deployed on a device <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2630.wlEmoticon-smile_39521E18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2630.wlEmoticon_2D00_smile_5F00_39521E18.png" /></p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3731.image_1B739A17.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3731.image_5F00_1B739A17.png" width="640" height="247" /></p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3515.image_3D5EFC9B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3515.image_5F00_3D5EFC9B.png" width="128" height="240" /></p>  <h1>VorlonJS </h1>  <p><img style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" src="https://www.vorlonjs.io/images/illustration-computer-devices.png" /></p>  <p>VorlonJS is a remote debugger, you can get more information about VorlonJS, here : <a href="https://www.vorlonjs.io">https://www.vorlonjs.io</a> </p>  <p>If you want to know even more on the last VorlonJS, my colleague Etienne (<a href="https://www.twitter.com/meulta">@meulta</a>) has written a blog post about it : <a href="https://bit.ly/vorlon-0-2-1">https://bit.ly/vorlon-0-2-1</a>&#160;</p>  <h1>Why create a VorlonJS Plugin for Office addin ?</h1>  <p>When you create an Office addin, you <strong>extend the Office features </strong>with a web app that lives within Office Applications.</p>  <p>It works both on Office desktop, Office online (Office 365 or Outlook.com), on mobile devices like IPAD, Android phone, IPhone, Windows Phone and so on…</p>  <p>Keep in mind that your Office addin “should” work everywhere, and you have to test it everywhere.    <br />But what can you do if your Office addin doesn’t work on a mobile ? How to debug it ? </p>  <p>This is the main reason why I created this plugin for VorlonJS. Being able to debug my addin, deployed on any device, during my development process</p>  <h1>Installing VorlonJS.</h1>  <p>VorlonJS installation is pretty straightforward. You will find a complete documentation here on how to install it. </p>  <p>In a nutshell, VorlonJS works on node.js. You can install it from <strong>npm</strong> or clone the <strong>Github</strong> repository locally.     <br />Since the Office addin plugin is currently available only in the <strong>dev branch</strong> from the <strong>Github</strong> repository, you have to clone locally the repository.</p>  <h2>Get the dev branch of VorlonJS</h2>  <p>If you’re familiar with <strong>GIT</strong>, cloning the repository is something you have already done multiples times ! <strong>Just don’t forget to checkout the dev branch</strong>.</p>  <p>Just in case, here are the command lines to clone VorlonJS on your machine:</p>  <blockquote>   <p><strong>git</strong> clone <a title="https://github.com/MicrosoftDX/Vorlonjs.git" href="https://github.com/MicrosoftDX/Vorlonjs.git">https://github.com/MicrosoftDX/Vorlonjs.git</a>&#160; <br /><strong>git</strong> checkout dev       <br /><strong>npm</strong> install</p> </blockquote>  <h2>Enabling HTTPS</h2>  <p>Actually, making an Office Addin requires to be in HTTPS. (You can disable HTTPS for Word / Excel Addin, but you can’t for Outlook)</p>  <p>So, you need to activate HTTPS for your VorlonJS website <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2630.wlEmoticon-smile_39521E18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2630.wlEmoticon_2D00_smile_5F00_39521E18.png" /></p>  <p>First of all, open the <strong>/Vorlon/config.json</strong> file and set the <strong>useSSL</strong> property to true :</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3583.image_0A8EF627.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3583.image_5F00_0A8EF627.png" width="240" height="165" /></p>  <p><strong>VorlonJS</strong> used a localhost certificate, not trusted. You need to install this certificate, to be able to debug your add’in. </p>  <p>Go to <strong>/Vorlon/server/cert/</strong> folder and :</p>  <table cellspacing="0" cellpadding="2" width="848" border="0"><tbody>     <tr>       <td valign="top" width="519">open the <strong>server.crt</strong> certificate and launch the <strong>install certificate </strong>wizard</td>        <td valign="top" width="327"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5554.image_6529F149.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5554.image_5F00_6529F149.png" width="368" height="408" /></td>     </tr>      <tr>       <td valign="top" width="519">Select the <strong>Local Machine</strong> certificate store</td>        <td valign="top" width="327"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/1261.image_79430DD2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/1261.image_5F00_79430DD2.png" width="364" height="356" /></td>     </tr>      <tr>       <td valign="top" width="519">Select the <strong>Trusted Root Cetification Autorithies</strong>, for your newly trusted certificate <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2630.wlEmoticon-smile_39521E18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2630.wlEmoticon_2D00_smile_5F00_39521E18.png" />&#160;</td>        <td valign="top" width="327"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3252.image_224DACCF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3252.image_5F00_224DACCF.png" width="367" height="393" /></td>     </tr>   </tbody></table>  <p>&#160;</p>  <p>You’re almost done.</p>  <h2>Enabling Office addin plugin </h2>  <p>Last step before using <strong>VorlonJS</strong> with the Office-Addin plugin, you need to activate it, since this plugin is not available by default.</p>  <p>Once again, in the <strong>config.json</strong> file, located in /<strong>Vorlon/Server/config.json</strong> and activate it (set to the property enabled to true)</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3580.image_25EE8B2E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3580.image_5F00_25EE8B2E.png" width="640" height="178" /></p>  <p>You’re done ! </p>  <h1>Using the Office-Addin plugin</h1>  <h2>Launch the Dashboard</h2>  <p>The first step is to launch <strong>VorlonJS</strong>. Once again pretty straightforward when you know how to deal with <strong>node.js</strong></p>  <p>you can also use <strong>npm start </strong>( it’s just a shortcut for the command line <strong>node /server/server.js</strong>)</p>  <blockquote>   <p><strong>npm</strong> start</p> </blockquote>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8547.image_2894835D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8547.image_5F00_2894835D.png" width="640" height="305" /></p>  <p>Open your favorite browser and go to the https address : <a href="https://localhost:1337">https://localhost:1337</a>.     <br />you should see the empty dashboard of <strong>VorlonJS</strong> :</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4336.image_31F04891.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4336.image_5F00_31F04891.png" width="615" height="480" /></p>  <h2>Adding VorlonJS script in your Office-Addin project</h2>  <p>In a nutshell, create or open your Office-Addin project, and add this script balise in your html page :</p>  <blockquote>   <p>&lt;script src=&quot;https://localhost:1337/vorlon.js&quot;&gt;&lt;/script&gt;</p> </blockquote>  <p>That’s all !</p>  <p><u>Note :</u> To show you the plugin features, I will use the default starter project created by Visual Studio when you choose a mail application :</p>  <table cellspacing="0" cellpadding="2" width="700" border="0"><tbody>     <tr>       <td valign="top" width="200"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0640.image_3C2BC7C7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0640.image_5F00_3C2BC7C7.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0602.image_thumb_6B6672D4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0602.image_5F00_thumb_5F00_6B6672D4.png" width="327" height="200" /></a></td>        <td valign="top" width="200" align="right">         <p align="right"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/7711.image_0DBE084E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/7711.image_5F00_0DBE084E.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: right; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2112.image_thumb_3AD2F51C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2112.image_5F00_thumb_5F00_3AD2F51C.png" width="273" align="right" height="200" /></a></p>       </td>     </tr>      <tr>       <td valign="top" width="200"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8231.image_2F3D37DD.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8231.image_5F00_2F3D37DD.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3704.image_thumb_5194CD56.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3704.image_5F00_thumb_5F00_5194CD56.png" width="273" height="200" /></a></td>        <td valign="top" width="200" align="right"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/1261.image_5EFAE05C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/1261.image_5F00_5EFAE05C.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3348.image_thumb_00E642E1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3348.image_5F00_thumb_5F00_00E642E1.png" width="302" height="200" /></a></td>     </tr>   </tbody></table>  <p>&#160;</p>  <p>In the <strong>AppCompose/Home/Home.html</strong> here is the script inserted :</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/6201.image_55AC00DC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/6201.image_5F00_55AC00DC.png" width="700" height="317" /></p>  <p>To be able to work with Outlook desktop, I configured the manifest project to launch Office Outlook desktop (instead of launching Office Outlook online)</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/6237.image_25A9943F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/6237.image_5F00_25A9943F.png" width="416" height="480" /></p>  <p>Press F5 and go !</p>  <h2>Use VorlonJS to debug</h2>  <p>Here is my Office-Addin launched in my Outlook desktop :</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0724.image_2297364A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0724.image_5F00_2297364A.png" width="540" height="480" /></p>  <p>And here is my VorlonJS dashboard (which has already made a link to my Office-Addin)</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2110.image_2C37BF9C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2110.image_5F00_2C37BF9C.png" width="800" height="562" /></p>  <p>Obviously, you can use the <strong>VorlonJS</strong> core plugins, like <strong>Dom Explorer</strong>, <strong>Obj Explorer</strong> or the <strong>Interactive Console</strong> to interact with your addin.</p>  <p>A straightforward test : use the <strong>Interactive Console </strong>to send the command to your addin:</p>  <blockquote>   <p>console.log(Office.context.mailbox.item.subject)</p> </blockquote>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5531.image_1B7A8A83.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5531.image_5F00_1B7A8A83.png" width="640" height="248" /></p>  <ol>   <li>VorlonJS will send the command to the Addin. </li>    <li>The Addin will execute it the command line order </li>    <li>VorlonJS will get the response back and show it in the console ! </li> </ol>  <p>&#160;</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2210.image_5D80F9C4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2210.image_5F00_5D80F9C4.png" width="640" height="245" /></p>  <p>Go to the Office-Addin tab</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/1016.image_2035CF68.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/1016.image_5F00_2035CF68.png" width="800" height="493" /></p>  <p>You will see every interesting properties from you Office instance !</p>  <p>for example, the subject is located in the <strong>Office </strong>/ <strong>context </strong>/ <strong>mailbox </strong>/ <strong>item </strong>/ <strong>subject </strong><img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2630.wlEmoticon-smile_39521E18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2630.wlEmoticon_2D00_smile_5F00_39521E18.png" /></p>  <p>You can, as well, execute some functions ! For instance, try to go to the <strong>/body</strong> node and click on the <strong>getAsync</strong> node. In the property window click the invoke, and voilà !</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2337.image_6509A5AF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2337.image_5F00_6509A5AF.png" width="800" height="493" /></p>  <p><strong>FYI</strong> : Some functions are only available in compose mode or in read mode. Don’t be surprise if some functions actually don’t work. Try again in the other mode (read / compose)</p>  <p>For fun, in Read mode, launch the method <strong>displayReplayAllForm</strong> :</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2313.image_099DC3E5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2313.image_5F00_099DC3E5.png" width="800" height="493" /></p>  <p>You should see the Reply Form popup !</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5661.image_7BF05C0F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5661.image_5F00_7BF05C0F.png" width="564" height="480" /></p>  <h1>Conclusion</h1>  <p>You have now a really straightforward tool to debug your Office-Addin, even if you’re debugging from a mobile device <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2630.wlEmoticon-smile_39521E18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2630.wlEmoticon_2D00_smile_5F00_39521E18.png" /></p>  <p>We don’t have seen every features, don’t forget to use the <strong>dom explorer</strong> to debug your layout, the <strong>object explorer</strong> to see any object instanciated in your addin, the <strong>XHR request manager</strong> to trace any xhr requests etc …</p>  <p>Seb</p>]]></content:encoded>
    </item>
    <item>
      <title>Babylonjs generator</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/babylonjs-generator</link>
      <pubDate>Thu, 03 Dec 2015 06:19:35 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/2015/12/03/babylonjs-generator/</guid>
      <description><![CDATA[Hi Everyone.  If you have any question about this article, feel free to contact me on twitter:...]]></description>
      <content:encoded><![CDATA[<p>Hi Everyone.</p> <blockquote> <p><i>If you have any question about this article, feel free to contact me on twitter: <a href="https://twitter.com/sebastienpertus">https://twitter.com/sebastienpertus</a> </i></p></blockquote> <p>Today I want to share with you a new project I work on those days. The idea is to bring you a new tool to generate code for <a href="https://www.babylonjs.com" target="_blank">BabylonJS</a></p> <p>Imagine you want to create a quick project with BabylonJS. You have to create a project, reference BabylonJS, create a simple scene, add assets and so on.</p> <p>It’s straightforward, but we can do better…</p> <p><a href="https://www.npmjs.com/package/generator-babylonjs" target="_blank">BabylonJS Generator</a> is a npm package based on <a href="https://yeoman.io/" target="_blank">Yeoman</a> to provide you a simple way to create a BabylonJS project, hosted on node.js</p> <p><a href="https://yeoman.io/" target="_blank">Yeoman</a> generator is already used with a lot of project (angular, webapp, wordpress, asp.net, office addins and so on …)</p> <p>Check the generators here : <a title="https://yeoman.io/generators/" href="https://yeoman.io/generators/">https://yeoman.io/generators/</a>&nbsp;</p> <h2>The Babylon generator</h2> <h3>Installation</h3> <p>First, install <a href="https://yeoman.io/">Yeoman</a> and generator-babylonjs using <a href="https://www.npmjs.com/">npm</a> (we assume you have pre-installed <a href="https://nodejs.org/">node.js</a>).  <p><strong>This step has to be done only one time. The “-g” argument will install those packages globally to your computer. </strong> <blockquote><pre><code><pre><p>npm install -g yo</p><p>npm install -g generator-babylonjs</p></pre></code></pre></blockquote>
<p>From now, you can generate your new project with this simple command :</p><code><pre><blockquote><p>yo babylonjs</p></blockquote></pre><pre>&nbsp;</pre><pre><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4744.image_271F138D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4744.image_5F00_271F138D.png" width="640" height="277"></pre><pre>&nbsp;</pre><pre><font face="Segoe UI">Actually you can choose the <strong>title</strong>, <strong>creating or not a folder</strong> for you solution and then choose the <strong>node.js port</strong>.</font></pre><pre><font face="Segoe UI">Once the generator is done, you can open your project with your favorite IDE  (<a href="https://code.visualstudio.com/">Visual Studio Code</a> for me ):</font></pre><pre><font face="Segoe UI">You will have a complete project based on :</font></pre>
<ol>
<li><font face="Segoe UI"><strong>Node.js</strong> for the server side</font></li>
<li><font face="Segoe UI"><strong>Jade</strong> for the client template engine (well to be honest, we just need a canvas element <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3531.wlEmoticon-smile_1712D587.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3531.wlEmoticon_2D00_smile_5F00_1712D587.png">)</font></li>
<li><font face="Segoe UI"><strong>Express</strong> for the routing / middleware engine.</font></li>
<li><font face="Segoe UI"><strong>BabylonJS</strong> (obviously !) for the 3D JavaScript engine.</font></li></ol><pre><font face="Segoe UI">All the required JavaScript code is located in the <strong>/public/scripts/index.js </strong>file.</font></pre><pre><font face="Segoe UI">From now, you can hit <strong>F5</strong> (on VS Code) or just run <strong>node</strong> :</font></pre>
<blockquote><pre><font face="Segoe UI">node app.js</font></pre></blockquote><pre><font face="Segoe UI">And we’re done !</font></pre><pre><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5468.image_4493F54A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5468.image_5F00_4493F54A.png" width="640" height="418"></pre></code><code></code>
<h3>Playground option</h3>
<p>here is an other interesting option : If you found a cool scene from the playground, you can generate the full code with the playground scene identifier : 
<p>Imagine this playground sample : <a href="https://www.babylonjs-playground.com/#11OYNB#12">https://www.babylonjs-playground.com/#11OYNB#12</a> 
<p><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/1307.image_30F4EC8E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/1307.image_5F00_30F4EC8E.png" width="640" height="355"> 
<p>would it be cool to generate the full project based on this sample ? <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3531.wlEmoticon-smile_1712D587.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3531.wlEmoticon_2D00_smile_5F00_1712D587.png"> 
<p>Well, just add the argument <strong>–playground</strong> to your command line to generate the full playground sample code :<pre><code><pre><blockquote><p>yo babylonjs --playground #11OYNB#12</p></blockquote><p>&nbsp;</p><p><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/7220.image_1191FA21.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/7220.image_5F00_1191FA21.png" width="452" height="480"></p><p>&nbsp;</p><p><font face="Segoe UI">With this option, all the code is downloaded from the playground and then injected in the <strong>index.js</strong> file :</font></p><p>&nbsp;</p><p><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3377.image_5A4B72E5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3377.image_5F00_5A4B72E5.png" width="640" height="403"></p><p>&nbsp;</p><p><font face="Segoe UI">Like we’ve done before, just hit <strong>F5</strong> or run <strong>node</strong> <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3531.wlEmoticon-smile_1712D587.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3531.wlEmoticon_2D00_smile_5F00_1712D587.png"></font></p><p><font face="Segoe UI"></font>&nbsp;</p><blockquote><p><font style="background-color: #ffffff" face="Segoe UI">node app.js</font></p></blockquote><p><font face="Segoe UI"></font>&nbsp;</p><p><font face="Segoe UI">and we’re done (again <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3531.wlEmoticon-smile_1712D587.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3531.wlEmoticon_2D00_smile_5F00_1712D587.png"> ) !</font></p><p>&nbsp;</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8156.image_02E9DEED.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8156.image_5F00_02E9DEED.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2465.image_thumb_2D1D2AE9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2465.image_5F00_thumb_5F00_2D1D2AE9.png" width="640" height="418"></a></p><p>&nbsp;</p><p><font face="Segoe UI">Cool ? <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3531.wlEmoticon-smile_1712D587.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3531.wlEmoticon_2D00_smile_5F00_1712D587.png"></font></p><font face="Segoe UI"></pre></code></pre></font>
<h4>More on BabylonJS</h4>
<p>Getting started? Play directly with the Babylon.js API via our <a href="https://www.babylonjs.com/playground">playground</a>. It contains also lot of simple samples to learn how to use it. 
<h5><a href="https://www.npmjs.com/package/generator-babylonjs#useful-links">Useful links</a></h5>
<ul>
<li>Official web site: <a href="https://www.babylonjs.com/">www.babylonjs.com</a> 
<li>Official <a href="https://www.html5gamedevs.com/forum/16-babylonjs/">forum</a> on www.html5gamedevs.com 
<li>Online <a href="https://www.babylonjs.com/sandbox">sandbox</a> where you can test your .babylon scenes with a simple drag'n'drop 
<li>Online <a href="https://www.babylonjs.com/cyos/">shader creation tool</a> where you can learn how to create GLSL shaders 
<li>3DS Max <a href="https://github.com/BabylonJS/Babylon.js/tree/master/Exporters/3ds%20Max">exporter</a> can be used to generate a .babylon file from 3DS Max 
<li>Blender <a href="https://github.com/BabylonJS/Babylon.js/tree/master/Exporters/Blender">exporter</a> can be used to generate a .babylon file from Blender 3d 
<li>Unity 5 <a href="https://github.com/BabylonJS/Babylon.js/tree/master/Exporters/Unity%205">exporter</a> can be used to export your geometries from Unity 5 scene editor 
<li>FBX command line <a href="https://github.com/BabylonJS/Babylon.js/tree/master/Exporters/FBX">exporter</a> can be used to generate a .babylon file from .FBX file (animations are supported)</li></ul>
<h5><a href="https://www.npmjs.com/package/generator-babylonjs#documentation">Documentation</a></h5>
<ul>
<li><a href="https://doc.babylonjs.com/">Documentation</a> 
<li><a href="https://doc.babylonjs.com/generals/Roadmap">Roadmap</a> 
<li><a href="https://github.com/BabylonJS/Samples">Samples</a> 
<li><a href="https://www.youtube.com/watch?v=z80TYMqsdEM">Video overview (1 hour) of BabylonJS features</a> 
<li><a href="https://www.microsoftvirtualacademy.com/training-courses/introduction-to-webgl-3d-with-html5-and-babylon-js">Complete course (8 hours)</a></li></ul>
<h4><a href="https://www.npmjs.com/package/generator-babylonjs#getting-to-know-yeoman">Getting To Know Yeoman</a></h4>
<p>Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced. Feel free to <a href="https://yeoman.io/">learn more about him</a>. 



]]></content:encoded>
    </item>
    <item>
      <title>Office 365 add in and BabylonJS</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/office-365-add-in-and-babylonjs</link>
      <pubDate>Mon, 02 Nov 2015 01:15:16 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/2015/11/02/office-365-add-in-and-babylonjs/</guid>
      <description><![CDATA[Hi everyone;  Today I want to share with you a very cool demo I realized for the French event...]]></description>
      <content:encoded><![CDATA[<p>Hi everyone;</p>  <p>Today I want to share with you a very cool demo I realized for the French event <a href="https://techdays.microsoft.fr/">Techdays 2015</a>.</p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4721.image_59BBF69A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4721.image_5F00_59BBF69A.png" width="800" height="293" /></p>  <p><em><font size="1">Yes, it’s me <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5127.wlEmoticon-smile_1005E864.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5127.wlEmoticon_2D00_smile_5F00_1005E864.png" />         <br />Yes, I forgot to take off my badge during the keynote! <img class="wlEmoticon wlEmoticon-openmouthedsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Rire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8468.wlEmoticon-openmouthedsmile_0EED3120.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8468.wlEmoticon_2D00_openmouthedsmile_5F00_0EED3120.png" /></font></em></p>  <p>Everything shown here is available in the official <strong>Office dev Github repository</strong>: <a title="https://github.com/OfficeDev/Excel-Add-in-JS-BabylonJS" href="https://github.com/OfficeDev/Excel-Add-in-JS-BabylonJS">https://github.com/OfficeDev/Excel-Add-in-JS-BabylonJS</a></p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8015.image_75E3BC70.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8015.image_5F00_75E3BC70.png" width="800" height="221" /></p>  <h2>Intro</h2>  <p>The goal is to demonstrate the easy use of Office 365 dev application model and the BabylonJS framework.    <br />The main purpose of this demo is to show the path-finding of people inside the Microsoft France Lobby as show in this screenshot:</p>  <p><img style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="" src="https://github.com/OfficeDev/Excel-Add-in-JS-BabylonJS/raw/master/ReadmeAssets/01.jpg" width="800" height="442" /></p>  <p>If you want to know more about BabylonJS and how to use it, feel free, all about this fantastic framework is available here : <a href="https://www.babylonjs.com">https://www.babylonjs.com</a></p>  <p>In my opinion, here are the three main interesting points of this development:</p>  <ol>   <li>Use of the <strong>Office.js</strong> SDK to be able to communicate between my add in and the current worksheet. </li>    <li>Use of the <strong>BabylonJS</strong> SDK to create a smooth and incredibles animations in a full 3D real time environment. </li>    <li>Use of <strong>Typescript</strong> to be able to write a full comprehensible and maintainable JavaScript project (and by the way, I'm a C# developer, Typescript is therefore obvious for me) </li> </ol>  <h2>Office Add In</h2>  <p>First of all, the main url for &quot;<em>All-Whant-You-Need</em>&quot; about Office dev, is here : <a href="https://dev.office.com">https://dev.office.com</a></p>  <p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3036.image_7B4083F9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3036.image_5F00_7B4083F9.png" width="800" height="200" /></p>  <h3>Geting datas from Excel worksheet</h3>  <p>The main source code is maintained in the <em>App/Welcome/Tracker.ts</em> file</p>  <p>The <strong>_setTableBinding</strong> method is called once the scene AND the file is completely loaded . I used the <strong>addFromNamedItemAsync</strong> method to create a basic binding:</p>  <p>By default, adding a table in <strong>Excel </strong>assigns the name &quot;Table1&quot; for the first table you add, &quot;Table2&quot; for the second table you add, and so on.     <br />Be careful, In <strong>Excel</strong>, when specifying a table as a named item, you must fully qualify the name to include the worksheet name in the name of the table in this format: &quot;<strong>Sheet1!Table1</strong>&quot;, as you can see in this code :</p>  <blockquote>   <p>private _setTableBinding() {      <br />&#160;&#160;&#160; /// &lt;signature&gt;       <br />&#160;&#160;&#160; ///&#160;&#160; &lt;summary&gt;Create a binding to later gate the datas&lt;/summary&gt;       <br />&#160;&#160;&#160; /// &lt;/signature&gt;</p>    <p>&#160;&#160;&#160; Office.context.document.bindings.addFromNamedItemAsync(&quot;Sheet1!Table1&quot;,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Office.BindingType.Table, { id: &quot;positions&quot; },       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (asyncResult: any) =&gt; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (asyncResult.status === &quot;failed&quot;) {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; console.log(&quot;Error: &quot; + asyncResult.error.message);       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this._tableBinding = asyncResult.value;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (e) {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; console.log(e);       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; });       <br />}       <br /></p> </blockquote> Before going in the <strong>BabylonJS</strong> code, you have to get all the datas from you <strong>Excel</strong> table. You will find the code in the <strong>playDatas()</strong> method:   <p>As you can see, I used two useful options when I get datas with the <strong>getDataSync</strong> method :</p>  <ol>   <li><strong>valueFormat : Office.ValueFormat.Unformatted</strong> : To be able to parse the current datas, useful for date, number etc … </li>    <li><strong>filterType: Office.FilterType.OnlyVisible</strong> : It’s a great option in my scenario, because with the Straightfoward filters in an Excel worksheet, I can isolate a particular path-finding ! </li> </ol>  <p>   <br />More about <strong>getDataAsync</strong> method : <a title="https://msdn.microsoft.com/en-us/library/office/fp161073.aspx" href="https://msdn.microsoft.com/en-us/library/office/fp161073.aspx">https://msdn.microsoft.com/en-us/library/office/fp161073.aspx</a></p>  <blockquote>   <p>// Get datas      <br />this._tableBinding.getDataAsync(       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Options : We can get filtered or not datas       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; filterType: Office.FilterType.OnlyVisible,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Options : To be able to work with those datas, no format will help, later       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; valueFormat: Office.ValueFormat.Unformatted       <br />&#160;&#160;&#160; },       <br />&#160;&#160;&#160; (result) =&gt; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (result.status === &quot;succeeded&quot;) {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Rows       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var rows = result.value.rows;</p>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // etc ...      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br />&#160;&#160;&#160; });</p> </blockquote>  <h3>Localization</h3>  <p>The UIStrings.js file is here to localize the application. Basically, you have to :</p>  <ol>   <li>Localize everything that is not handled by you : <strong>Title </strong>and <strong>Description</strong> in the ribbon for example </li>    <li>Localize your application handled by you </li> </ol>  <p>   <br />In the manifest file (you should open it in XML mode) check that you have corrects values for each language you handle :</p>  <blockquote>   <p>&lt;DefaultLocale&gt;en-US&lt;/DefaultLocale&gt;</p>    <p>&lt;DisplayName DefaultValue=&quot;Lobby pathfinding application&quot;&gt;      <br />&#160;&#160; &lt;Override Locale=&quot;fr-FR&quot; Value=&quot;Gestion des passages&quot;/&gt;       <br />&lt;/DisplayName&gt;       <br />&lt;Description DefaultValue=&quot;An app which show the people pathfinding&quot;&gt;       <br />&#160;&#160; &lt;Override Locale=&quot;fr-FR&quot; Value=&quot;Une application pour suivre les passages via le hall d'accueil&quot;/&gt;       <br />&lt;/Description&gt;</p> </blockquote>  <p>In the other hand, for everything else, you can use two kind of informatins to know what language you should apply. In my case I use the display language to localize my add in :</p>  <blockquote>   <p>// Document language      <br />var contentLanguage = Office.context.contentLanguage;       <br />// Display language       <br />var displayLanguage = Office.context.displayLanguage;</p>    <p>// Choose Display or Document language      <br />var UIText = UIStrings.getLocaleStrings(displayLanguage);</p> </blockquote>  <h2>BabylonJS</h2>  <p>In this sample using BabylonJS is pretty straightforward. for those of you interested in, here are the main steps to make babylonJS works :</p>  <ol>   <li>Get a HTML5 <strong>canvas</strong> render surface </li>    <li>Create a <strong>BabylonJS engine</strong> instance binded to your canvas </li>    <li>Create a <strong>scene</strong> composed of :       <ol>       <li>A complete 3D modelised scene (the lobby in this sample) (imported with the Babylon <strong>SceneLoader</strong> </li>        <li>Add a <strong>free camera</strong> </li>        <li>Add a <strong>light</strong> </li>     </ol>   </li>    <li>When my datas from my worksheet are loaded (and binded) create all the <strong>animations </strong>of every path-finding <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5127.wlEmoticon-smile_1005E864.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5127.wlEmoticon_2D00_smile_5F00_1005E864.png" /> </li>    <li><strong>Render</strong> the scene .. in a render loop <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5127.wlEmoticon-smile_1005E864.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5127.wlEmoticon_2D00_smile_5F00_1005E864.png" /> </li> </ol>  <p>   <br />The launchScene method is the main method where you initialize all what you need. This method is always called when your document&#160; AND when Office is ready :</p>  <blockquote>   <p>// launch the scene when office AND document are ready      <br />Office.initialize = function (reason) {       <br />&#160;&#160;&#160; $(document).ready(function () {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; tracker.launchScene();       <br />&#160;&#160;&#160; }       <br />});       <br /></p> </blockquote>  <p>Here is the <strong>launchScene</strong> method, as you can expect, we basically get the canvas, create an engine, create the scene, and call the render method :</p>  <blockquote>   <p>public launchScene() {      <br />&#160;&#160;&#160;&#160; /// &lt;signature&gt;       <br />&#160;&#160;&#160;&#160; ///&#160;&#160; &lt;summary&gt;Launch the scene &lt;/summary&gt;       <br />&#160;&#160;&#160;&#160; /// &lt;/signature&gt;</p>    <p>&#160;&#160;&#160;&#160; try {</p>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Check if BabylonJS is supported      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (!BABYLON.Engine.isSupported()) {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (this.engine) {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.engine.dispose();       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.engine = null;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.canvas = &lt;HTMLCanvasElement&gt;document.getElementById(&quot;renderCanvas&quot;);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.engine = new BABYLON.Engine(this.canvas, true);       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.scene = this._createScene();</p>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Here we go ! RENDERING BABY !      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.engine.runRenderLoop(() =&gt; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.scene.render();       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; });       <br />&#160;&#160;&#160;&#160; } catch (e) {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; console.log(e.message);       <br />&#160;&#160;&#160;&#160; }       <br />}</p> </blockquote>  <p><font style="background-color: #f9f9f9">Before creating the animations, we create the scene, as I said earlier :</font></p>  <blockquote>   <p>private _createScene() {      <br />&#160;&#160;&#160; /// &lt;signature&gt;       <br />&#160;&#160;&#160; ///&#160;&#160; &lt;summary&gt;Creating the scene (see BabylonJS documentation) &lt;/summary&gt;       <br />&#160;&#160;&#160; /// &lt;/signature&gt;</p>    <p>&#160;&#160;&#160; this.scene = new BABYLON.Scene(this.engine);</p>    <p>&#160;&#160;&#160; this._freeCamera = new BABYLON.FreeCamera(&quot;FreeCamera&quot;, new BABYLON.Vector3(0, 0, 5), this.scene);      <br />&#160;&#160;&#160; this._freeCamera.rotation = new BABYLON.Vector3(0, Math.PI, 0);</p>    <p>&#160;&#160;&#160; this.scene.activeCamera = this._freeCamera;      <br />&#160;&#160;&#160; this._freeCamera.attachControl(this.canvas, true);</p>    <p>&#160;&#160;&#160; var light = new BABYLON.HemisphericLight(&quot;hemi&quot;, new BABYLON.Vector3(0, 1, 0), this.scene);</p>    <p>&#160;&#160;&#160; // Resizing the add in      <br />&#160;&#160;&#160; window.addEventListener(&quot;resize&quot;, () =&gt; { this.engine.resize(); });</p>    <p>     <br />&#160;&#160;&#160; // The first parameter can be used to specify which mesh to import. Here we import all meshes       <br />&#160;&#160;&#160; BABYLON.SceneLoader.ImportMesh(&quot;&quot;, &quot;/Assets/&quot;, &quot;Welcome.babylon&quot;,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.scene, (newMeshes: BABYLON.AbstractMesh[]) =&gt; {</p>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // position Camera      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this._setFreeCameraPosition();</p>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //bind to existing datas      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this._setTableBinding();       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; });</p>    <p>&#160;&#160;&#160; return this.scene;      <br />}       <br /></p> </blockquote>  <p><font style="background-color: #f9f9f9"></font></p>  <p><font style="background-color: #f9f9f9">Animating every path-finding, thanks to BabylonJS, is pretty straightforward.      <br />When the user will click the Play button, I call the <strong>playDatas()</strong> method and I create all the animations then launch them :</font></p>  <p><font style="background-color: #f9f9f9"><em>The code presented here is not complete, it just highlights what I think is important <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5127.wlEmoticon-smile_1005E864.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5127.wlEmoticon_2D00_smile_5F00_1005E864.png" /> For the complete code, just refer the Github repo</em></font></p>  <blockquote>   <p>for (var i = 0; i &lt; lstGrp.length; i++) {      <br />&#160;&#160;&#160;&#160; var sphTab = lstGrp[i];</p>    <p>&#160;&#160;&#160;&#160; // Every sphere must have a uniquename      <br />&#160;&#160;&#160;&#160; var sphereName = &quot;d_&quot; + sphTab[0][0] + &quot;sphere&quot;;       <br />&#160;&#160;&#160;&#160; // Create the sphere       <br />&#160;&#160;&#160;&#160; var sphere = BABYLON.Mesh.CreateSphere(sphereName + &quot;_sphere&quot;, 8, 4, this.scene);</p>    <p>&#160;&#160;&#160;&#160; // Create a yellow texture      <br />&#160;&#160;&#160;&#160; var m = new BABYLON.StandardMaterial(&quot;texture2&quot;, this.scene);       <br />&#160;&#160;&#160;&#160; m.diffuseColor = new BABYLON.Color3(1, 1, 0); // yellow       <br />&#160;&#160;&#160;&#160; sphere.material = m;       <br />&#160;&#160;&#160;&#160; sphere.isPickable = true;</p>    <p>&#160;&#160;&#160;&#160; // Create an animation path      <br />&#160;&#160;&#160;&#160; var animationPath = new BABYLON.Animation(sphereName + &quot;_animation&quot;, &quot;position&quot;, (30 * this.accelerate),       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; BABYLON.Animation.ANIMATIONTYPE_VECTOR3,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);</p>    <p>&#160;&#160;&#160;&#160; this._animations.push(animationPath);</p>    <p>&#160;&#160;&#160;&#160; // Create all the frames for each sphere      <br />&#160;&#160;&#160;&#160; var keys = [];       <br />&#160;&#160;&#160;&#160; var maxFrame = 0;       <br />&#160;&#160;&#160;&#160; // in each group, each pos       <br />&#160;&#160;&#160;&#160; for (var j = 0; j &lt; sphTab.length; j++) {</p>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var pos = new BABYLON.Vector3(posX, posY, posZ);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; keys.push({ frame: currentFrame, value: pos });</p>    <p>&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160; animationPath.setKeys(keys);       <br />&#160;&#160;&#160;&#160; sphere.animations.push(animationPath);</p>    <p>&#160;&#160;&#160;&#160; // Launch the animation for this sphere      <br />&#160;&#160;&#160;&#160; this.scene.beginAnimation(sphere, 0, maxFrame, true);</p>    <p>}</p> </blockquote>  <h2>Try it out</h2>  <h3>Get the sample</h3>  <p>Clone or download the sample, open it with <strong>Visual Studio 2015</strong>.</p>  <p>Please check in add in project if the start object is &quot;<em>Accueil.xls</em>&quot;.     <br />This Excel file contains pre-populated datas, mandatory for the demo :</p>  <p><a href="https://github.com/OfficeDev/Excel-Add-in-JS-BabylonJS/blob/master/ReadmeAssets/03.jpg"><img alt="" src="https://github.com/OfficeDev/Excel-Add-in-JS-BabylonJS/raw/master/ReadmeAssets/03.jpg" /></a></p>  <p>Hit <strong>F5</strong> and try it !</p>]]></content:encoded>
    </item>
    <item>
      <title>Azure AD B2C</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/azure-ad-b2c</link>
      <pubDate>Wed, 23 Sep 2015 07:42:00 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/2015/09/23/azure-ad-b2c/</guid>
      <description><![CDATA[Bonjour &agrave; tous;
Le 16 Septembre a &eacute;t&eacute; annonc&eacute; l'arriv&eacute;e d'une...]]></description>
      <content:encoded><![CDATA[<p>Bonjour &agrave; tous;</p>
<p>Le 16 Septembre a &eacute;t&eacute; annonc&eacute; l'arriv&eacute;e d'une nouvelle fonctionnalit&eacute; dans Azure AD : le mode <strong>B2C</strong> et <strong>B2B</strong>. <br />Vous pouvez d'ailleurs lire l'annonce sur le blog officiel de l'&eacute;quipe Active Directory ici :&nbsp;<a href="https://blogs.technet.com/b/ad/archive/2015/09/09/azure-ad-b2c-and-b2b-are-now-in-public-preview.aspx">https://blogs.technet.com/b/ad/archive/2015/09/09/azure-ad-b2c-and-b2b-are-now-in-public-preview.aspx</a>&nbsp;</p>
<p>Aujourd'hui nous allons nous int&eacute;resser au mod&egrave;le B2C.</p>
<p><span style="font-size: 18pt;">L'int&eacute;ret du truc ?</span></p>
<p>Beaucoup d'entre vous ont d&eacute;j&agrave; utilis&eacute; diff&eacute;rents SDK pour g&eacute;rer l'authentification de vos utilisateurs par <strong>Facebook</strong>, <strong>Twitter</strong> ou <strong>Google+</strong> (ou <strong>Microsoft Account</strong> ? )</p>
<p>Bien entendu, on a pas attendu ce jour b&eacute;ni pour fournir des services "<strong><em>all in zi-box</em></strong>" pour g&eacute;rer l'authentification :</p>
<ul>
<li>Mutualisation de ces m&eacute;canismes dans <strong>Azure Mobile Services</strong>.</li>
<li><strong>Templates</strong> &eacute;volu&eacute;s <strong>ASP.NET</strong> pour g&eacute;rer le multi auth avec le middleware OWIN</li>
<li>Diff&eacute;rents SDK clients comme <strong>PASSPORT</strong> pour Node.js</li>
<li>Les SDK <strong>ADAL.NET</strong> et <strong>ADAL.JS</strong> pour g&eacute;rer l'authentification&nbsp;</li>
<li>Et plein d'autres dont je ne me rappelle plus et que vous connaissez suremment</li>
</ul>
<p>Tout &ccedil;a fonctionne bien, mais la question qui revient en boucle c'est "<strong>On fait quoi des informations de notre utilisateur une fois celui ci connect&eacute; ?</strong>"</p>
<p>Aujourd'hui, vous allez pouvoir <strong>g&eacute;rer vos utilisateurs dans un annuaire unique</strong>, quelque soit le fournisseur d'ac&egrave;s qu'a choisit votre utilisateur.<br />Avant, il fallait obligatoirement g&eacute;rer vos utilisateurs depuis votre propre backend (Bon, il faut bien avouer que beaucoup de choses &eacute;taient bien automatis&eacute;es et cr&eacute;&eacute;s pour vous, et qui masquaient la tuyauterie)</p>
<p>Vous n'avez PLUS besoin de g&eacute;rer les informations par vous m&ecirc;me lors du retour de l'API Facebook, Twitter ou autre. Avant, lors d'une authentification Facebook par exemple, il fallait r&eacute;cup&eacute;rer les informations de l'utilisateur comme son ID, email, Ville etc ... et les enregistrer dans une base locale ou autre.<br />Aujourd'hui ce service est fourni par <strong>Azure AD B2C</strong>.<br />Mieux, vous allez pouvoir <strong>ajouter vos propres champs personnalis&eacute;s</strong>, et c'est encore g&eacute;r&eacute; pour vous (et c'est cadeau)</p>
<p>Un <strong>meilleur management de vos fournisseurs d'acc&egrave;s</strong>. Avant, pour ajouter ou supprimer un fournisseur d'acc&egrave;s externe, il fallait, &agrave; <em>m'ment-donn&eacute; (Copyright Sud Ouest),</em>&nbsp;mettre les mains dans le camboui et ajouter ou supprimer du code, ne serait-ce que pour faire apparaitre ou disparaitre les boutons de login :)<br />Aujourd'hui, tout &ccedil;a est encore une fois g&eacute;r&eacute; pour vous.</p>
<p>Plus besoin de param&eacute;trer l'ensemble de vos <strong>ClientID</strong> / <strong>ClientSecret</strong> dans votre application, tout &ccedil;a se fait depuis Azure AD B2C. Cool !</p>
<p>Bref, un v&eacute;ritable concentrateur d'ididentit&eacute; externe arrive, et va vraiment nous faciliter la vie. Et &ccedil;a ... c'est swag...</p>
<p><span style="font-size: 14pt;">Cr&eacute;er votre AD B2C</span></p>
<p><strong>Attention</strong> : Une limitation "pour l'instant" : Une fois cr&eacute;&eacute;, vous ne pouvez plus supprimer votre annuaire (je vous aurai pr&eacute;venu hein. Pas taper, pas taper, &ccedil;a va venir)</p>
<p><strong>Attention bis</strong> : Une autre limitation : On cr&eacute;e l'annuaire depuis l'ancienne interface (<a href="https://manage.windowsazure.com">https://manage.windowsazure.com</a>) et on administre depuis la nouvelle interface (<a href="https://portal.azure.com">https://portal.azure.com</a>) (pas taper tou&ccedil;a tou&ccedil;a)</p>
<p>Vous vous loguez donc sur l'ancien portail et cr&eacute;&eacute; un Azure AD o&ugrave; vous pr&eacute;cisez bien que cet AD est un AD B2C :</p>
<p><img style="vertical-align: middle;" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3288.01.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3288.01.png" alt="" width="600" height="134" /></p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3036.02.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3036.02.png" alt="" width="400" height="333" /></p>
<p>Une fois cr&eacute;&eacute;, tout le reste se passe dans le nouveau portail. Il suffit donc de cliquer sur Gestion des param&egrave;tres B2C pour ouvrir le nouveau portail :</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0312.03.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0312.03.png" alt="" width="600" height="384" /></p>
<p>et hop !</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4113.04.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4113.04.png" alt="" width="600" height="510" /></p>
<p>A partir de l&agrave;, il ne reste plus qu'&agrave; configurer :)</p>
<p><span style="font-size: 14pt;">Applications</span></p>
<p>Vous cr&eacute;&eacute;z une application (un peu comme sur Facebook ou Twitter ou Microsoft Account) qui sera de type Web App / Native Client.<br />C'est cette application seule qui sera &agrave; configurer depuis votre application mobile ou votre site web (c'est elle qui f&eacute;d&egrave;re tous les autres)</p>
<p>Lorsque vous cr&eacute;&eacute;z votre application, n'oubliez pas de noter votre Application <strong>Client Id</strong> et votre <strong>App key</strong> (on dit souvent <strong>Client Secret</strong> aussi)</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0654.05.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0654.05.png" alt="" width="600" height="337" /></p>
<p><span style="font-size: 14pt;">Identity Providers</span></p>
<p>Ici vous allez empiler les fournisseurs que vous voulez utiliser pour authentifier vos utilisateurs.<br />Ce qui est <strong>TRES BIEN</strong> ici c'est que vous ajoutez et configurez vos fournisseurs, mais vous n'&ecirc;tes pas oblig&eacute; de tous les utiliser (dans un premier temps)<br />Globalement on ajoute des fournisseurs et on les utilise ... ou pas (sans &ecirc;tre oblig&eacute; de les supprimer)</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5123.06.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5123.06.png" alt="" width="600" height="258" /></p>
<p>Chaque fournisseur doit &ecirc;tre configur&eacute;. Voici une documentation r&eacute;cente sur comment &ccedil;a marche :</p>
<ol>
<li>Facebook :&nbsp;<a href="https://azure.microsoft.com/en-gb/documentation/articles/active-directory-b2c-setup-fb-app/">https://azure.microsoft.com/en-gb/documentation/articles/active-directory-b2c-setup-fb-app/</a></li>
<li>Google+ :&nbsp;<a href="https://azure.microsoft.com/en-gb/documentation/articles/active-directory-b2c-setup-goog-app/">https://azure.microsoft.com/en-gb/documentation/articles/active-directory-b2c-setup-goog-app/</a>&nbsp;</li>
<li>Amazon :&nbsp;<a href="https://azure.microsoft.com/en-gb/documentation/articles/active-directory-b2c-setup-amzn-app/">https://azure.microsoft.com/en-gb/documentation/articles/active-directory-b2c-setup-amzn-app/</a>&nbsp;</li>
<li>Linked IN :&nbsp;<a href="https://azure.microsoft.com/en-gb/documentation/articles/active-directory-b2c-setup-li-app/">https://azure.microsoft.com/en-gb/documentation/articles/active-directory-b2c-setup-li-app/</a>&nbsp;</li>
</ol>
<p>Oui je sais, il manque encore Twitter ou Microsoft Account (pas taper ...) &ccedil;a va venir !</p>
<p><span style="font-size: 14pt;">Attributs personnalis&eacute;s</span></p>
<p>Encore un truc bien cool et bien pens&eacute;. Par d&eacute;faut vous allez pouvoir utiliser des champs pour ajouter de la valeur au profil de votre utilisateur. De base &eacute;videmment, on a des champs disponibles comme le mail, nom, ville, User Object ID etc...</p>
<p>Mais vous pouvez en ajouter &agrave; volont&eacute;. Pour le moment, on est limit&eacute; &agrave; des chaines de caract&egrave;res. On peut imaginer un champ Fidility Points, repr&eacute;sentant des points de fid&eacute;lit&eacute; (imagination d&eacute;bordante de votre serviteur ...)&nbsp;</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4478.07.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4478.07.png" alt="" width="600" height="267" /></p>
<p><span style="font-size: 14pt;">Policies ou R&egrave;gles de s&eacute;curit&eacute;</span></p>
<p>Tout ce que nous avons fait jusque l&agrave; repr&eacute;sente de la configuration. C'est maitenant que nous allons vraiment utiliser notre application / &nbsp;fournisseurs / champs perso. pour cr&eacute;er une exp&eacute;rience d'authentification.&nbsp;Mais pas que ...</p>
<p>Comme on l'a vu, on va avoir la possiblit&eacute; de manager nos utilisateurs : S'inscrire, Se signer, Modifier son profil, Faire un reset de son mot de passe etc ...</p>
<p>Pour chaque grande famille, nous allons cr&eacute;er des "policies". Appelons &ccedil;a des r&egrave;gles de s&eacute;curit&eacute; :</p>
<ol>
<li>Une r&egrave;gle pour l'inscription</li>
<li>Une r&egrave;gle pour l'authentification</li>
<li>Une r&egrave;gle pour l'&eacute;dition du profil</li>
</ol>
<p>Chaque r&egrave;gle va comporter plusieurs choix :</p>
<ol>
<li>Quelle application ? (cette application qui contient ClientId / ClientSecret)</li>
<li>Quels fournisseurs ? Un ou plusieurs (Classique, Facebook, Google+ etc ...)</li>
<li>Quels attributs on veut exposer / r&eacute;cup&eacute;rer ? (On va voir &ccedil;a en d&eacute;tail)</li>
<li>Est-ce que l'authentification multifacteur doit &ecirc;tre activ&eacute;e ?</li>
<li>Comment personnaliser la page expos&eacute;e ?</li>
</ol>
<p><span style="font-size: 14pt;">R&egrave;gle pour l'inscription : Sign Up Policy</span></p>
<p>Cette r&egrave;gle doit ex&eacute;cuter plusieurs choses:</p>
<ol>
<li>Exposer les fournisseurs s'il y a plus d'un.</li>
<li>S'authentifier aupr&eacute;s du fournisseur et r&eacute;cup&eacute;rer les champs que vous avez configur&eacute;.</li>
<li>Proposer des champs de saisie pour les champs qui ne sont pas propos&eacute;s par le fournisseur.</li>
</ol>
<p>Pour mon exemple, je d&eacute;cide de cr&eacute;er une r&egrave;gle qui expose tous les fournisseurs, je la nomme <strong>ALL</strong> (A post&eacute;riori j'aurai d&ucirc; l'appeler <strong>ALL_SIGN_IN</strong>, vu que les noms de policies doivent &ecirc;tre uniques)</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4011.08.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4011.08.png" alt="" width="700" height="183" /></p>
<p>Si demain, vous decidiez de ne plus utiliser par exemple le fournisseur Google+ il suffit juste de le d&eacute;cocher ici, et vous n'avez pas besoin de reconfigurer / recompiler votre application :) good !</p>
<p><strong>Attributs</strong> : Ils repr&eacute;sentent les &eacute;l&eacute;ments que vous voulez utiliser pour enrichir le profil de votre utilisateur. Dans mon cas, je veux au moins g&eacute;rer les champs "Ville", "Nom d'usage", "Email" et mes fameux "FidelityPoints" :</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3225.09.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3225.09.png" alt="" width="600" height="307" /></p>
<p><strong>Applications Claims</strong> : Ici on param&egrave;tre les champs qu'on veut r&eacute;cup&eacute;rer par le fournisseur : Evidemment tous les fournisseurs ne fournissent pas tous les champs, mais on peut tout de m&ecirc;me tenter :)</p>
<p>Dans mon cas, je sais que Facebook me r&eacute;cup&egrave;re facilement la ville, email, given name, alors on va pas se priver ! Des champs int&eacute;ressants comme le User Object ID ou le User Is New peuvent aider..</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2514.10.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2514.10.png" alt="" width="600" height="358" /></p>
<p><strong>Testage</strong>&nbsp; (<span style="font-size: 8pt;"><em>C'est toulousain, cherchez pas</em></span>) : A partir de l&agrave; (et apr&egrave;s avoir sauvegard&eacute;), on peut d&eacute;j&agrave; tester le comportement de notre page d'inscription (bouton Run Now) !</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/7823.11.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/7823.11.png" alt="" width="600" height="303" /></p>
<p>Voici l'enchainement des &eacute;crans dans mon cas :</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/7536.12.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/7536.12.png" alt="" width="700" height="402" /></p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0777.13.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0777.13.png" alt="" width="700" height="402" /></p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/6012.14.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/6012.14.png" alt="" width="700" height="402" /></p>
<p>(J'ai zapp&eacute; l'&eacute;tape "<strong>V&eacute;rification du Mail</strong>" qui vous envoie un code par mail pour v&eacute;rifier toute inscription "fake")</p>
<p>Apr&eacute;s la cr&eacute;ation, nous sommes redirig&eacute;s vers l'application / site web h&ocirc;te, que nous n'avons pas encore cr&eacute;&eacute;. Ne vous &eacute;tonnez pas d'avoir une 404 au bout :)</p>
<p>Comment v&eacute;rifier que cet utilisateur existe ? Et bien, il suffit d'aller dans votre annuaire fraichement cr&eacute;&eacute; (depuis l'ancien portail, pas taper, tou&ccedil;a tou&ccedil;a)</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/6428.15.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/6428.15.png" alt="" width="700" height="450" /></p>
<p>Bon &eacute;videmment l&agrave;, on voit deux comptes m'appartenant, le premier est le compte admin de l'AD, le deuxi&egrave;me ... mon test ! Mais vous imaginez bien le truc.</p>
<p>Et evidemment si on regarde le d&eacute;tail de ce nouvel utilisateur, on voit tr&eacute;s bien l'int&eacute;ret de ce syst&egrave;me :</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/1732.16.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/1732.16.png" alt="" width="700" height="587" /></p>
<p><span style="font-size: 14pt;">R&egrave;gle pour l'authentification et R&egrave;gle pour l'&eacute;dition du profil / Sign In policy &amp; Editing policy</span></p>
<p>Ces deux r&egrave;gles se param&egrave;trent de la m&ecirc;me mani&egrave;re que la pr&eacute;c&eacute;dente. On r&egrave;gle les fournisseurs, et les &eacute;l&eacute;ments qu'on pr&eacute;sente et qu'on veut r&eacute;cup&eacute;rer dans le Token de retour.</p>
<p>Au final, je me retrouve avec mes trois r&egrave;gles param&eacute;tr&eacute;es :</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2768.17.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2768.17.png" alt="" width="700" height="666" /></p>
<p><em>Note : Les noms de r&egrave;gles &eacute;tant uniques, j'aurais suremment d&ucirc; appeler la premi&egrave;re r&egrave;gle ALL_SIGN_UP (le B2C_1_ &eacute;tant ajout&eacute; automatiquement par le syst&egrave;me)</em></p>
<p>Et voici l'exp&eacute;rience utilisateur, en test.</p>
<p><strong>S'authentifier :</strong></p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/6242.18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/6242.18.png" alt="" width="700" height="450" /></p>
<p><strong>Modifier son profil :</strong></p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2630.19.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2630.19.png" alt="" width="700" height="377" /></p>
<p><span style="font-size: 14pt;">Int&eacute;grer ce syst&egrave;me dans votre application Web</span></p>
<p>Aujourd'hui, les templates Visual Studio ne sont pas forc&eacute;ment &agrave; jour. Le mieux reste encore de prendre un exemple existant, et de l'adapter.</p>
<p>Vous trouverez sur le Github de l'&eacute;quipe Azure AD les exemples ad&eacute;quates :&nbsp;<a href="https://github.com/AzureADQuickStarts">https://github.com/AzureADQuickStarts</a>.<br />Dans notre cas, j'utilise celui ci :&nbsp;<a href="https://github.com/AzureADQuickStarts/B2C-WebAPI-DotNet">https://github.com/AzureADQuickStarts/B2C-WebAPI-DotNet</a>&nbsp;</p>
<p>Pour le faire fonctionner, il suffit "<em>juste</em>" de param&eacute;trer correctement le fichier de configuration :</p>
<ol>
<li>ClientId</li>
<li>Tenant</li>
<li>Policy de Sign Up</li>
<li>Policy de Sign In</li>
<li>Policy d'Edit</li>
</ol>
<p>Une copie d'&eacute;cran de mon fichier de configuration :</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/1212.20.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/1212.20.png" alt="" width="700" height="381" /></p>
<p><strong>That's ALL !</strong></p>
<p>Bon, vous remarquerez quand m&ecirc;me qu'il y a un peu de code dans le sample...</p>
<p>A noter :</p>
<ol>
<li>Fichier <strong>Startup.Auth.cs</strong>&nbsp;O&ugrave; vous allez param&eacute;trer votre middleware Owin pour utiliser l'authentification OpenId / Oauth2</li>
<li>R&eacute;pertoire <strong>PolicyAuthHelpers</strong> : Celui l&agrave; on va pas l'inventer, il permet de g&eacute;rer les r&egrave;gles expos&eacute;s par OpenId</li>
<li>Class <strong>AccountController</strong> : Les appels aux urls d'authentification / inscription / &eacute;dition de profil</li>
<li>Vue <strong>Claims.cshtml</strong> : L'&eacute;num&eacute;ration des "Claims" expos&eacute;s par votre fournisseur Azure AD B2C</li>
</ol>
<p>Voici, une fois connect&eacute;, la page Claims, r&eacute;capitulant les propri&eacute;t&eacute;s que j'ai param&eacute;tr&eacute;es et que je veux r&eacute;cup&eacute;rer apr&eacute;s authentification :</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0724.21.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0724.21.png" alt="" width="700" height="342" /></p>
<p>Vous noterez que je r&eacute;cup&egrave;re bien mon nombre de points fid&eacute;lit&eacute; :)</p>
<p>Bref, une bien belle nouveaut&eacute; qui arrive et qui va VRAIMENT permettre de mutualiser la gestion de l'identit&eacute;, sans &ecirc;tre oblig&eacute; de rajouter son propre syst&egrave;me &agrave; cot&eacute; pour g&eacute;rer tout ce qui n'est pas authentification et qui est pourtant si important :)</p>
<p>Pour les ressources, dont est bien inspir&eacute; l'article de votre serviteur : &nbsp;<a href="https://azure.microsoft.com/en-us/services/active-directory-b2c/">https://azure.microsoft.com/en-us/services/active-directory-b2c/</a>&nbsp;</p>
<p>Happy coding !</p>
<p>Seb</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Les fondamentaux C# Chapitre 2</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/les-fondamentaux-c-chapitre-2</link>
      <pubDate>Thu, 23 Jul 2015 01:54:00 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/2015/07/23/les-fondamentaux-c-chapitre-2/</guid>
      <description><![CDATA[Bonjour à tous;  C'est bientôt les vacances alors profitez en pour vous former. Ca va vous rappeller...]]></description>
      <content:encoded><![CDATA[<p>Bonjour à tous;</p>  <p>C'est bientôt les vacances alors profitez en pour vous former. Ca va vous rappeller vos cahiers de vacances ;)</p>  <p>Je viens de terminer <strong>la deuxième partie sur les fondamentaux C#</strong>. Au programme, 5 nouveaux modules composés de :</p>  <ol>   <li>Une vidéo. </li>    <li>Un fichier zip de sources. </li>    <li>Un descriptif powerpoint. </li>    <li>Un QCM d'évaluation. </li> </ol>  <p>Pour ceux qui veulent récupérer l'ensemble (vidéo, source, pptx), et continuer votre parcours via<strong>&#160;<a href="https://www.microsoftvirtualacademy.com/" target="_blank">Microsoft Virtual Academy</a></strong>, voici le lien direct vers le cours : <a href="https://www.microsoftvirtualacademy.com/training-courses/les-fondamentaux-du-developpement-en-c-chapitre-2" target="_blank">Les Fondamentaux C# Chapitre 2</a></p>  <p>Pour ceux qui veulent d'abord faire (ou refaire) la première partie des fondamentaux; voici le lien direct sur la plateforme MVA : <a href="https://www.microsoftvirtualacademy.com/training-courses/les-fondamentaux-du-developpement-en-c-sharp" target="_blank">Les Fondamentaux C# Chapitre 1</a>.</p>  <p><a href="https://www.microsoftvirtualacademy.com/" target="_blank">     <br /><img style="vertical-align: middle; margin-left: auto; display: block; margin-right: auto" border="0" alt="Microsoft Virtual Academy" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/6403.MVA.JPG" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/6403.MVA.JPG" width="623" height="288" />       <br /></a></p>  <p>J'ai tenté pour chaque module de rester pragmatique dans l'approche et j'ai essayé de limiter chaque vidéo à moins de 15 minutes.</p>  <p>J'ai pratiquement réussi :)</p>  <p>Bon le module 2 sur les délégués et évènements était trop compliqué à résumer à moins de 15 minutes... Allez, celui là fait environ 30 minutes, mais il le mérite bien !</p>  <p>Pour ceux qui veulent juste regarder les vidéos, voici chaque module avec la description !</p>  <p><strong>N'hésitez pas à me faire des retours sur ce nouveau chapitre.      <br />Si vous avez aussi des idées de sujets qui vous plaisent pour un chapitre 3, n'hésitez pas à m'en faire part !</strong></p>  <p><strong>&#160;</strong></p>  <p><span style="font-size: 18pt">Module 1 : Modèle Singleton</span></p>  <p>Ce premier module aborde le modèle singleton autrement appelé &quot;Pattern Singleton&quot;</p>  <p>Il va nous permettre d'étendre le modèle static, peu personnalisable. Utilisé généralement dans des classes de services, il est une bonne pratique de dévelopemment quelque soit le langage !</p>  <p><video controls="controls" poster="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/1070.Chapitre2Module1.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09/1070.Chapitre2Module1.jpg" height="380" width="623"><source type="video/mp4" src="https://sec.ch9.ms/ch9/42b0/a17c642d-7e93-45f4-b4e0-ceab22d742b0/ModeleSingleton_mid.mp4" /></video></p>  <p><span style="font-size: 18pt">Module 2 : Délégués et Evènements</span></p>  <p>Les délégués et les évènements font complètement partis du modèle de programmation orienté objet.</p>  <p>Souvent mal compris ou mal expliqués, les délégués peuvent parfois paraître obscures.</p>  <p>Dans ce module nous allons aborder ces deux concepts avec des exemples simples et pratiques pour démystifier le sujet.</p>  <p><video controls="controls" poster="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/1462.Chapitre2Module2.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09/1462.Chapitre2Module2.jpg" height="380" width="623"><source type="video/mp4" src="https://sec.ch9.ms/ch9/7ae4/d26abdb1-cb73-4232-8f26-fcaabadd7ae4/DeleguesetEvenements_mid.mp4" /></video></p>  <p><span style="font-size: 18pt">Module 3 : Méthodes anonymes et expressions lambdas</span></p>  <p>Les méthodes anonymes ont été introduites dans le Framework 2.0 pour simplifier l'écriture de délégué.</p>  <p>Ce concept a encore été poussé dans le framework 3.0 avec l'apparition des expressions lambdas et son utilisation intensive dans System.Linq</p>  <p><video controls="controls" poster="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/1513.Chapitre2Module3.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09/1513.Chapitre2Module3.jpg" height="380" width="623"><source type="video/mp4" src="https://sec.ch9.ms/ch9/951c/6a4c1b54-a44a-42a3-93c3-211b7f6b951c/Methodesanonymesetexpressionslambdas_mid.mp4" /></video></p>  <p><span style="font-size: 18pt">Module 4 : Méthodes d'extensions</span></p>  <p>Sucre syntaxique, les méthodes d'extensions permettent d'étendre le comportement de vos objets comme de ceux que vous ne possédez pas.</p>  <p>Dans ce module nous allons voir comment étendre une classe comme <strong>System.String</strong> pour vous faire entrapercevoir le potentiel des méthodes d'extensions :)<img id="__mce_tmp" alt="" /></p>  <p><video controls="controls" poster="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/7725.Chapitre2Module4.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09/7725.Chapitre2Module4.jpg" height="380" width="623"><source type="video/mp4" src="https://sec.ch9.ms/ch9/eef5/b674b89e-e7af-4a3e-b2eb-b3665138eef5/Methodesdextensions_mid.mp4" /></video></p>  <p><span style="font-size: 18pt">Module 5 : Itérateurs et indexeurs</span></p>  <p>Les itérateurs et les indexeurs sont utilisés dans les objets représentants des collections, permettant d'utiliser des syntaxe comme le foreach ou permettant d'accéder directement à un objet de la collection via un index.</p>  <p>Nous allons voir dans ce module comment recréer ces comportement dans nos propres objets.</p>  <p><video controls="controls" poster="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/1121.Chapitre2Module5.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09/1121.Chapitre2Module5.jpg" height="380" width="623"><source type="video/mp4" src="https://sec.ch9.ms/ch9/e2b7/53ec0bdd-38d1-4f7f-b675-63ac8c21e2b7/Iterateursetindexeurs_mid.mp4" /></video></p>  <p>&#160;</p>  <p>Bon visionnage :)</p>  <p>Seb</p>]]></content:encoded>
    </item>
    <item>
      <title>Windows 10. Quelques nouveautés intéressantes</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/windows-10-quelques-nouveauts-intressantes</link>
      <pubDate>Mon, 20 Apr 2015 08:20:00 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/2015/04/20/windows-10-quelques-nouveauts-intressantes/</guid>
      <description><![CDATA[Bonjour à tous;Voici les sources du projet, qui tourne avec Visual Studio 2015...]]></description>
      <content:encoded><![CDATA[<p>Bonjour à tous;</p><blockquote><p>Voici les sources du projet, qui tourne avec Visual Studio 2015 : <a href="https://github.com/Mimetis/Windows10Sample">https://github.com/Mimetis/Windows10Sample</a> </p></blockquote><p>Aujourd'hui présentation d'une petite application d'exemple Windows 10 permettant d'appréhender les nouveaux contrôles visuels et quelques astuces diverses :)</p><p>L'idée c'est de se rapprocher d'une application existante, Xbox music, et d'essayer de la recréer en mode Windows 10 compliant.</p><p>Voici ce vers quoi on veut tendre :</p><p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/6663.XboxMusic.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/6663.XboxMusic.jpg" alt="Application Windows 10 Musique" width="700" height="464" /></p><p>Et voici les thèmes que nous allons aborder :</p><ol><li><strong>SplitView</strong></li><li><strong>ApiInformation</strong></li><li><strong>Adaptive Triggers</strong></li><li><strong>RelativePanel</strong></li><li><strong>Binding Static</strong></li></ol><p>Avant de commencer par le SplitView, j'ai essayé de "coller" au thème et voici le rendu final de la page qui correspond au module Découvrir de l'application xbox musique :</p><table style="height: 421px; width: 847px;" border="0" width="847" cellspacing="5" cellpadding="5"><tbody><tr><td><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4456.FakeXboxMusic01.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4456.FakeXboxMusic01.jpg" alt="Application exemple Windows 10" width="600" height="416" /></td><td><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/7065.FakeXboxMusic02.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/7065.FakeXboxMusic02.jpg" alt="Application exemple Windows Phone 10" width="233" height="416" /></td></tr></tbody></table><h1>SplitView</h1><p>Le <strong>SplitView</strong> introduit un concept de navigation via un menu en overlay et appelable depuis un bouton "hamburger"</p><p>Le SplitView est intéressant, notamment sur la navigation car il contient lui même la frame navigable, dans sa propriété Content.</p><p>Vous trouverez le code nécessaire dans la vue <strong>Views/Shell.xaml</strong></p><p>On y aborde :</p><ul><li>L'utilisation des glyphs <strong>Segoe MDL2 Assets</strong>.</li><li>Les différents modes de visualisation (<strong>Overlay</strong>, <strong>CompactOverlay</strong> ...)</li><li>Un mécanisme sommaire de navigation, permettant de "binder" la propriété "<strong>Content</strong>" du <strong>SplitView</strong> à la frame en cours.</li></ul><p>Voici le code du <strong>SplitView</strong> coté <strong>XAML</strong> :</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>&lt;SplitView x:Name="SplitView" Background="Black"
        OpenPaneLength="240" CompactPaneLength="60" PaneClosed="SplitView_PaneClosed"
        DisplayMode="CompactOverlay" IsPaneOpen="False"
        PaneBackground="#343434"
        &gt;
    &lt;SplitView.Content&gt;
        &lt;ContentControl Content="{Binding}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  Background="#EBEBEB" /&gt;
    &lt;/SplitView.Content&gt;
    &lt;SplitView.Pane&gt;
        &lt;StackPanel x:Name="SplitViewPanePanel"&gt;
            &lt;RadioButton x:Name="BackRadioButton"
                Background="Green" Visibility="Visible"
                Tag="" Click="BackRadionButton_Click"
                Style="{StaticResource NavRadioButtonStyle}"
                Content="Back"/&gt;

            &lt;RadioButton x:Name="HamburgerRadioButton" Click="HamburgerRadioButton_Click"
                Style="{StaticResource NavRadioButtonStyle}"
                Tag=""
            Content="Menu" /&gt;

            &lt;RadioButton x:Name="HomeRadioButton"
                Tag="" Click="HomeRadioButton_Click"
                Style="{StaticResource NavRadioButtonStyle}"
                Content="Home" /&gt;

            &lt;RadioButton x:Name="FriendsRadioButton"
                Tag="" Click="FriendsRadioButton_Click"
                Style="{StaticResource NavRadioButtonStyle}"
                Content="Friends" /&gt;
        &lt;/StackPanel&gt;
    &lt;/SplitView.Pane&gt;
&lt;/SplitView&gt;
</code>
</pre><p>Notez que l'initialisation de l'objet <strong>Shell</strong> est faite dans depuis la class <strong>App</strong> (App.xaml.cs)</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>Shell shell = Window.Current.Content as Shell;

if (shell == null)
{
    shell = new Shell();

    if (rootFrame == null)
    {
        rootFrame = new Frame();
        rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

        rootFrame.NavigationFailed += OnNavigationFailed;

        if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
        {
        }
    }

    shell.DataContext = rootFrame;

    Window.Current.Content = shell;
}
</code>
</pre><p>Lorsque vous passez en mode <strong>Overlay</strong>, le <strong>SplitView</strong> disparaissant complètement, il est judicieux de placer un bouton hamburger cliquable pour pouvoir le rappeler :</p><p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3463.WPBurger.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3463.WPBurger.jpg" alt="Icone Hamburger Windows Phone 10" width="326" height="198" /></p><p>C'est ce qui est fait à l'aide d'un <strong>ToggleButton</strong>:</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>       &lt;ToggleButton
                x:Name="HamburguerButton"
                Click="HamburguerButton_Click"
                Style="{StaticResource SymbolButton}"
                VerticalAlignment="Top"
                Foreground="Green" 

                Margin="0,5,0,0"&gt;
            &lt;ToggleButton.Content&gt;
                &lt;Border Background="Transparent"
                        Width="40"
                        Height="40"&gt;
                    &lt;FontIcon Foreground="Green" x:Name="Hamburger"
                              FontFamily="Segoe MDL2 Assets"
                              Glyph="&amp;#xE700;" /&gt;
                &lt;/Border&gt;
            &lt;/ToggleButton.Content&gt;
        &lt;/ToggleButton&gt;
</code>
</pre><h1>ApiInformation</h1><p>Une grosse nouveauté concernant les capacités différentes entre application tablette et phone.</p><p>L'appel de <strong>l'ApiInformation</strong> va permettre de déterminer si une capacité est présente ou pas sur la plateforme où s'exécute le code.<br /> Pratique quand on veut savoir si on utilise un WP et si le bouton Back est présent :</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
    // Evènement présent
    HardwareButtons.BackPressed += (s, e) =&gt; { };
    // Label
    Text2.Text = "Windows Phone Platform";
    Text1.FontSize = 18;
    Text2.FontSize = 18;
}
else
{
    Text2.Text = "Windows Platform";
}
</code>
</pre><h1>AdaptiveTrigger</h1><p>Ici Nous allons utiliser les <strong>AdaptiveTriggers</strong> pour cacher / diminuer / remplacer des élments du layouts pour s'adapter au différents formats de périphériques.</p><p>Dans l'exemple, vous trouverez beaucoup <strong>d'AdaptiveTriggers</strong> :</p><ol><li><strong>MainPage.xaml</strong> : Disparition du bandeau haut et remplacement par un logo Xbox musique</li><li><strong>MainPage.xaml</strong> : Disparition du logo Universal App et diminution de la font pour que le message reste lisible sur Phone</li><li><strong>Shell.xaml</strong> : Disparition de la flèche retour et changement de mode de fonctionnement du SplitView (passage en mode <strong>Overlay</strong>)</li></ol><p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/7178.AdaptiveTriggers.JPG" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/7178.AdaptiveTriggers.JPG" alt="Adaptive Triggers" width="497" height="338" /></p><p>Voici le <strong>VisualStateGroup</strong> tiré de la page MainPage.xaml</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>&lt;VisualStateManager.VisualStateGroups&gt;
    &lt;VisualStateGroup&gt;
        &lt;VisualState x:Name="Min"&gt;
            &lt;VisualState.StateTriggers&gt;
                &lt;AdaptiveTrigger MinWindowWidth="1" /&gt;
            &lt;/VisualState.StateTriggers&gt;
            &lt;VisualState.Setters&gt;
                &lt;Setter Target="XboxMusicImage.Visibility" Value="Visible" /&gt;
                &lt;Setter Target="XboxMusicImage.Height" Value="100" /&gt;
                &lt;Setter Target="XboxMusicImage.Stretch" Value="Uniform" /&gt;
                &lt;Setter Target="FlipViewImages.Visibility" Value="Collapsed" /&gt;
                &lt;Setter Target="UAPImage.Visibility" Value="Collapsed" /&gt;
                &lt;Setter Target="TxtOne.FontSize" Value="14" /&gt;
                &lt;Setter Target="HLinkOne.FontSize" Value="14" /&gt;
            &lt;/VisualState.Setters&gt;
        &lt;/VisualState&gt;

        &lt;VisualState x:Name="Moy"&gt;
            &lt;VisualState.StateTriggers&gt;
                &lt;AdaptiveTrigger MinWindowWidth="400" /&gt;
            &lt;/VisualState.StateTriggers&gt;
            &lt;VisualState.Setters&gt;
                &lt;Setter Target="XboxMusicImage.Visibility" Value="Visible" /&gt;
                &lt;Setter Target="FlipViewImages.Visibility" Value="Collapsed" /&gt;
                &lt;Setter Target="UAPImage.Visibility" Value="Collapsed" /&gt;
                &lt;Setter Target="TxtOne.FontSize" Value="14" /&gt;
                &lt;Setter Target="HLinkOne.FontSize" Value="14" /&gt;
            &lt;/VisualState.Setters&gt;
        &lt;/VisualState&gt;

        &lt;VisualState x:Name="Max"&gt;
            &lt;VisualState.StateTriggers&gt;
                &lt;AdaptiveTrigger MinWindowWidth="600" /&gt;
            &lt;/VisualState.StateTriggers&gt;
            &lt;VisualState.Setters&gt;
                &lt;Setter Target="XboxMusicImage.Visibility" Value="Collapsed" /&gt;
                &lt;Setter Target="FlipViewImages.Visibility" Value="Visible" /&gt;
                &lt;Setter Target="UAPImage.Visibility" Value="Visible" /&gt;
            &lt;/VisualState.Setters&gt;
        &lt;/VisualState&gt;
    &lt;/VisualStateGroup&gt;
&lt;/VisualStateManager.VisualStateGroups&gt;

</code>
</pre><p><span style="text-decoration: underline;"><strong>Note Importante :</strong></span><strong> </strong> Dans mes tests, j'ai remarqué que les VisualState triggers ne fonctionnent que s'ils sont placés <strong>immédiatement aprés le premier conteneur</strong> de votre page (dans mon cas, la première Grid).<br /> Si vous le placez aprés, ça a tendance à ne pas marcher au poil...</p><p><span style="text-decoration: underline;"><strong>Pour aller plus loin :</strong></span></p><p>Vous pouvez aussi créer vos propres AdaptiveTriggers en héritant de StateTriggerBase :</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>public class IsTypePresentStateTrigger : StateTriggerBase
{
}

</code>
</pre><p>Vous trouverez un exemple dans <strong>WindowsStateTriggers/IsTypePresentStateTrigger.cs</strong></p><h1>RelativePanel</h1><p>Une de mes features préférées.</p><p>Le <strong>RelativePanel</strong> simplifie grandement l'agencement des éléments dans votre UI.</p><p>Voici le rendu final du bandeau publicitaire :</p><p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4426.UAP.JPG" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4426.UAP.JPG" alt="RelativePanel" width="800" height="77" /></p><p>Voici un code possible, que j'aurai écrit précédemment, avec utilisation de StackPanel + Grid :</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>&lt;StackPanel Orientation="Horizontal" Grid.Row="1" Margin="0,10,0,0"&gt;
    &lt;Image VerticalAlignment="Center" HorizontalAlignment="Left" Stretch="None" Source="Assets/UAPIcon.jpg" /&gt;
    &lt;Grid VerticalAlignment="Center"&gt;
        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition Height="0.5*" /&gt;
            &lt;RowDefinition Height="0.5*" /&gt;
        &lt;/Grid.RowDefinitions&gt;
        &lt;TextBlock VerticalAlignment="Center" FontSize="20" Text="Rien que de la musique, toute la musique, sans publicité, à écouter partout" /&gt;
        &lt;HyperlinkButton VerticalAlignment="Center" FontSize="20" Grid.Row="1" NavigateUri="https://www.bing.com" Content="Commencer un essai gratuit" /&gt;
    &lt;/Grid&gt;
&lt;/StackPanel&gt;
</code>
</pre><p>Et Voici un version à base de <strong>RelativePanel</strong>:</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>&lt;RelativePanel Grid.Row="1" Margin="10,10,0,0" HorizontalAlignment="Stretch"&gt;
    &lt;Image VerticalAlignment="Center" Visibility="Collapsed" Name="UAPImage" HorizontalAlignment="Left" Stretch="None" Source="Assets/UAPIcon.jpg" /&gt;
    &lt;TextBlock Name="TxtOne" RelativePanel.RightOf="UAPImage"  Foreground="#222222"  VerticalAlignment="Center" FontSize="20" Text="Rien que de la musique, toute la musique, sans publicité, à écouter partout" /&gt;
    &lt;HyperlinkButton Name="HLinkOne"  RelativePanel.AlignHorizontalCenterWith="TxtOne" RelativePanel.Below="TxtOne" VerticalAlignment="Center" FontSize="20" Grid.Row="1" NavigateUri="https://www.bing.com" Content="Commencer un essai gratuit" /&gt;
&lt;/RelativePanel&gt;

</code>
</pre><p>On voit vite l'intéret en terme de simplification de l'arbre visuel de votre code XAML :)</p><h1>Binding Static</h1><p>Une autre nouveauté apporté aux applications Windows 10 : La possibilité de créer des <strong>Binding statiques</strong>, permettant d'avoir une liaison forte entre votre source de données et votre ItemsControl :</p><p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5775.GridView.JPG" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5775.GridView.JPG" alt="GridView avec Binding statique" width="877" height="347" /></p><p>Le code est assez classique mais remarquez l'utilisation de la syntaxe "<strong>ItemsSource="{x:Bind Albums, Mode=OneTime}</strong>" :</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>&lt;GridView Grid.Row="3"
x:Name="GridAlbums"
Padding="10"
ItemsSource="{x:Bind Albums, Mode=OneTime}"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="True"&gt;
    &lt;GridView.ItemTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;RelativePanel&gt;
                &lt;Image  Source="{Binding Icon}" Name="Icon" Width="120" Height="120" Margin="10" Stretch="UniformToFill" /&gt;
                &lt;TextBlock RelativePanel.Below="Icon" RelativePanel.AlignLeftWith="Icon" Name="Name" Text="{Binding Name}" Margin="10,8,0,0"  Foreground="#222222"/&gt;
                &lt;TextBlock RelativePanel.Below="Name" RelativePanel.AlignLeftWith="Icon" Text="{Binding Author}"  TextWrapping="NoWrap" Margin="10,8,0,10" Foreground="#646464"/&gt;
            &lt;/RelativePanel&gt;
        &lt;/DataTemplate&gt;
    &lt;/GridView.ItemTemplate&gt;

&lt;/GridView&gt;
</code>
</pre><p>Un petit test à faire est de récupérer le code généré dans le fichier <strong>MainPage.g.cs</strong> où l'on peut voir, entre autre :</p><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee; font-size: 12px; border: 1px dashed #999999; line-height: 14px; padding: 5px; overflow: auto; width: 100%;"><code>// Fields for each control that has bindings.
internal global::Windows.UI.Xaml.Controls.GridView obj6;

// Update method for each path node used in binding steps.
internal void Update_Albums(global::App1.Model.Albums obj, bool isInitialUpdate = false)
{
    if (isInitialUpdate)
    {
        this.SetValue_obj6_ItemsSource(obj);
    }
}

private void SetValue_obj6_ItemsSource(global::App1.Model.Albums obj)
{
    try
    {
        this.obj6.ItemsSource = obj;
    }
    catch {}
}

</code>
</pre><p>Pretty Awesome non ? :)</p><p>Voilà pour un premier petit tour sur les applications modernes Windows 10.<br /> Bien-sûr tout ceci est sujet à évolution, et je mettrais à jour tout ça aprés la //Build</p>]]></content:encoded>
    </item>
    <item>
      <title>Virtual Academy : Les fondamentaux en C#</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/virtual-academy-les-fondamentaux-en-c</link>
      <pubDate>Fri, 05 Sep 2014 02:39:43 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/2014/09/05/virtual-academy-les-fondamentaux-en-c/</guid>
      <description><![CDATA[Bonjour à tous;  Aujourd’hui je publie mon deuxième cours sur Virtual Academy.  Fondamentaux en C# :...]]></description>
      <content:encoded><![CDATA[<p>Bonjour à tous;</p>  <p>Aujourd’hui je publie mon deuxième cours sur <a href="https://www.microsoftvirtualacademy.com/" target="_blank">Virtual Academy</a>.</p>  <p><a href="https://www.microsoftvirtualacademy.com/training-courses/les-fondamentaux-du-developpement-en-c-sharp" target="_blank">Fondamentaux en C#</a> : Il s’agit d’un cours complet en <strong>17 modules</strong> sur les fondamentaux C#</p>  <p><a href="https://www.microsoftvirtualacademy.com/training-courses/les-fondamentaux-du-developpement-en-c-sharp" target="_blank"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8400.image_4D02D804.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8400.image_5F00_4D02D804.png" width="660" height="380" /></a></p>  <p>Ce cours s’adresse à un public néophyte désirant acquérir les bases de programmation en C#. </p>  <p>IL y’a 17 modules comprenant chacun:</p>  <ul>   <li>Une vidéo allant de 10 à 20 minutes pour les plus longues.</li>    <li>Un fichier source contenant le zip du module en cours.</li> </ul>  <p>   <br />Pour vous donner une idée de ce qu’on va y retrouver voici la liste des modules :</p>  <ol>   <li>Introduction au développement C# : Hello World</li>    <li>Débogage pas à pas avec Visual Studio</li>    <li>Les variables en C#</li>    <li>Les opérateurs en C# : [if else]</li>    <li>Les opérateurs en C# : [for]</li>    <li>Les tableaux : [Array]</li>    <li>Les méthodes</li>    <li>Les opérateurs en C# : [while]</li>    <li>Les chaines de caractères : [String]</li>    <li>Le concept objet en C# : Les classes partie 1</li>    <li>Le concept objet en C# : Les classes partie 2</li>    <li>L’héritage en C#</li>    <li>Les espaces de nommages : Les namespaces</li>    <li>Enumération et opérateur en C# : [foreach]</li>    <li>Les exceptions et comment traiter une erreur</li>    <li>Les collections en mémoire en C#</li>    <li>Un exemple complet : Accéder à une base de données</li> </ol>  <p>&#160;</p>  <p>Voilà j’espère que ce cours saura vous mettre le pied à l’étrier et vous donner les bases du langage C#</p>  <p>D’ailleurs en y repensant, ces bases sont vraiment communes à beaucoup de langages et vous permettront de découvrir comment le développement et les bases peuvent être abordées.</p>  <p>Bon visionnage, et surtout, si vous avez des retours (et des cours qui vous intéresseraient) n’hésitez pas à m’en faire part par mail ou via les commentaires.</p>  <p>Seb</p>]]></content:encoded>
    </item>
    <item>
      <title>Create a WinRT brokered component : Feedback from a “real life” developement</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/create-a-winrt-brokered-component-feedback-from-a-real-life-developement</link>
      <pubDate>Tue, 24 Jun 2014 09:48:26 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/2014/06/24/create-a-winrt-brokered-component-feedback-from-a-real-life-developement/</guid>
      <description><![CDATA[Hi;  Since the Windows 8.1 launch, we can use a new feature, called Brokered Component, to manage...]]></description>
      <content:encoded><![CDATA[<p>Hi;</p>  <p>Since the Windows 8.1 launch, we can use a new feature, called Brokered Component, to manage legacy components and then writing code for Modern UI application that call desktop .NET objects (pretty cool !).</p>  <p>You can create a Brokered Component project within Visual Studio 2013. You need to install new templates projects, available here : <a title="https://visualstudiogallery.msdn.microsoft.com/527286e4-b06a-4234-adde-d313c9c3c23e" href="https://visualstudiogallery.msdn.microsoft.com/527286e4-b06a-4234-adde-d313c9c3c23e">https://visualstudiogallery.msdn.microsoft.com/527286e4-b06a-4234-adde-d313c9c3c23e</a></p>  <p>For more informations about Brokered Components, just check those articles / videos :</p>  <ol>   <li>Creating a brokered component from scratch (3 parts) : <a title="https://devhawk.net/2014/04/25/brokered-winrt-components-step-one/" href="https://devhawk.net/2014/04/25/brokered-winrt-components-step-one/">https://devhawk.net/2014/04/25/brokered-winrt-components-step-one/</a> </li>    <li>A data acces layer within a brokered component : <a title="https://blogs.u2u.be/diederik/post/2014/04/25/Building-Enterprise-apps-using-Brokered-Windows-Runtime-Components.aspx" href="https://blogs.u2u.be/diederik/post/2014/04/25/Building-Enterprise-apps-using-Brokered-Windows-Runtime-Components.aspx">https://blogs.u2u.be/diederik/post/2014/04/25/Building-Enterprise-apps-using-Brokered-Windows-Runtime-Components.aspx</a> </li>    <li>//Build 2014 video presenting the feature : <a title="https://channel9.msdn.com/Events/Build/2014/2-515" href="https://channel9.msdn.com/Events/Build/2014/2-515">https://channel9.msdn.com/Events/Build/2014/2-515</a> </li>    <li>MSDN documentation : <a title="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx" href="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx">https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx</a>       <br /></li> </ol>  <p>In this article, I will provide a feedback on a full component; assuming you already know what is a brokered component (I suggest you to check at least the links below)</p>  <p>Here are my observations during the full migration of a legacy component to a brokered component:</p>  <h2>Debugging</h2>  <p>Yes, you need to debug. Especialy when you create a brokered component (believe me <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0601.wlEmoticon-smile_785959FC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0601.wlEmoticon_2D00_smile_5F00_785959FC.png" />)</p>  <p>During runtime, no breakpoint will be called in your Brokered Component, since it is hosted by <strong>dllhost.exe</strong>. By the way, your component is not loaded until you have called your class constructor.</p>  <p>To be able to debug easily, I suggest you to provide a simple constructor in your brokered component. Thus you can add easily a breakpoint in your code.</p>  <p><u><strong>In a nutshell :</strong></u></p>  <ol>   <li>Put a breakpoint after the initialization of your Brokered Component in your modern UI application code.</li>    <li>Put a breakpoint in your Brokered component (In the method you want to debug)</li>    <li>Launch your application and wait for you first breakpoint to be called :     <br />      <br /><img title="image21" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image21" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0020.image21_7A95E2B8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0020.image21_5F00_7A95E2B8.png" width="608" height="179" />      <br />      <br /></li>    <li>Attach to the <strong>dllhost.exe</strong> (Yes, DURING your actual session) :&#160; <br />      <br /><img title="image7[2]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image7[2]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/7802.image72_2ECA0BFF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/7802.image72_5F00_2ECA0BFF.png" width="800" height="336" />      <br /></li>    <li>You can now debug your Brokered component <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0601.wlEmoticon-smile_785959FC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0601.wlEmoticon_2D00_smile_5F00_785959FC.png" />       <br />      <br />      <br /><img title="image15[2]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image15[2]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/7357.image152_2504A487.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/7357.image152_5F00_2504A487.png" width="800" height="248" /> </li> </ol>  <h2>   <br />Runtime Policy Helper</h2>  <p>Yes, often your legacy compoent will be an old component, mainly develop with the FX 2.*</p>  <p>To be able to reuse this component in a .NET 4.* application, you should add a Policy in your configuration file, like this :</p>  <div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:734557ca-05cc-4fe4-a272-89d247f2c4f2" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">   <pre style="overflow: auto; height: 141px; font-family: microsoft sans serif; width: 670px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080">1</span> <span style="color: #0000ff">&lt;?</span><span style="color: #ff00ff">xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; </span><span style="color: #0000ff">?&gt;</span><span style="color: #000000">
</span><span style="color: #008080">2</span> <span style="color: #000000"></span><span style="color: #0000ff">&lt;</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">3</span> <span style="color: #000000">  </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">startup </span><span style="color: #ff0000">useLegacyV2RuntimeActivationPolicy</span><span style="color: #0000ff">=&quot;true&quot;</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">4</span> <span style="color: #000000">    </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">supportedRuntime </span><span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;v4.0&quot;</span><span style="color: #0000ff">/&gt;</span><span style="color: #000000">
</span><span style="color: #008080">5</span> <span style="color: #000000">  </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">startup</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">6</span> <span style="color: #000000"></span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Unfortunately, we can’t add a config file in our Brokered Component. The solution is to be able to configure this legacy runtime Policy with some code...&#160; <br />Here are two articles on the subject :</p>

<ol>
  <li><a title="https://blogs.msdn.com/b/jomo_fisher/archive/2009/11/17/f-scripting-net-4-0-and-mixed-mode-assemblies.aspx" href="https://blogs.msdn.com/b/jomo_fisher/archive/2009/11/17/f-scripting-net-4-0-and-mixed-mode-assemblies.aspx">https://blogs.msdn.com/b/jomo_fisher/archive/2009/11/17/f-scripting-net-4-0-and-mixed-mode-assemblies.aspx</a> </li>

  <li><a title="https://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/" href="https://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/">https://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/</a> </li>
</ol>

<p>
  <br />I have integrated this class directly as a private nested class in my Brokered component :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:86d27068-0ee7-4d77-9c1c-c49f8ffa4a6f" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: auto; height: 500px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">sealed</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> SqlServerReplicationProvider : IReplicationProvider
    {
        </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> RuntimePolicyHelper
        {
            </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">bool</span><span style="color: #000000"> legacyV2RuntimeEnabledSuccessfully;

            </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">bool</span><span style="color: #000000"> TryEnableLegacyV2Runtime()
            {
                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (legacyV2RuntimeEnabledSuccessfully)
                    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">true</span><span style="color: #000000">;

                ICLRRuntimeInfo clrRuntimeInfo </span><span style="color: #000000">=</span><span style="color: #000000"> (ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(Guid.Empty,
                </span><span style="color: #0000ff">typeof</span><span style="color: #000000">(ICLRRuntimeInfo).GUID);

                </span><span style="color: #0000ff">try</span><span style="color: #000000">
                {
                    clrRuntimeInfo.BindAsLegacyV2Runtime();
                    legacyV2RuntimeEnabledSuccessfully </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">true</span><span style="color: #000000">;
                }
                </span><span style="color: #0000ff">catch</span><span style="color: #000000"> (COMException)
                {
                    legacyV2RuntimeEnabledSuccessfully </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">;
                }

                </span><span style="color: #0000ff">return</span><span style="color: #000000"> legacyV2RuntimeEnabledSuccessfully;
            }


            [ComImport]
            [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid(</span><span style="color: #800000">&quot;</span><span style="color: #800000">BD39D1D2-BA2F-486A-89B0-B4B0CB466891</span><span style="color: #800000">&quot;</span><span style="color: #000000">)]
            </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> ICLRRuntimeInfo
            {
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xGetVersionString();
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xGetRuntimeDirectory();
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xIsLoaded();
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xIsLoadable();
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xLoadErrorString();
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xLoadLibrary();
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xGetProcAddress();
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xGetInterface();
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xSetDefaultStartupFlags();
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> xGetDefaultStartupFlags();

                [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType </span><span style="color: #000000">=</span><span style="color: #000000"> MethodCodeType.Runtime)]
                </span><span style="color: #0000ff">void</span><span style="color: #000000"> BindAsLegacyV2Runtime();
            }
        }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Then I called the <strong>TryEnableLegacyV2Runtime</strong> method in my class constructor, pretty straighforward :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:9a864b3e-f253-416a-acf4-d52eebe5c1a3" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: auto; height: 141px; font-family: microsoft sans serif; width: 670px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080">1</span> <span style="color: #000000">       </span><span style="color: #0000ff">public</span><span style="color: #000000"> SqlServerReplicationProvider()
</span><span style="color: #008080">2</span> <span style="color: #000000">        {
</span><span style="color: #008080">3</span> <span style="color: #000000">            </span><span style="color: #008000">//</span><span style="color: #008000"> Activer la compatibilité .NET 2.*</span><span style="color: #008000">
</span><span style="color: #008080">4</span> <span style="color: #008000"></span><span style="color: #000000">            RuntimePolicyHelper.TryEnableLegacyV2Runtime();
</span><span style="color: #008080">5</span> <span style="color: #000000">
</span><span style="color: #008080">6</span> <span style="color: #000000">        }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<h2>Abstract Class / Interface</h2>

<p>Abstract classes are not available in any Windows Runtime component. Every public class should be sealed and abstract class can’t be sealed…</p>

<p><img title="image33" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image33" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4336.image33_747126CE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4336.image33_5F00_747126CE.png" width="544" height="346" /></p>

<p>So you need to use interface, like this :</p>

<p><img title="image32" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image32" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/1524.image32_7D60B90D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/1524.image32_5F00_7D60B90D.png" width="595" height="366" /></p>

<h2>Enums</h2>

<p>Enums works fine in any WinRT project, but they don’t work within a brokered component.</p>

<p>Here is an enum example : </p>



<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:9a66b871-0e0b-4251-b6f0-bcbfd6d9249f" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: auto; height: 106px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080">1</span> <span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">enum</span><span style="color: #000000"> SyncSecurityMode
</span><span style="color: #008080">2</span> <span style="color: #000000">    {
</span><span style="color: #008080">3</span> <span style="color: #000000">        Standard </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800080">0</span><span style="color: #000000">,
</span><span style="color: #008080">4</span> <span style="color: #000000">        Integrated </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800080">1</span><span style="color: #000000">
</span><span style="color: #008080">5</span> <span style="color: #000000">    }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>



<p>
  <br />Even if I don’t use this enum in my code, It will raise an error during execution. And to be clear, the <strong>BadImageFormatException</strong> exception won’t help you <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0601.wlEmoticon-smile_785959FC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0601.wlEmoticon_2D00_smile_5F00_785959FC.png" />&#160;</p>

<p>&#160;</p>

<p><img title="image39" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image39" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4604.image39_4D396E4A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4604.image39_5F00_4D396E4A.png" width="640" height="77" /></p>

<p>To replace your enum you could:</p>

<ol>
  <li>Use an int. Not very maintenable.</li>

  <li>Put the enum in a C++/CX Winmd component. Well … creating a project just to handle an enum is a little bit to complex in my opinion.</li>

  <li>Create a sealed object able to reproduce the enum behavior. </li>
</ol>

<p>
  <br />Here are some tips I used to create a sealed object to reproduce the enum usage:</p>

<ul>
  <li>I have creates the real enum in a private nested enum within my class.</li>

  <li>I have creates some static methods to be able to create objects like this :</li>
</ul>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:6b59bebf-7d0a-4c3c-a129-2615a54977b3" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: auto; height: 24px; font-family: microsoft sans serif; width: 554px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080">1</span> <span style="color: #000000">var ssm </span><span style="color: #000000">=</span><span style="color: #000000"> SyncSecurityMode.Standard;</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<ul>
  <li>I have overrided the <strong>Equals</strong> methods (You can’t override <strong>==</strong> and <strong>!=</strong> methods in a WinRT component).&#160; <br />You need to change the way you use the enum comparaison:</li>
</ul>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:9c1df687-d562-460a-ab80-4b025feae3c9" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: auto; height: 23px; font-family: microsoft sans serif; width: 608px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080">1</span> <span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #0000ff">this</span><span style="color: #000000">.PublisherSecurityMode.Equals(SyncSecurityMode.Standard))</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<ul>
  <li>Finally, I have overrides the <strong>ToString()</strong> method to be able to easily debug my enum class</li>
</ul>

<p>
  <br />Here is the full implementation :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:3adf6be2-55e8-4ca7-96a0-190b272064b5" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: auto; height: 531px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">   </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">sealed</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> SyncSecurityMode
</span><span style="color: #008080"> 2</span> <span style="color: #000000">    {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">enum</span><span style="color: #000000"> SyncSecurityModeEnum
</span><span style="color: #008080"> 4</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 5</span> <span style="color: #000000">            Standard </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800080">0</span><span style="color: #000000">,
</span><span style="color: #008080"> 6</span> <span style="color: #000000">            Integrated </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800080">1</span><span style="color: #000000">
</span><span style="color: #008080"> 7</span> <span style="color: #000000">        }
</span><span style="color: #008080"> 8</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> SyncSecurityMode(SyncSecurityModeEnum value)
</span><span style="color: #008080"> 9</span> <span style="color: #000000">        {
</span><span style="color: #008080">10</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.syncSecurityModeEnum </span><span style="color: #000000">=</span><span style="color: #000000"> value;
</span><span style="color: #008080">11</span> <span style="color: #000000">        }
</span><span style="color: #008080">12</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> SyncSecurityMode()
</span><span style="color: #008080">13</span> <span style="color: #000000">        {
</span><span style="color: #008080">14</span> <span style="color: #000000">        }
</span><span style="color: #008080">15</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> SyncSecurityModeEnum syncSecurityModeEnum;
</span><span style="color: #008080">16</span> <span style="color: #000000">
</span><span style="color: #008080">17</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> SyncSecurityMode Standard { </span><span style="color: #0000ff">get</span><span style="color: #000000"> { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SyncSecurityMode(SyncSecurityModeEnum.Standard); } }
</span><span style="color: #008080">18</span> <span style="color: #000000">    
</span><span style="color: #008080">19</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> SyncSecurityMode Integrated { </span><span style="color: #0000ff">get</span><span style="color: #000000"> { </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SyncSecurityMode(SyncSecurityModeEnum.Integrated); } }
</span><span style="color: #008080">20</span> <span style="color: #000000">
</span><span style="color: #008080">21</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">override</span><span style="color: #000000"> </span><span style="color: #0000ff">bool</span><span style="color: #000000"> Equals(</span><span style="color: #0000ff">object</span><span style="color: #000000"> obj)
</span><span style="color: #008080">22</span> <span style="color: #000000">        {
</span><span style="color: #008080">23</span> <span style="color: #000000">            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (obj </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">;
</span><span style="color: #008080">24</span> <span style="color: #000000">
</span><span style="color: #008080">25</span> <span style="color: #000000">            SyncSecurityMode other </span><span style="color: #000000">=</span><span style="color: #000000"> (SyncSecurityMode)obj;
</span><span style="color: #008080">26</span> <span style="color: #000000">            </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">this</span><span style="color: #000000">.syncSecurityModeEnum.Equals(other.syncSecurityModeEnum);
</span><span style="color: #008080">27</span> <span style="color: #000000">        }
</span><span style="color: #008080">28</span> <span style="color: #000000">
</span><span style="color: #008080">29</span> <span style="color: #000000">   }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<h2><strong>IDisposable</strong></h2>

<p>Every WinRT class should implement IDisposable, especially within a brokered component. During all my tests, each time a class without IDisposable interface ran into an exception (not managed by code) the dllhost.exe wasn’t unload…</p>

<p>I used the IDisposable pattern, where i disposed managed and non-managed ressources :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:0a1a3dfa-3b3f-4187-93c9-7fb48fb5fb05" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: auto; height: 547px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">       </span><span style="color: #808080">///</span><span style="color: #008000"> </span><span style="color: #808080">&lt;summary&gt;</span><span style="color: #008000">
</span><span style="color: #008080"> 2</span> <span style="color: #008000">        </span><span style="color: #808080">///</span><span style="color: #008000"> Dispose pattern
</span><span style="color: #008080"> 3</span> <span style="color: #008000">        </span><span style="color: #808080">///</span><span style="color: #008000"> </span><span style="color: #808080">&lt;/summary&gt;</span><span style="color: #808080">
</span><span style="color: #008080"> 4</span> <span style="color: #808080"></span><span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">bool</span><span style="color: #000000"> disposed; </span><span style="color: #008000">//</span><span style="color: #008000"> to detect redundant calls</span><span style="color: #008000">
</span><span style="color: #008080"> 5</span> <span style="color: #008000"></span><span style="color: #000000">
</span><span style="color: #008080"> 6</span> <span style="color: #000000">        </span><span style="color: #808080">///</span><span style="color: #008000"> </span><span style="color: #808080">&lt;summary&gt;</span><span style="color: #008000">
</span><span style="color: #008080"> 7</span> <span style="color: #008000">        </span><span style="color: #808080">///</span><span style="color: #008000"> Closes and dispose.
</span><span style="color: #008080"> 8</span> <span style="color: #008000">        </span><span style="color: #808080">///</span><span style="color: #008000"> </span><span style="color: #808080">&lt;/summary&gt;</span><span style="color: #808080">
</span><span style="color: #008080"> 9</span> <span style="color: #808080"></span><span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> Close()
</span><span style="color: #008080">10</span> <span style="color: #000000">        {
</span><span style="color: #008080">11</span> <span style="color: #000000">            Dispose(</span><span style="color: #0000ff">true</span><span style="color: #000000">);
</span><span style="color: #008080">12</span> <span style="color: #000000">            GC.SuppressFinalize(</span><span style="color: #0000ff">this</span><span style="color: #000000">);
</span><span style="color: #008080">13</span> <span style="color: #000000">        }
</span><span style="color: #008080">14</span> <span style="color: #000000">
</span><span style="color: #008080">15</span> <span style="color: #000000">        </span><span style="color: #000000">~</span><span style="color: #000000">SqlServerReplicationProvider()
</span><span style="color: #008080">16</span> <span style="color: #000000">        {
</span><span style="color: #008080">17</span> <span style="color: #000000">            Dispose(</span><span style="color: #0000ff">false</span><span style="color: #000000">);
</span><span style="color: #008080">18</span> <span style="color: #000000">        }
</span><span style="color: #008080">19</span> <span style="color: #000000">        </span><span style="color: #808080">///</span><span style="color: #008000"> </span><span style="color: #808080">&lt;summary&gt;</span><span style="color: #008000">
</span><span style="color: #008080">20</span> <span style="color: #008000">        </span><span style="color: #808080">///</span><span style="color: #008000"> Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
</span><span style="color: #008080">21</span> <span style="color: #008000">        </span><span style="color: #808080">///</span><span style="color: #008000"> call Close() method
</span><span style="color: #008080">22</span> <span style="color: #008000">        </span><span style="color: #808080">///</span><span style="color: #008000"> </span><span style="color: #808080">&lt;/summary&gt;</span><span style="color: #808080">
</span><span style="color: #008080">23</span> <span style="color: #808080"></span><span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> Dispose()
</span><span style="color: #008080">24</span> <span style="color: #000000">        {
</span><span style="color: #008080">25</span> <span style="color: #000000">            Close();
</span><span style="color: #008080">26</span> <span style="color: #000000">        }
</span><span style="color: #008080">27</span> <span style="color: #000000">
</span><span style="color: #008080">28</span> <span style="color: #000000">        </span><span style="color: #0000ff">protected</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> Dispose(</span><span style="color: #0000ff">bool</span><span style="color: #000000"> disposing)
</span><span style="color: #008080">29</span> <span style="color: #000000">        {
</span><span style="color: #008080">30</span> <span style="color: #000000">            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #000000">!</span><span style="color: #000000">disposed)
</span><span style="color: #008080">31</span> <span style="color: #000000">            {
</span><span style="color: #008080">32</span> <span style="color: #000000">                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (disposing)
</span><span style="color: #008080">33</span> <span style="color: #000000">                {
</span><span style="color: #008080">34</span> <span style="color: #000000">                    </span><span style="color: #008000">//</span><span style="color: #008000"> Dispose managed resources.</span><span style="color: #008000">
</span><span style="color: #008080">35</span> <span style="color: #008000"></span><span style="color: #000000">                    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (subscriberConn </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000"> subscriberConn.IsOpen)
</span><span style="color: #008080">36</span> <span style="color: #000000">                        subscriberConn.Disconnect();
</span><span style="color: #008080">37</span> <span style="color: #000000">
</span><span style="color: #008080">38</span> <span style="color: #000000">                    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (publisherConn </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000"> publisherConn.IsOpen)
</span><span style="color: #008080">39</span> <span style="color: #000000">                        publisherConn.Disconnect();
</span><span style="color: #008080">40</span> <span style="color: #000000">                }
</span><span style="color: #008080">41</span> <span style="color: #000000">
</span><span style="color: #008080">42</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> There are no unmanaged resources to release, but
</span><span style="color: #008080">43</span> <span style="color: #008000">                </span><span style="color: #008000">//</span><span style="color: #008000"> if we add them, they need to be released here.</span><span style="color: #008000">
</span><span style="color: #008080">44</span> <span style="color: #008000"></span><span style="color: #000000">            }
</span><span style="color: #008080">45</span> <span style="color: #000000">            disposed </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">true</span><span style="color: #000000">;
</span><span style="color: #008080">46</span> <span style="color: #000000">        }
</span><span style="color: #008080">47</span> <span style="color: #000000"></span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>More informations available here : <a title="https://msdn.microsoft.com/en-us/library/system.idisposable(v=vs.110).aspx" href="https://msdn.microsoft.com/en-us/library/system.idisposable(v=vs.110).aspx">https://msdn.microsoft.com/en-us/library/system.idisposable(v=vs.110).aspx</a></p>

<h2>Legacy Objects : handle events</h2>

<p>Within FX .NET 2.*, we usually used events in our components. Not a bad idead, except when those events specifie the end of the business logic.</p>

<p>In this particular case, It will be difficult to create an async component (Task) with the IProgress&lt;T&gt; pattern.</p>

<p>Here is a very simple example of one of those kind of component :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:2ce0caed-4bbf-4d29-bd71-afcff2bdb80b" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: auto; height: 467px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">   </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> TimeSource : IDisposable
</span><span style="color: #008080"> 2</span> <span style="color: #000000">    {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">readonly</span><span style="color: #000000"> Timer timer;
</span><span style="color: #008080"> 4</span> <span style="color: #000000">
</span><span style="color: #008080"> 5</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">event</span><span style="color: #000000"> EventHandler</span><span style="color: #000000">&lt;</span><span style="color: #000000">DateTime</span><span style="color: #000000">&gt;</span><span style="color: #000000"> OnTick;
</span><span style="color: #008080"> 6</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">event</span><span style="color: #000000"> EventHandler</span><span style="color: #000000">&lt;</span><span style="color: #000000">DateTime</span><span style="color: #000000">&gt;</span><span style="color: #000000"> Started;
</span><span style="color: #008080"> 7</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">event</span><span style="color: #000000"> EventHandler</span><span style="color: #000000">&lt;</span><span style="color: #000000">DateTime</span><span style="color: #000000">&gt;</span><span style="color: #000000"> Ended;
</span><span style="color: #008080"> 8</span> <span style="color: #000000">
</span><span style="color: #008080"> 9</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> tickCount </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800080">0</span><span style="color: #000000">;
</span><span style="color: #008080">10</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> maxTick </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800080">5</span><span style="color: #000000">;
</span><span style="color: #008080">11</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> Double tickDuration </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800080">1000</span><span style="color: #000000">;
</span><span style="color: #008080">12</span> <span style="color: #000000">
</span><span style="color: #008080">13</span> <span style="color: #000000">
</span><span style="color: #008080">14</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> DateTime Value { </span><span style="color: #0000ff">get</span><span style="color: #000000">; </span><span style="color: #0000ff">set</span><span style="color: #000000">; }
</span><span style="color: #008080">15</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> TimeSource()
</span><span style="color: #008080">16</span> <span style="color: #000000">        {
</span><span style="color: #008080">17</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.timer </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Timer(tickDuration);
</span><span style="color: #008080">18</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.timer.Elapsed </span><span style="color: #000000">+=</span><span style="color: #000000"> TimerOnElapsed;
</span><span style="color: #008080">19</span> <span style="color: #000000">       }
</span><span style="color: #008080">20</span> <span style="color: #000000">
</span><span style="color: #008080">21</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> Start()
</span><span style="color: #008080">22</span> <span style="color: #000000">        {
</span><span style="color: #008080">23</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.timer.Start();
</span><span style="color: #008080">24</span> <span style="color: #000000">            Value </span><span style="color: #000000">=</span><span style="color: #000000"> DateTime.Now;
</span><span style="color: #008080">25</span> <span style="color: #000000">
</span><span style="color: #008080">26</span> <span style="color: #000000">            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (Started </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)
</span><span style="color: #008080">27</span> <span style="color: #000000">                Started(</span><span style="color: #0000ff">this</span><span style="color: #000000">, Value);
</span><span style="color: #008080">28</span> <span style="color: #000000"> 
</span><span style="color: #008080">29</span> <span style="color: #000000">        }
</span><span style="color: #008080">30</span> <span style="color: #000000">
</span><span style="color: #008080">31</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> Stop()
</span><span style="color: #008080">32</span> <span style="color: #000000">        {
</span><span style="color: #008080">33</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.timer.Stop();
</span><span style="color: #008080">34</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.tickCount </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800080">0</span><span style="color: #000000">;
</span><span style="color: #008080">35</span> <span style="color: #000000">
</span><span style="color: #008080">36</span> <span style="color: #000000">            Value </span><span style="color: #000000">=</span><span style="color: #000000"> DateTime.Now;
</span><span style="color: #008080">37</span> <span style="color: #000000">
</span><span style="color: #008080">38</span> <span style="color: #000000">            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (Ended </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)
</span><span style="color: #008080">39</span> <span style="color: #000000">                Ended(</span><span style="color: #0000ff">this</span><span style="color: #000000">, Value);
</span><span style="color: #008080">40</span> <span style="color: #000000">
</span><span style="color: #008080">41</span> <span style="color: #000000">        }
</span><span style="color: #008080">42</span> <span style="color: #000000">
</span><span style="color: #008080">43</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> TimerOnElapsed(</span><span style="color: #0000ff">object</span><span style="color: #000000"> sender, ElapsedEventArgs elapsedEventArgs)
</span><span style="color: #008080">44</span> <span style="color: #000000">        {
</span><span style="color: #008080">45</span> <span style="color: #000000">            </span><span style="color: #0000ff">try</span><span style="color: #000000">
</span><span style="color: #008080">46</span> <span style="color: #000000">            {
</span><span style="color: #008080">47</span> <span style="color: #000000">                Value </span><span style="color: #000000">=</span><span style="color: #000000"> DateTime.Now;
</span><span style="color: #008080">48</span> <span style="color: #000000">                
</span><span style="color: #008080">49</span> <span style="color: #000000">                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (tickCount </span><span style="color: #000000">&gt;=</span><span style="color: #000000"> maxTick)
</span><span style="color: #008080">50</span> <span style="color: #000000">                {
</span><span style="color: #008080">51</span> <span style="color: #000000">                    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (Ended </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)
</span><span style="color: #008080">52</span> <span style="color: #000000">                        Ended(</span><span style="color: #0000ff">this</span><span style="color: #000000">, Value);
</span><span style="color: #008080">53</span> <span style="color: #000000">                    
</span><span style="color: #008080">54</span> <span style="color: #000000">                    </span><span style="color: #0000ff">this</span><span style="color: #000000">.timer.Stop();
</span><span style="color: #008080">55</span> <span style="color: #000000">                    
</span><span style="color: #008080">56</span> <span style="color: #000000">                    tickCount </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800080">0</span><span style="color: #000000">;
</span><span style="color: #008080">57</span> <span style="color: #000000">                }
</span><span style="color: #008080">58</span> <span style="color: #000000">                </span><span style="color: #0000ff">else</span><span style="color: #000000">
</span><span style="color: #008080">59</span> <span style="color: #000000">                {
</span><span style="color: #008080">60</span> <span style="color: #000000">                    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (OnTick </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)
</span><span style="color: #008080">61</span> <span style="color: #000000">                        OnTick(</span><span style="color: #0000ff">this</span><span style="color: #000000">, Value);
</span><span style="color: #008080">62</span> <span style="color: #000000">
</span><span style="color: #008080">63</span> <span style="color: #000000">                    tickCount</span><span style="color: #000000">++</span><span style="color: #000000">;
</span><span style="color: #008080">64</span> <span style="color: #000000">
</span><span style="color: #008080">65</span> <span style="color: #000000">                }
</span><span style="color: #008080">66</span> <span style="color: #000000">            }
</span><span style="color: #008080">67</span> <span style="color: #000000">            </span><span style="color: #0000ff">catch</span><span style="color: #000000"> (Exception ex)
</span><span style="color: #008080">68</span> <span style="color: #000000">            {
</span><span style="color: #008080">69</span> <span style="color: #000000">                Console.WriteLine(ex.Message);
</span><span style="color: #008080">70</span> <span style="color: #000000">            }
</span><span style="color: #008080">71</span> <span style="color: #000000">        }
</span><span style="color: #008080">72</span> <span style="color: #000000">
</span><span style="color: #008080">73</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> Dispose()
</span><span style="color: #008080">74</span> <span style="color: #000000">        {
</span><span style="color: #008080">75</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.timer.Stop();
</span><span style="color: #008080">76</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.timer.Elapsed </span><span style="color: #000000">-=</span><span style="color: #000000"> TimerOnElapsed;
</span><span style="color: #008080">77</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.timer.Dispose();
</span><span style="color: #008080">78</span> <span style="color: #000000">        }
</span><span style="color: #008080">79</span> <span style="color: #000000">
</span><span style="color: #008080">80</span> <span style="color: #000000">    }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>&#160;</p>

<p>To be simple, TimeSource handle multiples events. Once the Ended event is called, the business logic is ended and the inner timer is stopped.</p>

<p>How to encapsulate those object to be able to create a Task and then use an await ?</p>

<p>Well, we will use <strong>TaskCompletionSource&lt;T&gt;</strong>. This object will offer us the ability to control the lifetime of our new Task. If you want more information about <strong>TaskCompletionSource&lt;T&gt;</strong>, here is a very good article by Stephen Toub : <a title="https://blogs.msdn.com/b/pfxteam/archive/2009/06/02/9685804.aspx" href="https://blogs.msdn.com/b/pfxteam/archive/2009/06/02/9685804.aspx">https://blogs.msdn.com/b/pfxteam/archive/2009/06/02/9685804.aspx</a></p>

<p>The most important methods of TaskCompletionSource&lt;T&gt; :</p>

<ul>
  <li><strong>SetResult&lt;T&gt;</strong> : Set the Task result and return the task</li>

  <li><strong>SetException&lt;T&gt; </strong>: Handle exception </li>

  <li><strong>SetCanceled</strong> : Handle the CancellationToken of the task if provided</li>
</ul>

<p>
  <br />Here is the <strong>TimeSourceAsync</strong> class that encapsulate the <strong>TimeSource</strong> class :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:40191f47-2f75-4817-a3ad-2afa178b799d" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: visible; height: 582px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> TimeSourceAsync
</span><span style="color: #008080"> 2</span> <span style="color: #000000">    {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">
</span><span style="color: #008080"> 4</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> TimeSource innerTimeSource </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> TimeSource();
</span><span style="color: #008080"> 5</span> <span style="color: #000000">
</span><span style="color: #008080"> 6</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> async Task</span><span style="color: #000000">&lt;</span><span style="color: #000000">DateTime</span><span style="color: #000000">&gt;</span><span style="color: #000000"> LaunchAsync(IProgress</span><span style="color: #000000">&lt;</span><span style="color: #000000">DateTime</span><span style="color: #000000">&gt;</span><span style="color: #000000"> progress)
</span><span style="color: #008080"> 7</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 8</span> <span style="color: #000000">           
</span><span style="color: #008080"> 9</span> <span style="color: #000000">            </span><span style="color: #0000ff">return</span><span style="color: #000000"> await Task.Run</span><span style="color: #000000">&lt;</span><span style="color: #000000">DateTime</span><span style="color: #000000">&gt;</span><span style="color: #000000">(() </span><span style="color: #000000">=&gt;</span><span style="color: #000000">
</span><span style="color: #008080">10</span> <span style="color: #000000">            {
</span><span style="color: #008080">11</span> <span style="color: #000000">                var tcs </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> TaskCompletionSource</span><span style="color: #000000">&lt;</span><span style="color: #000000">DateTime</span><span style="color: #000000">&gt;</span><span style="color: #000000">();
</span><span style="color: #008080">12</span> <span style="color: #000000">
</span><span style="color: #008080">13</span> <span style="color: #000000">                innerTimeSource.Started </span><span style="color: #000000">+=</span><span style="color: #000000"> (s, e) </span><span style="color: #000000">=&gt;</span><span style="color: #000000"> progress.Report(e);
</span><span style="color: #008080">14</span> <span style="color: #000000">                innerTimeSource.OnTick </span><span style="color: #000000">+=</span><span style="color: #000000"> (s, e) </span><span style="color: #000000">=&gt;</span><span style="color: #000000"> progress.Report(e);
</span><span style="color: #008080">15</span> <span style="color: #000000">
</span><span style="color: #008080">16</span> <span style="color: #000000">                innerTimeSource.Ended </span><span style="color: #000000">+=</span><span style="color: #000000"> (s, e) </span><span style="color: #000000">=&gt;</span><span style="color: #000000">
</span><span style="color: #008080">17</span> <span style="color: #000000">                    {
</span><span style="color: #008080">18</span> <span style="color: #000000">                        tcs.SetResult(innerTimeSource.Value);
</span><span style="color: #008080">19</span> <span style="color: #000000">                    };
</span><span style="color: #008080">20</span> <span style="color: #000000">
</span><span style="color: #008080">21</span> <span style="color: #000000">                innerTimeSource.Start();
</span><span style="color: #008080">22</span> <span style="color: #000000">
</span><span style="color: #008080">23</span> <span style="color: #000000">                </span><span style="color: #0000ff">return</span><span style="color: #000000"> tcs.Task ;
</span><span style="color: #008080">24</span> <span style="color: #000000">            });
</span><span style="color: #008080">25</span> <span style="color: #000000">        }
</span><span style="color: #008080">26</span> <span style="color: #000000">
</span><span style="color: #008080">27</span> <span style="color: #000000">    }</span></div></pre>
</div>

<p>&#160;</p>

<h2>Task, AsyncInfo, IAsyncAction, IAsyncOperation, IProgress, CancellationToken …</h2>

<p>Obviously, we should implement asynchronous methods within our component.</p>

<p>Creating a <strong>Task&lt;T&gt;</strong>, like this :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:2f968a79-16a5-4d32-8e0a-cfdbd4f3c7a8" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: visible; word-wrap: break-word; height: 248px; font-family: microsoft sans serif; width: 800px; white-space: pre-wrap; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> async Task Sync()
</span><span style="color: #008080"> 2</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">            </span><span style="color: #0000ff">return</span><span style="color: #000000"> await Task.Run(() </span><span style="color: #000000">=&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 4</span> <span style="color: #000000">            {
</span><span style="color: #008080"> 5</span> <span style="color: #000000">                SyncStatistics statistics </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SyncStatistics();
</span><span style="color: #008080"> 6</span> <span style="color: #000000">                MergeSynchronizationAgent syncAgent </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">;
</span><span style="color: #008080"> 7</span> <span style="color: #000000">
</span><span style="color: #008080"> 8</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> bla bla bla </span><span style="color: #008000">
</span><span style="color: #008080"> 9</span> <span style="color: #008000"></span><span style="color: #000000">
</span><span style="color: #008080">10</span> <span style="color: #000000">                </span><span style="color: #0000ff">return</span><span style="color: #000000">;
</span><span style="color: #008080">11</span> <span style="color: #000000">            });
</span><span style="color: #008080">12</span> <span style="color: #000000">        }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Or like this (returning a type) :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:565ba814-4831-4bdd-a566-37683dabcd05" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: visible; height: 248px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> async Task</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics</span><span style="color: #000000">&gt;</span><span style="color: #000000"> Sync()
</span><span style="color: #008080"> 2</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">            </span><span style="color: #0000ff">return</span><span style="color: #000000"> await Task.Run</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics</span><span style="color: #000000">&gt;</span><span style="color: #000000">(() </span><span style="color: #000000">=&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 4</span> <span style="color: #000000">            {
</span><span style="color: #008080"> 5</span> <span style="color: #000000">                SyncStatistics statistics </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SyncStatistics();
</span><span style="color: #008080"> 6</span> <span style="color: #000000">                MergeSynchronizationAgent syncAgent </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">;
</span><span style="color: #008080"> 7</span> <span style="color: #000000">
</span><span style="color: #008080"> 8</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> bla bla bla </span><span style="color: #008000">
</span><span style="color: #008080"> 9</span> <span style="color: #008000"></span><span style="color: #000000">
</span><span style="color: #008080">10</span> <span style="color: #000000">                </span><span style="color: #0000ff">return</span><span style="color: #000000"> statistics;
</span><span style="color: #008080">11</span> <span style="color: #000000">            });
</span><span style="color: #008080">12</span> <span style="color: #000000">        }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Or like this, returning a type, and handling <strong>CancellationToken</strong> and <strong>IProgress&lt;T&gt;</strong> :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:66869893-e365-487c-92f3-0e4ddc272f5a" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: visible; height: 436px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> async Task</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics</span><span style="color: #000000">&gt;</span><span style="color: #000000"> Sync(CancellationToken cancellationToken, 
</span><span style="color: #008080"> 2</span> <span style="color: #000000">                                         IProgress</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics</span><span style="color: #000000">&gt;</span><span style="color: #000000"> progress)
</span><span style="color: #008080"> 3</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 4</span> <span style="color: #000000">            </span><span style="color: #0000ff">return</span><span style="color: #000000"> await Task.Run</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics</span><span style="color: #000000">&gt;</span><span style="color: #000000">(() </span><span style="color: #000000">=&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 5</span> <span style="color: #000000">            {
</span><span style="color: #008080"> 6</span> <span style="color: #000000">                SyncStatistics statistics </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SyncStatistics();
</span><span style="color: #008080"> 7</span> <span style="color: #000000">                MergeSynchronizationAgent syncAgent </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">;
</span><span style="color: #008080"> 8</span> <span style="color: #000000">
</span><span style="color: #008080"> 9</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> Check if cancellation has occured</span><span style="color: #008000">
</span><span style="color: #008080">10</span> <span style="color: #008000"></span><span style="color: #000000">                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (cancellationToken.IsCancellationRequested)
</span><span style="color: #008080">11</span> <span style="color: #000000">                    cancellationToken.ThrowIfCancellationRequested();
</span><span style="color: #008080">12</span> <span style="color: #000000">                
</span><span style="color: #008080">13</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> Report progress</span><span style="color: #008000">
</span><span style="color: #008080">14</span> <span style="color: #008000"></span><span style="color: #000000">                progress.Report(statistics);
</span><span style="color: #008080">15</span> <span style="color: #000000">
</span><span style="color: #008080">16</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> bla bla bla </span><span style="color: #008000">
</span><span style="color: #008080">17</span> <span style="color: #008000"></span><span style="color: #000000">
</span><span style="color: #008080">18</span> <span style="color: #000000">                </span><span style="color: #0000ff">return</span><span style="color: #000000"> statistics;
</span><span style="color: #008080">19</span> <span style="color: #000000">            });
</span><span style="color: #008080">20</span> <span style="color: #000000">        }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>But …. </p>

<p><img title="image_thumb[2]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image_thumb[2]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/4532.image_thumb2_638F138F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/4532.image_5F00_thumb2_5F00_638F138F.png" width="800" height="48" /></p>

<p>To be able to expose such methods, we need to implements some interfaces :</p>

<ul>
  <li><strong>IAsyncAction </strong>: Handle a simple async method.</li>

  <li><strong>IAsyncOperation </strong>: Handle a simple async method returning a type</li>

  <li><strong>IAsyncActionWithProgress </strong>: Handle a simple async method with progression steps</li>

  <li><strong>IAsyncOperationWithProgress </strong>: Handle a simple async method returning a type with progression steps</li>
</ul>

<p>&#160;</p>

<p>For more informations about IAsyncAction and IAsyncOperation, you should take a look at those articles, by <strong>Stephen Toub</strong> :</p>

<ol>
  <li><a title="https://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx" href="https://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx">https://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx</a></li>

  <li><a title="https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx" href="https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx">https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx</a></li>
</ol>

<p>&#160;</p>

<p>To be clear, you have two solutions to return <strong>IAsyncAction</strong> or <strong>IAsyncOperation</strong> :</p>

<ol>
  <li>Use the extensions methods of Task&lt;T&gt; : <strong>AsAsyncOperation()</strong> ou <strong>AsAsyncAction()</strong></li>

  <li>Use the <strong>AsyncInfo</strong> object and its <strong>Run() </strong>method.</li>
</ol>

<p>&#160;</p>

<h3>Extension methods AsAsyncOperation() ou AsAsyncAction()</h3>

<p>Pretty Straightforward. Just call the extension method on your <strong>Task&lt;T&gt;</strong> and it’s over ! Unfortunately you can’t handle <strong>IProgress&lt;T&gt;</strong> or <strong>CancellationToken</strong> :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:2e9bf06b-be6b-40d8-9726-930f58ba7d3f" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: visible; height: 537px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> IAsyncOperation</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics</span><span style="color: #000000">&gt;</span><span style="color: #000000"> SynchronizeAsync()
</span><span style="color: #008080"> 2</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">            </span><span style="color: #0000ff">return</span><span style="color: #000000"> InternalSync(CancellationToken.None, </span><span style="color: #0000ff">null</span><span style="color: #000000">).AsAsyncOperation();
</span><span style="color: #008080"> 4</span> <span style="color: #000000">
</span><span style="color: #008080"> 5</span> <span style="color: #000000">        }
</span><span style="color: #008080"> 6</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> Task</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics</span><span style="color: #000000">&gt;</span><span style="color: #000000"> InternalSync(CancellationToken cancellationToken, IProgress</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000"> progress)
</span><span style="color: #008080"> 7</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 8</span> <span style="color: #000000">            </span><span style="color: #0000ff">return</span><span style="color: #000000"> Task.Run</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics</span><span style="color: #000000">&gt;</span><span style="color: #000000">(() </span><span style="color: #000000">=&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 9</span> <span style="color: #000000">            {
</span><span style="color: #008080">10</span> <span style="color: #000000">                SyncStatistics statistics </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SyncStatistics();
</span><span style="color: #008080">11</span> <span style="color: #000000">                MergeSynchronizationAgent syncAgent </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">;
</span><span style="color: #008080">12</span> <span style="color: #000000">
</span><span style="color: #008080">13</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> Check if cancellation has occured</span><span style="color: #008000">
</span><span style="color: #008080">14</span> <span style="color: #008000"></span><span style="color: #000000">                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (cancellationToken.IsCancellationRequested)
</span><span style="color: #008080">15</span> <span style="color: #000000">                    cancellationToken.ThrowIfCancellationRequested();
</span><span style="color: #008080">16</span> <span style="color: #000000">
</span><span style="color: #008080">17</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> Report progress</span><span style="color: #008000">
</span><span style="color: #008080">18</span> <span style="color: #008000"></span><span style="color: #000000">                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (progress </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)
</span><span style="color: #008080">19</span> <span style="color: #000000">                    progress.Report(</span><span style="color: #800080">0</span><span style="color: #000000">);
</span><span style="color: #008080">20</span> <span style="color: #000000">
</span><span style="color: #008080">21</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> bla bla bla </span><span style="color: #008000">
</span><span style="color: #008080">22</span> <span style="color: #008000"></span><span style="color: #000000">
</span><span style="color: #008080">23</span> <span style="color: #000000">                </span><span style="color: #0000ff">return</span><span style="color: #000000"> statistics;
</span><span style="color: #008080">24</span> <span style="color: #000000">            });
</span><span style="color: #008080">25</span> <span style="color: #000000">        }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>&#160;</p>

<h3>AsyncInfo.Run()</h3>

<p>You have more flexibility within <strong>AsyncInfo</strong> and its method <strong>Run</strong>. As you can see, we have 4 static methods with CancellationToken and IProgress behaviors:</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:2317bcb4-4ddc-4fd4-8a08-018ff9b14dfc" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: visible; height: 241px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> AsyncInfo
</span><span style="color: #008080"> 2</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">            </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> IAsyncOperationWithProgress</span><span style="color: #000000">&lt;</span><span style="color: #000000">TResult, TProgress</span><span style="color: #000000">&gt;</span><span style="color: #000000"> Run</span><span style="color: #000000">&lt;</span><span style="color: #000000">TResult, TProgress</span><span style="color: #000000">&gt;</span><span style="color: #000000">(
</span><span style="color: #008080"> 4</span> <span style="color: #000000">                Func</span><span style="color: #000000">&lt;</span><span style="color: #000000">CancellationToken, IProgress</span><span style="color: #000000">&lt;</span><span style="color: #000000">TProgress</span><span style="color: #000000">&gt;</span><span style="color: #000000">, Task</span><span style="color: #000000">&lt;</span><span style="color: #000000">TResult</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000"> taskProvider);
</span><span style="color: #008080"> 5</span> <span style="color: #000000">            </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> IAsyncActionWithProgress</span><span style="color: #000000">&lt;</span><span style="color: #000000">TProgress</span><span style="color: #000000">&gt;</span><span style="color: #000000"> Run</span><span style="color: #000000">&lt;</span><span style="color: #000000">TProgress</span><span style="color: #000000">&gt;</span><span style="color: #000000">(
</span><span style="color: #008080"> 6</span> <span style="color: #000000">                Func</span><span style="color: #000000">&lt;</span><span style="color: #000000">CancellationToken, IProgress</span><span style="color: #000000">&lt;</span><span style="color: #000000">TProgress</span><span style="color: #000000">&gt;</span><span style="color: #000000">, Task</span><span style="color: #000000">&gt;</span><span style="color: #000000"> taskProvider);
</span><span style="color: #008080"> 7</span> <span style="color: #000000">            </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> IAsyncOperation</span><span style="color: #000000">&lt;</span><span style="color: #000000">TResult</span><span style="color: #000000">&gt;</span><span style="color: #000000"> Run</span><span style="color: #000000">&lt;</span><span style="color: #000000">TResult</span><span style="color: #000000">&gt;</span><span style="color: #000000">(
</span><span style="color: #008080"> 8</span> <span style="color: #000000">                Func</span><span style="color: #000000">&lt;</span><span style="color: #000000">CancellationToken, Task</span><span style="color: #000000">&lt;</span><span style="color: #000000">TResult</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000"> taskProvider);
</span><span style="color: #008080"> 9</span> <span style="color: #000000">            </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> IAsyncAction Run(
</span><span style="color: #008080">10</span> <span style="color: #000000">                Func</span><span style="color: #000000">&lt;</span><span style="color: #000000">CancellationToken, Task</span><span style="color: #000000">&gt;</span><span style="color: #000000"> taskProvider);
</span><span style="color: #008080">11</span> <span style="color: #000000">        }
</span><span style="color: #008080">12</span> <span style="color: #000000">    }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Here is an example within <strong>IAsyncOperationWithProgress&lt;T1, T2&gt;</strong> :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:23dd8afd-d58b-4aec-8b98-dfe168f138be" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: visible; height: 127px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080">1</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> IAsyncOperationWithProgress</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics, </span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000"> SynchronizeAsync()
</span><span style="color: #008080">2</span> <span style="color: #000000">        {
</span><span style="color: #008080">3</span> <span style="color: #000000">            </span><span style="color: #0000ff">return</span><span style="color: #000000"> AsyncInfo.Run</span><span style="color: #000000">&lt;</span><span style="color: #000000">SyncStatistics, </span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000">((cancellationToken, progress) </span><span style="color: #000000">=&gt;</span><span style="color: #000000">
</span><span style="color: #008080">4</span> <span style="color: #000000">                     InternalSync(cancellationToken, progress));
</span><span style="color: #008080">5</span> <span style="color: #000000">        }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Even if it’s not a Task returning from you component, you can still use the await pattern to call your method, like this :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:af10bf63-d9c6-438e-b03d-1431893493d9" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: visible; height: 179px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080">1</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> async </span><span style="color: #0000ff">void</span><span style="color: #000000"> btnSynchronize_Click(</span><span style="color: #0000ff">object</span><span style="color: #000000"> sender, RoutedEventArgs e)
</span><span style="color: #008080">2</span> <span style="color: #000000">        {
</span><span style="color: #008080">3</span> <span style="color: #000000">           </span><span style="color: #008000">//</span><span style="color: #008000"> Constructeur de mon composant WinRT Brokered</span><span style="color: #008000">
</span><span style="color: #008080">4</span> <span style="color: #008000"></span><span style="color: #000000">            syncProvider </span><span style="color: #000000">=</span><span style="color: #000000"> GetSyncProvider();
</span><span style="color: #008080">5</span> <span style="color: #000000">
</span><span style="color: #008080">6</span> <span style="color: #000000">            </span><span style="color: #008000">//</span><span style="color: #008000"> Launch Sync</span><span style="color: #008000">
</span><span style="color: #008080">7</span> <span style="color: #008000"></span><span style="color: #000000">            var syncCheck </span><span style="color: #000000">=</span><span style="color: #000000"> await syncProvider.SynchronizeAsync();
</span><span style="color: #008080">8</span> <span style="color: #000000">        }
</span><span style="color: #008080">9</span> <span style="color: #000000"></span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>The main proble is that you don’t have any method available to pass any CancellationToken or IProgress&lt;T&gt; parameters, even if we have correctly implement IAsyncOperationWithProgress&lt;T1,T2&gt;</p>

<p>To be able to pass those parameters, we should use the <strong>AsTask() </strong>extension method. Again, take a look on this article if you want more informations on the subject : <a title="https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx" href="https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx">https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx</a></p>

<p>Here is the final code, using the <strong>AsTask()</strong> method:</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:a232dbac-6099-437b-af4f-e812ded0fd5d" class="class" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
  <pre style="overflow: visible; height: 428px; font-family: microsoft sans serif; width: 800px; background-color: white"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080"> 1</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> async </span><span style="color: #0000ff">void</span><span style="color: #000000"> btnSynchronize_Click(</span><span style="color: #0000ff">object</span><span style="color: #000000"> sender, RoutedEventArgs e)
</span><span style="color: #008080"> 2</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">            </span><span style="color: #008000">//</span><span style="color: #008000"> Déclaration de ma progression</span><span style="color: #008000">
</span><span style="color: #008080"> 4</span> <span style="color: #008000"></span><span style="color: #000000">            Progress</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000"> progress </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Progress</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000">((p) </span><span style="color: #000000">=&gt;</span><span style="color: #000000"> lstEvents.Items.Add(String.Format(</span><span style="color: #800000">&quot;</span><span style="color: #800000">{0} % </span><span style="color: #800000">&quot;</span><span style="color: #000000">, p)));
</span><span style="color: #008080"> 5</span> <span style="color: #000000">           
</span><span style="color: #008080"> 6</span> <span style="color: #000000">            </span><span style="color: #008000">//</span><span style="color: #008000"> Jeton d'annulation</span><span style="color: #008000">
</span><span style="color: #008080"> 7</span> <span style="color: #008000"></span><span style="color: #000000">            CancellationTokenSource cancelTokenSource </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> CancellationTokenSource();
</span><span style="color: #008080"> 8</span> <span style="color: #000000">            </span><span style="color: #0000ff">try</span><span style="color: #000000">
</span><span style="color: #008080"> 9</span> <span style="color: #000000">            {
</span><span style="color: #008080">10</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> Constructeur de mon composant WinRT Brokered</span><span style="color: #008000">
</span><span style="color: #008080">11</span> <span style="color: #008000"></span><span style="color: #000000">                syncProvider </span><span style="color: #000000">=</span><span style="color: #000000"> GetSyncProvider();
</span><span style="color: #008080">12</span> <span style="color: #000000">      
</span><span style="color: #008080">13</span> <span style="color: #000000">                </span><span style="color: #008000">//</span><span style="color: #008000"> Launch Sync</span><span style="color: #008000">
</span><span style="color: #008080">14</span> <span style="color: #008000"></span><span style="color: #000000">                var syncCheck </span><span style="color: #000000">=</span><span style="color: #000000"> await syncProvider.SynchronizeAsync().AsTask(cancelTokenSource.Token, progress);
</span><span style="color: #008080">15</span> <span style="color: #000000">
</span><span style="color: #008080">16</span> <span style="color: #000000">            }
</span><span style="color: #008080">17</span> <span style="color: #000000">            </span><span style="color: #0000ff">catch</span><span style="color: #000000"> (Exception)
</span><span style="color: #008080">18</span> <span style="color: #000000">            {
</span><span style="color: #008080">19</span> <span style="color: #000000">                cancelTokenSource.Cancel();
</span><span style="color: #008080">20</span> <span style="color: #000000">                </span><span style="color: #0000ff">throw</span><span style="color: #000000">;
</span><span style="color: #008080">21</span> <span style="color: #000000">            }
</span><span style="color: #008080">22</span> <span style="color: #000000">
</span><span style="color: #008080">23</span> <span style="color: #000000">        }</span></div></pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>&#160;</p>

<p>&#160;</p>

<p>If you want more performance tips on brokered component, take a look on MSDN : <a title="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx" href="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx">https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx</a></p>

<p>Especially the paragraph about using <strong>struct</strong> and returning <strong>array</strong> of objects instead of <strong>List&lt;T&gt;.</strong></p>

<p>Bon développement ! (Hum that’s french … ok, happy coding so ! <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0601.wlEmoticon-smile_785959FC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0601.wlEmoticon_2D00_smile_5F00_785959FC.png" /> )</p>

<p>/Seb </p>]]></content:encoded>
    </item>
    <item>
      <title>Post Mortem développement d’un Brokered Component dans la vraie vie !</title>
      <link>https://docs.microsoft.com/archive/blogs/mim/post-mortem-dveloppement-dun-brokered-component-dans-la-vraie-vie</link>
      <pubDate>Tue, 24 Jun 2014 05:53:41 GMT</pubDate>
      <dc:creator><![CDATA[Sebastien Pertus]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mim/2014/06/24/post-mortem-dveloppement-dun-brokered-component-dans-la-vraie-vie/</guid>
      <description><![CDATA[Bonjour;  Depuis l’arrivée de Windows 8.1, nous avons la possibilité de créer des composants...]]></description>
      <content:encoded><![CDATA[<p>Bonjour;</p>  <p>Depuis l’arrivée de Windows 8.1, nous avons la possibilité de créer des composants Brokered Component pour permettre une passerelle entre le monde ModernUI WinRT et le monde Desktop .NET</p>  <p>Il existe depuis peu les templates de projets associés au développement de Brokered Component, disponible ici :</p>  <p><a title="https://visualstudiogallery.msdn.microsoft.com/527286e4-b06a-4234-adde-d313c9c3c23e" href="https://visualstudiogallery.msdn.microsoft.com/527286e4-b06a-4234-adde-d313c9c3c23e">https://visualstudiogallery.msdn.microsoft.com/527286e4-b06a-4234-adde-d313c9c3c23e</a></p>  <p>Pour plus d’informations, je vous suggère quelques articles, vidéos sur le sujet :</p>  <ol>   <li>Un tutorial en 3 parties : <a title="https://devhawk.net/2014/04/25/brokered-winrt-components-step-one/" href="https://devhawk.net/2014/04/25/brokered-winrt-components-step-one/">https://devhawk.net/2014/04/25/brokered-winrt-components-step-one/</a> </li>    <li>Une couche d’accès aux données : <a title="https://blogs.u2u.be/diederik/post/2014/04/25/Building-Enterprise-apps-using-Brokered-Windows-Runtime-Components.aspx" href="https://blogs.u2u.be/diederik/post/2014/04/25/Building-Enterprise-apps-using-Brokered-Windows-Runtime-Components.aspx">https://blogs.u2u.be/diederik/post/2014/04/25/Building-Enterprise-apps-using-Brokered-Windows-Runtime-Components.aspx</a> </li>    <li>La vidéo de présentation de la //Build 2014 : <a title="https://channel9.msdn.com/Events/Build/2014/2-515" href="https://channel9.msdn.com/Events/Build/2014/2-515">https://channel9.msdn.com/Events/Build/2014/2-515</a> </li>    <li>La documentation MSDN : <a title="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx" href="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx">https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx</a>       <br /></li> </ol>  <p>Dans cet article, je vais m’attacher à faire un retour d’expérience de la création d’un composant complet “de la vraie vie”. Bref, un composant qui fait un peu plus que Hello World ou récupérer 10 lignes d’une base de données <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8078.wlEmoticon-smile_620EA54F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8078.wlEmoticon_2D00_smile_5F00_620EA54F.png" /></p>  <p>Je vais partir du principe que vous connaissez déjà la composants Brokered WinRT et qu’au moins votre hello world fonctionne correctement.</p>  <p>A partir de là, quand on veut aller “plus loin” , on peut rencontrer quelques problèmes, et voici quelques remarques sur ce que j’ai pu observer.</p>  <h2>Debugging</h2>  <p>Premier point, et non des moindres, le debugging de votre composant WinRT Brokered.</p>  <p>Au runtime, aucun point d’arrêt dans votre composant n’est appelé lors votre exécution. En effet ce composant est hosté par un autre processus, appelé <strong>dllhost.exe</strong>. Il va falloir s’attacher à celui-ci.     <br />Autre chose, le composant n’est chargé que lors de la première instanciation d’un objet de votre Brokered Component.</p>  <p>De mon coté, j’ai donc un constructeur simple, public, qui charge mon composant, et qui me permet de poser un point d’arrêt correctement.</p>  <p><u><strong>Dans les faits :</strong></u></p>  <ol>   <li>Mettre un point d’arrêt après l’instanciation de votre composant WinRT dans votre application ModernUI. </li>    <li>Mettre un point d’arrêt dans votre composant WinRT sur la méthode à débuguer. </li>    <li>Lancer l’application en debug et s’arrêter au point d’arrêt situé après l’instanciation de votre composant.     <br />       <br /><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5707.image_123880C4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5707.image_5F00_123880C4.png" width="608" height="179" />      <br />      <br /> </li>    <li>S’attacher au processus <strong>dllhost.exe</strong> de votre composant (oui oui, PENDANT l’exécution) :&#160; <br />      <br /><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/3527.image7_1584D207.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/3527.image7_5F00_1584D207.png" width="800" height="336" />      <br /> </li>    <li>Débuguer votre composant WinRT, maintenant accessible <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8078.wlEmoticon-smile_620EA54F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8078.wlEmoticon_2D00_smile_5F00_620EA54F.png" />       <br />      <br />      <br /><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/6607.image15_477F0342.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/6607.image15_5F00_477F0342.png" width="800" height="248" /> </li> </ol>  <h2>   <br />Runtime Policy Helper</h2>  <p>Et oui, le propre d’un composant Brokered component, c’est pouvoir réutiliser du code .NET existant. Souvent, ce code est déjà compilé, et parfois (souvent) dans une version du Framework 2.*</p>  <p>Pour activer la compatibilité descendante, la méthode la plus simple, c’est de rajouter dans votre fichier de configuration, le nœud de configuration suivant :</p>  <div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:734557ca-05cc-4fe4-a272-89d247f2c4f2" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 670px; height: 141px;background-color:White;overflow: auto;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #0000FF;">&lt;?</span><span style="color: #FF00FF;">xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; </span><span style="color: #0000FF;">?&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">2</span> <span style="color: #000000;"></span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">configuration</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">3</span> <span style="color: #000000;">  </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">startup </span><span style="color: #FF0000;">useLegacyV2RuntimeActivationPolicy</span><span style="color: #0000FF;">=&quot;true&quot;</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">4</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">supportedRuntime </span><span style="color: #FF0000;">version</span><span style="color: #0000FF;">=&quot;v4.0&quot;</span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">5</span> <span style="color: #000000;">  </span><span style="color: #0000FF;">&lt;/</span><span style="color: #800000;">startup</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">6</span> <span style="color: #000000;"></span><span style="color: #0000FF;">&lt;/</span><span style="color: #800000;">configuration</span><span style="color: #0000FF;">&gt;</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Sauf que dans notre cas, impossible de rajouter un fichier de configuration à notre composant. Il va falloir réaliser cette configuration par le code. 
  <br />Je me suis inspiré de deux articles sur le sujet :</p>

<ol>
  <li><a title="https://blogs.msdn.com/b/jomo_fisher/archive/2009/11/17/f-scripting-net-4-0-and-mixed-mode-assemblies.aspx" href="https://blogs.msdn.com/b/jomo_fisher/archive/2009/11/17/f-scripting-net-4-0-and-mixed-mode-assemblies.aspx">https://blogs.msdn.com/b/jomo_fisher/archive/2009/11/17/f-scripting-net-4-0-and-mixed-mode-assemblies.aspx</a> </li>

  <li><a title="https://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/" href="https://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/">https://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/</a> </li>
</ol>

<p>
  <br />A l’intégration, j’ai rajouté cette classe directement dans mon composant Brokered, en privé, en mode Nested :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:86d27068-0ee7-4d77-9c1c-c49f8ffa4a6f" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 500px;background-color:White;overflow: auto;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #000000;"> </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">sealed</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> SqlServerReplicationProvider : IReplicationProvider
    {
        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> RuntimePolicyHelper
        {
            </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">bool</span><span style="color: #000000;"> legacyV2RuntimeEnabledSuccessfully;

            </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">bool</span><span style="color: #000000;"> TryEnableLegacyV2Runtime()
            {
                </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (legacyV2RuntimeEnabledSuccessfully)
                    </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;

                ICLRRuntimeInfo clrRuntimeInfo </span><span style="color: #000000;">=</span><span style="color: #000000;"> (ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(Guid.Empty,
                </span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(ICLRRuntimeInfo).GUID);

                </span><span style="color: #0000FF;">try</span><span style="color: #000000;">
                {
                    clrRuntimeInfo.BindAsLegacyV2Runtime();
                    legacyV2RuntimeEnabledSuccessfully </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;
                }
                </span><span style="color: #0000FF;">catch</span><span style="color: #000000;"> (COMException)
                {
                    legacyV2RuntimeEnabledSuccessfully </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">false</span><span style="color: #000000;">;
                }

                </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> legacyV2RuntimeEnabledSuccessfully;
            }


            [ComImport]
            [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">BD39D1D2-BA2F-486A-89B0-B4B0CB466891</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)]
            </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">interface</span><span style="color: #000000;"> ICLRRuntimeInfo
            {
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xGetVersionString();
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xGetRuntimeDirectory();
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xIsLoaded();
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xIsLoadable();
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xLoadErrorString();
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xLoadLibrary();
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xGetProcAddress();
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xGetInterface();
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xSetDefaultStartupFlags();
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> xGetDefaultStartupFlags();

                [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType </span><span style="color: #000000;">=</span><span style="color: #000000;"> MethodCodeType.Runtime)]
                </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> BindAsLegacyV2Runtime();
            }
        }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Et j’appelle la méthode TryEnableLegacyV2Runtime dans le constructeur de mon composant, ce qui me va bien, si on reprend le point 1 au sujet du débugging <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8078.wlEmoticon-smile_620EA54F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8078.wlEmoticon_2D00_smile_5F00_620EA54F.png" /></p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:9a864b3e-f253-416a-acf4-d52eebe5c1a3" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 670px; height: 141px;background-color:White;overflow: auto;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #000000;">       </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> SqlServerReplicationProvider()
</span><span style="color: #008080;">2</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">3</span> <span style="color: #000000;">            </span><span style="color: #008000;">//</span><span style="color: #008000;"> Activer la compatibilit&#233; .NET 2.*</span><span style="color: #008000;">
</span><span style="color: #008080;">4</span> <span style="color: #008000;"></span><span style="color: #000000;">            RuntimePolicyHelper.TryEnableLegacyV2Runtime();
</span><span style="color: #008080;">5</span> <span style="color: #000000;">
</span><span style="color: #008080;">6</span> <span style="color: #000000;">        }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<h2>Classe abstraite / Interface</h2>

<p>Bon, les classes abstraites, ça marche pas. Vos classes doivent être sealed pour être exposées en WinRT. Malheureusement les classes abstraites ne peuvent être sealed :</p>

<p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2061.image_40B42115.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2061.image_5F00_40B42115.png" width="544" height="346" /></p>

<p>J’ai donc tout migré pour passer par une interface :</p>

<p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2821.image_452D328D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2821.image_5F00_452D328D.png" width="595" height="366" /></p>

<h2>Enumération</h2>

<p>Alors là, grosse déception au niveau des énumérations. </p>

<p>
  <br />Les énumérations fonctionnent correctement avec des projets WinRT, mais ne fonctionnent pas dans le cas d’un Brokered Component.. 

  <br />Le simple fait de rajouter (sans même l’utiliser !) une énumération comme celle-ci, va générer une erreur : </p>

<p>
  <div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:9a66b871-0e0b-4251-b6f0-bcbfd6d9249f" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 106px;background-color:White;overflow: auto;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">enum</span><span style="color: #000000;"> SyncSecurityMode
</span><span style="color: #008080;">2</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">3</span> <span style="color: #000000;">        Standard </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">0</span><span style="color: #000000;">,
</span><span style="color: #008080;">4</span> <span style="color: #000000;">        Integrated </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">1</span><span style="color: #000000;">
</span><span style="color: #008080;">5</span> <span style="color: #000000;">    }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>
</p>

<p>
  <br />Le pire c’est que l’erreur n’est remontée qu’au runtime, et que celle ci n’est pas du tout explicite. Vous rencontrez une simple <strong>BadImageFormatException</strong> :</p>

<p>&#160;</p>

<p><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/2311.image_392B4259.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/2311.image_5F00_392B4259.png" width="640" height="77" /></p>

<p>Bref, si vous avez un soucis incompréhensible dans votre composant avec ce type d’erreur, cherchez du coté de vos énumérations <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8078.wlEmoticon-smile_620EA54F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8078.wlEmoticon_2D00_smile_5F00_620EA54F.png" /></p>

<p>Pour remplacer votre énumération, vous pouvez :</p>

<ol>
  <li>Passer par un simple entier (int) mais la lisibilité de votre code va pas mal en souffrir. </li>

  <li>Ecrire un composant non pas en C# mais directement en C++ WinMD. ça me semble complexe pour pas grand chose.. </li>

  <li>Créer une solution de contournement utilisant un véritable objet (sealed donc) C’est cette solution que j’ai utilisée </li>
</ol>

<p>
  <br />J’ai pas mal cherché, j’ai fait pas mal de tests, je n’ai rien trouvé de très concluant pour palier ce problème. Du coup, je vous propose une solution, sujette à débat (si vous avez une idée, n’hésitez pas à commenter).</p>

<p>Pour faire simple :</p>

<ul>
  <li>J’intègre en mode privé l’énumération en nested class, manière de l’utiliser en interne </li>

  <li>J’utilise des méthodes statiques me permettant d’utiliser la syntaxe : 
    <br /></li>
</ul>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:6b59bebf-7d0a-4c3c-a129-2615a54977b3" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 554px; height: 24px;background-color:White;overflow: auto;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #000000;">var ssm </span><span style="color: #000000;">=</span><span style="color: #000000;"> SyncSecurityMode.Standard;</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<ul>
  <li>Je surcharge la méthode <strong>Equals</strong>, ce qui me permet de traiter la comparaison. Malheureusement surcharger les opérateurs <strong>==</strong> et <strong>!=</strong> auraient été plus judicieux, mais la création de composants WinRT l’interdit. 

    <br />Mes comparaisons deviennent donc : 

    <br /></li>
</ul>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:9c1df687-d562-460a-ab80-4b025feae3c9" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 608px; height: 23px;background-color:White;overflow: auto;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #0000FF;">this</span><span style="color: #000000;">.PublisherSecurityMode.Equals(SyncSecurityMode.Standard))</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<ul>
  <li>Enfin, je surcharge la méthode <strong>ToString()</strong> pour pouvoir facilement afficher la valeur de l’énumération (encore une fois, pratique en mode Debug) </li>
</ul>

<p>
  <br />Voici l’extrait de la classe SyncSecurityMode que j’ai donc migré pour qu’elle fonctionne correctement :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:3adf6be2-55e8-4ca7-96a0-190b272064b5" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 531px;background-color:White;overflow: auto;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">   </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">sealed</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> SyncSecurityMode
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">    {
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">enum</span><span style="color: #000000;"> SyncSecurityModeEnum
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">            Standard </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">0</span><span style="color: #000000;">,
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">            Integrated </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">1</span><span style="color: #000000;">
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> SyncSecurityMode(SyncSecurityModeEnum value)
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">10</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.syncSecurityModeEnum </span><span style="color: #000000;">=</span><span style="color: #000000;"> value;
</span><span style="color: #008080;">11</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">12</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> SyncSecurityMode()
</span><span style="color: #008080;">13</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">14</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">15</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> SyncSecurityModeEnum syncSecurityModeEnum;
</span><span style="color: #008080;">16</span> <span style="color: #000000;">
</span><span style="color: #008080;">17</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> SyncSecurityMode Standard { </span><span style="color: #0000FF;">get</span><span style="color: #000000;"> { </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> SyncSecurityMode(SyncSecurityModeEnum.Standard); } }
</span><span style="color: #008080;">18</span> <span style="color: #000000;">    
</span><span style="color: #008080;">19</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> SyncSecurityMode Integrated { </span><span style="color: #0000FF;">get</span><span style="color: #000000;"> { </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> SyncSecurityMode(SyncSecurityModeEnum.Integrated); } }
</span><span style="color: #008080;">20</span> <span style="color: #000000;">
</span><span style="color: #008080;">21</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">bool</span><span style="color: #000000;"> Equals(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> obj)
</span><span style="color: #008080;">22</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">23</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (obj </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">) </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">false</span><span style="color: #000000;">;
</span><span style="color: #008080;">24</span> <span style="color: #000000;">
</span><span style="color: #008080;">25</span> <span style="color: #000000;">            SyncSecurityMode other </span><span style="color: #000000;">=</span><span style="color: #000000;"> (SyncSecurityMode)obj;
</span><span style="color: #008080;">26</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.syncSecurityModeEnum.Equals(other.syncSecurityModeEnum);
</span><span style="color: #008080;">27</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">28</span> <span style="color: #000000;">
</span><span style="color: #008080;">29</span> <span style="color: #000000;">   }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<h2><strong>IDisposable</strong></h2>

<p>Toutes vos classes WinRT se doivent d’être IDisposable. Sur l’ensemble de mes tests, ne pas implémenter IDisposable avait tendance à laisser le composant chargé en mémoire (surtout lors de la levé d’exceptions non managées par mon composant) dans dllhost.exe</p>

<p>J’utilise le pattern IDIsposable classique, où je différencie le moment de disposer mes ressources managées et non managées :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:0a1a3dfa-3b3f-4187-93c9-7fb48fb5fb05" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 547px;background-color:White;overflow: auto;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">       </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;summary&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;"> 2</span> <span style="color: #008000;">        </span><span style="color: #808080;">///</span><span style="color: #008000;"> Dispose pattern
</span><span style="color: #008080;"> 3</span> <span style="color: #008000;">        </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;/summary&gt;</span><span style="color: #808080;">
</span><span style="color: #008080;"> 4</span> <span style="color: #808080;"></span><span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">bool</span><span style="color: #000000;"> disposed; </span><span style="color: #008000;">//</span><span style="color: #008000;"> to detect redundant calls</span><span style="color: #008000;">
</span><span style="color: #008080;"> 5</span> <span style="color: #008000;"></span><span style="color: #000000;">
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">        </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;summary&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;"> 7</span> <span style="color: #008000;">        </span><span style="color: #808080;">///</span><span style="color: #008000;"> Closes and dispose.
</span><span style="color: #008080;"> 8</span> <span style="color: #008000;">        </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;/summary&gt;</span><span style="color: #808080;">
</span><span style="color: #008080;"> 9</span> <span style="color: #808080;"></span><span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Close()
</span><span style="color: #008080;">10</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">11</span> <span style="color: #000000;">            Dispose(</span><span style="color: #0000FF;">true</span><span style="color: #000000;">);
</span><span style="color: #008080;">12</span> <span style="color: #000000;">            GC.SuppressFinalize(</span><span style="color: #0000FF;">this</span><span style="color: #000000;">);
</span><span style="color: #008080;">13</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">14</span> <span style="color: #000000;">
</span><span style="color: #008080;">15</span> <span style="color: #000000;">        </span><span style="color: #000000;">~</span><span style="color: #000000;">SqlServerReplicationProvider()
</span><span style="color: #008080;">16</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">17</span> <span style="color: #000000;">            Dispose(</span><span style="color: #0000FF;">false</span><span style="color: #000000;">);
</span><span style="color: #008080;">18</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">19</span> <span style="color: #000000;">        </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;summary&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;">20</span> <span style="color: #008000;">        </span><span style="color: #808080;">///</span><span style="color: #008000;"> Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
</span><span style="color: #008080;">21</span> <span style="color: #008000;">        </span><span style="color: #808080;">///</span><span style="color: #008000;"> call Close() method
</span><span style="color: #008080;">22</span> <span style="color: #008000;">        </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;/summary&gt;</span><span style="color: #808080;">
</span><span style="color: #008080;">23</span> <span style="color: #808080;"></span><span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Dispose()
</span><span style="color: #008080;">24</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">25</span> <span style="color: #000000;">            Close();
</span><span style="color: #008080;">26</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">27</span> <span style="color: #000000;">
</span><span style="color: #008080;">28</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">protected</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Dispose(</span><span style="color: #0000FF;">bool</span><span style="color: #000000;"> disposing)
</span><span style="color: #008080;">29</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">30</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">disposed)
</span><span style="color: #008080;">31</span> <span style="color: #000000;">            {
</span><span style="color: #008080;">32</span> <span style="color: #000000;">                </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (disposing)
</span><span style="color: #008080;">33</span> <span style="color: #000000;">                {
</span><span style="color: #008080;">34</span> <span style="color: #000000;">                    </span><span style="color: #008000;">//</span><span style="color: #008000;"> Dispose managed resources.</span><span style="color: #008000;">
</span><span style="color: #008080;">35</span> <span style="color: #008000;"></span><span style="color: #000000;">                    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (subscriberConn </span><span style="color: #000000;">!=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;"> </span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;"> subscriberConn.IsOpen)
</span><span style="color: #008080;">36</span> <span style="color: #000000;">                        subscriberConn.Disconnect();
</span><span style="color: #008080;">37</span> <span style="color: #000000;">
</span><span style="color: #008080;">38</span> <span style="color: #000000;">                    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (publisherConn </span><span style="color: #000000;">!=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;"> </span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;"> publisherConn.IsOpen)
</span><span style="color: #008080;">39</span> <span style="color: #000000;">                        publisherConn.Disconnect();
</span><span style="color: #008080;">40</span> <span style="color: #000000;">                }
</span><span style="color: #008080;">41</span> <span style="color: #000000;">
</span><span style="color: #008080;">42</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> There are no unmanaged resources to release, but
</span><span style="color: #008080;">43</span> <span style="color: #008000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> if we add them, they need to be released here.</span><span style="color: #008000;">
</span><span style="color: #008080;">44</span> <span style="color: #008000;"></span><span style="color: #000000;">            }
</span><span style="color: #008080;">45</span> <span style="color: #000000;">            disposed </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;
</span><span style="color: #008080;">46</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">47</span> <span style="color: #000000;"></span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Plus d’informations sur le pattern IDisposable ici : <a title="https://msdn.microsoft.com/en-us/library/system.idisposable(v=vs.110).aspx" href="https://msdn.microsoft.com/en-us/library/system.idisposable(v=vs.110).aspx">https://msdn.microsoft.com/en-us/library/system.idisposable(v=vs.110).aspx</a></p>

<h2>Legacy Objects : Gérer les évènements</h2>

<p>Et oui, avant on avait plutôt l’habitude de léver des évènements dans nos objets. Ce qui pouvait poser quelques problèmes quand on est en asynchrone (revenir sur le thread UI etc … vous voyez suremment de quoi je parle <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/8078.wlEmoticon-smile_620EA54F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/8078.wlEmoticon_2D00_smile_5F00_620EA54F.png" />)</p>

<p>Aujourd’hui, quand on parle pattern asynchrone, on pense IProgress&lt;T&gt; qui permet de lever une progression et ne pas avoir à gérer le problème de threading.</p>

<p>Pour présenter le problème que j’ai rencontré voici un exemple, simple, de la situation que j’ai dû résoudre :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:2ce0caed-4bbf-4d29-bd71-afcff2bdb80b" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 467px;background-color:White;overflow: auto;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">   </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> TimeSource : IDisposable
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">    {
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">readonly</span><span style="color: #000000;"> Timer timer;
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">event</span><span style="color: #000000;"> EventHandler</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DateTime</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> OnTick;
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">event</span><span style="color: #000000;"> EventHandler</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DateTime</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> Started;
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">event</span><span style="color: #000000;"> EventHandler</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DateTime</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> Ended;
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> tickCount </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">0</span><span style="color: #000000;">;
</span><span style="color: #008080;">10</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> maxTick </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">5</span><span style="color: #000000;">;
</span><span style="color: #008080;">11</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> Double tickDuration </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">1000</span><span style="color: #000000;">;
</span><span style="color: #008080;">12</span> <span style="color: #000000;">
</span><span style="color: #008080;">13</span> <span style="color: #000000;">
</span><span style="color: #008080;">14</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> DateTime Value { </span><span style="color: #0000FF;">get</span><span style="color: #000000;">; </span><span style="color: #0000FF;">set</span><span style="color: #000000;">; }
</span><span style="color: #008080;">15</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> TimeSource()
</span><span style="color: #008080;">16</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">17</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.timer </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Timer(tickDuration);
</span><span style="color: #008080;">18</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.timer.Elapsed </span><span style="color: #000000;">+=</span><span style="color: #000000;"> TimerOnElapsed;
</span><span style="color: #008080;">19</span> <span style="color: #000000;">       }
</span><span style="color: #008080;">20</span> <span style="color: #000000;">
</span><span style="color: #008080;">21</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Start()
</span><span style="color: #008080;">22</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">23</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.timer.Start();
</span><span style="color: #008080;">24</span> <span style="color: #000000;">            Value </span><span style="color: #000000;">=</span><span style="color: #000000;"> DateTime.Now;
</span><span style="color: #008080;">25</span> <span style="color: #000000;">
</span><span style="color: #008080;">26</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (Started </span><span style="color: #000000;">!=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)
</span><span style="color: #008080;">27</span> <span style="color: #000000;">                Started(</span><span style="color: #0000FF;">this</span><span style="color: #000000;">, Value);
</span><span style="color: #008080;">28</span> <span style="color: #000000;"> 
</span><span style="color: #008080;">29</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">30</span> <span style="color: #000000;">
</span><span style="color: #008080;">31</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Stop()
</span><span style="color: #008080;">32</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">33</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.timer.Stop();
</span><span style="color: #008080;">34</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.tickCount </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">0</span><span style="color: #000000;">;
</span><span style="color: #008080;">35</span> <span style="color: #000000;">
</span><span style="color: #008080;">36</span> <span style="color: #000000;">            Value </span><span style="color: #000000;">=</span><span style="color: #000000;"> DateTime.Now;
</span><span style="color: #008080;">37</span> <span style="color: #000000;">
</span><span style="color: #008080;">38</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (Ended </span><span style="color: #000000;">!=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)
</span><span style="color: #008080;">39</span> <span style="color: #000000;">                Ended(</span><span style="color: #0000FF;">this</span><span style="color: #000000;">, Value);
</span><span style="color: #008080;">40</span> <span style="color: #000000;">
</span><span style="color: #008080;">41</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">42</span> <span style="color: #000000;">
</span><span style="color: #008080;">43</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> TimerOnElapsed(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> sender, ElapsedEventArgs elapsedEventArgs)
</span><span style="color: #008080;">44</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">45</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">try</span><span style="color: #000000;">
</span><span style="color: #008080;">46</span> <span style="color: #000000;">            {
</span><span style="color: #008080;">47</span> <span style="color: #000000;">                Value </span><span style="color: #000000;">=</span><span style="color: #000000;"> DateTime.Now;
</span><span style="color: #008080;">48</span> <span style="color: #000000;">                
</span><span style="color: #008080;">49</span> <span style="color: #000000;">                </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (tickCount </span><span style="color: #000000;">&gt;=</span><span style="color: #000000;"> maxTick)
</span><span style="color: #008080;">50</span> <span style="color: #000000;">                {
</span><span style="color: #008080;">51</span> <span style="color: #000000;">                    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (Ended </span><span style="color: #000000;">!=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)
</span><span style="color: #008080;">52</span> <span style="color: #000000;">                        Ended(</span><span style="color: #0000FF;">this</span><span style="color: #000000;">, Value);
</span><span style="color: #008080;">53</span> <span style="color: #000000;">                    
</span><span style="color: #008080;">54</span> <span style="color: #000000;">                    </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.timer.Stop();
</span><span style="color: #008080;">55</span> <span style="color: #000000;">                    
</span><span style="color: #008080;">56</span> <span style="color: #000000;">                    tickCount </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">0</span><span style="color: #000000;">;
</span><span style="color: #008080;">57</span> <span style="color: #000000;">                }
</span><span style="color: #008080;">58</span> <span style="color: #000000;">                </span><span style="color: #0000FF;">else</span><span style="color: #000000;">
</span><span style="color: #008080;">59</span> <span style="color: #000000;">                {
</span><span style="color: #008080;">60</span> <span style="color: #000000;">                    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (OnTick </span><span style="color: #000000;">!=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)
</span><span style="color: #008080;">61</span> <span style="color: #000000;">                        OnTick(</span><span style="color: #0000FF;">this</span><span style="color: #000000;">, Value);
</span><span style="color: #008080;">62</span> <span style="color: #000000;">
</span><span style="color: #008080;">63</span> <span style="color: #000000;">                    tickCount</span><span style="color: #000000;">++</span><span style="color: #000000;">;
</span><span style="color: #008080;">64</span> <span style="color: #000000;">
</span><span style="color: #008080;">65</span> <span style="color: #000000;">                }
</span><span style="color: #008080;">66</span> <span style="color: #000000;">            }
</span><span style="color: #008080;">67</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">catch</span><span style="color: #000000;"> (Exception ex)
</span><span style="color: #008080;">68</span> <span style="color: #000000;">            {
</span><span style="color: #008080;">69</span> <span style="color: #000000;">                Console.WriteLine(ex.Message);
</span><span style="color: #008080;">70</span> <span style="color: #000000;">            }
</span><span style="color: #008080;">71</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">72</span> <span style="color: #000000;">
</span><span style="color: #008080;">73</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Dispose()
</span><span style="color: #008080;">74</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">75</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.timer.Stop();
</span><span style="color: #008080;">76</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.timer.Elapsed </span><span style="color: #000000;">-=</span><span style="color: #000000;"> TimerOnElapsed;
</span><span style="color: #008080;">77</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.timer.Dispose();
</span><span style="color: #008080;">78</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">79</span> <span style="color: #000000;">
</span><span style="color: #008080;">80</span> <span style="color: #000000;">    }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>&#160;</p>

<p>Pour faire simple, l’objet <strong>TimeSource</strong> lève des évènements au fur et à mesure du déroulement de son métier. Lorsque le dernier évènement et levé, la tache est terminée.</p>

<p>Comment faire pour encapsuler cet objet (si on ne peut pas le modifier) pour en créer une Task, et pouvoir faire un await dessus ?</p>

<p>En utilisant l’objet <strong>TaskCompletionSource&lt;T&gt;</strong> qui va nous permettre d’attendre l’évènement de fin pour compléter la tache.</p>

<p>Les méthodes importantes de TaskCompletionSource&lt;T&gt; à implémenter :</p>

<ul>
  <li><strong>SetResult&lt;T&gt;</strong> : Permet d’affecter le résultat et finir la tache</li>

  <li><strong>SetException&lt;T&gt; </strong>: Permet de gérer les exceptions et renvoyer l’exception au niveau de la tache</li>

  <li><strong>SetCanceled</strong> : Permet de gérer l’appel Cancel d’un jeton CancellationToken</li>
</ul>

<p>
  <br />Voici l’implémentation de ce pattern dans la classe <strong>TimeSourceAsync</strong> :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:40191f47-2f75-4817-a3ad-2afa178b799d" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 582px;background-color:White;overflow: visible;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> TimeSourceAsync
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">    {
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> TimeSource innerTimeSource </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> TimeSource();
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> async Task</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DateTime</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> LaunchAsync(IProgress</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DateTime</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> progress)
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">           
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> await Task.Run</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DateTime</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(() </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">10</span> <span style="color: #000000;">            {
</span><span style="color: #008080;">11</span> <span style="color: #000000;">                var tcs </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> TaskCompletionSource</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DateTime</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">();
</span><span style="color: #008080;">12</span> <span style="color: #000000;">
</span><span style="color: #008080;">13</span> <span style="color: #000000;">                innerTimeSource.Started </span><span style="color: #000000;">+=</span><span style="color: #000000;"> (s, e) </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;"> progress.Report(e);
</span><span style="color: #008080;">14</span> <span style="color: #000000;">                innerTimeSource.OnTick </span><span style="color: #000000;">+=</span><span style="color: #000000;"> (s, e) </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;"> progress.Report(e);
</span><span style="color: #008080;">15</span> <span style="color: #000000;">
</span><span style="color: #008080;">16</span> <span style="color: #000000;">                innerTimeSource.Ended </span><span style="color: #000000;">+=</span><span style="color: #000000;"> (s, e) </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">17</span> <span style="color: #000000;">                    {
</span><span style="color: #008080;">18</span> <span style="color: #000000;">                        tcs.SetResult(innerTimeSource.Value);
</span><span style="color: #008080;">19</span> <span style="color: #000000;">                    };
</span><span style="color: #008080;">20</span> <span style="color: #000000;">
</span><span style="color: #008080;">21</span> <span style="color: #000000;">                innerTimeSource.Start();
</span><span style="color: #008080;">22</span> <span style="color: #000000;">
</span><span style="color: #008080;">23</span> <span style="color: #000000;">                </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> tcs.Task ;
</span><span style="color: #008080;">24</span> <span style="color: #000000;">            });
</span><span style="color: #008080;">25</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">26</span> <span style="color: #000000;">
</span><span style="color: #008080;">27</span> <span style="color: #000000;">    }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Evidemment pour aller plus loin que cet exemple trivial, n’hésitez pas aussi à implémenter le code permettant d’utiliser un jeton d’annulation (<strong>CancellationToken</strong>) qui appellera la méthode <strong>SetCancel()</strong> du <strong>TaskCompletationSource&lt;T&gt;</strong>

  <br />Dans mon cas simpliste, je n’ai pas utiliser un <strong>Try Catch</strong>, mais n’oubliez pas de l’implémenter et gérer l’exception avec la méthode <strong>SetException(Exception)</strong>

  <br /></p>

<h2>Task, AsyncInfo, IAsyncAction, IAsyncOperation, IProgress, CancellationToken …</h2>

<p>Lors de la création de votre composant, vous voulez bien-sûr privilégier le mode asynchrone pour les taches lourdes.</p>

<p>Evidemment le premier réflexe est donc de créer une <strong>Task&lt;T&gt;</strong>, comme ceci par exemple :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:2f968a79-16a5-4d32-8e0a-cfdbd4f3c7a8" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 248px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: visible;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> async Task Sync()
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> await Task.Run(() </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">            {
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">                SyncStatistics statistics </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> SyncStatistics();
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">                MergeSynchronizationAgent syncAgent </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> bla bla bla </span><span style="color: #008000;">
</span><span style="color: #008080;"> 9</span> <span style="color: #008000;"></span><span style="color: #000000;">
</span><span style="color: #008080;">10</span> <span style="color: #000000;">                </span><span style="color: #0000FF;">return</span><span style="color: #000000;">;
</span><span style="color: #008080;">11</span> <span style="color: #000000;">            });
</span><span style="color: #008080;">12</span> <span style="color: #000000;">        }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Voir une tache qui renvoie un type, comme ceci :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:565ba814-4831-4bdd-a566-37683dabcd05" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 248px;background-color:White;overflow: visible;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> async Task</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> Sync()
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> await Task.Run</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(() </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">            {
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">                SyncStatistics statistics </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> SyncStatistics();
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">                MergeSynchronizationAgent syncAgent </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> bla bla bla </span><span style="color: #008000;">
</span><span style="color: #008080;"> 9</span> <span style="color: #008000;"></span><span style="color: #000000;">
</span><span style="color: #008080;">10</span> <span style="color: #000000;">                </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> statistics;
</span><span style="color: #008080;">11</span> <span style="color: #000000;">            });
</span><span style="color: #008080;">12</span> <span style="color: #000000;">        }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Et pour aller encore plus loin, créer une <strong>Task&lt;T&gt;</strong>, qui renvoie un type T, et qui gère un <strong>CancellationToken</strong> et un <strong>IProgress&lt;T&gt;</strong>, comme ceci :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:66869893-e365-487c-92f3-0e4ddc272f5a" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 436px;background-color:White;overflow: visible;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> async Task</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> Sync(CancellationToken cancellationToken, 
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">                                         IProgress</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> progress)
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> await Task.Run</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(() </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">            {
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">                SyncStatistics statistics </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> SyncStatistics();
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">                MergeSynchronizationAgent syncAgent </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> Check if cancellation has occured</span><span style="color: #008000;">
</span><span style="color: #008080;">10</span> <span style="color: #008000;"></span><span style="color: #000000;">                </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (cancellationToken.IsCancellationRequested)
</span><span style="color: #008080;">11</span> <span style="color: #000000;">                    cancellationToken.ThrowIfCancellationRequested();
</span><span style="color: #008080;">12</span> <span style="color: #000000;">                
</span><span style="color: #008080;">13</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> Report progress</span><span style="color: #008000;">
</span><span style="color: #008080;">14</span> <span style="color: #008000;"></span><span style="color: #000000;">                progress.Report(statistics);
</span><span style="color: #008080;">15</span> <span style="color: #000000;">
</span><span style="color: #008080;">16</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> bla bla bla </span><span style="color: #008000;">
</span><span style="color: #008080;">17</span> <span style="color: #008000;"></span><span style="color: #000000;">
</span><span style="color: #008080;">18</span> <span style="color: #000000;">                </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> statistics;
</span><span style="color: #008080;">19</span> <span style="color: #000000;">            });
</span><span style="color: #008080;">20</span> <span style="color: #000000;">        }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Sauf que ça, ça ne fonctionne pas pour un composant WinRT. L’erreur est explicite</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/5460.image_0BC1FB40.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/5460.image_5F00_0BC1FB40.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/09/metablogapi/0383.image_thumb_18BBDB51.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-09-metablogapi/0383.image_5F00_thumb_5F00_18BBDB51.png" width="800" height="48" /></a></p>

<p>Pour exposer une méthode en asynchrone, on doit renvoyer un interface, au minium, de type <strong>IAsyncAction ou IAsyncOperation.</strong></p>

<p>Pour faire simple:</p>

<ul>
  <li><strong>IAsyncAction </strong>: Permet de gérer un appel asynchrone</li>

  <li><strong>IAsyncOperation </strong>: Permet de gérer un appel asynchrone et renvoie un résultat</li>

  <li><strong>IAsyncActionWithProgress </strong>: Permet de gérer un appel asynchrone avec progression</li>

  <li><strong>IAsyncOperationWithProgress </strong>: Permet de gérer un appel asynchrone avec progression et qui renvoie un résultat</li>
</ul>

<p>&#160;</p>

<p>Pour plus d’informations sur le sujet, je vous suggère ces deux articles du Dieu en la matière <strong>Stephen Toub</strong> :</p>

<ol>
  <li><a title="https://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx" href="https://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx">https://blogs.msdn.com/b/windowsappdev/archive/2012/06/14/exposing-net-tasks-as-winrt-asynchronous-operations.aspx</a></li>

  <li><a title="https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx" href="https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx">https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx</a></li>
</ol>

<p>&#160;</p>

<p>Pour résumé, vous avez deux possibilités pour retourner <strong>IAsyncAction</strong> ou <strong>IAsyncOperation</strong> :</p>

<ol>
  <li>Utiliser les méthodes d’extensions de Task&lt;T&gt; : <strong>AsAsyncOperation()</strong> ou <strong>AsAsyncAction()</strong></li>

  <li>Utiliser l’objet <strong>AsyncInfo</strong> et la méthode statique <strong>Run()</strong></li>
</ol>

<p>&#160;</p>

<h3>Méthodes d’extension AsAsyncOperation() ou AsAsyncAction()</h3>

<p>C’est de loin la méthode la plus simple. Elle est rapide à mettre en place, mais malheureusement ne prend pas en compte la progression (<strong>IProgress&lt;T&gt;</strong>) ou l’annulation (<strong>CancellationToken</strong>)</p>

<p>Dans mon cas, j’ai tout d’abord créer une méthode privée qui renvoie une <strong>Task&lt;T&gt;</strong>, puis j’ai créé la méthode publique encapsulant l’appel en utilisant dans mon cas <strong>AsAsyncOperation()</strong> :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:2e9bf06b-be6b-40d8-9726-930f58ba7d3f" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 537px;background-color:White;overflow: visible;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> IAsyncOperation</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> SynchronizeAsync()
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> InternalSync(CancellationToken.None, </span><span style="color: #0000FF;">null</span><span style="color: #000000;">).AsAsyncOperation();
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> Task</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> InternalSync(CancellationToken cancellationToken, IProgress</span><span style="color: #000000;">&lt;</span><span style="color: #0000FF;">int</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> progress)
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> Task.Run</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(() </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">            {
</span><span style="color: #008080;">10</span> <span style="color: #000000;">                SyncStatistics statistics </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> SyncStatistics();
</span><span style="color: #008080;">11</span> <span style="color: #000000;">                MergeSynchronizationAgent syncAgent </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;">12</span> <span style="color: #000000;">
</span><span style="color: #008080;">13</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> Check if cancellation has occured</span><span style="color: #008000;">
</span><span style="color: #008080;">14</span> <span style="color: #008000;"></span><span style="color: #000000;">                </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (cancellationToken.IsCancellationRequested)
</span><span style="color: #008080;">15</span> <span style="color: #000000;">                    cancellationToken.ThrowIfCancellationRequested();
</span><span style="color: #008080;">16</span> <span style="color: #000000;">
</span><span style="color: #008080;">17</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> Report progress</span><span style="color: #008000;">
</span><span style="color: #008080;">18</span> <span style="color: #008000;"></span><span style="color: #000000;">                </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (progress </span><span style="color: #000000;">!=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)
</span><span style="color: #008080;">19</span> <span style="color: #000000;">                    progress.Report(</span><span style="color: #800080;">0</span><span style="color: #000000;">);
</span><span style="color: #008080;">20</span> <span style="color: #000000;">
</span><span style="color: #008080;">21</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> bla bla bla </span><span style="color: #008000;">
</span><span style="color: #008080;">22</span> <span style="color: #008000;"></span><span style="color: #000000;">
</span><span style="color: #008080;">23</span> <span style="color: #000000;">                </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> statistics;
</span><span style="color: #008080;">24</span> <span style="color: #000000;">            });
</span><span style="color: #008080;">25</span> <span style="color: #000000;">        }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Comme on le remarque, on se passe de la progression et du jeton d’annulation</p>

<h3>AsyncInfo.Run()</h3>

<p>Ici plus de souplesse d’utilisation, mais un peu plus de complexité à la mise en œuvre (et encore que …)</p>

<p>L’objet <strong>AsyncInfo</strong> possède 4 méthodes statiques, permettant de renvoyer chacune des interfaces qui nous intéresse :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:2317bcb4-4ddc-4fd4-8a08-018ff9b14dfc" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 241px;background-color:White;overflow: visible;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> AsyncInfo
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> IAsyncOperationWithProgress</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TResult, TProgress</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> Run</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TResult, TProgress</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">                Func</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">CancellationToken, IProgress</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TProgress</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">, Task</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TResult</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> taskProvider);
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> IAsyncActionWithProgress</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TProgress</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> Run</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TProgress</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">                Func</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">CancellationToken, IProgress</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TProgress</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">, Task</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> taskProvider);
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> IAsyncOperation</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TResult</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> Run</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TResult</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">                Func</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">CancellationToken, Task</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TResult</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> taskProvider);
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> IAsyncAction Run(
</span><span style="color: #008080;">10</span> <span style="color: #000000;">                Func</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">CancellationToken, Task</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> taskProvider);
</span><span style="color: #008080;">11</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">12</span> <span style="color: #000000;">    }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Dans notre cas, l’implémentation est assez simple, j’utilise la méthode <strong>IAsyncOperationWithProgress&lt;T,T2&gt; :</strong></p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:23dd8afd-d58b-4aec-8b98-dfe168f138be" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 127px;background-color:White;overflow: visible;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> IAsyncOperationWithProgress</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics, </span><span style="color: #0000FF;">int</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> SynchronizeAsync()
</span><span style="color: #008080;">2</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">3</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> AsyncInfo.Run</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">SyncStatistics, </span><span style="color: #0000FF;">int</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">((cancellationToken, progress) </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">4</span> <span style="color: #000000;">                     InternalSync(cancellationToken, progress));
</span><span style="color: #008080;">5</span> <span style="color: #000000;">        }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>A partir de là, nous avons un appel d’une méthode asynchrone gérant facilement le jeton d’annulation et la progression.</p>

<h3>Implémentation et appel du code asynchrone du Brokered Component</h3>

<p>L’appel coté code se fait de façon plutôt simple, tel que vous avez l’habitude de faire :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:af10bf63-d9c6-438e-b03d-1431893493d9" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 179px;background-color:White;overflow: visible;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> async </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> btnSynchronize_Click(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> sender, RoutedEventArgs e)
</span><span style="color: #008080;">2</span> <span style="color: #000000;">        {
</span><span style="color: #008080;">3</span> <span style="color: #000000;">           </span><span style="color: #008000;">//</span><span style="color: #008000;"> Constructeur de mon composant WinRT Brokered</span><span style="color: #008000;">
</span><span style="color: #008080;">4</span> <span style="color: #008000;"></span><span style="color: #000000;">            syncProvider </span><span style="color: #000000;">=</span><span style="color: #000000;"> GetSyncProvider();
</span><span style="color: #008080;">5</span> <span style="color: #000000;">
</span><span style="color: #008080;">6</span> <span style="color: #000000;">            </span><span style="color: #008000;">//</span><span style="color: #008000;"> Launch Sync</span><span style="color: #008000;">
</span><span style="color: #008080;">7</span> <span style="color: #008000;"></span><span style="color: #000000;">            var syncCheck </span><span style="color: #000000;">=</span><span style="color: #000000;"> await syncProvider.SynchronizeAsync();
</span><span style="color: #008080;">8</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">9</span> <span style="color: #000000;"></span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>Le problème c’est que votre méthode ne prend PAS de paramètre <strong>CancellationToken </strong>ou <strong>IProgress&lt;T&gt;</strong>, alors que nous avons bien implémenter (grace à l’objet <strong>AsyncInfo</strong>) le code nécessaire pour faire fonctionner ce pattern.</p>

<p>Nous allons utiliser la méthode d’extension <strong>AsTask()</strong> qui va du coup nous renvoyer une Task tel qu’on a l’habitude de faire, et ainsi gérer le jeton d’annulation et la progression. </p>

<p>J’en ai déjà parlé en préambule mais si vous voulez apprendre comment fonctionne AsTask(), n’hésitez pas à regarder cet article de Monsieur Toub (Oui Monsieur, avec un M majuscule, lui il y a droit. Y’a des gens comme ça ….) : <a title="https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx" href="https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx">https://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx</a></p>

<p>Voici l’implémentation complète de mon appel :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:a232dbac-6099-437b-af4f-e812ded0fd5d" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 800px; height: 428px;background-color:White;overflow: visible;;font-family:Microsoft Sans Serif;font-size:8,25"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> async </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> btnSynchronize_Click(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> sender, RoutedEventArgs e)
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">            </span><span style="color: #008000;">//</span><span style="color: #008000;"> D&#233;claration de ma progression</span><span style="color: #008000;">
</span><span style="color: #008080;"> 4</span> <span style="color: #008000;"></span><span style="color: #000000;">            Progress</span><span style="color: #000000;">&lt;</span><span style="color: #0000FF;">int</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> progress </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Progress</span><span style="color: #000000;">&lt;</span><span style="color: #0000FF;">int</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">((p) </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;"> lstEvents.Items.Add(String.Format(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">{0} % </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">, p)));
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">           
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">            </span><span style="color: #008000;">//</span><span style="color: #008000;"> Jeton d'annulation</span><span style="color: #008000;">
</span><span style="color: #008080;"> 7</span> <span style="color: #008000;"></span><span style="color: #000000;">            CancellationTokenSource cancelTokenSource </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> CancellationTokenSource();
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">try</span><span style="color: #000000;">
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">            {
</span><span style="color: #008080;">10</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> Constructeur de mon composant WinRT Brokered</span><span style="color: #008000;">
</span><span style="color: #008080;">11</span> <span style="color: #008000;"></span><span style="color: #000000;">                syncProvider </span><span style="color: #000000;">=</span><span style="color: #000000;"> GetSyncProvider();
</span><span style="color: #008080;">12</span> <span style="color: #000000;">      
</span><span style="color: #008080;">13</span> <span style="color: #000000;">                </span><span style="color: #008000;">//</span><span style="color: #008000;"> Launch Sync</span><span style="color: #008000;">
</span><span style="color: #008080;">14</span> <span style="color: #008000;"></span><span style="color: #000000;">                var syncCheck </span><span style="color: #000000;">=</span><span style="color: #000000;"> await syncProvider.SynchronizeAsync().AsTask(cancelTokenSource.Token, progress);
</span><span style="color: #008080;">15</span> <span style="color: #000000;">
</span><span style="color: #008080;">16</span> <span style="color: #000000;">            }
</span><span style="color: #008080;">17</span> <span style="color: #000000;">            </span><span style="color: #0000FF;">catch</span><span style="color: #000000;"> (Exception)
</span><span style="color: #008080;">18</span> <span style="color: #000000;">            {
</span><span style="color: #008080;">19</span> <span style="color: #000000;">                cancelTokenSource.Cancel();
</span><span style="color: #008080;">20</span> <span style="color: #000000;">                </span><span style="color: #0000FF;">throw</span><span style="color: #000000;">;
</span><span style="color: #008080;">21</span> <span style="color: #000000;">            }
</span><span style="color: #008080;">22</span> <span style="color: #000000;">
</span><span style="color: #008080;">23</span> <span style="color: #000000;">        }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>&#160;</p>

<p>&#160;</p>

<p>Voilà un premier retour d’expérience de la création d’un composant Brokered Component, dans la vraie vie.</p>

<p>Si vous voulez d’autre pointeurs sur la performance d’un Brokered Component, n’hésitez pas à consulter l’article MSDN sur le sujet : <a title="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx" href="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx">https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx</a></p>

<p>On y parle notamment de l’utilisation de <strong>struct</strong> et du renvoie <strong>d’array</strong> plutôt que de<strong> List&lt;T&gt;</strong> lorsque vous devez renvoyer “plus de 10 lignes” d’une base de données SQL Server par exemple.</p>

<p>Bon développement !</p>

<p>/Seb</p>]]></content:encoded>
    </item>
  </channel>
</rss>