<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Sagui Itay</title>
	<atom:link href="https://itaysagui.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://itaysagui.wordpress.com</link>
	<description>Developement on the run</description>
	<lastBuildDate>Wed, 02 Nov 2016 19:08:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='itaysagui.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s2.wp.com/i/buttonw-com.png</url>
		<title>Sagui Itay</title>
		<link>https://itaysagui.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://itaysagui.wordpress.com/osd.xml" title="Sagui Itay" />
	<atom:link rel='hub' href='https://itaysagui.wordpress.com/?pushpress=hub'/>
	<item>
		<title>Byte Rot: Performance Counters for your HttpClient</title>
		<link>https://itaysagui.wordpress.com/2014/09/30/byte-rot-performance-counters-for-your-httpclient/</link>
		<comments>https://itaysagui.wordpress.com/2014/09/30/byte-rot-performance-counters-for-your-httpclient/#respond</comments>
		<pubDate>Tue, 30 Sep 2014 19:07:00 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[httpclient]]></category>

		<guid isPermaLink="false">http://saguiitay.com/?p=681</guid>
		<description><![CDATA[I&#8217;ve been an avid user of HttpClient over the last couple of years. You can see me using them in my various Windows Phone applications (Using the LibraryThing API from C#), and in my work at Cloudsfer (Throttling HttpClient requests and Accessing OneDrive via .Net). As you can imagine, I always love to find new [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=681&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been an avid user of <a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.118).aspx">HttpClient</a> over the last couple of years. You can see me using them in my various Windows Phone applications (<a title="Using the LibraryThing API from C#" href="http://saguiitay.com/2014/09/24/using-the-librarything-api-from-c/">Using the LibraryThing API from C#</a>), and in my work at Cloudsfer (<a title="Throttling HttpClient requests" href="http://saguiitay.com/2014/05/05/throttling-httpclient-requests/">Throttling HttpClient requests</a> and <a title="Accessing OneDrive via .Net" href="http://saguiitay.com/2014/08/20/accessing-onedrive-via-net/">Accessing OneDrive via .Net</a>).</p>
<p>As you can imagine, I always love to find new functionalities related to HttpClient, and new ways to improve my work with it.</p>
<p>In his blog, <a href="http://byterot.blogspot.com/">Byte Rot</a>, <a href="https://twitter.com/aliostad">@aliostad</a> shows a way to monitor HttpClient requests using PerformanceCounters, via a <a href="http://msdn.microsoft.com/en-us/library/system.net.http.delegatinghandler(v=vs.118).aspx">DelegatingHandler</a>. Although I refrain from using PerformanceCounters in my code, due to some <a href="http://ayende.com/blog/165217/performance-counters-sucks">bad experience</a> with them, I do like his clean and simple approach. The use of DelegatingHandler provides a nice separation of concerns, and I can easily see someone use it with my <a href="https://github.com/saguiitay/OneDriveRestAPI">OneDrive REST API</a> library.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/681/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=681&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/09/30/byte-rot-performance-counters-for-your-httpclient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>
	</item>
		<item>
		<title>KnockoutJS Mapping plugin to the rescue</title>
		<link>https://itaysagui.wordpress.com/2014/09/29/knockoutjs-mapping-plugin-to-the-rescue/</link>
		<comments>https://itaysagui.wordpress.com/2014/09/29/knockoutjs-mapping-plugin-to-the-rescue/#respond</comments>
		<pubDate>Mon, 29 Sep 2014 18:47:00 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[knockoutJS]]></category>

		<guid isPermaLink="false">http://saguiitay.com/?p=677</guid>
		<description><![CDATA[I&#8217;ve been using KnockoutJS for a long time now, but only recently found the magic that is the Knockout-Mapping plugin. A few days ago, I spent some time refining some old code, and encountered something along the following lines: function report(reportData) { var self = reportData; self.StartedText = friendlyPastMoment(reportData.Started); if (reportData.Ended == "0001-01-01T00:00:00") { self.EndedText [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=677&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://knockoutjs.com/">KnockoutJS</a> for a long time now, but only recently found the magic that is the <a href="http://knockoutjs.com/documentation/plugins-mapping.html">Knockout-Mapping plugin</a>.</p>
<p>A few days ago, I spent some time refining some old code, and encountered something along the following lines:</p>
<pre>function report(reportData) {
    var self = reportData;
    self.StartedText = friendlyPastMoment(reportData.Started);
    if (reportData.Ended == "0001-01-01T00:00:00") {
        self.EndedText = 'Still running...';
    }
    else {
        self.EndedText = friendlyPastMoment(reportData.Ended);
    }

    return self;
}
</pre>
<p>(the <code style="display:inline;">friendlyPastMoment()</code> method is just a small wrapper method around <a href="http://momentjs.com">MomentJS</a>, for handling edge cases)</p>
<p>We had a couple more properties handled similarly. Now, this worked just fine when the information displayed to the end-user was static &#8211; we just added a few text binding to a couple of span nodes, and the <code>StartedText</code> and <code>EndedText</code> were displayed beautifully.</p>
<p>But we&#8217;ve decided that we want to updated the information displayed to the user automatically, which meant that I now had to replace those simple <code>StartedText</code> and <code>EndedText</code> properties into Knockout computed properties. But for that to work, I had to change the implementation &#8211; the <code>Started</code> and <code>Ended</code> properties of the report need to be <a href="http://knockoutjs.com/documentation/observables.html">observable properties</a>.</p>
<p>I&#8217;ve started with a naïve implementation:</p>
<pre>function report(reportData) {
    var self = reportData;
    self.Started = ko.observable(reportData.Started);
    self.Ended = ko.observable(reportData.Ended);

    self.StartedText = ko.computed(function() { return friendlyPastMoment(self.Started()) });
    self.EndedText = ko.computed(function() { 
        if (self.Ended() == "0001-01-01T00:00:00") {
            return 'Still running...';
        }
        else {
            return friendlyPastMoment(self.Ended());
        }});

    return self;
}
</pre>
<p>But since we had several properties in <code>reportData</code> that needed to implement this behavior, this started to become a code-smell. I was certain that there must be a better way for handling these kind of scenarios.</p>
<p>The <a href="http://knockoutjs.com/documentation/plugins-mapping.html">Knockout-Mapping plugin</a> was created exactly for such cases &#8211; it convert a simple POCO object into its Knockout equivalent, with all properties implemented as observable properties, with arrays and all:</p>
<pre>function report(reportData) {
    ko.mapping.fromJS(reportData, {}, this);

    var self = this;

    self.StartedText = ko.computed(function() { return friendlyPastMoment(self.Started()) });
    self.EndedText = ko.computed(function() { 
        if (self.Ended() == "0001-01-01T00:00:00") {
            return 'Still running...';
        }
        else {
            return friendlyPastMoment(self.Ended());
        }});

    return self;
}
</pre>
<p>As you can see, the first line calls the <code>fromJS</code> method, which takes a regular JavaScript object, an options object (empty <code>{}</code> in the line above), and the destination object. The result will be that this object will have the same properties as <code>reportData</code>, implemented as Knockout observable properties.</p>
<p>Now, it is very easy to add a refresh function to report, which will retrieve the most current information from the server, and update the report:</p>
<pre>    self.refresh = function() {
        $.getJSON("api/report?id=" + self.Id(), function (data) {
            ko.mapping.fromJS(data, self);
        });
    };
</pre>
<p>As you can see, we&#8217;re making a <code>getJSON</code> call to the server, and once we get the data back, we just call the <code>fromJS</code> method again, this time passing the data retrieved from the server, and our current report instance.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/677/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/677/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=677&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/09/29/knockoutjs-mapping-plugin-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>
	</item>
		<item>
		<title>New Domain &#8211; saguiitay.com</title>
		<link>https://itaysagui.wordpress.com/2014/09/28/new-domain-saguiitay-com/</link>
		<comments>https://itaysagui.wordpress.com/2014/09/28/new-domain-saguiitay-com/#respond</comments>
		<pubDate>Sun, 28 Sep 2014 19:35:42 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://saguiitay.com/?p=674</guid>
		<description><![CDATA[After running this blog on the free WordPress.com for the last couple of years, I&#8217;ve decided that it&#8217;s time for me to have my own domain, and to start looking for another publishing platform. As a first step, and in preparation for a future move, I&#8217;ve purchased my own domain, saguiitay.com. This will be the [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=674&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>After running this blog on the free <a href="http://WordPress.com">WordPress.com</a> for the last couple of years, I&#8217;ve decided that it&#8217;s time for me to have my own domain, and to start looking for another publishing platform.</p>
<p>As a first step, and in preparation for a future move, I&#8217;ve purchased my own domain, <a href="http://saguiitay.com">saguiitay.com</a>. This will be the primary domain going forward (you will be automatically redirected if you reach hear using the old domain &#8211; <a href="https://itaysagui.wordpress.com">itaysagui.wordpress.com</a>).</p>
<p>In the near future, I&#8217;ll decide on which platform to use. I&#8217;m tending towards using <a href="http://jekyllrb.com/">Jekyll</a> with <a href="https://pages.github.com/">Github Pages</a> for hosting the pages and images.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/674/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=674&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/09/28/new-domain-saguiitay-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the LibraryThing API from C#</title>
		<link>https://itaysagui.wordpress.com/2014/09/24/using-the-librarything-api-from-c/</link>
		<comments>https://itaysagui.wordpress.com/2014/09/24/using-the-librarything-api-from-c/#comments</comments>
		<pubDate>Wed, 24 Sep 2014 11:19:46 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[httpclient]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[LibraryThing]]></category>

		<guid isPermaLink="false">http://itaysagui.wordpress.com/?p=672</guid>
		<description><![CDATA[If you are not familiar with LibraryThing, go ahead and visit their website &#8211; it&#8217;s probably the most comprehensive books collection in the web. LibraryThing provide several APIs, one of them a RESTful API, which can be invoked from C# relatively easily. In this post I&#8217;ll describe how to use that API. First, you need [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=672&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>If you are not familiar with LibraryThing, go ahead and visit their <a href="http://www.librarything.com/">website</a> &#8211; it&#8217;s probably the most comprehensive books collection in the web.</p>
<p>LibraryThing provide several APIs, one of them a RESTful API, which can be invoked from C# relatively easily. In this post I&#8217;ll describe how to use that API.</p>
<p>First, you need to get a Developer Key. You can do that here: <a href="http://www.librarything.com/services/keys.php">http://www.librarything.com/services/keys.php</a></p>
<p>Here&#8217;s the most important thing you need:</p>
<pre><span style="font-family:Consolas;">private</span> <span style="font-family:Consolas;">const</span> <span style="font-family:Consolas;">string</span> CollectionByUser = <span style="font-family:Consolas;">"http://www.librarything.com/api_getdata.php?userid={0}&amp;resultsets=books&amp;max=9999&amp;&amp;booksort=title&amp;responseType=json&amp;key="</span> + DevKey;
<span style="font-family:Consolas;">private</span> <span style="font-family:Consolas;">const</span> <span style="font-family:Consolas;">string</span> WorkUrlByISBN = <span style="font-family:Consolas;">"http://www.librarything.com/services/rest/1.1/?method=librarything.ck.getwork&amp;isbn={0}&amp;apikey="</span> + DevKey;
<span style="font-family:Consolas;">private</span> <span style="font-family:Consolas;">const</span> <span style="font-family:Consolas;">string</span> WorkUrlById = <span style="font-family:Consolas;">"http://www.librarything.com/services/rest/1.1/?method=librarything.ck.getwork&amp;id={0}&amp;apikey="</span> + DevKey;
<span style="font-family:Consolas;">private</span> <span style="font-family:Consolas;">const</span> <span style="font-family:Consolas;">string</span> WorkUrlByLCCN = <span style="font-family:Consolas;">"http://www.librarything.com/services/rest/1.1/?method=librarything.ck.getwork&amp;lccn={0}&amp;apikey="</span> + DevKey;
<span style="font-family:Consolas;">private</span> <span style="font-family:Consolas;">const</span> <span style="font-family:Consolas;">string</span> WorkUrlByOCLC = <span style="font-family:Consolas;">"http://www.librarything.com/services/rest/1.1/?method=librarything.ck.getwork&amp;oclc={0}&amp;apikey="</span> + DevKey;
<span style="font-family:Consolas;">private</span> <span style="font-family:Consolas;">const</span> <span style="font-family:Consolas;">string</span> AuthorUrlByCode = <span style="font-family:Consolas;">"http://www.librarything.com/services/rest/1.1/?method=librarything.ck.getauthor&amp;authorcode={0}&amp;apikey="</span> + DevKey;
<span style="font-family:Consolas;">private</span> <span style="font-family:Consolas;">const</span> <span style="font-family:Consolas;">string</span> ImageUrl = <span style="font-family:Consolas;">"http://covers.librarything.com/devkey/"</span> + DevKey + <span style="font-family:Consolas;">"/{0}/isbn/{1}"</span>;
</pre>
<p>These URLs allow you to retrieve information from LibraryThing, by providing a Developer Key, and the details about which data you want to get:</p>
<ul>
<li>CollectionByUser: Retrieve the list of books that a user has added in his collection. Notice that the URL returns the &#8220;books&#8221; result-set (you can also get the users&#8217; ratings, reviews and tags).</li>
<li>WorkUrlByISBN: Retrieve information about a specific work (book), provided the book&#8217;s ISBN.</li>
<li>WorkUrlById: Retrieve information about a specific work (book), provided the book&#8217;s LibraryThing ID.</li>
<li>WorkUrlByLCCN: Retrieve information about a specific work (book), provided the book&#8217;s LCCN (Library of Congress Control Number).</li>
<li>WorkUrlByOCLC: Retrieve information about a specific work (book), provided the book&#8217;s OCLC (<span id="dscexpitem_1">Online Computer Library Center</span>).</li>
<li>AuthorUrlByCode: Retrieve information about a specific author, provided the author&#8217;s LibraryThing author-code.</li>
<li>ImageUrl: Retrieve the cover image of a book, provided the book&#8217;s ISBN, and the requested image size (</li>
</ul>
<p>Now, if you want to see some code, we&#8217;ll start by creating an HttpClient instance:</p>
<pre>_handler = <span style="font-family:Consolas;">new</span> <span style="font-family:Consolas;">HttpClientHandler</span>();
<span style="font-family:Consolas;">if</span> (_handler.SupportsAutomaticDecompression)
    _handler.AutomaticDecompression = <span style="font-family:Consolas;">DecompressionMethods</span>.Deflate | <span style="font-family:Consolas;">DecompressionMethods</span>.GZip;
_httpClient = <span style="font-family:Consolas;">new</span> <span style="font-family:Consolas;">HttpClient</span>(_handler);
</pre>
<p>To get a book&#8217;s details, we&#8217;ll make the following call to the LibraryThing API:</p>
<pre><span style="font-family:Consolas;">var</span> url = <span style="font-family:Consolas;">string</span>.Format(WorkUrlByISBN, isbn);
<span style="font-family:Consolas;">string</span> content;
<span style="font-family:Consolas;">try</span>
{
    <span style="font-family:Consolas;">var</span> response = <span style="font-family:Consolas;">await</span> _httpClient.GetAsync(url).ConfigureAwait(<span style="font-family:Consolas;">false</span>);
    <span style="font-family:Consolas;">if</span> (!response.IsSuccessStatusCode)
        <span style="font-family:Consolas;">return</span> <span style="font-family:Consolas;">null</span>;
 
    content = <span style="font-family:Consolas;">await</span> response.Content.ReadAsStringAsync().ConfigureAwait(<span style="font-family:Consolas;">false</span>);
}
<span style="font-family:Consolas;">catch</span> (<span style="font-family:Consolas;">Exception</span>)
{
    <span style="font-family:Consolas;">return</span> <span style="font-family:Consolas;">null</span>;
}
</pre>
<p>You can then parse the result into a workable object model. The model is a bit complex, so I&#8217;ve posted it as Gist: <a href="https://gist.github.com/saguiitay/be3868dae2efb12802a2">https://gist.github.com/saguiitay/be3868dae2efb12802a2</a></p>
<p>One method in that Gist requires some explanation &#8211; the parsing of the Xml returned from LibraryThing is not straight forward &#8211; you need to &#8220;decode&#8221; it, in order for some Xml entities to be processed correctly. For that, I&#8217;ve created an extension method for String (<a href="https://gist.github.com/saguiitay/be3868dae2efb12802a2#file-stringextensions-cs">https://gist.github.com/saguiitay/be3868dae2efb12802a2#file-stringextensions-cs</a>), that replaced the XmlEntities into their equivalent character.</p>
<p>All in all, LibraryThing provides an extensive API to their data, which is mostly painless to work with, and provide detailed and valuable information.</p>
<p>You can see the results of using LibraryThing to retrieve information about books and authors in my Windows Phone App &#8220;Library&#8221;, which you can download here: <a href="http://www.windowsphone.com/s?appid=01f350f2-01d1-4210-a83b-9874b71e9496">http://www.windowsphone.com/s?appid=01f350f2-01d1-4210-a83b-9874b71e9496</a></p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/672/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/672/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=672&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/09/24/using-the-librarything-api-from-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>
	</item>
		<item>
		<title>NDepend &#8211; impressions and review</title>
		<link>https://itaysagui.wordpress.com/2014/09/20/ndepend-impressions-and-review/</link>
		<comments>https://itaysagui.wordpress.com/2014/09/20/ndepend-impressions-and-review/#respond</comments>
		<pubDate>Sat, 20 Sep 2014 18:09:14 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[NDepend]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://itaysagui.wordpress.com/?p=664</guid>
		<description><![CDATA[DISCLAIMER: I haven&#8217;t been paid for this review and won&#8217;t be. However, I did receive a free copy of the software. After downloading NDepend, my initial reaction to their &#8220;installation&#8221; process was REALLY?! you expect me to manually copy the files, and don&#8217;t include an installation/setup?! After ignoring the instructions, and copying everything to my Program Files folder, [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=664&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="color:#000000;"><strong>DISCLAIMER: I haven&#8217;t been paid for this review and won&#8217;t be. However, I did receive a free copy of the software.</strong></span></p>
<p>After downloading NDepend, my initial reaction to their &#8220;installation&#8221; process was REALLY?! you expect me to manually copy the files, and don&#8217;t include an installation/setup?! After ignoring the instructions, and copying everything to my Program Files folder, I&#8217;ve decided to give this baby a shot.</p>
<p>I&#8217;ve heard of NDepend for a long time now, and even played a bit (5-10 minutes top) with an older version in the past. I was interesting to see what it can do for me in my day-to-day job, so I started to visual tool, and pointed it to the source code of our main product. That was a mistake. This is a 50-ish projects solution, with dependencies from here till tomorrow. Don&#8217;t get me wrong, NDepend handled it without any problems (not an easy feat &#8211; even ReSharper is having a tough time). My problem was with the sheer amount of information it threw at me &#8211; I didn&#8217;t know where to start.</p>
<p>So I decided to take a step back, and decided to start small. I reran the tool, this time on my <a href="https://github.com/saguiitay/OneDriveRestAPI" target="_blank">OneDrive REST API</a> library. This time I got something a bit less scary when I&#8217;ve opened the dashboard:</p>
<p><a href="https://itaysagui.files.wordpress.com/2014/09/ndepend-dashboard.png"><img class="alignnone size-medium wp-image-665" src="https://itaysagui.files.wordpress.com/2014/09/ndepend-dashboard.png?w=300&#038;h=243" alt="NDepend Dashboard" width="300" height="243" srcset="https://itaysagui.files.wordpress.com/2014/09/ndepend-dashboard.png?w=300&amp;h=243 300w, https://itaysagui.files.wordpress.com/2014/09/ndepend-dashboard.png?w=598&amp;h=486 598w, https://itaysagui.files.wordpress.com/2014/09/ndepend-dashboard.png?w=150&amp;h=122 150w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>As you can see, we got some statistics about the code, including lines of code/comments, numbers of assemblies/types/etc. as well as Complexity indicators. The most important part, at least for now, is the Code Rules.</p>
<p>Apparently, my library violates only a single rule, and only once. Clicking the link there, brings you to the &#8220;Queries and Rules Explorer&#8221;:</p>
<p><a href="https://itaysagui.files.wordpress.com/2014/09/ndepend-queries-and-rules-explorer.png"><img class="alignnone size-medium wp-image-666" src="https://itaysagui.files.wordpress.com/2014/09/ndepend-queries-and-rules-explorer.png?w=300&#038;h=128" alt="NDepend Queries and Rules Explorer" width="300" height="128" srcset="https://itaysagui.files.wordpress.com/2014/09/ndepend-queries-and-rules-explorer.png?w=298&amp;h=128 298w, https://itaysagui.files.wordpress.com/2014/09/ndepend-queries-and-rules-explorer.png?w=595&amp;h=256 595w, https://itaysagui.files.wordpress.com/2014/09/ndepend-queries-and-rules-explorer.png?w=150&amp;h=64 150w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>As you can see, NDepend comes with quite a <a href="http://www.ndepend.com/default-rules/webframe.html" target="_blank">lot of rules</a> &#8211; I still need to explore these, but those that probably interest me the most would be &#8220;Code Quality&#8221; and &#8220;Design&#8221;. In this case, the critical rule that is violated is under the &#8220;Naming Conventions&#8221; category. There are some &#8220;old fashioned&#8221; rules in there, such as requiring private fields to start with &#8220;m_&#8221; &#8211; something I haven&#8217;t used or seen in the last few years &#8211; luckily you can <a href="http://www.ndepend.com/docs/cqlinq-syntax" target="_blank">edit these rules</a> for yourself.</p>
<p>Going back to the critical rule, it appears that I have a type called &#8220;HttpException&#8221;. The name itself has nothing wrong with it, but System.Web already has such a type (my implementation of HttpException actually inherits from it). In this case, I&#8217;ve decided to rename my class to HttpServiceException.</p>
<p>I&#8217;ve then decided to move to the Code Quality category, and see what&#8217;s going on there. Things didn&#8217;t go so smoothly here. A couple of rules bothered me:</p>
<ul>
<li>Methods with too many overloads: My HttpException class has 8 constructors, all of which are just passing the arguments to the base class. Sure, I could probably reduce that number, but since this class was mostly auto-generated by ReSharper, and since these 8 constructors came from the .Net Framework itself, I didn&#8217;t see the point of changing the code.</li>
<li>Methods too complex: I&#8217;m always happy to simplify my code, especially in an open source project like this one. However, NDepend pointed me to a couple of Async methods, and gave me the build-generated &#8220;MoveNext&#8221; method as the too-complex methods. Not a lot I can do here. Ever more bothering, is the fact that NDepend doesn&#8217;t appear to play-nicely with async-based code.</li>
</ul>
<p>At t his point, I&#8217;ve decided to take a look at the other features of NDepend. I went back to my &#8220;monster&#8221; project. To be honest, the Code Rules violations scared the hell out of me. I know we don&#8217;t write perfect code, but 322 critical violations, 17700 violations total seems a bit harsh.</p>
<p>The Dependency Graph, after some clean-ups, showed me what I already knew about the solution &#8211; it&#8217;s built by several major areas &#8211; some common assemblies, which contains the model of the product, a group of several mostly-external &#8220;services&#8221;, a middle layer of concrete services, and lastly the actual &#8220;implementation&#8221; of the system (front-end, NServiceBus endpoints, etc.):</p>
<p><a href="https://itaysagui.files.wordpress.com/2014/09/ndepend-graph.png"><img class="alignnone size-medium wp-image-667" src="https://itaysagui.files.wordpress.com/2014/09/ndepend-graph.png?w=273&#038;h=300" alt="NDepend Graph" width="273" height="300" srcset="https://itaysagui.files.wordpress.com/2014/09/ndepend-graph.png?w=273&amp;h=300 273w, https://itaysagui.files.wordpress.com/2014/09/ndepend-graph.png?w=546&amp;h=600 546w, https://itaysagui.files.wordpress.com/2014/09/ndepend-graph.png?w=137&amp;h=150 137w" sizes="(max-width: 273px) 100vw, 273px" /></a></p>
<p>It is nice to see this visually, but it&#8217;s nothing I didn&#8217;t already know, from designing and building the system. I guess this might come handy when introducing new team members to the source code.</p>
<p>That&#8217;s it for now.</p>
<p>All in all, I did find NDepend a useful tool to get some insights into your code. I am still not sure how and if I&#8217;ll integrate it into my day-to-day workflow. The main feature that spiked my interest is the Code rules, but I still need to further review it, learn how to better use it, and see if it enhance my productivity in the long run.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/664/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/664/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=664&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/09/20/ndepend-impressions-and-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>

		<media:content url="http://itaysagui.files.wordpress.com/2014/09/ndepend-dashboard.png?w=300" medium="image">
			<media:title type="html">NDepend Dashboard</media:title>
		</media:content>

		<media:content url="http://itaysagui.files.wordpress.com/2014/09/ndepend-queries-and-rules-explorer.png?w=300" medium="image">
			<media:title type="html">NDepend Queries and Rules Explorer</media:title>
		</media:content>

		<media:content url="http://itaysagui.files.wordpress.com/2014/09/ndepend-graph.png?w=273" medium="image">
			<media:title type="html">NDepend Graph</media:title>
		</media:content>
	</item>
		<item>
		<title>Compacting a RavenDb database</title>
		<link>https://itaysagui.wordpress.com/2014/09/04/compacting-a-ravendb-database/</link>
		<comments>https://itaysagui.wordpress.com/2014/09/04/compacting-a-ravendb-database/#respond</comments>
		<pubDate>Thu, 04 Sep 2014 18:07:00 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[RavenDb]]></category>

		<guid isPermaLink="false">http://itaysagui.wordpress.com/2014/09/04/compacting-a-ravendb-database/</guid>
		<description><![CDATA[One of my RavenDb databases grew to an unrealistic size &#8211; 36GB when it contains around 500,000 documents which are mostly small. After some back-and-forth with the RavenDb support team, I was suggested to compact the database. Sounds easy, if you know what you&#8217;re doing, since documentation on that is &#8230; let&#8217;s say lacking&#8230; Here&#8217;s [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=660&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>One of my <a href="http://ravendb.net" target="_blank">RavenDb</a> databases grew to an unrealistic size &#8211; 36GB when it contains around 500,000 documents which are mostly small.</p>
<p>After some back-and-forth with the RavenDb support team, I was suggested to compact the database. Sounds easy, if you know what you&#8217;re doing, since documentation on that is &#8230; let&#8217;s say lacking&#8230;</p>
<p>Here&#8217;s what you do, for my own future reference:</p>
<p>Using <a href="http://curl.haxx.se/" target="_blank">cUrl</a>, do a POST request to <a href="http://&lt;servername&gt;/admin/compact?database=&lt;DatabaseName&gt;" target="_blank">http://&lt;servername&gt;/admin/compact?database=&lt;DatabaseName&gt;</a></p>
<p>Here&#8217;s a sample call:</p>
<pre>cUrl -F 'database=UsersDatabase' <a href="http://localhost:8080/admin/compact?database=UsersDatabase" target="_blank">http://localhost:8080/admin/compact?database=UsersDatabase</a></pre>
<p>Notice, that if you&#8217;re using any form of authentication, you need to provide that too. Here&#8217;s how it&#8217;s done for NTLM Authentication:</p>
<pre>cUrl --ntlm --user username:password -F 'database=UsersDatabase' <a href="http://localhost:8080/admin/compact?database=UsersDatabase" target="_blank">http://localhost:8080/admin/compact?database=UsersDatabase</a>
</pre>
<p><span style="color:#ff0000;text-decoration:underline;"><strong>NOTICE: Your database will be off-line during the compact process, and won&#8217;t be accessible.</strong></span></p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/660/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/660/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=660&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/09/04/compacting-a-ravendb-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>
	</item>
		<item>
		<title>Accessing OneDrive via .Net</title>
		<link>https://itaysagui.wordpress.com/2014/08/20/accessing-onedrive-via-net/</link>
		<comments>https://itaysagui.wordpress.com/2014/08/20/accessing-onedrive-via-net/#comments</comments>
		<pubDate>Wed, 20 Aug 2014 13:34:58 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[nuget]]></category>
		<category><![CDATA[OneDrive]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SkyDrive]]></category>

		<guid isPermaLink="false">http://itaysagui.wordpress.com/?p=658</guid>
		<description><![CDATA[TLDR; I created a new NuGet package/GitHub repository for a library to allow you access to OneDrive via .Net Over the last few days, I&#8217;ve implemented a .Net Class library to provide .Net access to OneDrive. Although Microsoft provides its own SDK (which is found at http://msdn.microsoft.com/en-US/live/ff621310), that library is not very developer friendly &#8211; [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=658&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>TLDR; I created a new <a href="https://www.nuget.org/packages/OneDriveRestAPI" target="_blank">NuGet package</a>/<a href="https://github.com/saguiitay/OneDriveRestAPI" target="_blank">GitHub repository</a> for a library to allow you access to OneDrive via .Net</p>
<p>Over the last few days, I&#8217;ve implemented a .Net Class library to provide .Net access to OneDrive. Although Microsoft provides its own SDK (which is found at <a href="http://msdn.microsoft.com/en-US/live/ff621310" rel="nofollow">http://msdn.microsoft.com/en-US/live/ff621310</a>), that library is not very developer friendly &#8211; it&#8217;s hard to debug, and harder to extend. I&#8217;ve search for alternatives on the internet, but the only usable solution I&#8217;ve found was <a href="https://twitter.com/johnhoerr" target="_blank">John Hoerr</a>&#8216;s <a href="https://github.com/jhoerr/SkyNet" target="_blank">SkyNet</a> project. Although useful as a start, I&#8217;ve encountered several issues with it:</p>
<ul>
<li>It didn&#8217;t support Async patterns</li>
<li>It&#8217;s support for downloading/uploading file was limited (mostly because it relies on RestSharp)</li>
<li>It&#8217;s Object Model wasn&#8217;t complete (some objects and methods were missing)</li>
<li>It wasn&#8217;t updated in a while</li>
</ul>
<p>I&#8217;ve decided to implement my own library. I&#8217;ve started with the SkyNet repository.</p>
<p>The first thing I did was replace all <a href="http://restsharp.org/" target="_blank">RestSharp</a> code with simpler HttpClient (from the <a href="https://www.nuget.org/packages/Microsoft.Net.Http" target="_blank">Microsoft.Net.Http</a> NuGet). This meant that I had to implement a simplified version of the <a href="https://github.com/saguiitay/OneDriveRestAPI/blob/master/src/OneDriveRestAPI/Util/Request.cs" target="_blank">Request</a> object. Nothing too complex &#8211; just enough to allow me to organize the code in a sensible manner. That immediately forced me to modify all method to Async, which was great, since I planned to do that anyway.</p>
<p>Then I&#8217;ve added a few models, such as Error and UserProfile, along with their relevant methods.</p>
<p>After that, came some extendibility requirements. The code that I&#8217;m currently work on (and which will use this Library) makes quite a few requests to OneDrive. I needed a way to throttling all these requests. For the moment, I implemented this by providing callers the ability to wrap the HttpMessageHandler that the HttpClient is using. Thus I&#8217;m able to use a <a title="Throttling web requests" href="https://itaysagui.wordpress.com/2014/05/02/throttling-web-requests/">TimeSpanSemaphore</a> to throttle all requests.</p>
<p>I&#8217;ve also decided to implement auto-token-refresh. I&#8217;m using OneDriveRestAPI in a long-running process. That means that the AccessToken returned by OneDrive might expire during my processing. Using a RefreshToken, the library automatically retrieve an updated AccessToken (as long as the user didn&#8217;t revoke permissions on OneDrive).</p>
<p>You are of course welcome to send me any feedback, fork and repository, and send pull requests.</p>
<p>I&#8217;ll try to keep this up-to-date as much as possible.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/658/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/658/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=658&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/08/20/accessing-onedrive-via-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>
	</item>
		<item>
		<title>Querying our GitHub &#038; NuGet data</title>
		<link>https://itaysagui.wordpress.com/2014/06/07/querying-our-github-nuget-data/</link>
		<comments>https://itaysagui.wordpress.com/2014/06/07/querying-our-github-nuget-data/#respond</comments>
		<pubDate>Sat, 07 Jun 2014 14:27:56 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[nuget]]></category>
		<category><![CDATA[RavenDb]]></category>

		<guid isPermaLink="false">http://itaysagui.wordpress.com/?p=645</guid>
		<description><![CDATA[In my previous posts, I&#8217;ve discussed how to retrieve the list of top repositories from GitHub, get the list of packages each one uses, and store all that information in a RavenDb database. Now, it&#8217;s time to query all the data. RavenDb provides Map/Reduce indexes for querying the data. Let&#8217;s see some of the basic [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=645&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In my previous posts, I&#8217;ve discussed how to <a href="https://itaysagui.wordpress.com/2014/06/03/playing-with-github-api-octokit-net/">retrieve the list of top repositories from GitHub</a>, get the <a href="https://itaysagui.wordpress.com/2014/06/04/getting-all-nuget-packages-used-by-a-github-repository/">list of packages each one uses</a>, and <a href="https://itaysagui.wordpress.com/2014/06/06/modeling-github-repositories-and-nuget-packages/">store all that information in a RavenDb database</a>.</p>
<p>Now, it&#8217;s time to query all the data.</p>
<p>RavenDb provides Map/Reduce indexes for querying the data. Let&#8217;s see some of the basic ones that interest us.</p>
<p><code>    <span style="text-decoration:underline;"><strong>Repositories/ByName</strong></span><br />
<span style="color:blue;">    from</span> repo <span style="color:blue;">in</span> docs<span class="sc10">.</span>Repos<br />
<span style="color:blue;">    select</span> <span style="color:blue;">new</span> <span class="sc10">{</span><br />
<span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>Name <span class="sc10">=</span> repo<span class="sc10">.</span>Name<span class="sc10">,</span><br />
<span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>FullName <span class="sc10">=</span> repo<span class="sc10">.</span>FullName<br />
<span class="sc10">    }</span></code></p>
<p><code>    <span style="text-decoration:underline;"><strong>Packages<span class="sc10">/</span>ByName</strong></span><br />
<span style="color:blue;">    from</span> package <span style="color:blue;">in</span> docs<span class="sc10">.</span>Packages<br />
<span style="color:blue;">    select</span> <span style="color:blue;">new</span> <span class="sc10">{</span><br />
<span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>Name <span class="sc10">=</span> package<span class="sc10">.</span>Name<br />
<span class="sc10">    }</span></code></p>
<p><code>    <span style="text-decoration:underline;"><strong>Packages<span class="sc10">/</span>ByTag</strong></span><br />
<span style="color:blue;">    from</span> package <span style="color:blue;">in</span> docs<span class="sc10">.</span>Packages<br />
<span style="color:blue;">    from</span> tag <span style="color:blue;">in</span> package<span class="sc10">.</span>Tags<br />
<span style="color:blue;">    select</span> <span style="color:blue;">new</span> <span class="sc10">{</span><br />
<span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>Tag <span class="sc10">=</span> tag<br />
<span class="sc10">    }</span></code></p>
<p>These are all simple indexes, which are there mostly for searching and viewing our data. Much more interesting is to see the relations between repositories and packages. Let&#8217;s look at an index that allows us to get a list of repositories that use a certain package. Here&#8217;s the index definition:</p>
<p><span style="font-family:Courier New;">   <strong> <span style="text-decoration:underline;">Repositories/ByPackage</span></strong><br />
<span style="font-family:Courier New;"><span style="color:blue;">    from</span> repo <span style="color:blue;">in</span> docs<span class="sc10">.</span>Repos</span><br />
</span><span style="font-family:Courier New;"><span style="color:blue;">    from</span> package <span style="color:blue;">in</span> <span style="font-family:Courier New;">repo</span><span class="sc10">.</span>Packages<br />
<span style="color:blue;">    from</span> tag <span style="color:blue;">in</span> package<span class="sc10">.</span>Tags<br />
<span style="color:blue;">    select</span> <span style="color:blue;">new</span> <span class="sc10">{</span><br />
<span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>PackageName = package.Name,<br />
<span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>PackageVersion = package.Version<br />
<span class="sc10"><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>}</span></span></p>
<p>Querying this index gives us a nice list of repositories:</p>
<p><a href="https://itaysagui.files.wordpress.com/2014/06/github-nuget-index1.png"><img class="aligncenter size-large wp-image-647" src="https://itaysagui.files.wordpress.com/2014/06/github-nuget-index1.png?w=630&#038;h=334" alt="GitHub-NuGet-Index1" width="630" height="334" srcset="https://itaysagui.files.wordpress.com/2014/06/github-nuget-index1.png?w=630&amp;h=334 630w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index1.png?w=150&amp;h=80 150w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index1.png?w=300&amp;h=159 300w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index1.png 726w" sizes="(max-width: 630px) 100vw, 630px" /></a></p>
<p>We can also create a more complex index, that will tell us which package (regardless of its versions) is the most popularly used:</p>
<ul>
<li>MAP:<br />
<code><span style="font-family:Courier New;"><span style="color:blue;">    <span style="color:#000000;"><span style="color:#0000ff;">from</span> repo <span style="color:#0000ff;">in</span> docs.Repos</span><br />
<span style="color:#000000;"><span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:#0000ff;">from</span> packageRef <span style="color:#0000ff;">in</span> repo.Packages</span><br />
<span style="color:#000000;"><span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:#0000ff;">let</span> package = LoadDocument(packageRef.Id)</span><br />
<span style="color:#000000;"><span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:#0000ff;">select new</span> {</span><br />
<span style="color:#000000;"><span style="color:blue;"><span style="font-family:Courier New;">    <span style="color:blue;"><span style="font-family:Courier New;">    </span></span></span></span>PackageName = packageRef.Name,</span><br />
<span style="color:#000000;"><span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>Repos = <span style="color:#0000ff;">new string</span>[] { repo.FullName },</span><br />
<span style="color:#000000;"><span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>Tags = package.Tags,</span><br />
<span style="color:#000000;"><span style="color:blue;"><span style="font-family:Courier New;">    </span></span><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>Count = 1</span><br />
<span style="color:#000000;"><span style="color:blue;"><span style="font-family:Courier New;">    </span></span>}</span></span></span></code></li>
<li>REDUCE:<br />
<code>    <span style="color:#0000ff;">from</span> r <span style="color:#0000ff;">in</span> results<br />
<span style="font-family:Courier New;">    </span><span style="color:#0000ff;">group</span> r <span style="color:#0000ff;">by</span> r.PackageName <span style="color:#0000ff;">into</span> g<br />
<span style="font-family:Courier New;">    </span><span style="color:#0000ff;">select new</span> {<br />
<span style="font-family:Courier New;">    </span><span style="font-family:Courier New;">    </span>PackageName = g.Key,<br />
<span style="font-family:Courier New;">    </span><span style="font-family:Courier New;">    </span>Repos = g.SelectMany(x =&gt; x.Repos).Distinct(),<br />
<span style="font-family:Courier New;">    </span><span style="font-family:Courier New;">    </span>Tags = g.SelectMany(x =&gt; x.Tags).Distinct(),<br />
<span style="font-family:Courier New;">    </span><span style="font-family:Courier New;">    </span>Count = g.Sum(x =&gt; x.Count)<br />
<span style="font-family:Courier New;">    </span>}</code></li>
<li>FIELDS:
<ul>
<li>Tags:
<ul>
<li>Storage: Yes</li>
<li>Indexing: Analyze</li>
</ul>
</li>
<li>Count:
<ul>
<li>Sort: Int</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>This index allows us to see which packages are the most widely used:</p>
<p><a href="https://itaysagui.files.wordpress.com/2014/06/github-nuget-index2.png"><img class="aligncenter size-large wp-image-648" src="https://itaysagui.files.wordpress.com/2014/06/github-nuget-index2.png?w=630&#038;h=337" alt="GitHub-NuGet-Index2" width="630" height="337" srcset="https://itaysagui.files.wordpress.com/2014/06/github-nuget-index2.png?w=628&amp;h=337 628w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index2.png?w=150&amp;h=80 150w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index2.png?w=300&amp;h=161 300w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index2.png?w=768&amp;h=412 768w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index2.png 783w" sizes="(max-width: 630px) 100vw, 630px" /></a></p>
<p>And even drill further into the data, and for example, see which of the packages that have the &#8220;sql&#8221; tag is most widely used (and by which repositories):</p>
<p><a href="https://itaysagui.files.wordpress.com/2014/06/github-nuget-index3.png"><img class="aligncenter size-large wp-image-649" src="https://itaysagui.files.wordpress.com/2014/06/github-nuget-index3.png?w=630&#038;h=337" alt="GitHub-NuGet-Index3" width="630" height="337" srcset="https://itaysagui.files.wordpress.com/2014/06/github-nuget-index3.png?w=628&amp;h=337 628w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index3.png?w=150&amp;h=80 150w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index3.png?w=300&amp;h=161 300w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index3.png?w=768&amp;h=412 768w, https://itaysagui.files.wordpress.com/2014/06/github-nuget-index3.png 783w" sizes="(max-width: 630px) 100vw, 630px" /></a></p>
<p>Here I&#8217;ve shown you how to query the data. In my next post, I&#8217;ll try to gain some insights from the data, and see if I can see some usage patterns.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/645/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/645/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=645&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/06/07/querying-our-github-nuget-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>

		<media:content url="http://itaysagui.files.wordpress.com/2014/06/github-nuget-index1.png?w=630" medium="image">
			<media:title type="html">GitHub-NuGet-Index1</media:title>
		</media:content>

		<media:content url="http://itaysagui.files.wordpress.com/2014/06/github-nuget-index2.png?w=630" medium="image">
			<media:title type="html">GitHub-NuGet-Index2</media:title>
		</media:content>

		<media:content url="http://itaysagui.files.wordpress.com/2014/06/github-nuget-index3.png?w=630" medium="image">
			<media:title type="html">GitHub-NuGet-Index3</media:title>
		</media:content>
	</item>
		<item>
		<title>Modeling GitHub Repositories and NuGet Packages</title>
		<link>https://itaysagui.wordpress.com/2014/06/06/modeling-github-repositories-and-nuget-packages/</link>
		<comments>https://itaysagui.wordpress.com/2014/06/06/modeling-github-repositories-and-nuget-packages/#comments</comments>
		<pubDate>Fri, 06 Jun 2014 12:44:33 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[nuget]]></category>

		<guid isPermaLink="false">http://itaysagui.wordpress.com/?p=641</guid>
		<description><![CDATA[I&#8217;m planning to do some research and statistics on NuGet packages usage in GitHub repositories. Here&#8217;s some sample questions I would like to answer: Which NuGet packages are really popular (real usage vs. just download numbers)? Which NuGet packages are most popular for specific areas (logging, testing, etc.)? Which repositories are using specific NuGet packages? [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=641&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m planning to do some research and statistics on <a href="http://www.nuget.org" target="_blank">NuGet</a> packages usage in <a href="http://www.github.com" target="_blank">GitHub</a> repositories. Here&#8217;s some sample questions I would like to answer:</p>
<ul>
<li>Which NuGet packages are <strong>really</strong> popular (real usage vs. just download numbers)?</li>
<li>Which NuGet packages are most popular for specific areas (logging, testing, etc.)?</li>
<li>Which repositories are using specific NuGet packages?</li>
</ul>
<p>I&#8217;ve shown in my previous post how to <a href="https://itaysagui.wordpress.com/2014/06/04/getting-all-nuget-packages-used-by-a-github-repository/">retrieve the list of packages used by  specific GitHub repository</a>. And in a different post, I&#8217;ve shown how to <a href="https://itaysagui.wordpress.com/2014/06/05/getting-nuget-package-details/">retrieve the information of a NuGet package</a>. We can use all that to collect all the information we need to answer the above questions.</p>
<p>I&#8217;ll start by creating my model:</p>
<pre style="background:white;color:black;font-family:Consolas;font-size:13px;"><span style="color:blue;">    public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Repo</span>
    {
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Id { <span style="color:blue;">get</span> { <span style="color:blue;">return</span> <span style="color:#a31515;">"Repositories/"</span> + RepoId; } }
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> RepoId { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Name { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> FullName { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
        <span style="color:blue;">public</span> <span style="color:#2b91af;">DateTime</span> Updated { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
 
        <span style="color:blue;">public</span> <span style="color:blue;">int</span> ForksCount { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
        <span style="color:blue;">public</span> <span style="color:blue;">int</span> WatchersCount { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
 
        <span style="color:blue;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">PackageRef</span>&gt; Packages { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
    }</pre>
<pre style="background:white;color:black;font-family:Consolas;font-size:13px;"><span style="color:blue;">    public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Package</span>
    {
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Id { <span style="color:blue;">get</span> { <span style="color:blue;">return</span> <span style="color:#a31515;">"Packages/"</span> + Name + <span style="color:#a31515;">"/"</span> + Version; } }
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Name { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Version { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }

        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Summary { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
        <span style="color:blue;">public</span> <span style="color:#2b91af;">DateTime</span>? Updated { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
        <span style="color:blue;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:blue;">string</span>&gt; Tags { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
    }</pre>
<pre style="background:white;color:black;font-family:Consolas;font-size:13px;"><span style="color:blue;">    public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">PackageRef</span>
    {
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Id { <span style="color:blue;">get</span> { <span style="color:blue;">return</span> <span style="color:#a31515;">"Packages/"</span> + Name + <span style="color:#a31515;">"/"</span> + Version; } }
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Name { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Version { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
    }</pre>
<p>As you can see, we have a simple Repository class, with its Name, Full-Name, a bit of metadata, and a list of references to Packages. We also have a Package model, which includes the Name, Version, Tags and some additional fields.</p>
<p>If you&#8217;re asking yourself why I&#8217;ve modeled things this way, it is because I&#8217;ll be using <a href="http://ravendb.net/" target="_blank">RavenDb</a> as my storage, and this follows <a href="http://ravendb.net/docs/2.5/theory/document-structure-design" target="_blank">RavenDb&#8217;s recommendation/conventions</a> for document Ids, relationships and (de)normalization.</p>
<p>After this, it&#8217;s just a matter of writing a &#8220;crawler&#8221;. I&#8217;ll show only the pseudo code here, since it&#8217;s nothing groundbreaking:</p>
<ul>
<li>Search all C# repositories in GitHub</li>
<li>For each repository:
<ul>
<li>Get list of packages</li>
<li>Save repository in the database</li>
</ul>
</li>
<li>For each collected package:
<ul>
<li>Get package details from NuGet</li>
<li>Save package in the database</li>
</ul>
</li>
</ul>
<p>There are of course a few challenges worth mentioning:</p>
<ol>
<li>The GitHub API returns paged results, so we need to make sure we iterate over the repositories in pages (<a href="https://developer.github.com/v3/#pagination" target="_blank">https://developer.github.com/v3/#pagination</a>)</li>
<li>The GitHub API have a rate-limit, so we need to throttle our requests (<a href="https://developer.github.com/v3/#rate-limiting" target="_blank">https://developer.github.com/v3/#rate-limiting</a>)</li>
<li>We are working in a big-data world &#8211; we&#8217;ll have to work with &#8220;chunks&#8221; of data, and save/load things from our database as we go along. This means that we also need to be careful not to do unnecessary work, by checking the database if we&#8217;ve already have all the relevant information instead of re-querying the (GitHub, NuGet) services.</li>
</ol><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/641/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/641/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=641&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/06/06/modeling-github-repositories-and-nuget-packages/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting NuGet package details</title>
		<link>https://itaysagui.wordpress.com/2014/06/05/getting-nuget-package-details/</link>
		<comments>https://itaysagui.wordpress.com/2014/06/05/getting-nuget-package-details/#comments</comments>
		<pubDate>Thu, 05 Jun 2014 13:07:56 +0000</pubDate>
		<dc:creator><![CDATA[Sagui Itay]]></dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[nuget]]></category>

		<guid isPermaLink="false">http://itaysagui.wordpress.com/?p=643</guid>
		<description><![CDATA[In my previous post I&#8217;ve shown how to get the list of NuGet packages used by a GitHub repository. Let&#8217;s see how we can retrieve some additional information for each package. The NuGet Gallery provides an OData feed, which can be used to easily query and search its database. It&#8217;s base URL is http://packages.nuget.org/v1/FeedService.svc. I&#8217;ll [&#8230;]<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=643&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In my <a href="https://itaysagui.wordpress.com/2014/06/04/getting-all-nuget-packages-used-by-a-github-repository/">previous post</a> I&#8217;ve shown how to get the list of <a href="http://www.nuget.org" target="_blank">NuGet</a> packages used by a <a href="http://www.github.com" target="_blank">GitHub</a> repository. Let&#8217;s see how we can retrieve some additional information for each package.</p>
<p>The NuGet Gallery provides an OData feed, which can be used to easily query and search its database. It&#8217;s base URL is <a href="http://packages.nuget.org/v1/FeedService.svc" target="_blank">http://packages.nuget.org/v1/FeedService.svc</a>. I&#8217;ll not go over the details and capabilities of an OData feed &#8211; you can read about it <a href="http://msdn.microsoft.com/en-us/library/ff478141.aspx" target="_blank">here</a>. All I require are the details of a specific version of a specific package. So let&#8217;s see the code:</p>
<pre style="background:white;color:black;font-family:Consolas;font-size:13px;"><span style="color:blue;">    private</span> <span style="color:blue;">void</span> UpdatePackageDetails(<span style="color:#2b91af;">Package</span> package)
    {
        <span style="color:blue;">var</span> url = <span style="color:blue;">string</span>.Format(<span style="color:#a31515;">"http://packages.nuget.org/v1/FeedService.svc/Packages(Id='</span><span style="color:mediumseagreen;">{0}</span><span style="color:#a31515;">',Version='</span><span style="color:mediumseagreen;">{1}</span><span style="color:#a31515;">')"</span>,
            package.Name, package.Version);
 
        <span style="color:blue;">try</span>
        {
<span style="color:#2b91af;">            XDocument</span> xdoc = <span style="color:#2b91af;">XDocument</span>.Load(url);
 
<span style="color:#2b91af;">    </span>        <span style="color:blue;">var</span> tags = xdoc.Descendants(<span style="color:#a31515;">"{http://schemas.microsoft.com/ado/2007/08/dataservices}Tags"</span>).FirstOrDefault();
<span style="color:#2b91af;">    </span>        <span style="color:blue;">if</span> (tags != <span style="color:blue;">null</span>)
<span style="color:#2b91af;">    </span>            package.Tags = tags.Value.Split(<span style="color:blue;">new</span>[] { <span style="color:#a31515;">' '</span> }, <span style="color:#2b91af;">StringSplitOptions</span>.RemoveEmptyEntries);
 
<span style="color:#2b91af;">    </span>        <span style="color:blue;">var</span> summary = xdoc.Root.Element(<span style="color:#a31515;">"{http://www.w3.org/2005/Atom}summary"</span>);
<span style="color:#2b91af;">    </span>        <span style="color:blue;">if</span> (summary != <span style="color:blue;">null</span>)
<span style="color:#2b91af;">    </span>            package.Summary = summary.Value;

<span style="color:#2b91af;">    </span>        <span style="color:blue;">var</span> updated = xdoc.Root.Element(<span style="color:#a31515;">"{http://www.w3.org/2005/Atom}updated"</span>);
<span style="color:#2b91af;">    </span>        <span style="color:blue;">if</span> (updated != <span style="color:blue;">null</span>)
<span style="color:#2b91af;">    </span>            package.Updated = <span style="color:#2b91af;">DateTime</span>.Parse(updated.Value);
        }
        <span style="color:blue;">catch</span> (<span style="color:#2b91af;">WebException</span>)
        { }
    }</pre>
<p>This code assumes that you have the Package class introduced in the <a href="https://itaysagui.wordpress.com/2014/06/04/getting-all-nuget-packages-used-by-a-github-repository/">previous post</a>, with the Name and Version properties already populated. It&#8217;s a very simple piece of code &#8211; it creates the URL for the Feed entry of the package/version we need, loads it into an <a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument(v=vs.110).aspx" target="_blank">XDocument</a>, and update the package instance with the metadata we require &#8211; Tags, Summary, and Updated date.</p>
<p>&nbsp;</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itaysagui.wordpress.com/643/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itaysagui.wordpress.com/643/" /></a> <img alt="" border="0" src="https://pixel.wp.com/b.gif?host=itaysagui.wordpress.com&#038;blog=30958414&#038;post=643&#038;subd=itaysagui&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://itaysagui.wordpress.com/2014/06/05/getting-nuget-package-details/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b6e4d9eea69a9c88097f9f53cdc61568?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguiitay</media:title>
		</media:content>
	</item>
	</channel>
</rss>
