<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Cloudy Computing</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/flaviencharlon/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/feed.xml</link>
    <description>Software Development and Cloud Computing in Dublin</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:21:41 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Getting change notifications from any dependency property in Windows Store Apps</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/getting-change-notifications-from-any-dependency-property-in-windows-store-apps</link>
      <pubDate>Fri, 07 Dec 2012 05:04:00 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/12/07/getting-change-notifications-from-any-dependency-property-in-windows-store-apps/</guid>
      <description><![CDATA[When declaring a dependency property, you can specify a callback to be called when the property...]]></description>
      <content:encoded><![CDATA[<p>When declaring a dependency property, you can specify a callback to be called when the property changes. However if you want to be notified of changes of a property that is already declared, you have to rely on the class exposing an event for it (like TextChanged on the TextBox for the Text property). This event doesn't always exist. In WFP you could use the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dependencypropertydescriptor.aspx">DependencyPropertyDescriptor</a> class to register for change notifications of any property. In Silverlight and Windows Store Apps, this class doesn't exist. Fortunately,&nbsp;there is a little trick to achieve that: you need to declare your own dependency property, and add a change notification callback, then bind the property that you are really interested in to that property you just declared. When the property changes, the binding gets updated, your property (the one you declared) gets changed and the callback is triggered.</p>
<p>Here is a class that will do all of that for you:</p>
<pre class="script">public class DependencyPropertyWatcher&lt;T&gt; : DependencyObject, IDisposable
{
    public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register(
            "Value",
            typeof(object),
            typeof(DependencyPropertyWatcher),
            new PropertyMetadata(null, OnPropertyChanged));

    public event EventHandler PropertyChanged;

    public DependencyPropertyWatcher(DependencyObject target, string propertyPath)
    {
        this.Target = target;
        BindingOperations.SetBinding(
            this,
            ValueProperty,
            new Binding() { Source = target, Path = new PropertyPath(propertyPath), Mode = BindingMode.OneWay });
    }

    public DependencyObject Target { get; private set; }

    public T Value
    {
        get { return (T)this.GetValue(ValueProperty); }
    }

    public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs args)
    {
        DependencyPropertyWatcher&lt;T&gt; source = (DependencyPropertyWatcher&lt;T&gt;)sender;
            
        if (source.PropertyChanged != null)
        {
            source.PropertyChanged(source, EventArgs.Empty);
        }
    }

    public void Dispose()
    {
        this.ClearValue(ValueProperty);
    }
}
</pre>
<p>And here is how to use it:</p>
<pre class="script">private DependencyPropertyWatcher&lt;string&gt; watcher;
        
protected override void LoadState(Object navigationParameter, Dictionary pageState)
{
    watcher = new DependencyPropertyWatcher&lt;string&gt;(this.textBox, "Text");            
    watcher.PropertyChanged += OnTextChanged;
}

private void OnTextChanged(object sender, EventArgs e)
{
    var text = watcher.Value;
    // ...
}
</pre>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Why dependency properties need a wrapper</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/why-dependency-properties-need-a-wrapper</link>
      <pubDate>Thu, 06 Dec 2012 09:12:00 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/12/06/why-dependency-properties-need-a-wrapper/</guid>
      <description><![CDATA[Dependency properties are not a new thing, they have been part of WPF and Silverlight for years....]]></description>
      <content:encoded><![CDATA[<p>Dependency properties are not a new thing, they have been part of WPF and Silverlight for years. They enable key features such as data binding, styles, animations, change notifications and&nbsp;default values.</p>
<p>Their behavior however can differ slightly from API to API, WPF and Silverlight for example, have slightly different behaviors when it comes to dependency properties. This blog post will look in the details of how dependency properties work in Windows Store Apps.</p>
<h2>Implementing a dependency property</h2>
<p>The first thing to know about dependency properties is that the infrastructure that make them work is in the DependencyObject class. Therefore, you will need to inherit from DependencyObject if you want to use dependency properties.</p>
<h3>Declaring the dependency property</h3>
<p>Declaring a dependency property is done through a static method. This will return a&nbsp;key (of type DependencyProperty) that you will be able to pass to <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.dependencyobject.getvalue">GetValue</a> and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.dependencyobject.setvalue">SetValue</a> to get and set the property on a specific DependencyObject. Here is how to declare the dependency property:</p>
<pre class="script">public static readonly DependencyProperty IsSpinningProperty = 
    DependencyProperty.Register(
        "<span style="color: #ff0000;">IsSpinning</span>",
        typeof(bool),
        typeof(SpinningControl),
        new PropertyMetadata(false)<br />    );
</pre>
<p>Declaring an <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh965327.aspx">attached dependency property</a> is very similar:</p>
<pre class="script">public static readonly DependencyProperty IsMovableProperty =
    DependencyProperty.RegisterAttached(
        "<span style="color: #ff0000;">IsMovable</span>",
        typeof(bool),
        typeof(ObjectContainer),
        new PropertyMetadata(false)
    );
</pre>
<p>In both snippets, I have highlighted in red the string that will identify the property within the dependency property infrastructure. This name will be used for example when you want to animate the property from XAML.</p>
<h3>Implementing the wrapper</h3>
<p>A wrapper for&nbsp;GetValue and SetValue is usually defined along with the dependency property. There are some specific conventions on how they should be declared. Here is how to implement them:</p>
<pre class="script">public bool <span style="color: #ff0000;">IsSpinning</span>
{
    get { return (bool)GetValue(IsSpinningProperty); }
    set { SetValue(IsSpinningProperty, value); }
}
</pre>
<p>And for a dependency property, the wrapper should be as follow:</p>
<pre class="script">public static void Set<span style="color: #ff0000;">IsMovable</span>(DependencyObject dependencyObject, bool value)
{
    dependencyObject.SetValue(IsMovableProperty, value);
}

public static bool Get<span style="color: #ff0000;">IsMovable</span>(DependencyObject dependencyObject)
{
    return (bool)dependencyObject.GetValue(IsMovableProperty);
}</pre>
<p>I have highlighted in red the name of the property that will be looked up in some occasions (see below) when using the property from XAML.</p>
<h3>When is the wrapper used?</h3>
<p>Dependency property&nbsp;wrappers are not just wrappers. If you don't implement them, you won't be able to use the dependency property from XAML. When setting a dependency property from XAML, the compiler will check that the dependency property you are using actually exists. It can only do so by performing a static analysis of the code. As a result, it is unable to know that you declared a property called "IsSpinning" by calling <a href="http://msdn.microsoft.com/en-gb/library/windows/apps/hh701829.aspx">DependencyProperty.Register</a>. What the compiler does instead is check the existence (and type) of the wrapper. If you use a non-attached dependency property, it will check for the property wrapper, and if you use an attached property, it will check for the GetX and SetX methods (as shown above). This check is also done for example when you declare a Setter in a Style, targeting a specific property. Note however that the compiler doesn't check what happens inside that wrapper. It could be empty, or do something completely different, but as long as it exists and the type matches, compilation will succeed.</p>
<p>When setting a property in XAML to a static value, Windows will actually call the wrapper. That means that it will work even if it is a standard .NET property that is not backed by a dependency property. The SetX method is called if you use the syntax of an attached dependency property. However if you try anything such as setting the value to a binding, or using the property in a style or an animation, Windows will no longer use the wrapper, and will call directly GetValue or SetValue, matching the name of the property that you are using in XAML with the name you declared when you called DependencyProperty.Register. If that name doesn't exist, you will get a runtime error. That's why the name in the wrapper and the name in DependencyProperty.Register (all in red above) have to match. If they don't match, you will either get a compile time or runtime error.</p>
<p>Here are the key takeaways about how dependency properties work when used from XAML:</p>
<ol>
<li><strong>Compile time</strong>
<ul>
<li>Compile time check is always performed by looking at the name and type of the wrapper.</li>
</ul>
</li>
<li><strong>Runtime</strong>
<ul>
<li>Setting the property to a static value in XAML will cause the wrapper to be called (looked up by its name). That works even if there is no dependency property registered to that name.</li>
<li>With any other advanced feature (data binding, styles, animations...), <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.dependencyobject.getvalue">GetValue</a> and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.dependencyobject.setvalue">SetValue</a> are called directly and&nbsp;the wrapper is bypassed.&nbsp;There must be a dependency property registered with that name.</li>
</ul>
</li>
</ol>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>The golden rules of Windows Store Apps design</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/the-golden-rules-of-windows-store-apps-design</link>
      <pubDate>Wed, 05 Dec 2012 02:37:14 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/12/05/the-golden-rules-of-windows-store-apps-design/</guid>
      <description><![CDATA[After my previous article about default styles and templates of XAML controls, here is the next set...]]></description>
      <content:encoded><![CDATA[<p>After my previous article about <a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/12/04/default-styles-and-templates-of-xaml-controls-for-windows-store-apps.aspx">default styles and templates</a> of XAML controls, here is the next set of useful MSDN resources for a Windows 8 app developer/designer.</p>
<p>Those two pages give the golden rules of a Windows Store App design:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-gb/library/windows/apps/hh872191.aspx" target="_blank">Laying out an app page</a></li>
<li><a href="http://msdn.microsoft.com/en-gb/library/windows/apps/hh700394.aspx">Guidelines for fonts</a></li>
</ul>
<p>Following those guidelines will ensure you have a sleek UI, that is consistent with the other apps.</p>
<p>The documents use the notion of unit, which is a 20 pixels space, and can be divided in 4 sub-units of 5 pixels each.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/8311.IC571944.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/8311.IC571944.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/8311.IC571944.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/8311.IC571944.png" alt="" border="0" /></a></p>
<p>In a standard page, the top region containing the header will be 140 pixels (7 units) and the left margin will be 120 pixels (6 units). The bottom margin will be between 50 and 130 pixels (2.5 to 6.5 units) depending on your content.</p>]]></content:encoded>
    </item>
    <item>
      <title>Default styles and templates of XAML controls for Windows Store Apps</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/default-styles-and-templates-of-xaml-controls-for-windows-store-apps</link>
      <pubDate>Tue, 04 Dec 2012 05:24:00 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/12/04/default-styles-and-templates-of-xaml-controls-for-windows-store-apps/</guid>
      <description><![CDATA[In the early days of WPF and Silverlight, the only way you could get information about the default...]]></description>
      <content:encoded><![CDATA[<p>In the early days of WPF and Silverlight, the only way you could get information about the default templates and styles of controls would be by opening Blend and editing a copy of the default style. Fortunately, this information is now documented on MSDN, however it is not always easy to find. In order to make it easier to lookup, I have made this list of all the MSDN articles about default styles and templates for Windows Store Apps controls:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj710186.aspx" target="_blank">AppBar</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709909.aspx" target="_blank">Button</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709910.aspx" target="_blank">CheckBox</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709912.aspx" target="_blank">ComboBox</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709911.aspx" target="_blank">ComboBoxItem</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj710187.aspx" target="_blank">ContentControl</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709914.aspx" target="_blank">FlipView</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709913.aspx" target="_blank">FlipViewItem</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709916.aspx" target="_blank">GridView</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709915.aspx" target="_blank">GridViewItem</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709917.aspx" target="_blank">GroupItem</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709918.aspx" target="_blank">HyperlinkButton</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709920.aspx" target="_blank">ListBox</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709919.aspx" target="_blank">ListBoxItem</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709922.aspx" target="_blank">ListView</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709921.aspx" target="_blank">ListViewItem</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj710188.aspx" target="_blank">PasswordBox</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709923.aspx" target="_blank">ProgressBar</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709924.aspx" target="_blank">ProgressRing</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709925.aspx" target="_blank">RadioButton</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709926.aspx" target="_blank">RepeatButton</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj710189.aspx" target="_blank">RichEditBox</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj710190.aspx" target="_blank">ScrollBar</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709927.aspx" target="_blank">ScrollViewer</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709928.aspx" target="_blank">SemanticZoom</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709929.aspx" target="_blank">Slider</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj710191.aspx" target="_blank">TextBox</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj710192.aspx" target="_blank">Thumb</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709930.aspx" target="_blank">ToggleButton</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709931.aspx" target="_blank">ToggleSwitch</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709932.aspx" target="_blank">ToolTip</a></li>
</ul>
<p>Note that you will also find those default styles and templates in the following file on your disk: C:\Program Files (x86)\Windows Kits\8.0\Include\WinRT\Xaml\Design\generic.xaml.</p>]]></content:encoded>
    </item>
    <item>
      <title>Pin any executable to the Windows 8 Start screen</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/pin-any-executable-to-the-windows-8-start-screen</link>
      <pubDate>Thu, 08 Nov 2012 05:53:00 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/11/08/pin-any-executable-to-the-windows-8-start-screen/</guid>
      <description><![CDATA[The Start screen in Windows 8 is a full screen replacement of the old Start menu. You can...]]></description>
      <content:encoded><![CDATA[<p>The Start screen in Windows 8 is a full screen replacement of the old Start menu. You can think&nbsp;of it as a Start menu 2.0. It has been designed to not only work for classic mouse and keyboard input, but also for touch devices, and let's admit it, it is much more aesthetically pleasing than the old Start menu. It is also every bit as powerful as the old Start menu, and&nbsp;highly customizable.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/3250.Windows_8_Start_menu.jpg" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/3250.Windows_5F00_8_5F00_Start_5F00_menu.jpg"><img style="max-width: 550px;" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/3250.Windows_8_Start_menu.jpg" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/3250.Windows_5F00_8_5F00_Start_5F00_menu.jpg" alt="" border="0" /></a></p>
<p>In this article, I will explain how to pin any shortcut to the start screen. Let's say for example that you would like to pin a file to the Start screen. It works with really anything: executables, batch files, documents, images, etc...</p>
<ol>
<li>Start creating a shortcut to what you want to pin.</li>
<li>Navigate to <strong>%ProgramData%\Microsoft\Windows\Start Menu\Programs</strong> (Press Windows + R and paste it there to open it directly)</li>
<li>Copy the shortcut there</li>
</ol>
<p>That's it, the tile should have appeared in your Start screen. If it hasn't, you'll find it in "All apps" in the bottom bar (right click, or swipe your touch screen from the bottom). You can then right click on the tile and select "Pin to Start".</p>]]></content:encoded>
    </item>
    <item>
      <title>A foreach statement for IObservable</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/a-foreach-statement-for-iobservable</link>
      <pubDate>Wed, 15 Aug 2012 06:56:00 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/08/15/a-foreach-statement-for-iobservable/</guid>
      <description><![CDATA[Asynchronous programming is a very powerful tool. It is key for responsiveness on the client, and...]]></description>
      <content:encoded><![CDATA[<p href="http://en.wikipedia.org/wiki/C10k_problem">Asynchronous programming is a very powerful tool. It is key for responsiveness on the client, and scalability on the server (see the <a href="http://en.wikipedia.org/wiki/C10k_problem">C10K problem</a>). However in most modern programming languages, it comes at a pretty high price: when you want to consume the result of an asynchronous operation, you have to provide a callback function to be called upon completion of the operation. The problem is that this introduces an inversion of control, and if you want to use a slightly elaborated control flow around your asynchronous operation, (like if statements, loops, exception handling), it becomes quickly a nightmare, and the code often becomes unreadable and hard to maintain.</p>
<p>People are starting to realize the need for asynchronous programming, but even the most popular frameworks for asynchronous programming, like Node.JS or Tornado with Python are callback based.</p>
<p>This was also the case with C# until recently, but as you know, C# 5.0 introduces the new async/await keywords. Those keywords are the Holy Grail of asynchronous programming. Asynchronous code written using async/await will be as readable as synchronous code, because it no longer requires the use of callbacks.</p>
<p>Async and await can be used out of the box with Task&lt;T&gt;, but any object implementing the awaitable pattern can be used with await. IObservable though, represents a collection, and await only allows to deal with single values. Note that you can await an observable, but that will only yield the last value of that observable. You could also use <a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/08/06/task-lt-t-gt-vs-iobservable-lt-t-gt-when-to-use-what.aspx">BufferAllAsync </a>that I showed in my last article, then await the result, but that will require the whole enumeration to be buffered, and you won't be able to do any processing before the observable has completed. What we would need is an async flavor of foreach, something like:</p>
<pre class="script">private static async Task EnumerateAsync(IObservable&lt;string&gt; observable)
{
    async foreach (var item in observable)
    {
        Console.WriteLine(item);
    }
}
</pre>
<p>Unfortunately, the C# language designers preferred not to overwhelm developers, and did not include that feature in C# 5.0.</p>
<p>Fortunately, it is not hard to recreate. The secret is to transform the IObservable&lt;T&gt; into a IAsyncEnumerable&lt;T&gt;, then use await to enumerate asynchronously over it. IAsyncEnumerable&lt;T&gt; is part of the interactive side of the Reactive Extensions. You will need to add a reference to System.Interactive.Async, which you can find in the Ix_Experimental-Async NuGet package. IAsyncEnumerable&lt;T&gt; is basically a replica of the IEnumerable&lt;T&gt; interface, the only difference is that MoveNext returns Task&lt;bool&gt; on the IAsyncEnumerator instead of bool on the normal IEnumerator. This makes perfect sense, as in the asynchronous case, MoveNext should only complete when the source IObservable has a new value to provide, when the observable completes, or if it throws.</p>
<p>Let&rsquo;s assume we have an observable that we want to iterate over:</p>
<pre class="script">IObservable&lt;string&gt; io = Observable.Interval(TimeSpan.FromSeconds(1)).Select(v =&gt; "Tick " + v);
EnumerateAsync(io);</pre>
<p>We can implement an async foreach by copying the expanded form of foreach, and adding the await keyword when calling MoveNext. The result is this:</p>
<pre class="script">private static async Task EnumerateAsync(IObservable&lt;string&gt; observable)
{
    using (var enumerator = observable.ToAsyncEnumerable().GetEnumerator())
    {
        while (await enumerator.MoveNext())
        {
            await Task.Yield();

            var item = enumerator.Current;

            // Your code here
            Console.WriteLine(value);
        }
    }
}
</pre>
<p>The Task.Yield statement is necessary because of <a href="http://social.msdn.microsoft.com/Forums/en-US/rx/thread/f1b0ca02-675f-4dd7-9519-9670b6b2594a">a bug</a> in the implementation of ToAsyncEnumerable. Using that construct, you can process observables in a pull fashion. That means you can wrap the loop in a try/catch statement, use break from the loop, and the disposal of the subscription is automatically handled. That also guarantees that each iteration of the loop will be done one after the other, in a sequential fashion, making your code thread-safe by design.</p>]]></content:encoded>
    </item>
    <item>
      <title>Task&lt;T&gt; vs IObservable&lt;T&gt;: when to use what?</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/taskt-vs-iobservablet-when-to-use-what</link>
      <pubDate>Mon, 06 Aug 2012 04:15:00 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/08/06/taskt-vs-iobservablet-when-to-use-what/</guid>
      <description><![CDATA[The Task&lt;T&gt; class was integrated with the .NET Framework in .NET 4.0, as part of what is known...]]></description>
      <content:encoded><![CDATA[<p>The Task&lt;T&gt; class was integrated with the .NET Framework in .NET 4.0, as part of what is known as the Task Parallel Library. The main purpose of the TPL was to facilitate writing parallel code, making it easier to run code on multiple cores, for instance. That is why the class itself was called Task, it represented a piece of program you could run in parallel with other pieces of program. Task, however, is much more versatile than that. In .NET 4.5 (now RTM, and on MSDN next week), Task will be the primary actor for working with the new async/await language feature.</p>
<p>What Task is in reality is a &ldquo;<a href="http://en.wikipedia.org/wiki/Future_(programming)">future</a>&rdquo;. A future is an object that represents a value which may or may not exist yet. When you run a piece of code using Task.Run, what the Task returned represents is the return value of your piece of code. It will only be available when the piece of code finished running. However, Task is suited to represent any sort of operation that hasn&rsquo;t completed yet, parallel computation but also&nbsp;IO. If parallel computing is important in some fields, asynchronous IO is capital for almost any application (Client and server).</p>
<p><a href="http://msdn.microsoft.com/en-us/data/gg577609.aspx">Reactive Extensions</a> (Rx) is a project that was started by Erik Meijer before the TPL even existed. It was only released recently though (2010). Rx is providing a new interface (IObservable&lt;T&gt;) that can be combined by the means of operators, the same way you can use LINQ on IEnumerable&lt;T&gt;.</p>
<p>Historically, the async/await feature did not exist yet when the Rx project started. As a result, they have now a great deal of overlap in what they can do. It doesn&rsquo;t mean that one must disappear, there are situations where one or the other will be better suited. Let&rsquo;s now see which one is better suited for what.</p>
<h2>Reasons for using Task&lt;T&gt;</h2>
<p>Let&rsquo;s say you are turning a synchronous function returning int to async, you could do two things: return IObservable&lt;int&gt; or Task&lt;int&gt;.</p>
<p>Rx provides you with a bunch of operators, one of them is Observable.Return. This returns an observable that pushes a single value, then completes immediately. My opinion is that returning Task&lt;int&gt; is better, and here are the reasons why:</p>
<ol>
<li>Task is included in .NET, whereas the reactive extensions are not. Your code will require the reactive extensions if you chose to return IObservable.</li>
<li>In C# 5.0, the async/await language feature can only return Task or Task&lt;T&gt; (or void), so you can use that feature and don&rsquo;t need any conversion.</li>
<li>The IObservable&lt;T&gt; contract is very broad, it just represents a stream of values. It could be&nbsp;zero value, one value, or multiple values. And after a value has been pushed, it could complete immediately, or later. On the other hand, a Task&lt;T&gt; represents always a single value of type T, and when the value is available, it becomes the result of the task, and the task is considered completed. At this point, the task is immutable, and you know it will never change state again. The contract is much simpler.<br />If someone&nbsp;consuming your function looks at the signature, it is clear that it returns a single value if your return Task&lt;T&gt;. If you return IObservable&lt;T&gt; however, there are many things it could return.</li>
<li>The threading model is more straightforward with Task&lt;T&gt;. When you are handed a task, and want to attach a continuation to it, you are in complete control of what thread it will run on, no matter where that task comes from. If you don&rsquo;t specify any scheduler for your continuation, it will run on the current scheduler, or the default scheduler (Task pool) if there is no current scheduler. That behavior is always true, and completely independent from the task you are attaching a continuation on.<br />In the reactive extensions, on the other hand, when you subscribe to an observable, the scheduler on which the callback will run depends on how the observable was constructed. This allows IObservable to have better performance, since it doesn&rsquo;t switch thread at each step of the computation, but on the other hand, the abstraction leaks, and a piece of code working with an IObservable could behave differently depending on which scheduler that IObservable runs on.</li>
<li>This is an extension of the previous point, but with the reactive extensions, depending on how the observable is constructed, your consuming code (the code in the callback) could be blocking the producing code.<br />Task on the other hand, is just a piece of data. There is no producing code associated to it. This model is easier to reason with.</li>
</ol>
<h2>Reasons for using IObservable&lt;T&gt;</h2>
<p>As you saw in the previous section, Task is a better abstraction and easier to reason with, but there are situations where Task&lt;T&gt; is not the best tool for the job. Task&lt;T&gt; represents a future for a single value of type T. Sometimes, you need to return a stream of values. Here is an example: let&rsquo;s imagine you are writing an asynchronous function that reads a database table, and returns it. If you return task, you will have to return something like Task&lt;List&lt;Row&gt;&gt;, that means you will be buffering all the rows in memory, and complete the task when the whole table is buffered. You can probably see why this can become a scalability issue.&nbsp;A better option is to return IObservable&lt;Row&gt;. Each row, as it is read from the database, is pushed through the IObservable. The consumer can then process rows as they become available, and there is never more than one row in memory at the same time.</p>
<p>Note that if as a consumer, you still want to buffer all the rows, you can easily convert the IObservable&lt;Row&gt; to a Task&lt;IList&lt;Row&gt;&gt;, using this function:</p>
<pre class="script">public static Task&lt;IList&lt;T&gt;&gt; BufferAllAsync&lt;T&gt;(this IObservable&lt;T&gt; observable)
{
    List&lt;T&gt; result = new List&lt;T&gt;();
    object gate = new object();
    TaskCompletionSource&lt;IList&lt;T&gt;&gt; finalTask = new TaskCompletionSource&lt;IList&lt;T&gt;&gt;();

    observable.Subscribe(
        value =&gt;
        {
            lock (gate)
            {
                result.Add(value);
            }
        },
        exception =&gt; finalTask.TrySetException(exception),
        () =&gt; finalTask.SetResult(result.AsReadOnly())
    );

    return finalTask.Task;
}
</pre>
<p>To wrap up, I would suggest to use Task whenever you can, and use IObservable if you get into a more complex situation where you need an entire collection to be turned asynchronous.</p>]]></content:encoded>
    </item>
    <item>
      <title>Git on the cloud with Windows Azure</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/git-on-the-cloud-with-windows-azure</link>
      <pubDate>Wed, 01 Aug 2012 05:42:38 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/08/01/git-on-the-cloud-with-windows-azure/</guid>
      <description><![CDATA[Here are the four parts of the walkthrough I wrote about using a Linux virtual machine on Windows...]]></description>
      <content:encoded><![CDATA[<p>Here are the four parts of the walkthrough I wrote about using a Linux <a href="http://www.windowsazure.com/en-us/home/scenarios/virtual-machines/">virtual machine on Windows Azure</a>&nbsp;for hosting a Git repository on the cloud:</p>
<ol>
<li><a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/07/09/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-1.aspx">Introduction</a></li>
<li><a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/07/12/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-2.aspx">Provisionning a virtual machine on Windows Azure</a></li>
<li><a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/07/17/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-3.aspx">Setting up the server</a></li>
<li><a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/07/24/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-4.aspx">Configuring your client</a></li>
</ol>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Hosting Git on the Cloud with Windows Azure Virtual Machines (Part 4)</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-4</link>
      <pubDate>Tue, 24 Jul 2012 09:55:23 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/07/24/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-4/</guid>
      <description><![CDATA[In part 2 and part 3, we have created a Virtual Machine running Linux though Windows Azure Virtual...]]></description>
      <content:encoded><![CDATA[<p>In <a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/07/12/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-2.aspx">part 2</a> and <a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/07/17/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-3.aspx">part 3</a>, we have created a Virtual Machine running Linux though Windows Azure Virtual Machines, and we have setup a Git repository on the VM. We are now going to see how to clone the repository, and push back the changes. In this blog post, we will use TortoiseGit on Windows as a client, but you can use any Git client tool, or the command line, and from any operating system.</p>
<p>Make sure you have the private key (the PPK file) we generated in part 2 using Puttygen.</p>
<p>What we will do first is create an empty repository on the server. We will need to log in onto the server to do that.</p>
<ol>
<li>
<p>Start putty and enter your hostname (xxxx.cloudapp.net).</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/5315.img5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/5315.img5.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/5315.img5.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/5315.img5.png" /></a></p>
</li>
<li>
<p>On the left, click on &ldquo;Auth&rdquo;, under &ldquo;SSH&rdquo;, under &ldquo;Connections&rdquo;. Click Browse where it says &ldquo;Private key file for authentication&rdquo;, and find your private key file. Click Open.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/7180.img9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/7180.img9.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/7180.img9.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/7180.img9.png" /></a></p>
</li>
<li>
<p>When you are prompted for your username, type &ldquo;git&rdquo; (the git user). Putty should then authenticate you using your private key. It will ask you for the passphrase you chose when you generated the key pair.</p>
</li>
<li>
<p>You should now be logged in. Create a new repository by doing:</p>
<pre class="script">cd /git
git init --bare myrepo.git
</pre>
</li>
</ol>
<p>You can now log out from the server. The repository has been created on the VM. Let&rsquo;s now clone it on your machine.</p>
<p>First make sure you have installed msysgit on your client machine. You can download it from <a href="http://code.google.com/p/msysgit/downloads/list">here</a>. Then you can install TortoiseGit, it you haven&rsquo;t done so already. You can download it at <a href="http://code.google.com/p/tortoisegit/wiki/Download?tm=2">this location</a>.</p>
<p>You should now be all prepared to use Git from your client machine.</p>
<ol>
<li>
<p>Right click on the folder where you want to clone the repository, and select &ldquo;Git Clone&hellip;&rdquo;. A popup will appear.</p>
</li>
<li>
<p>In the URL, type a URL such as: ssh://&lt;your-clouapp-host-name&gt;/git/&lt;your-repository-name&gt;</p>
<p>In our example, &lt;your-repository-name&gt; would be myrepo.git.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/0284.img10.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/0284.img10.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/0284.img10.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/0284.img10.png" /></a></p>
</li>
<li>
<p>Check &ldquo;Load Putty Key&rdquo;, and browse for your private key. Click OK.</p>
</li>
<li>
<p>You will be prompted for the user, type &ldquo;git&rdquo;, you may also have to type the passphrase of your private key.</p>
</li>
</ol>
<p>This is it, the repository is cloned. The repository will be empty of course, but you can now make some changes (add a file), commit the changes.</p>
<p>After pushing back your commits to origin (the virtual machine), your changes will be safely and durably stored on Windows Azure, and you will benefit from the Geo-replication. Any contributor who owns a private key (as configured in <a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/07/12/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-3.aspx">part 3</a>) can create new repositories, push and pull code. You can create as many repositories as you want by following the first 4 steps of this article. You should have about 25 GB free on the disk for storing your repositories, if you chose the default Ubuntu image provided by Windows Azure. In case you need more space, you can attach an additional virtual disk. The current price for Geo-Replicated storage is $0.125 per GB per month. This solution is more complex than setting up a repository on GitHub, especially for a small one, but if you have many repositories and/or large ones, this will be a very economical solution.</p>]]></content:encoded>
    </item>
    <item>
      <title>Hosting Git on the Cloud with Windows Azure Virtual Machines (Part 3)</title>
      <link>https://docs.microsoft.com/archive/blogs/flaviencharlon/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-3</link>
      <pubDate>Tue, 17 Jul 2012 08:09:00 GMT</pubDate>
      <dc:creator><![CDATA[Flavien Charlon]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/flaviencharlon/2012/07/17/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-3/</guid>
      <description><![CDATA[In the previous post, we have seen how to create a Virtual Machine on Windows Azure running Linux...]]></description>
      <content:encoded><![CDATA[<p>In the <a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/07/12/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-2.aspx">previous post</a>, we have seen how to create a Virtual Machine on Windows Azure running Linux (Ubuntu Server). We are now going to see how to setup Git on that machine.</p>
<ol>
<li>
<p>I will assume you are running Windows on your client machine. We will use Putty to connect to the Virtual Machine using the SSH protocol. Download it from <a href="http://www.chiark.greenend.org.uk/%7Esgtatham/putty/download.html">this webpage</a>, and make sure you take the Zip file that contains all the binaries.</p>
</li>
<li>
<p>Launch Putty. You will then need to specify the host name of your VM. It will take the form of xxxx.cloudapp.net. The first part (xxxx) is what you have chosen in part 2 of this series. If you don&rsquo;t remember what you chose, you can find it by going back to the Azure Portal. It will be displayed on the right. Leave the rest as the default (port should be 22). Windows Azure has automatically opened the port 22 on the load balancer to let traffic in. All the other ports will be closed to reduce the surface of attack.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/5315.img5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/5315.img5.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/5315.img5.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/5315.img5.png" /></a></p>
</li>
<li>
<p>You will be prompted for your username and the password. Once you have typed them, you will be logged in remotely on the Virtual Machine.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/7206.img6b.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/7206.img6b.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/7206.img6b.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/7206.img6b.png" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/4314.img6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/4314.img6.png"></a></p>
</li>
<li>
<p>Run those commands to make sure your OS is up to date and to install git.</p>
<pre class="script">sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install git-core</pre>
</li>
<li>
<p>Let&rsquo;s create a user &lsquo;git&rsquo; that we will use to access the repositories:</p>
<pre class="script">adduser git</pre>
<p>All the contributors will use that user to push or pull from the repositories, however that doesn&rsquo;t mean that they will have to share the password. We will see later why.</p>
</li>
<li>
<p>We will now create the directory where all the repositories will be stored. We will create that directory under the main user's own home directory (/home/flavien in our case). Since the 'git' user doesn&rsquo;t have write permissions in that user's home directory, it will not be able to delete the &lsquo;repositories&rsquo; directory:</p>
<pre class="script">mkdir ~/repositories</pre>
<p>However we want only the 'git' user to have full access to the content of the directory.</p>
<p>First, we need to install the ACL package. That will give us the ability to set a default ACL on the directory. A default ACL is a special kind of ACL defining the access ACL that files and subdirectories directly under the directory inherit when they are created.</p>
<p>Install the ACL package by running this command:</p>
<pre class="script">sudo apt-get install acl</pre>
<p>Now, run the following commands to set the proper permissions on the 'repositories' directory:</p>
<pre class="script">chmod 700 ~/repositories
setfacl -m defaut:user::rwx ~/repositories
sudo chown git:git ~/repositories</pre>
<p>If you run the command &laquo; getfacl ~/repositories &raquo;, you should see the following:</p>
<pre class="script"># file: repositories
# owner: git
# group: git
user::rwx
group::---
other::---
default:user::rwx
default:group::---
default:other::---</pre>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/7610.img6c.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/7610.img6c.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/7610.img6c.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/7610.img6c.png" /></a></p>
</li>
<li>
<p>We are now going to create a symbolic link to simplify access to the repositories. Type the following command:</p>
<pre class="script">sudo ln -s /home/$USER/repositories /git</pre>
<p>You can check that the symbolic link was properly created by running:</p>
<pre class="script">ls -al /git</pre>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/0131.img6d.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/0131.img6d.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/0131.img6d.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/0131.img6d.png" /></a></p>
</li>
<li>
<p>Let&rsquo;s now configure authentication. Each contributor will use a private key of their own. All those keys will be configured to grant access to the &lsquo;git&rsquo; account, so that all the contributors will share the 'git' account on the virtual machine, without having to share the password.</p>
<p>On your Windows client, start Puttygen, and generate a key (it should be part of the zip file you downloaded on the Putty website). Enter a passphrase, and save the private key on your disk. Copy the public key (where it says &ldquo;Public key for pasting into OpenSSH authorized_keys file&rdquo;).</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/1680.img7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/1680.img7.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/53/98/1680.img7.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-53-98/1680.img7.png" /></a></p>
<p>Now go back to the VM on putty, and type:</p>
<pre class="script">mkdir /home/git/.ssh
echo "<span style="color: #ff0000;">ssh-rsa AAAAB3N[&hellip;]B+Q== rsa-key-20120704</span>" &gt;&gt; /home/git/.ssh/authorized_keys</pre>
<p>In the second command, you need to replace the part in red with the public key you copied from Puttygen.</p>
<p>Each contributor should generate a key pair with Puttygen, and send you the public key. You will need to add all those public keys to the authorized_keys file by repeating the command above. Each contributor will then have a key that they can use to connect to the VM on behalf of the git user.</p>
</li>
</ol>
<p>The setup of the VM is now complete. Git is installed on the machine, we have created a dedicated user for accessing repositories, and only that user has access to them, which means that if you install more services on the virtual machine, there is no risk of them changing or deleting the repositories. We have also created key pairs for every contributor, so that they can pull and push to the git repository on the machine, using SSH. In the <a href="http://blogs.msdn.com/b/flaviencharlon/archive/2012/07/24/hosting-git-on-the-cloud-with-windows-azure-virtual-machines-part-4.aspx">last post</a> in this series, we will see how to configure TortoiseGit, create a new repository on the virtual machine, and push changes from a client.</p>]]></content:encoded>
    </item>
  </channel>
</rss>