<?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/"
	>

<channel>
	<title>Avivo Tech Blog &#187; Programming Techniques</title>
	<atom:link href="http://tech.avivo.si/category/programming-techniques/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.avivo.si</link>
	<description>Solving problems</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:46:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Visual Source Safe Analyze and Repair tool problems</title>
		<link>http://tech.avivo.si/2011/12/visual-source-safe-analyze-and-repair-tool-problems/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=visual-source-safe-analyze-and-repair-tool-problems</link>
		<comments>http://tech.avivo.si/2011/12/visual-source-safe-analyze-and-repair-tool-problems/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 08:28:47 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[System administration]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[analyze and repair]]></category>
		<category><![CDATA[Cannot rebuild the database while Visual SourceSafe is being run. Make sure all users have exited SourceSafe and try again.]]></category>
		<category><![CDATA[microsoft visual sorce safe]]></category>
		<category><![CDATA[source safe]]></category>
		<category><![CDATA[version control software]]></category>
		<category><![CDATA[vss]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1438</guid>
		<description><![CDATA[This is the solution if you got this error message when trying to do Analyze and Repair some VSS database using does prompt command: C:\&#62;&#8221;C:\Program Files (x86)\Microsoft Visual SourceSafe\analyze.exe&#8221; -F -V3 -D &#8220;\\my_server\my_vss_database\data Error was: Database analysis in progress File ../data/status.dat is already open Cannot rebuild the database while Visual SourceSafe is being run. Make [...]]]></description>
			<content:encoded><![CDATA[<p>This is the solution if you got this error message when trying to do Analyze and Repair some VSS database using does prompt command:<br />
<strong>C:\&gt;&#8221;C:\Program Files (x86)\Microsoft Visual SourceSafe\analyze.exe&#8221; -F -V3 -D &#8220;\\my_server\my_vss_database\data</strong></p>
<p>Error was:</p>
<p><span style="color: #ff0000;">Database analysis in progress</span> <span style="color: #ff0000;"> File ../data/status.dat is already open</span> <span style="color: #ff0000;"> Cannot rebuild the database while Visual SourceSafe is being run. Make sure all users have exited SourceSafe and try again.</span></p>
<p><strong>Solution</strong></p>
<p>Make sure there are no users connected to the VSS database (running <strong>ssexp</strong>, <strong>ssadmin</strong>, etc), that users cannot connect to the database using the web service (they connect only for short times, so it&#8217;s hard to see them listed as logged in with <strong>ssadmin</strong>), and that <strong>VSS LAN Service is stopped</strong> (use <strong>net stop ssservice</strong>), as it may keep a connection open to the database.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/12/visual-source-safe-analyze-and-repair-tool-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get all project files from Visual Source Safe for a given date</title>
		<link>http://tech.avivo.si/2011/08/get-all-project-files-from-visual-source-safe-for-given-date/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=get-all-project-files-from-visual-source-safe-for-given-date</link>
		<comments>http://tech.avivo.si/2011/08/get-all-project-files-from-visual-source-safe-for-given-date/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 11:52:03 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[System administration]]></category>
		<category><![CDATA[get all projects files from visual source safe for a given date]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[microsoft visual source safe]]></category>
		<category><![CDATA[version control]]></category>
		<category><![CDATA[visual source safe]]></category>
		<category><![CDATA[vss]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1362</guid>
		<description><![CDATA[If you are developing some application and use Visual Source Safe as version control software then you probably needed (at least one time) to retrieve all files from your project for specific day from the past. Visual Source Safe does not allow you to do this from its GUI but there is a DOS command [...]]]></description>
			<content:encoded><![CDATA[<p>If you are developing some application and use Visual Source Safe as version control software then you probably needed (at least one time) to retrieve all files from your project for specific day from the past.<br />
Visual Source Safe does not allow you to do this from its GUI but there is a DOS command that can help you.</p>
<p>To use the command-line, you must set the Environment Variable for <strong>SSDIR</strong> to the location of your working SourceSafe database, such as <strong>\\Dev1\VSS</strong> where Dev1 is the name of the server and VSS is the name of the share where the database is located. You may also need to add ss.exe path to your <strong>PATH </strong>variable &#8211; it is usually in folder: <strong>c:\Program Files (x86)\Microsoft Visual SourceSafe\</strong></p>
<p>This is the command:</p>
<div style="margin:20px 0;">
<pre>ss Get "$/your_vss_folder" -R -Vd15-03-2009;2:00a</pre>
</div>
<p>or just without an hour</p>
<div style="margin:20px 0;">
<pre>ss Get "$/your_vss_folder" -R -Vd15-03-2009</pre>
</div>
<ul>
<li>First parameter is folder under your Visual Source Safe project</li>
<li>-R means to get all files recursively</li>
<li>-V means date and in this example we get all files for 15.3.2009</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/08/get-all-project-files-from-visual-source-safe-for-given-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QR Codes API &#8211; automatically generated for given content</title>
		<link>http://tech.avivo.si/2011/05/qr-codes-api-automatically-generated-for-given-content/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=qr-codes-api-automatically-generated-for-given-content</link>
		<comments>http://tech.avivo.si/2011/05/qr-codes-api-automatically-generated-for-given-content/#comments</comments>
		<pubDate>Mon, 16 May 2011 18:31:05 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[HTML, Javascript and CSS]]></category>
		<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Social networks]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[barcode]]></category>
		<category><![CDATA[branding]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[qr code generators]]></category>
		<category><![CDATA[qr codes]]></category>
		<category><![CDATA[qrcode]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[smart phones]]></category>
		<category><![CDATA[social networks]]></category>
		<category><![CDATA[tracking]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1318</guid>
		<description><![CDATA[There are a lot of  QR Code generators on a web and there is also listed our generator &#8211; available at http://qrcode.good-survey.com It already went over simple generator functionality and new features are adding. Basically, beside QR Code generation, we are offering as addition: Tracking of generated QR Codes &#8211; for marketing managers ti know [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of  <a title="QR Code generators" href="http://2d-code.co.uk/qr-code-generators/" target="_blank">QR Code generators</a> on a web and there is also listed our generator &#8211; available at <a title="Good Survey QR Code Generator and Tracking" href="http://qrcode.good-survey.com" target="_blank">http://qrcode.good-survey.com</a></p>
<p>It already went over simple generator functionality and new features are adding.</p>
<div id="attachment_1325" class="wp-caption alignnone" style="width: 710px"><img class="size-large wp-image-1325" title="QR Codes Generator and API" src="http://tech.avivo.si/wp-content/uploads/2011/05/qr-codes-generator-and-api-700x475.jpg" alt="QR Codes Generator and API" width="700" height="475" /><p class="wp-caption-text">QR Codes Generator and API</p></div>
<p>Basically, beside QR Code generation, we are offering as addition:</p>
<ul>
<li>Tracking of generated QR Codes &#8211; for marketing managers ti know which locations work best (i.e. posters with printed QR Code)</li>
<li>Dynamic QR Codes &#8211; if some QR Code is already printed you can make it point to completely different URL without changing the printed code</li>
<li>Adding your logo inside QR Code (with readability testing) &#8211; branding feature</li>
<li>All types of content are supported (hyperlinks, custom text, vCard, Bizcard, Mecard,  vCalendar, social networks &#8211; Twitter, Facebook, YouTube, Geo locations and maps, SMS messages, phones,&#8230;)</li>
<li>Strong use of API &#8211; automating generation process and possibility to use from your application/website &#8211; this is what we will talk about a little bit more in this article&#8230;</li>
</ul>
<p>Using API is not complicated at all, <a title="QR Codes API" href="http://qrcode.good-survey.com/help" target="_blank">we wrote a tutorial</a> which is easy to understand.</p>
<p>Here is an example how you can have instantly QR Code image on your website:</p>
<p>This are direct links:</p>
<ul>
<li><a href="http://qrcode.good-survey.com/api/v2/generate?content=Hello%20World&amp;format=png&amp;padding=2&amp;size=10&amp;em=byte&amp;ec=m" target="_blank">Hello World custom text</a></li>
<li><a href="http://qrcode.good-survey.com/api/v2/generate?content=http%3a%2f%2fmaps.google.com%2fmaps%3ff%3dq%26q%3d46.043286%2c14.492791300000022%26q%3d30%2bTeslova%2bUlica%252c%2bLjubljana%2b1000%252c%2bSlovenia&amp;format=png&amp;padding=2&amp;size=10&amp;em=byte&amp;ec=m" target="_blank">Google Maps location of company&#8217;s office</a></li>
<li><a href="http://qrcode.good-survey.com/api/v2/generate?content=http%3a%2f%2fqrcode.good-survey.com&amp;format=png&amp;padding=2&amp;size=10&amp;em=byte&amp;ec=m" target="_blank">QR Code generator URL</a></li>
</ul>
<p>This how it could look like inside your website (just put this hyperlink inside your IMG tag)</p>
<pre lang="csharp">&lt;img src="http://qrcode.good-survey.com/api/v2/generate?content=
http%3a%2f%2fmaps.google.com%2fmaps%3ff%3dq%26q%3d46.043286%2c14.492791300000022%
26q%3d30%2bTeslova%2bUlica%252c%2bLjubljana%2b1000%252c%2bSlovenia&amp;
format=png&amp;padding=2&amp;size=10&amp;em=byte&amp;ec=m" alt="Avivo location" /&gt;</pre>
<div style="margin-top:20px;">
Try it also by yourself &#8211; just download <a title="QR Codes API demo application" href="http://qrcodeapi.codeplex.com/" target="_blank">DEMO API application</a> from CodePlex and you can play with supported API features.</div>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/05/qr-codes-api-automatically-generated-for-given-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get Twitter statuses and Retweets together?</title>
		<link>http://tech.avivo.si/2011/05/how-to-get-twitter-statuses-and-retweets-together/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-get-twitter-statuses-and-retweets-together</link>
		<comments>http://tech.avivo.si/2011/05/how-to-get-twitter-statuses-and-retweets-together/#comments</comments>
		<pubDate>Tue, 03 May 2011 22:00:49 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Social networks]]></category>
		<category><![CDATA[get tweets and retweets]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[twitter api]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1312</guid>
		<description><![CDATA[Use Twitter API http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=avivo&#38;include_rts=true Where avivo is Twitter username (replace with yours) Check API Rate limitation (anonymous: 150 requests/hour, authenticated: 350 requests/hour) http://api.twitter.com/1/account/rate_limit_status.xml]]></description>
			<content:encoded><![CDATA[<p>Use Twitter API</p>
<pre><a href="http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=avivo&amp;include_rts=true" target="_blank"><strong>http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=avivo&amp;include_rts=true</strong></a></pre>
<p>Where <strong>avivo </strong>is Twitter username (replace with yours)</p>
<p>Check API Rate limitation (anonymous: 150 requests/hour, authenticated: 350 requests/hour)</p>
<pre><a href="http://api.twitter.com/1/account/rate_limit_status.xml" target="_blank"><strong>http://api.twitter.com/1/account/rate_limit_status.xml</strong></a>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/05/how-to-get-twitter-statuses-and-retweets-together/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transact SQL paging Store Procedure &#8211; LINQ Skip Take alternative</title>
		<link>http://tech.avivo.si/2011/04/transact-sql-paging-store-procedure-linq-skip-take-alternative/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=transact-sql-paging-store-procedure-linq-skip-take-alternative</link>
		<comments>http://tech.avivo.si/2011/04/transact-sql-paging-store-procedure-linq-skip-take-alternative/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 08:03:10 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[linq skip take alternative]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[paging in t-sql]]></category>
		<category><![CDATA[store procedure]]></category>
		<category><![CDATA[transact sql]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1307</guid>
		<description><![CDATA[This Transact-SQL Store Procedure allows you to do paging on your SQL table by providing only two parameters: Current page Record to display per page It returns chosen records and also total count as output parameter if you need to display this information or calculate how many pages you have in paging control. CREATE PROCEDURE [...]]]></description>
			<content:encoded><![CDATA[<p>This Transact-SQL Store Procedure allows you to do paging on your SQL table by providing only two parameters:</p>
<ul>
<li> Current page</li>
<li> Record to display per page</li>
</ul>
<p>It returns chosen records and also total count as output parameter if you need to display this information or calculate how many pages you have in paging control.</p>
<pre class="sql">CREATE PROCEDURE [dbo].[YourProcedureName]
  @CurrentPage int,
  @RecordsPerPage int,
  @Count int OUTPUT
AS
BEGIN
  -- The number of rows affected by the different commands
  -- does not interest the application, so turn NOCOUNT ON
  SET NOCOUNT ON

  -- Determine the first record and last record
  DECLARE @FirstRecord int, @LastRecord int

  SELECT @FirstRecord = (@CurrentPage - 1) * @RecordsPerPage
  SELECT @LastRecord = (@CurrentPage * @RecordsPerPage + 1)
  SET @Count = (SELECT COUNT(*) FROM YourTable);

  WITH TempResult as
  (
    SELECT	ROW_NUMBER() OVER(ORDER BY Field1 DESC) as RowNumber,
            Field1,
            Field2
    FROM    YourTable
  )
  SELECT  TOP (@LastRecord - 1) *
  FROM    TempResult
  WHERE   RowNumber &gt; @FirstRecord AND
          RowNumber &lt; @LastRecord

  -- Turn NOCOUNT back OFF
  SET NOCOUNT OFF
END</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/04/transact-sql-paging-store-procedure-linq-skip-take-alternative/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create random web hex color in C# / ASP.NET MVC</title>
		<link>http://tech.avivo.si/2011/04/create-random-web-hex-color-in-c-asp-net-mvc/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=create-random-web-hex-color-in-c-asp-net-mvc</link>
		<comments>http://tech.avivo.si/2011/04/create-random-web-hex-color-in-c-asp-net-mvc/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 22:46:16 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[colour]]></category>
		<category><![CDATA[hash color]]></category>
		<category><![CDATA[random color]]></category>
		<category><![CDATA[web color]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1305</guid>
		<description><![CDATA[Random random = new Random(); int red = random.Next(0, 255); int green = random.Next(0, 255); int blue = random.Next(0, 255); string hexColour = String.Format("#{0:X2}{1:X2}{2:X2}", red, green, blue);]]></description>
			<content:encoded><![CDATA[<pre class=csharp>
Random random = new Random();
int red = random.Next(0, 255);
int green = random.Next(0, 255);
int blue = random.Next(0, 255);
string hexColour = String.Format("#{0:X2}{1:X2}{2:X2}", red, green, blue);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/04/create-random-web-hex-color-in-c-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to copy validation message from one element to another in ASP.NET MVC 2?</title>
		<link>http://tech.avivo.si/2011/04/how-to-copy-validation-message-from-one-element-to-another-in-asp-net-mvc-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-copy-validation-message-from-one-element-to-another-in-asp-net-mvc-2</link>
		<comments>http://tech.avivo.si/2011/04/how-to-copy-validation-message-from-one-element-to-another-in-asp-net-mvc-2/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 14:47:58 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[copy validation message]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[mvc 2]]></category>
		<category><![CDATA[validation in mvc 2]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1271</guid>
		<description><![CDATA[Just create an extension to ModelStateDictionary like this: using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Web.Mvc; namespace Avivo.Web.Common { public static class ModelStateDictionaryExtensions { /// &#60;summary&#62; /// Copy validation message from one field to another /// &#60;/summary&#62; /// &#60;param name="modelState"&#62;model state&#60;/param&#62; /// &#60;param name="source"&#62;field to copy from&#60;/param&#62; /// &#60;param name="target"&#62;field to copy to&#60;/param&#62; [...]]]></description>
			<content:encoded><![CDATA[<div style="margin-bottom:30px;">Just create an extension to <strong>ModelStateDictionary </strong>like this:</div>
<pre class="csharp">
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.Mvc;

namespace Avivo.Web.Common
{
  public static class ModelStateDictionaryExtensions
  {
    /// &lt;summary&gt;
    /// Copy validation message from one field to another
    /// &lt;/summary&gt;
    /// &lt;param name="modelState"&gt;model state&lt;/param&gt;
    /// &lt;param name="source"&gt;field to copy from&lt;/param&gt;
    /// &lt;param name="target"&gt;field to copy to&lt;/param&gt;
    public static void CopyMessage(this ModelStateDictionary modelState, string source,
      string target)
    {
      if (modelState.ContainsKey(source) &#038;&#038; modelState.Errors.Count &gt; 0)
      {
        modelState.AddModelError(target, modelState.Errors[0].ErrorMessage);
      }
    }
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/04/how-to-copy-validation-message-from-one-element-to-another-in-asp-net-mvc-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQ Max and Min functions upgraded</title>
		<link>http://tech.avivo.si/2011/04/linq-max-and-min-functions-upgraded/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linq-max-and-min-functions-upgraded</link>
		<comments>http://tech.avivo.si/2011/04/linq-max-and-min-functions-upgraded/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 09:00:06 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[datacontext]]></category>
		<category><![CDATA[first]]></category>
		<category><![CDATA[firstordefault]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[linq min function throws an exception]]></category>
		<category><![CDATA[max]]></category>
		<category><![CDATA[min]]></category>
		<category><![CDATA[min linq function throws an exception]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1266</guid>
		<description><![CDATA[Classic LINQ Max and Min functions have the same problem as First function &#8211; exception can occur, so we use FirstOrDefault which returns null instead of exception. So, this is how you can extend Min and Max functions into MinOrDefault and MaxOrDefault; public static class IEnumerableExtensions { public static int MinOrDefault(this IEnumerable source, Func selector, [...]]]></description>
			<content:encoded><![CDATA[<p>Classic LINQ <strong>Max </strong>and <strong>Min </strong>functions have the same problem as <strong>First </strong>function &#8211; exception can occur, so we use <strong>FirstOrDefault </strong>which returns <strong>null </strong>instead of exception.</p>
<p>So, this is how you can extend <strong>Min </strong>and <strong>Max </strong>functions into <strong>MinOrDefault </strong>and <strong>MaxOrDefault</strong>;</p>
<pre class="csharp">
public static class IEnumerableExtensions
{
  public static int MinOrDefault<TSource>(this IEnumerable<TSource> source,
    Func<TSource, int> selector, int defaultValue)
  {
    if (source.Any<TSource>())
      return source.Min<TSource>(selector);

    return defaultValue;
  }

  public static int MaxOrDefault<TSource>(this IEnumerable<TSource> source,
    Func<TSource, int> selector, int defaultValue)
  {
    if (source.Any<TSource>())
      return source.Max<TSource>(selector);

    return defaultValue;
  }
}
</pre>
<p>&nbsp;</p>
<p><strong>Usage example:</strong></p>
<pre class="csharp">
  YourDataContext db = new YourDataContext();
  int maxVisits = db.SomeEntityTables.MaxOrDefault(x => x.SomeFieldYouSearchForMaximum, 0);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/04/linq-max-and-min-functions-upgraded/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight: Equidistant items in a stack panel</title>
		<link>http://tech.avivo.si/2011/03/silverlight-xaml-equidistant-items-in-a-stack-panel/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=silverlight-xaml-equidistant-items-in-a-stack-panel</link>
		<comments>http://tech.avivo.si/2011/03/silverlight-xaml-equidistant-items-in-a-stack-panel/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 13:00:28 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[axis]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[coordinates]]></category>
		<category><![CDATA[equidistant]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[stackpanel]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1164</guid>
		<description><![CDATA[This post describes how to align items in a container so the two neighbour items are always aligned with equal distance. Solution should be flexible, meaning that when items are changed or when container is resized items should keep equal distance in between. Reader should have some basic knowledge about C# and XAML for Silverlight. [...]]]></description>
			<content:encoded><![CDATA[<p>This post describes how to align items in a container so the two neighbour items are always aligned with equal distance. Solution should be flexible, meaning that when items are changed or when container is resized items should keep equal distance in between. Reader should have some basic knowledge about C# and XAML for Silverlight.</p>
<h2>Ideas</h2>
<ul>
<li>using Canvas and positioning items with <strong>absolute coordinates</strong> &#8211; items are always fixed, coordinates need to be calculated, so it is the least flexible approach, no</li>
<li>using <strong>StackPanel</strong> with items that have margin &#8211; margins need to be recalculated when an item is added or removed or when container is resized, maybe</li>
<li>using Grid with <strong>predefined rows and columns</strong> &#8211; notice <em>predefined</em>, means less flexibility, but offers equal size rows/columns, maybe</li>
<li>using a <strong>custom control</strong> &#8211; making Grid more dynamic but extending number of rows/columns when items are added, yes</li>
</ul>
<h2>Custom Control: EqualDistanceStackPanel</h2>
<p>As written before, custom control should extend Grid to become more flexible</p>
<pre style="background: #eeeeee; padding: 15px;">public class EqualDistanceStackPanel : Grid
{
}</pre>
<p>&nbsp;</p>
<p><em>EqualDistanceStackPanel</em> should implement <em>ItemsSource</em> and <em>ItemTemplate</em> just like <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol%28v=vs.95%29.aspx" target="_blank">ItemsControl</a></em></p>
<pre style="background: #eeeeee; padding: 15px;">#region ItemsSource
public IEnumerable ItemsSource
{
  get { return (IEnumerable)GetValue(ItemsSourceProperty); }
  set { SetValue(ItemsSourceProperty, value); }
}

public static readonly DependencyProperty ItemsSourceProperty =
  DependencyProperty.Register("ItemsSource", typeof(IEnumerable),
  typeof(EqualDistanceStackPanel), new PropertyMetadata(ItemsSourceChanged));

private static void ItemsSourceChanged(DependencyObject d,
  DependencyPropertyChangedEventArgs e)
{
  var panel = d as EqualDistanceStackPanel;
  if (panel != null)
  {
    if (e.OldValue != null)
    {
      panel.ClearItems();
    }
    if (e.NewValue != null)
    {
      panel.BindItems(e.NewValue as IEnumerable);
    }
  }
}
#endregion

public DataTemplate ItemTemplate
{
  get;
  set;
}</pre>
<p>&nbsp;</p>
<p><em>ClearItems</em> method deletes all previous elements from the panel and <em>BindItems</em> attaches fresh controls from item template.</p>
<pre style="background: #eeeeee; padding: 15px;">protected void ClearItems()
{
  this.Children.Clear();
}

protected void BindItems(IEnumerable items)
{
  if (this.ItemTemplate == null)
  {
    return;
  }

  //Create and attach children
  foreach (var item in items)
  {
    var element = this.ItemTemplate.LoadContent() as FrameworkElement;
    element.DataContext = item;
    this.Children.Add(element);
  }

  //Realign in container
  Refresh();
}</pre>
<p>&nbsp;</p>
<p>How should the custom control look in XAML? <em>EqualDistanceStackPanel</em> gets a collection of items, e.g. of UIElement type.</p>
<pre style="background: #eeeeee; padding: 15px;">&lt;Grid xmlns:c="clr-namespace:Avivo.Controls"&gt;
  &lt;c:EqualDistanceStackPanel ItemsSource="{Binding Items}" Orientation="Vertical"&gt;
    &lt;c:EqualDistanceStackPanel.ItemTemplate&gt;
      &lt;DataTemplate&gt;
        &lt;ContentPresenter Content="{Binding}" /&gt;
      &lt;/DataTemplate&gt;
    &lt;/c:EqualDistanceStackPanel.ItemTemplate&gt;
  &lt;/c:EqualDistanceStackPanel&gt;
&lt;/Grid&gt;</pre>
<p>&nbsp;</p>
<h2>Example</h2>
<p>Ruler has been made to demonstrate the usage of EqualDistanceStackPanel. Numbers are bound to the control and ticks are bound to another control using the same binding collection. Left image represents container height 300px and right when resized to 460px &#8211; elements are automatically aligned with equal distance.<br />
<img class="alignnone size-full wp-image-1177" title="Example of a ruler" src="http://tech.avivo.si/wp-content/uploads/2011/01/equidistant-stack-panel.jpg" alt="" width="414" height="734" /></p>
<p><a href="http://labs.avivo.si/equidistant/" target="_blank">Try demo</a>, resize browser to see the effect. This control has been originally developed for custom chart axes in <a href="http://qrcode.good-survey.com/" target="_blank">QR Code Statistics</a> application. <em>EqualDistanceStackPanel</em> control is lightweight, works for the statistics application and should be improved for general usage.</p>
<h2>Source code</h2>
<ul>
<li><a href="http://labs.avivo.si/equidistant/EqualDistanceStackPanel.zip">Source code</a>, Visual Studio sample Silverlight and web project</li>
</ul>
<h2>References</h2>
<ul>
<li><a href="http://chris.59north.com/post/Using-DataTemplates-in-custom-controls.aspx" target="_blank">Using DataTemplates in custom controls</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/03/silverlight-xaml-equidistant-items-in-a-stack-panel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where is the Twitter user&#8217;s RSS button or how to get Twitter user ID?</title>
		<link>http://tech.avivo.si/2011/02/where-is-the-twitter-users-rss-button-or-how-to-get-twitter-user-id/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=where-is-the-twitter-users-rss-button-or-how-to-get-twitter-user-id</link>
		<comments>http://tech.avivo.si/2011/02/where-is-the-twitter-users-rss-button-or-how-to-get-twitter-user-id/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 16:29:11 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Social networks]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[can not find twitter rss]]></category>
		<category><![CDATA[feeds]]></category>
		<category><![CDATA[get twitter user id]]></category>
		<category><![CDATA[how to get twitter user id]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[where is rss button at twitter]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1189</guid>
		<description><![CDATA[Strange thing. RSS button under Twitter user&#8217;s profile somehow disappeared. They wrote a tutorial how to find it but right now we see nothing. This is a trick we used: http://api.twitter.com/users/show/[your Twitter username].json So this is an example call http://api.twitter.com/users/show/avivo.json You can find your ID at the bottom (see the orange box):]]></description>
			<content:encoded><![CDATA[<p>Strange thing.<br />
RSS button under Twitter user&#8217;s profile somehow disappeared.<br />
They <a href="http://support.twitter.com/entries/15361-how-to-find-your-rss-feed" target="_blank">wrote a tutorial</a> how to find it but right now we see nothing.</p>
<h2>This is a trick we used:</h2>
<pre class="html">http://api.twitter.com/users/show/[your Twitter username].json
</pre>
<h2>So this is an example call</h2>
<pre class="html">http://api.twitter.com/users/show/avivo.json
</pre>
<h2>You can find your ID at the bottom (see the orange box):</h2>
<p><img class="alignnone size-large wp-image-1190" title="twitter-id" src="http://tech.avivo.si/wp-content/uploads/2011/02/twitter-id-700x641.jpg" alt="" width="700" height="641" /></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/02/where-is-the-twitter-users-rss-button-or-how-to-get-twitter-user-id/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

