<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Dmytro Shteflyuk's Home</title>
	
	<link>http://kpumuk.info</link>
	<description>In my blog I'll try to describe about interesting technologies, my discovery in IT and some useful things about programming.</description>
	<pubDate>Mon, 16 Jun 2008 13:51:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://kpumuk.info/feed/" type="application/rss+xml" /><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><item>
		<title>fb:editor FBML tag in Facebook applications</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/217793934/</link>
		<comments>http://kpumuk.info/facebook/fbeditor-editor-tag-in-facebook-applications/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 18:59:56 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[Facebook]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[fbml]]></category>

		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://kpumuk.info/facebook/fbeditor-editor-tag-in-facebook-applications/</guid>
		<description><![CDATA[Some time ago I have started posting about Facebook Application Platform (see my posts about setFBML and Facebook libraries for .NET). Today&#8217;s topic is fb:editor. As you may see, Facebook has nice look and feel, and all applications usually adapted in some way to its interface. fb:editor FBML tag allows you to create forms which [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I have started posting about Facebook Application Platform (see my posts about <a href="http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/">setFBML</a> and <a href="http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/">Facebook libraries for .NET</a>). Today&#8217;s topic is <tt>fb:editor</tt>. As you may see, Facebook has nice look and feel, and all applications usually adapted in some way to its interface. <tt>fb:editor</tt> FBML tag allows you to create forms which looks just like native ones, but it has great limitation: it generates it&#8217;s own <tt>form</tt> tag, so can&#8217;t be used within ASP.NET server form. In this short post I&#8217;ll show HTML generated by <tt>fb:editor</tt> and a way how to use it in your ASP.NET application.</p>
<p><span id="more-183"></span></p>
<p>Here is example from <a href="http://wiki.developers.facebook.com/index.php/Fb:editor" onclick="javascript:pageTracker._trackPageview ('/outbound/wiki.developers.facebook.com');">fb:editor</a> documentation:</p>
<p><img src='http://kpumuk.info/wp-content/uploads/2007/09/fb-editor.png' alt='fb:editor' /></p>
<p>First we need to include <tt>fb:editor</tt> tag to the page to force loading of CSS files:</p>
<div class="codecolorer-container html" style="height:35px;"><div class="codecolorer" style="font-family: monospace;"><span class="sc2"><span class="kw2">&lt;div</span> <span class="kw3">style</span>=<span class="st0">&quot;display:none&quot;</span><span class="kw2">&gt;</span></span><span class="sc2">&lt;fb:editor /<span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;/div&gt;</span></span></div></div>
<p>Now we should define basic structure of the form:</p>
<div class="codecolorer-container html" style="height:280px;"><div class="codecolorer" style="font-family: monospace;"><span class="sc2"><span class="kw2">&lt;table</span> <span class="kw3">class</span>=<span class="st0">&quot;editorkit&quot;</span> <span class="kw3">border</span>=<span class="st0">&quot;0&quot;</span> <span class="kw3">cellspacing</span>=<span class="st0">&quot;0&quot;</span> <span class="kw3">style</span>=<span class="st0">&quot;width:400px&quot;</span><span class="kw2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;tr</span> <span class="kw3">class</span>=<span class="st0">&quot;width_setter&quot;</span><span class="kw2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;th</span> <span class="kw3">style</span>=<span class="st0">&quot;width:50px&quot;</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;/th&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;td&gt;</span></span><span class="sc2"><span class="kw2">&lt;/td&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;/tr&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;tr&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;th</span> <span class="kw3">class</span>=<span class="st0">&quot;detached_label&quot;</span><span class="kw2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;label</span> <span class="kw3">for</span>=<span class="st0">&quot;login&quot;</span><span class="kw2">&gt;</span></span>Login:<span class="sc2"><span class="kw2">&lt;br&gt;</span></span><span class="sc2"><span class="kw2">&lt;small&gt;</span></span>(required)<span class="sc2"><span class="kw2">&lt;/small&gt;</span></span><span class="sc2"><span class="kw2">&lt;/label&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;/th&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;td</span> <span class="kw3">class</span>=<span class="st0">&quot;editorkit_row&quot;</span><span class="kw2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;input</span> <span class="kw3">name</span>=<span class="st0">&quot;login&quot;</span> <span class="kw3">id</span>=<span class="st0">&quot;login&quot;</span> /<span class="kw2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;/td&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;td</span> <span class="kw3">class</span>=<span class="st0">&quot;right_padding&quot;</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;/td&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;/tr&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;tr&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;th&gt;</span></span><span class="sc2"><span class="kw2">&lt;/th&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;td</span> <span class="kw3">class</span>=<span class="st0">&quot;editorkit_buttonset&quot;</span><span class="kw2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;input</span> <span class="kw3">type</span>=<span class="st0">&quot;submit&quot;</span> <span class="kw3">class</span>=<span class="st0">&quot;editorkit_button action&quot;</span> <span class="kw3">value</span>=<span class="st0">&quot;Submit&quot;</span> /<span class="kw2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;/td&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;td</span> <span class="kw3">class</span>=<span class="st0">&quot;right_padding&quot;</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;/td&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;/tr&gt;</span></span><br />
<span class="sc2"><span class="kw2">&lt;/table&gt;</span></span></div></div>
<p>BTW, we have several enhancements in the original layout: we have specified <tt>for</tt> attribute for the <tt>label</tt> tag (now if you would click to the label, corresponding input would be selected), and added ability to mark required fields with <em>required</em> text (it&#8217;s impossible with <tt>fb:editor</tt>).</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=0MGElDd"><img src="http://feeds.feedburner.com/~f/kpumuk?i=0MGElDd" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=A6XaJNd"><img src="http://feeds.feedburner.com/~f/kpumuk?i=A6XaJNd" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=EqGdTFd"><img src="http://feeds.feedburner.com/~f/kpumuk?i=EqGdTFd" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=nzMai7D"><img src="http://feeds.feedburner.com/~f/kpumuk?i=nzMai7D" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/217793934" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/facebook/fbeditor-editor-tag-in-facebook-applications/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/facebook/fbeditor-editor-tag-in-facebook-applications/</feedburner:origLink></item>
		<item>
		<title>Coalesce ?? operator in C# 2.0</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/216601394/</link>
		<comments>http://kpumuk.info/asp-net/coalesce-operator-in-c-sharp-2-0/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 19:18:27 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[.net]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[syntax]]></category>

		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://kpumuk.info/asp-net/coalesce-operator-in-c-sharp-2-0/</guid>
		<description><![CDATA[Operator ??, that was introduced in the .NET 2.0, takes first place in my top used C# idioms list a long time, but unfortunately it is rarely used in projects I&#8217;ve participated. Therefore these snippets could be found in production code very often:
public string Caption
&#123;
&#160; &#160; get &#123; return ViewState&#91;&#34;Caption&#34;&#93; != null ? &#40;string&#41; ViewState&#91;&#34;Caption&#34;&#93; [...]]]></description>
			<content:encoded><![CDATA[<p>Operator <tt>??</tt>, that was introduced in the .NET 2.0, takes first place in my top used C# idioms list a long time, but unfortunately it is rarely used in projects I&#8217;ve participated. Therefore these snippets could be found in production code very often:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;">public <span class="kw4">string</span> Caption<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> != <span class="kw2">null</span> ? <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> : <span class="st0">&quot;&quot;</span>; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> = value; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p><span id="more-191"></span></p>
<p>Or even:</p>
<div class="codecolorer-container c#" style="height:280px;"><div class="codecolorer" style="font-family: monospace;">public <span class="kw4">string</span> VisibleStatistic<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">string</span> retval = <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;VisibleStatistic&quot;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> retval == <span class="kw2">null</span> ? <span class="st0">&quot;&quot;</span> : retval;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ViewState<span class="br0">&#91;</span><span class="st0">&quot;VisibleStatistic&quot;</span><span class="br0">&#93;</span> = value;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<br />
public <span class="kw4">string</span> SelectedCategoryName<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; object retval = ViewState<span class="br0">&#91;</span><span class="st0">&quot;SelectedCategoryName&quot;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>retval != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> retval;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw4">String</span>.<span class="me1">Empty</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ViewState<span class="br0">&#91;</span><span class="st0">&quot;SelectedCategoryName&quot;</span><span class="br0">&#93;</span> = value;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>Almost 50% of this could be easily removed, and you will get beautiful and clear code, just right after you will understand what the hell is operator <tt>??</tt>. Here is information from MSDN:</p>
<blockquote><div>The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.</div>
</blockquote>
<p>Easy and clean explanation. Let&#8217;s try to rewrite all these examples using this operator:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;">public <span class="kw4">string</span> Caption<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> ?? <span class="kw4">String</span>.<span class="me1">Empty</span>; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> = value; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<br />
public <span class="kw4">string</span> VisibleStatistic<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;VisibleStatistic&quot;</span><span class="br0">&#93;</span> ?? <span class="kw4">String</span>.<span class="me1">Empty</span>; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;VisibleStatistic&quot;</span><span class="br0">&#93;</span> = value; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<br />
public <span class="kw4">string</span> SelectedCategoryName<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;SelectedCategoryName&quot;</span><span class="br0">&#93;</span> ?? <span class="kw4">String</span>.<span class="me1">Empty</span>; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;SelectedCategoryName&quot;</span><span class="br0">&#93;</span> = value; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>In case of value-types this approach will not work: you will get <tt>NullReferenceException</tt>. But do not worry &#8212; in this case we can use <tt>Nullable</tt>-types. Before:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;">public <span class="kw4">int</span> FirstWidth<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> != <span class="kw2">null</span> ? <span class="br0">&#40;</span><span class="kw4">int</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> : <span class="nu0">0</span>; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> = value; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>After:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;">public <span class="kw4">int</span> FirstWidth<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">int</span>?<span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> ?? <span class="nu0">0</span>; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> = value; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>When you are using <tt>??</tt> operator, expression will be evaluated in the left to right order, so you can use something like this:</p>
<div class="codecolorer-container c#" style="height:35px;"><div class="codecolorer" style="font-family: monospace;"><span class="kw4">string</span> name = FirstName ?? LastName ?? <span class="st0">&quot;Anonymous&quot;</span>;</div></div>
<p>Of course, it looks more readably than the:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;"><span class="kw4">string</span> name;<br />
<span class="kw1">if</span> <span class="br0">&#40;</span>FirstName != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; name = FirstName;<br />
<span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>LastName != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; name = LastName;<br />
<span class="kw1">else</span><br />
&nbsp; &nbsp; name = <span class="st0">&quot;Anonymous&quot;</span>;</div></div>
<p>And a fortiori than:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;"><span class="kw4">string</span> name = FirstName != <span class="kw2">null</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ? FirstName<br />
&nbsp; &nbsp; &nbsp; &nbsp; : <span class="br0">&#40;</span>LastName != <span class="kw2">null</span> ? LastName : <span class="st0">&quot;Anonymous&quot;</span><span class="br0">&#41;</span>;</div></div>
<p>Add it to your armoury!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=eUdzuid"><img src="http://feeds.feedburner.com/~f/kpumuk?i=eUdzuid" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=2cVdLad"><img src="http://feeds.feedburner.com/~f/kpumuk?i=2cVdLad" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=vci6BEd"><img src="http://feeds.feedburner.com/~f/kpumuk?i=vci6BEd" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=kYi64fD"><img src="http://feeds.feedburner.com/~f/kpumuk?i=kYi64fD" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/216601394" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/asp-net/coalesce-operator-in-c-sharp-2-0/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/asp-net/coalesce-operator-in-c-sharp-2-0/</feedburner:origLink></item>
		<item>
		<title>Correct using Cache in ASP.NET</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/215627214/</link>
		<comments>http://kpumuk.info/asp-net/correct-using-cache-in-aspnet/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 19:22:00 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[caching]]></category>

		<guid isPermaLink="false">http://kpumuk.info/asp-net/correct-using-cache-in-aspnet/</guid>
		<description><![CDATA[Often in ASP.NET application we see a code which looks like this one:
if &#40;Cache&#91;&#34;SomeData&#34;&#93; != null&#41;
&#123;
&#160; &#160; string name = &#40;&#40;SomeClass&#41; Cache&#91;&#34;SomeData&#34;&#93;&#41;.Name;
&#160; &#160; //.....
&#125;
Experienced developer, even if he is not a paranoiac, will find possible problem immediately &#8212; NullReferenceException. That&#8217;s because of caching implementation in ASP.NET. In ideal case an object, that has been cached, [...]]]></description>
			<content:encoded><![CDATA[<p>Often in ASP.NET application we see a code which looks like this one:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">if</span> <span class="br0">&#40;</span>Cache<span class="br0">&#91;</span><span class="st0">&quot;SomeData&quot;</span><span class="br0">&#93;</span> != <span class="kw2">null</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">string</span> name = <span class="br0">&#40;</span><span class="br0">&#40;</span>SomeClass<span class="br0">&#41;</span> Cache<span class="br0">&#91;</span><span class="st0">&quot;SomeData&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">Name</span>;<br />
&nbsp; &nbsp; <span class="co1">//.....</span><br />
<span class="br0">&#125;</span></div></div>
<p>Experienced developer, even if he is not a paranoiac, will find possible problem immediately &#8212; <tt>NullReferenceException</tt>. That&#8217;s because of caching implementation in ASP.NET. In ideal case an object, that has been cached, will stay there up to application restart, but in real world it could be deleted between two calls: by the garbage collector when memory is over (because cache uses weak references <tt>WeakReference</tt>); by another thread to refresh cached data.</p>
<p>So the code I have mentioned before works in 99% of all cases, but sometimes you will get errors in your log, which can not be reproduced easily. Here is right cache usage approach:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;">SomeClass someClass = Cache<span class="br0">&#91;</span><span class="st0">&quot;SomeData&quot;</span><span class="br0">&#93;</span> as SomeClass;<br />
<span class="kw1">if</span> <span class="br0">&#40;</span>someClass != <span class="kw2">null</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">string</span> name = someClass.<span class="me1">Name</span>;<br />
&nbsp; &nbsp; <span class="co1">//.....</span><br />
<span class="br0">&#125;</span></div></div>
<p>Do not relax your vigilance, it&#8217;s exactly what <strong>they</strong> are waiting for! (about bugs)</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=EILwcjd"><img src="http://feeds.feedburner.com/~f/kpumuk?i=EILwcjd" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=lFKOQRd"><img src="http://feeds.feedburner.com/~f/kpumuk?i=lFKOQRd" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=r6q6Nod"><img src="http://feeds.feedburner.com/~f/kpumuk?i=r6q6Nod" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=Ijf5CrD"><img src="http://feeds.feedburner.com/~f/kpumuk?i=Ijf5CrD" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/215627214" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/asp-net/correct-using-cache-in-aspnet/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/asp-net/correct-using-cache-in-aspnet/</feedburner:origLink></item>
		<item>
		<title>Crazy piece of code: Checking query parameter</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/201834488/</link>
		<comments>http://kpumuk.info/asp-net/crazy-piece-of-code-checking-query-parameter/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 20:47:35 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://kpumuk.info/asp-net/crazy-piece-of-code-checking-query-parameter/</guid>
		<description><![CDATA[How often you are laughing out loud when looking on the someone&#8217;s code? Today I found great code in my current project and I can&#8217;t hold posting this to my blog. So,
if &#40;Request.QueryString.HasKeys&#40;&#41;&#41;
&#123;
&#160; &#160; string&#91;&#93; keys = Request.QueryString.AllKeys;
&#160; &#160; foreach &#40;string k in keys&#41;
&#160; &#160; &#123;
&#160; &#160; &#160; &#160; if &#40;k == &#34;memberpagemode&#34; &#38;&#38; &#40;string&#41;Request.QueryString.GetValues&#40;k&#41;.GetValue&#40;0&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>How often you are laughing out loud when looking on the someone&#8217;s code? Today I found great code in my current project and I can&#8217;t hold posting this to my blog. So,</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">if</span> <span class="br0">&#40;</span>Request.<span class="me1">QueryString</span>.<span class="me1">HasKeys</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">string</span><span class="br0">&#91;</span><span class="br0">&#93;</span> keys = Request.<span class="me1">QueryString</span>.<span class="me1">AllKeys</span>;<br />
&nbsp; &nbsp; foreach <span class="br0">&#40;</span><span class="kw4">string</span> k in keys<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>k == <span class="st0">&quot;memberpagemode&quot;</span> &amp;&amp; <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span>Request.<span class="me1">QueryString</span>.<span class="me1">GetValues</span><span class="br0">&#40;</span>k<span class="br0">&#41;</span>.<span class="me1">GetValue</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span> == <span class="st0">&quot;edit&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pSett.<span class="me1">ChangeFormViewMode</span><span class="br0">&#40;</span>FormViewMode.<span class="me1">Edit</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>And how do you search through the hash for a key with specified value?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=AcYB2Tc"><img src="http://feeds.feedburner.com/~f/kpumuk?i=AcYB2Tc" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=OwfX8Jc"><img src="http://feeds.feedburner.com/~f/kpumuk?i=OwfX8Jc" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=rgp6ssc"><img src="http://feeds.feedburner.com/~f/kpumuk?i=rgp6ssc" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=abN864D"><img src="http://feeds.feedburner.com/~f/kpumuk?i=abN864D" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/201834488" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/asp-net/crazy-piece-of-code-checking-query-parameter/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/asp-net/crazy-piece-of-code-checking-query-parameter/</feedburner:origLink></item>
		<item>
		<title>Sphinx Client API 0.3.1 and 0.4.0 r909 for Sphinx 0.9.8 r909 released</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/197652198/</link>
		<comments>http://kpumuk.info/ror-plugins/sphinx-client-api-0-3-1-and-0-4-0-r909-for-sphinx-0-9-8-r909-released/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 18:33:10 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[RoR Plugins]]></category>

		<category><![CDATA[fulltext]]></category>

		<category><![CDATA[library]]></category>

		<category><![CDATA[plugin]]></category>

		<category><![CDATA[postgresql]]></category>

		<category><![CDATA[proximity]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[scalability]]></category>

		<category><![CDATA[search]]></category>

		<category><![CDATA[sphinx]]></category>

		<category><![CDATA[stemming]]></category>

		<guid isPermaLink="false">http://kpumuk.info/ror-plugins/sphinx-client-api-0-3-1-and-0-4-0-r909-for-sphinx-0-9-8-r909-released/</guid>
		<description><![CDATA[ I have a good news: Sphinx Client API has been updated and now it supports all brand new features of the unstable Sphinx 0.9.8 development snapshot. What does it mean for you as a developer? What features you will get if you would decide to switch to the new version? I will describe most [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://kpumuk.info/wp-content/uploads/2007/12/sphinx.jpg' alt='Sphinx Search Engine' align="right" class="post-image" /> I have a good news: Sphinx Client API has been updated and now it supports all brand new features of the unstable Sphinx 0.9.8 development snapshot. What does it mean for you as a developer? What features you will get if you would decide to switch to the new version? I will describe most valuable improvements of the Sphinx in this article, and will show how to use them with new <a href="http://kpumuk.info/projects/ror-plugins/sphinx/">Sphinx Client API 0.4.0 r909</a>.</p>
<p><span id="more-188"></span></p>
<h2>Table of contents</h2>
<ul>
<li><a href="#multi-query">Multi-query support</a></li>
<li><a href="#engine-v2">Extended engine V2</a></li>
<li><a href="#64-bit">64-bit document and word IDs support</a></li>
<li><a href="#multiple-valued">Multiple-valued attributes</a></li>
<li><a href="#geodistance">Geodistance feature</a></li>
<li><a href="#download">Download</a></li>
</ul>
<p><a name="multi-query"></a></p>
<h2>Multi-query support</h2>
<p>What does it mean? Multi-query support means sending multiple search queries to Sphinx at once. It&#8217;s saving network connection overheads and other round-trip costs. But what&#8217;s much more important, it unlocks possibilities to optimize &#8220;related&#8221; queries internally. Here is quote from the Sphinx home page:</p>
<blockquote><div>
<p>One typical Sphinx usage pattern is to return several different &#8220;views&#8221; on the search results. For instance, one might need to display per-category match counts along with product search results, or maybe a graph of matches over time. Yes, that could be easily done earlier using the grouping features. However, one had to run the same query multiple times, but with different settings.</p>
<p>From now on, if you submit such queries through newly added multi-query interface (as a side note, ye good olde Query() interface is not going anywhere, and compatibility with older clients should also be in place), Sphinx notices that the full-text search query is the same and it is just sorting/grouping settings which are different. In this case it only performs expensive full-text search once, but builds several different (differently sorted and/or grouped) result sets from retrieved matches. I&#8217;ve seen speedups of 1.5-2 times on my simple synthetic queries; depending on different factors, the speedup could be even greater in practice.</p>
</div>
</blockquote>
<p>To perform multi-query you should add several queries using <tt>AddQuery</tt> method (parameters are exactly the same as in <tt>Query</tt> call), and then call <tt>RunQueries</tt>. Please note, that all parameters, filters, query settings are stored between <tt>AddQuery</tt> calls. It means that if you have specified sort mode using <tt>SetSortMode</tt> before first <tt>AddQuery</tt> call, then sort mode will be the same for the second <tt>AddQuery</tt> call. Currently you can reset only filters (using <tt>ResetFilters</tt>) and group by (<tt>ResetGroupBy</tt>) settings. BTW, you can use <tt>Query</tt> as usually to perform single query, but don&#8217;t try to make this call after you have added query into the batch using <tt>AddQuery</tt>.</p>
<p>Stop speaking, let&#8217;s look the example:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
sphinx.<span class="me1">SetFilter</span><span class="br0">&#40;</span><span class="st0">'group_id'</span>, <span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
sphinx.<span class="me1">AddQuery</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span><br />
<br />
sphinx.<span class="me1">ResetFilters</span><br />
sphinx.<span class="me1">SetFilter</span><span class="br0">&#40;</span><span class="st0">'group_id'</span>, <span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
sphinx.<span class="me1">AddQuery</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span><br />
<br />
results = sphinx.<span class="me1">RunQueries</span><br />
pp results</div></div>
<p>As the result we will get array of 2 hashes:</p>
<div class="codecolorer-container ruby" style="height:280px;"><div class="codecolorer" style="font-family: monospace;"><span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;total_found&quot;</span>=&gt;<span class="nu0">2</span>,<br />
&nbsp; <span class="st0">&quot;status&quot;</span>=&gt;<span class="nu0">0</span>,<br />
&nbsp; <span class="st0">&quot;matches&quot;</span>=&gt;<br />
&nbsp; &nbsp;<span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span>=&gt;<span class="nu0">1</span>, <span class="st0">&quot;created_at&quot;</span>=&gt;<span class="nu0">1175658647</span><span class="br0">&#125;</span>, <span class="st0">&quot;weight&quot;</span>=&gt;<span class="nu0">2</span>, <span class="st0">&quot;id&quot;</span>=&gt;<span class="nu0">3</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span>=&gt;<span class="nu0">1</span>, <span class="st0">&quot;created_at&quot;</span>=&gt;<span class="nu0">1175658490</span><span class="br0">&#125;</span>, <span class="st0">&quot;weight&quot;</span>=&gt;<span class="nu0">1</span>, <span class="st0">&quot;id&quot;</span>=&gt;<span class="nu0">1</span><span class="br0">&#125;</span><span class="br0">&#93;</span>,<br />
&nbsp; <span class="st0">&quot;error&quot;</span>=&gt;<span class="st0">&quot;&quot;</span>,<br />
&nbsp; <span class="st0">&quot;words&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;wifi&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;hits&quot;</span>=&gt;<span class="nu0">6</span>, <span class="st0">&quot;docs&quot;</span>=&gt;<span class="nu0">3</span><span class="br0">&#125;</span><span class="br0">&#125;</span>,<br />
&nbsp; <span class="st0">&quot;time&quot;</span>=&gt;<span class="st0">&quot;0.000&quot;</span>,<br />
&nbsp; <span class="st0">&quot;attrs&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span>=&gt;<span class="nu0">1</span>, <span class="st0">&quot;created_at&quot;</span>=&gt;<span class="nu0">2</span><span class="br0">&#125;</span>,<br />
&nbsp; <span class="st0">&quot;fields&quot;</span>=&gt;<span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span>, <span class="st0">&quot;description&quot;</span><span class="br0">&#93;</span>,<br />
&nbsp; <span class="st0">&quot;total&quot;</span>=&gt;<span class="nu0">2</span>,<br />
&nbsp; <span class="st0">&quot;warning&quot;</span>=&gt;<span class="st0">&quot;&quot;</span><span class="br0">&#125;</span>,<br />
&nbsp;<span class="br0">&#123;</span><span class="st0">&quot;total_found&quot;</span>=&gt;<span class="nu0">1</span>,<br />
&nbsp; <span class="st0">&quot;status&quot;</span>=&gt;<span class="nu0">0</span>,<br />
&nbsp; <span class="st0">&quot;matches&quot;</span>=&gt;<br />
&nbsp; &nbsp;<span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span>=&gt;<span class="nu0">2</span>, <span class="st0">&quot;created_at&quot;</span>=&gt;<span class="nu0">1175658555</span><span class="br0">&#125;</span>, <span class="st0">&quot;weight&quot;</span>=&gt;<span class="nu0">2</span>, <span class="st0">&quot;id&quot;</span>=&gt;<span class="nu0">2</span><span class="br0">&#125;</span><span class="br0">&#93;</span>,<br />
&nbsp; <span class="st0">&quot;error&quot;</span>=&gt;<span class="st0">&quot;&quot;</span>,<br />
&nbsp; <span class="st0">&quot;words&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;wifi&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;hits&quot;</span>=&gt;<span class="nu0">6</span>, <span class="st0">&quot;docs&quot;</span>=&gt;<span class="nu0">3</span><span class="br0">&#125;</span><span class="br0">&#125;</span>,<br />
&nbsp; <span class="st0">&quot;time&quot;</span>=&gt;<span class="st0">&quot;0.000&quot;</span>,<br />
&nbsp; <span class="st0">&quot;attrs&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span>=&gt;<span class="nu0">1</span>, <span class="st0">&quot;created_at&quot;</span>=&gt;<span class="nu0">2</span><span class="br0">&#125;</span>,<br />
&nbsp; <span class="st0">&quot;fields&quot;</span>=&gt;<span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span>, <span class="st0">&quot;description&quot;</span><span class="br0">&#93;</span>,<br />
&nbsp; <span class="st0">&quot;total&quot;</span>=&gt;<span class="nu0">1</span>,<br />
&nbsp; <span class="st0">&quot;warning&quot;</span>=&gt;<span class="st0">&quot;&quot;</span><span class="br0">&#125;</span><span class="br0">&#93;</span></div></div>
<p>Each hash contains the same data as result of <tt>Query</tt> method call. Also they have additional fields <tt>error</tt> and <tt>warning</tt> which contains error and warning message respectively when not empty.</p>
<p>Note: I have added <tt>ResetFilters</tt> call before creating second query. Without this call our query will have two filters with conflicting conditions, so there will be no results at all.</p>
<p><a name="engine-v2"></a></p>
<h2>Extended engine V2</h2>
<p>New querying engine (codenamed &#8220;extended engine V2&#8243;) is going to gradually replace all the currently existing matching modes. At the moment, it is fully identical to extended mode in functionality, but is much less CPU intensive for some queries. Here are notes from Sphinx author:</p>
<blockquote><div>
<p>I have already seen improvements of up to 3-5 times in extreme cases. The only currently known case when it&#8217;s slower is processing complex extended queries with tens to thousands keywords; but forthcoming optimizations will fix that.</p>
<p>V2 engine is currently in alpha state and does not affect any other matching mode yet. Temporary SPH_MATCH_EXTENDED2 mode was added to provide a way to test it easily. We are in the middle of extensive internal testing process (under simulated production load, and then actual production load) right now. Your independent testing results would be appreciated, too!</p>
</div>
</blockquote>
<p>So, to use new matching mode we should use <tt>SPH_MATCH_EXTENDED2</tt> mode. Let&#8217;s do it!</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
sphinx.<span class="me1">SetMatchMode</span><span class="br0">&#40;</span><span class="re2">Sphinx::Client::SPH_MATCH_EXTENDED2</span><span class="br0">&#41;</span><br />
sphinx.<span class="me1">Query</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span></div></div>
<p>Easy enough, right? You should try it by yourself to feel power of new engine. Please note, that this mode is temporary and it will be removed after release.</p>
<p><a name="64-bit"></a></p>
<h2>64-bit document and word IDs support</h2>
<p>Before version 0.9.8 the Sphinx was limited to index up to 4 billion documents because of using 32-bit keys. From here on it has ability to use 64-bit IDs, and new feature does not impact on 32-bit keys performance. Let&#8217;s look at the example. First we will make query to DB with 32-bit keys:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
result = sphinx.<span class="me1">Query</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span><br />
pp result<span class="br0">&#91;</span><span class="st0">'matches'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">'id'</span><span class="br0">&#93;</span>.<span class="kw1">class</span></div></div>
<p>As you can see, class of the <tt>id</tt> field is <tt>Fixnum</tt>. Let&#8217;s try to make call to index with 64-bit keys. You will get <tt>Bignum</tt> as the result, and it means that you can have more than 4 billion documents!</p>
<p><a name="multiple-valued"></a></p>
<h2>Multiple-valued attributes</h2>
<p>Plain attributes only allow to attach 1 value per each document. However, there are cases (such as tags or categories) when it is necessary to attach multiple values of the same attribute and be able to apply filtering to value lists. In these cases we can use multiple-valued attributes now.</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
sphinx.<span class="me1">SetFilter</span><span class="br0">&#40;</span><span class="st0">'tag'</span>, <span class="br0">&#91;</span><span class="nu0">1</span>,<span class="nu0">5</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
pp sphinx.<span class="me1">Query</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span></div></div>
<p>In case of using miltiple-valued attribute <tt>tag</tt> you will get result like:</p>
<div class="codecolorer-container ruby" style="height:280px;"><div class="codecolorer" style="font-family: monospace;"><span class="br0">&#123;</span><span class="st0">&quot;total_found&quot;</span>=&gt;<span class="nu0">2</span>,<br />
&nbsp;<span class="st0">&quot;status&quot;</span>=&gt;<span class="nu0">0</span>,<br />
&nbsp;<span class="st0">&quot;matches&quot;</span>=&gt;<br />
&nbsp; <span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span>=&gt;<br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span><span class="st0">&quot;tag&quot;</span>=&gt;<span class="br0">&#91;</span><span class="nu0">4</span>, <span class="nu0">5</span><span class="br0">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span>=&gt;<span class="nu0">2</span>,<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;created_at&quot;</span>=&gt;<span class="nu0">1175658555</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="st0">&quot;weight&quot;</span>=&gt;<span class="nu0">2</span>,<br />
&nbsp; &nbsp; <span class="st0">&quot;id&quot;</span>=&gt;<span class="nu0">2</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp;<span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span>=&gt;<br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span><span class="st0">&quot;tag&quot;</span>=&gt;<span class="br0">&#91;</span><span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span><span class="br0">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span>=&gt;<span class="nu0">1</span>,<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;created_at&quot;</span>=&gt;<span class="nu0">1175658490</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="st0">&quot;weight&quot;</span>=&gt;<span class="nu0">1</span>,<br />
&nbsp; &nbsp; <span class="st0">&quot;id&quot;</span>=&gt;<span class="nu0">1</span><span class="br0">&#125;</span><span class="br0">&#93;</span>,<br />
&nbsp;<span class="st0">&quot;error&quot;</span>=&gt;<span class="st0">&quot;&quot;</span>,<br />
&nbsp;<span class="st0">&quot;words&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;wifi&quot;</span>=&gt;<span class="br0">&#123;</span><span class="st0">&quot;hits&quot;</span>=&gt;<span class="nu0">6</span>, <span class="st0">&quot;docs&quot;</span>=&gt;<span class="nu0">3</span><span class="br0">&#125;</span><span class="br0">&#125;</span>,<br />
&nbsp;<span class="st0">&quot;time&quot;</span>=&gt;<span class="st0">&quot;0.000&quot;</span>,<br />
&nbsp;<span class="st0">&quot;attrs&quot;</span>=&gt;<br />
&nbsp; <span class="br0">&#123;</span><span class="st0">&quot;price&quot;</span>=&gt;<span class="nu0">5</span>,<br />
&nbsp; &nbsp;<span class="st0">&quot;tag&quot;</span>=&gt;<span class="nu0">1073741825</span>,<br />
&nbsp; &nbsp;<span class="st0">&quot;is_active&quot;</span>=&gt;<span class="nu0">4</span>,<br />
&nbsp; &nbsp;<span class="st0">&quot;group_id&quot;</span>=&gt;<span class="nu0">1</span>,<br />
&nbsp; &nbsp;<span class="st0">&quot;created_at&quot;</span>=&gt;<span class="nu0">2</span><span class="br0">&#125;</span>,<br />
&nbsp;<span class="st0">&quot;fields&quot;</span>=&gt;<span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span>, <span class="st0">&quot;description&quot;</span><span class="br0">&#93;</span>,<br />
&nbsp;<span class="st0">&quot;total&quot;</span>=&gt;<span class="nu0">2</span>,<br />
&nbsp;<span class="st0">&quot;warning&quot;</span>=&gt;<span class="st0">&quot;&quot;</span><span class="br0">&#125;</span></div></div>
<p>As you can see, multiple-valued attributes returned as array of integers.</p>
<p><a name="geodistance"></a></p>
<h2>Geodistance feature</h2>
<p>Sphinx now is able to compute geographical distance between two points specified by latitude and longitude pairs (in radians). So you now can specify per-query &#8220;anchor point&#8221; (and attribute names to fetch per-entry latitude and longitude from), and then use &#8220;@geodist&#8221; virtual attribute both in the filters and in the sorting clause. In this case distance (in meters) from anchor point to each match will be computed, used for filtering and/or sorting, and returned as a virtual attribute too.</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
sphinx.<span class="me1">SetGeoAnchor</span><span class="br0">&#40;</span><span class="st0">'lat'</span>, <span class="st0">'long'</span>, <span class="nu0">0.87248</span>, <span class="nu0">0.63195</span><span class="br0">&#41;</span><br />
result = sphinx.<span class="me1">Query</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span></div></div>
<p><a name="download"></a></p>
<h2>Download</h2>
<p>As always, you can download Sphinx Client API from <a href="http://kpumuk.info/projects/ror-plugins/sphinx/">project home page</a>. Take into account that version 0.3.1 of the client API intended to use with Sphinx 0.9.7, and Sphinx Client API 0.4.0 r909 requires Sphinx 0.9.8 r909 development snapshot. You could download Sphinx from the Download section of the <a href="http://www.sphinxsearch.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.sphinxsearch.com');">Sphinx home page</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=lUtkGhc"><img src="http://feeds.feedburner.com/~f/kpumuk?i=lUtkGhc" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=gVeNWtc"><img src="http://feeds.feedburner.com/~f/kpumuk?i=gVeNWtc" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=GHd4QIc"><img src="http://feeds.feedburner.com/~f/kpumuk?i=GHd4QIc" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=dNAKfqD"><img src="http://feeds.feedburner.com/~f/kpumuk?i=dNAKfqD" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/197652198" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/ror-plugins/sphinx-client-api-0-3-1-and-0-4-0-r909-for-sphinx-0-9-8-r909-released/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/ror-plugins/sphinx-client-api-0-3-1-and-0-4-0-r909-for-sphinx-0-9-8-r909-released/</feedburner:origLink></item>
		<item>
		<title>What the fuck? Are Developers of Facebook client libraries for ASP.NET stupid?</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/158096462/</link>
		<comments>http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/#comments</comments>
		<pubDate>Tue, 18 Sep 2007 14:49:19 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Facebook]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[fbml]]></category>

		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/</guid>
		<description><![CDATA[Last week I faced strange bug in Facebook Developer Toolkit. When I tried to call setFBML method (I mentioned it in my previous post) I&#8217;ve got an exception about invalid signature. &#8220;Haha&#8221; I said and downloaded toolkit sources. After some debugging, I&#8217;ve found a few lines which just killed me:
// Compute the MD5 hash of [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I faced strange bug in <a href="http://www.codeplex.com/FacebookToolkit/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.codeplex.com');">Facebook Developer Toolkit</a>. When I tried to call <tt>setFBML</tt> method (I mentioned it in my <a href="http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/">previous post</a>) I&#8217;ve got an exception about invalid signature. &#8220;Haha&#8221; I said and downloaded toolkit sources. After some debugging, I&#8217;ve found a few lines which just killed me:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;"><span class="co1">// Compute the MD5 hash of the signature builder</span><br />
hash = md5.<span class="me1">ComputeHash</span><span class="br0">&#40;</span>Encoding.<span class="kw1">Default</span>.<span class="me1">GetBytes</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; signatureBuilder.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">Trim</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div></div>
<p><span id="more-182"></span></p>
<p>Just take a look into the MSDN&#8217;s topic about <tt>Encoding.Default</tt>: Gets an encoding for the system&#8217;s current ANSI code page. And below we can find <strong>Caution</strong>:</p>
<blockquote><div>
Different systems might use different encodings as the default; therefore, data streamed from one system to another might be translated incorrectly. To ensure that the encoded bytes are decoded properly, use a Unicode encoding (that is, <tt>UTF8Encoding</tt>, <tt>UnicodeEncoding</tt>, or <tt>UTF32Encoding</tt>) with a preamble. Another option is to use a higher level protocol to ensure that the same format is used for encoding and decoding.
</div>
</blockquote>
<p>Holly shit! Guys, did you read MSDN before writing libraries for others to use? I think you didn&#8217;t.</p>
<p>Anyways, I have fixed my local copy:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;"><span class="co1">// Compute the MD5 hash of the signature builder</span><br />
hash = md5.<span class="me1">ComputeHash</span><span class="br0">&#40;</span>Encoding.<span class="me1">UTF8</span>.<span class="me1">GetBytes</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; signatureBuilder.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">Trim</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div></div>
<p>Of course, it started working perfectly. I have posted a <a href="http://www.codeplex.com/FacebookToolkit/WorkItem/View.aspx?WorkItemId=6645" onclick="javascript:pageTracker._trackPageview ('/outbound/www.codeplex.com');">bug</a> to the tracker and decided to look at the <a href="http://www.codeplex.com/FacebookNET" onclick="javascript:pageTracker._trackPageview ('/outbound/www.codeplex.com');">Facebook.NET</a>, a better and much cleaner implementation according to <a href="http://www.ajaxninja.com/?p=131" onclick="javascript:pageTracker._trackPageview ('/outbound/www.ajaxninja.com');">AjaxNinja</a>.</p>
<p>And what do you think? Just open <tt>CreateSignature</tt> method in <em>Framework/Service/Core/FacebookRequestParameterList.cs</em> file:</p>
<div class="codecolorer-container c#" style="height:35px;"><div class="codecolorer" style="font-family: monospace;">byte<span class="br0">&#91;</span><span class="br0">&#93;</span> hash = md5.<span class="me1">ComputeHash</span><span class="br0">&#40;</span>Encoding.<span class="kw1">Default</span>.<span class="me1">GetBytes</span><span class="br0">&#40;</span>sigBuilder.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div></div>
<p>Aaaaaaaaaa. They ate my brain! I don&#8217;t know what to do. I don&#8217;t know, how to explain to all developers about non-ASCII code pages. We are living in world that is not ideal. We have tons of languages, encodings, code pages. And we have UTF8, which should simplify our life. Hey, guys, WTF?</p>
<p><em>Updated 23 Sep 2007</em>: Facebook.NET developers has closed <a href="http://www.codeplex.com/FacebookNET/WorkItem/View.aspx?WorkItemId=1483" onclick="javascript:pageTracker._trackPageview ('/outbound/www.codeplex.com');">this bug</a>. Hope I will never see something like this again. Facebook Development Toolkit still does not working for me. I see 27 open bugs in its tracker, so I decided to use <a href="http://www.codeplex.com/FacebookNET" onclick="javascript:pageTracker._trackPageview ('/outbound/www.codeplex.com');">Facebook.NET</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=x3e1zAi9"><img src="http://feeds.feedburner.com/~f/kpumuk?i=x3e1zAi9" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=51lpQ58l"><img src="http://feeds.feedburner.com/~f/kpumuk?i=51lpQ58l" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=rpu4KCbw"><img src="http://feeds.feedburner.com/~f/kpumuk?i=rpu4KCbw" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=zXIsuBD"><img src="http://feeds.feedburner.com/~f/kpumuk?i=zXIsuBD" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/158096462" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/</feedburner:origLink></item>
		<item>
		<title>Crazy PHP world</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/156141271/</link>
		<comments>http://kpumuk.info/php/crazy-php-world/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 21:56:03 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[optimization]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://kpumuk.info/php/crazy-php-world/</guid>
		<description><![CDATA[We are living in XXI century, but PHPists can&#8217;t decide yet how to write: &#34;text $b&#34; or &#39;text &#39; . $b. I&#8217;m going slightly mad.
via Artjom Kurapov&#8217;s blog.
]]></description>
			<content:encoded><![CDATA[<p>We are living in XXI century, but PHPists can&#8217;t decide yet how to write: <tt>&quot;text $b&quot;</tt> or <tt>&#39;text &#39; . $b</tt>. I&#8217;m going slightly mad.</p>
<p>via <a href="http://kurapov.name/article/1741" onclick="javascript:pageTracker._trackPageview ('/outbound/kurapov.name');">Artjom Kurapov</a>&#8217;s blog.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=mdyu2lBY"><img src="http://feeds.feedburner.com/~f/kpumuk?i=mdyu2lBY" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=TOUlbl0L"><img src="http://feeds.feedburner.com/~f/kpumuk?i=TOUlbl0L" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=nBuhDfQT"><img src="http://feeds.feedburner.com/~f/kpumuk?i=nBuhDfQT" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=9XGbDrD"><img src="http://feeds.feedburner.com/~f/kpumuk?i=9XGbDrD" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/156141271" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/php/crazy-php-world/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/php/crazy-php-world/</feedburner:origLink></item>
		<item>
		<title>Generating content for the Facebook’s setFBML method in ASP.NET</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/156141272/</link>
		<comments>http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 21:43:30 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Facebook]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[controls]]></category>

		<category><![CDATA[fbml]]></category>

		<category><![CDATA[profile]]></category>

		<category><![CDATA[setFBML]]></category>

		<guid isPermaLink="false">http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/</guid>
		<description><![CDATA[In my current project we decided to build a Facebook application. This is really great platform with many interesting ideas inside, which usually means that you will spend a much time to make your application working as expected. Today I wanna talk about user profiles. Any Facebook application could add some action links, which will [...]]]></description>
			<content:encoded><![CDATA[<p>In my current project we decided to build a <a href="http://www.facebook.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.facebook.com');">Facebook</a> application. This is really great platform with many interesting ideas inside, which usually means that you will spend a much time to make your application working as expected. Today I wanna talk about user profiles. Any Facebook application could add some action links, which will be displayed under the user&#8217;s picture, and some content for wide or narrow column. Of course, you can use FBML syntax, especially <tt>fb:if-&#8230;</tt> tags set to choose which content to show on specific profiles to concrete users.</p>
<p><span id="more-180"></span></p>
<p>For the beginning, I&#8217;ll post a few key points about user profiles. If you want to add some content to the profile of specific user, you should call <tt>profile.setFBML</tt> routine. For users that you have not called <tt>profile.setFBML</tt> for, the actions are read from the content in &#8220;Default FBML&#8221; section of your application settings. For the most part, this will apply to any user who has not added your application. What is &#8220;Default FBML&#8221; itself? If you have added application, you will see &#8220;Default FBML&#8221; on <strong>all profiles</strong> of users that you have not called <tt>profile.setFBML</tt> for, and it does not matter, if they have added your application or not (good place to put &#8220;Invite&#8221; link). The same behavior you would see, if you would call <tt>profile.setFBML</tt> for all users (and if you are crazy enough.)</p>
<p>Please note, &#8220;Default FBML&#8221; is cached indefinitely, so wait some time to get your content on profiles. Another thing &#8212; you can add only action links to user profiles, that have not added your application, and only your application user will see them. This is most important part of the documentation, and you should completely understand it. More detailed description could be found in the documentation for <a href="http://wiki.developers.facebook.com/index.php/Fb:profile-action" onclick="javascript:pageTracker._trackPageview ('/outbound/wiki.developers.facebook.com');">fb:profile-action</a> tag and <a href="http://wiki.developers.facebook.com/index.php/Profile.setFBML" onclick="javascript:pageTracker._trackPageview ('/outbound/wiki.developers.facebook.com');">profile.setFBML</a> routine.</p>
<h2>FBML-content for user profiles</h2>
<p>There are 4 profile-specific FBML tags exist:</p>
<ul>
<li><tt>fb:profile-action</tt> is used to add action links under the user picture.</li>
<li><tt>fb:subtitle</tt> will be shown right under the title of the your application box.</li>
<li><tt>fb:wide</tt> specifies content to be shown when your application box placed in wide column.</li>
<li><tt>fb:narrow</tt> specifies content to be shown when your application box placed in narrow column.</li>
</ul>
<p>Easy, right? So let&#8217;s examine these tags more precisely.</p>
<p>As I said early, <tt>fb:profile-action</tt> is used to place action links on the user&#8217;s profile. Usually you will add one link:</p>
<div class="codecolorer-container xml"><div class="codecolorer" style="font-family: monospace;"><span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://www.mysite.com/action/&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; Perform Action<br />
<span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span></div></div>
<p>What about following scenario: I want to see the link &#8220;View my products&#8221; when I&#8217;m looking my own profile, &#8220;View Taisia&#8217;s products&#8221;, if I&#8217;m looking profile of my wife Taisia (and she has added application too), and &#8220;Invite Roman to MyApp&#8221; when I&#8217;m looking profile of my friend Roman, and he has not added application. Here is the code:</p>
<div class="codecolorer-container xml"><div class="codecolorer" style="font-family: monospace;"><span class="sc3"><span class="re1">&lt;fb:if-is-own-profile<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Products.aspx&quot;</span><span class="re2">&gt;</span></span>View my products<span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:if-is-app-user</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Products.aspx&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; View <span class="sc3"><span class="re1">&lt;fb:name</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span> <span class="re0">firstnameonly</span>=<span class="st0">&quot;true&quot;</span> <span class="re0">possessive</span>=<span class="st0">&quot;true&quot;</span> <span class="re2">/&gt;</span></span> products<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Invite.aspx&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Invite <span class="sc3"><span class="re1">&lt;fb:name</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span> <span class="re0">firstnameonly</span>=<span class="st0">&quot;true&quot;</span> <span class="re2">/&gt;</span></span> to MyApp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:if-is-app-user<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:else<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/fb:if-is-own-profile<span class="re2">&gt;</span></span></span></div></div>
<p>Please note: this example is similar to example on the <a href="http://wiki.developers.facebook.com/index.php/Fb:profile-action" onclick="javascript:pageTracker._trackPageview ('/outbound/wiki.developers.facebook.com');">fb:profile-action</a> documentation page, but has one big difference &#8212; it&#8217;s working: <tt>fb:if-is-app-user uid=&quot;profileowner&quot;</tt> (in documentation example <tt>uid</tt> takes default value &#8220;loggedinuser&#8221;, but we need <tt>uid</tt> of the profile owner.)</p>
<p>This code will work completely only if you will put it into the &#8220;Default FBML&#8221; section of your application settings, or if you will call <tt>profile.setFBML</tt> for user, that has not added your application (but this is madness, what I have talked about early): I have specified action &#8220;Invite someone to MyApp&#8221; in section, which will be shown only on profile of user that has not added application.</p>
<p>BTW, do not forget to remove all line breaks before updating &#8220;Default FBML&#8221;, because Facebook replaces them with <tt>&lt;br/&gt;</tt>.</p>
<p>Another interesting thing you could see from working example: Facebook adds parameter <tt>id</tt> for all links in <tt>profile-action</tt>, and it equals to owner&#8217;s of the profile ID. In my previous example, if I will navigate to Roman&#8217;s profile, I will see hyperlink with URL <tt>http://apps.facebook.com/myapp/Invite.aspx?id=603839739</tt>. Great!</p>
<p>This example is simple, so let&#8217;s move ahead. We have two columns on the profile: left (narrow) and right (wide). You can specify in application settings which one will be default. To put content in wide column, use <tt>fb:wide</tt>, in narrow column &#8212; <tt>fb:narrow</tt>. Quite clear, right?</p>
<p>One more interesting issue. You can specify as many <tt>fb:wide</tt> and <tt>fb:narrow</tt> tags as you wish. All content, specified in <tt>fb:wide</tt> tags will be shown if you application box placed in wide column, all content from <tt>fb:narrow</tt> tags &#8212; when application box placed in narrow column. You can add content outside one of these tags, and it will be shown in both cases &#8212; when application in wide or narrow column. If no content specified for one of column, Facebook will show &#8220;No content to display.&#8221; text.</p>
<h2>When to generate profile FBML?</h2>
<p>Your application box on the user&#8217;s profile should reflect latest changes related to him. Facebook does not know when to update profile information, so you need to do it by yourself (anyway, only you as application developer know when something changes). So, usually you would call <tt>profile.setFBML</tt> after some changes in your application (for example, user or his friends added some data), depending on which information you are rendering on the profile. Sometimes it&#8217;s a good idea to set default data after user has added your application.</p>
<h2>Creating profile FBML content with ASP.NET</h2>
<p>For profile content generating I propose to use <tt>UserControl</tt>s:</p>
<div class="codecolorer-container xml" style="height:280px;"><div class="codecolorer" style="font-family: monospace;"><span class="sc3"><span class="re1">&lt;</span>%@ Control <span class="re0">Language</span>=<span class="st0">&quot;C#&quot;</span> <span class="re0">AutoEventWireup</span>=<span class="st0">&quot;true&quot;</span> <span class="re0">CodeBehind</span>=<span class="st0">&quot;ProfileFBML.ascx.cs&quot;</span> <span class="re0">Inherits</span>=<span class="st0">&quot;ProfileFBML&quot;</span> %<span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;fb:if-is-own-profile<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Products.aspx&quot;</span><span class="re2">&gt;</span></span>View my products<span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:if-is-app-user</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Products.aspx&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; View <span class="sc3"><span class="re1">&lt;fb:name</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span> <span class="re0">firstnameonly</span>=<span class="st0">&quot;true&quot;</span> <span class="re0">possessive</span>=<span class="st0">&quot;true&quot;</span> <span class="re2">/&gt;</span></span> products<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Invite.aspx&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Invite <span class="sc3"><span class="re1">&lt;fb:name</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span> <span class="re0">firstnameonly</span>=<span class="st0">&quot;true&quot;</span> <span class="re2">/&gt;</span></span> to MyApp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:if-is-app-user<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:else<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/fb:if-is-own-profile<span class="re2">&gt;</span></span></span><br />
<br />
<span class="sc3"><span class="re1">&lt;asp:XmlDataSource</span> <span class="re0">runat</span>=<span class="st0">&quot;server&quot;</span> <span class="re0">ID</span>=<span class="st0">&quot;xdsCountries&quot;</span><br />
&nbsp; &nbsp; <span class="re0">DataFile</span>=<span class="st0">&quot;~/App_Data/CountryCodeList.xml&quot;</span> <span class="re2">/&gt;</span></span><br />
<br />
<span class="sc3"><span class="re1">&lt;fb:wide<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;asp:Repeater</span> <span class="re0">runat</span>=<span class="st0">&quot;server&quot;</span> <span class="re0">DataSourceID</span>=<span class="st0">&quot;xdsCountries&quot;</span> <span class="re0">ID</span>=<span class="st0">&quot;rptCountriesWide&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;ItemTemplate<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;div<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;</span>%# XPath<span class="br0">&#40;</span><span class="st0">&quot;CountryCoded&quot;</span><span class="br0">&#41;</span> %<span class="re2">&gt;</span></span> - <span class="sc3"><span class="re1">&lt;</span>%# XPath<span class="br0">&#40;</span><span class="st0">&quot;CountryName&quot;</span><span class="br0">&#41;</span> %<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/ItemTemplate<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/asp:Repeater<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/fb:wide<span class="re2">&gt;</span></span></span><br />
<br />
<span class="sc3"><span class="re1">&lt;fb:narrow<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;asp:Repeater</span> <span class="re0">runat</span>=<span class="st0">&quot;server&quot;</span> <span class="re0">DataSourceID</span>=<span class="st0">&quot;xdsCountries&quot;</span> <span class="re0">ID</span>=<span class="st0">&quot;rptCountriesNarrow&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;ItemTemplate<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;div<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;</span>%# XPath<span class="br0">&#40;</span><span class="st0">&quot;CountryCoded&quot;</span><span class="br0">&#41;</span> %<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/ItemTemplate<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/asp:Repeater<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/fb:narrow<span class="re2">&gt;</span></span></span></div></div>
<p>How to get string to put it into the <tt>profile.setFBML</tt>? Here is the code:</p>
<div class="codecolorer-container c#"><div class="codecolorer" style="font-family: monospace;">StringBuilder sb = new StringBuilder<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
StringWriter tw = new StringWriter<span class="br0">&#40;</span>sb<span class="br0">&#41;</span>;<br />
HtmlTextWriter hw = new HtmlTextWriter<span class="br0">&#40;</span>tw<span class="br0">&#41;</span>;<br />
Control c = LoadControl<span class="br0">&#40;</span><span class="st0">&quot;~/ProfileFBML.ascx&quot;</span><span class="br0">&#41;</span>;<br />
Controls.<span class="me1">Add</span><span class="br0">&#40;</span>c<span class="br0">&#41;</span>;<br />
c.<span class="me1">RenderControl</span><span class="br0">&#40;</span>hw<span class="br0">&#41;</span>;<br />
Controls.<span class="me1">Remove</span><span class="br0">&#40;</span>c<span class="br0">&#41;</span>;<br />
<span class="kw4">string</span> fbml = sb.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div></div>
<p>I&#8217;ve added control to the <tt>Controls</tt> collection to get events fired. If you would call this snippet from <tt>OnLoad</tt>, only <tt>OnInit</tt> would be fired in <tt>ProfileFBML</tt>, so do not forget to call <tt>DataBind</tt> method to force data binding from <tt>OnInit</tt> in this case.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=mrLkhwSt"><img src="http://feeds.feedburner.com/~f/kpumuk?i=mrLkhwSt" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=7wLHAbiF"><img src="http://feeds.feedburner.com/~f/kpumuk?i=7wLHAbiF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=4jLrzEe0"><img src="http://feeds.feedburner.com/~f/kpumuk?i=4jLrzEe0" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=cWHfCiD"><img src="http://feeds.feedburner.com/~f/kpumuk?i=cWHfCiD" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/156141272" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/</feedburner:origLink></item>
		<item>
		<title>Synchronous page method call in ASP.NET AJAX library</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/154729705/</link>
		<comments>http://kpumuk.info/asp-net/synchronous-page-method-call-in-asp-net-ajax-library/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 20:15:28 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[AJAX]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[asp.net-ajax]]></category>

		<category><![CDATA[Synchronous]]></category>

		<guid isPermaLink="false">http://kpumuk.info/asp-net/synchronous-page-method-call-in-asp-net-ajax-library/</guid>
		<description><![CDATA[Sometimes we need to do some tasks, that libraries developers even have not foreseen. One of such cases is to make synchronous AJAX call (Asynchronous JavaScript And XML). Below you could find quick solution.

Please note: my solution is just copy/past of the XmlHttpExecutor code with two small changes:

I have passed false as third parameter of [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we need to do some tasks, that libraries developers even have not foreseen. One of such cases is to make synchronous AJAX call (Asynchronous JavaScript And XML). Below you could find quick solution.</p>
<p><span id="more-178"></span></p>
<p>Please note: my solution is just copy/past of the <a href="http://asp.net/ajax/documentation/live/clientreference/Sys.Net/XmlHttpExecutorClass/default.aspx" onclick="javascript:pageTracker._trackPageview ('/outbound/asp.net');">XmlHttpExecutor</a> code with two small changes:</p>
<ul>
<li>I have passed <tt>false</tt> as third parameter of the <tt>XMLHttpRequest.open</tt> method to make synchronous call.</li>
<li>I have cached request results in <tt>XMLHttpSyncExecutor</tt> members before freeing <tt>XMLHttpRequest</tt> in the <tt>_onReadyStateChange</tt> function.</li>
</ul>
<p>So let&#8217;s get started. First of all we would define <tt>XMLHttpSyncExecutor</tt> class, descendant of the <a href="http://asp.net/ajax/documentation/live/clientreference/Sys.Net/WebRequestExecutorClass/default.aspx" onclick="javascript:pageTracker._trackPageview ('/outbound/asp.net');">WebRequestExecutor</a>.</p>
<div class="codecolorer-container javascript" style="height:280px;"><div class="codecolorer" style="font-family: monospace;">Type.<span class="me1">registerNamespace</span><span class="br0">&#40;</span><span class="st0">'Sys.Net'</span><span class="br0">&#41;</span>;<br />
<br />
Sys.<span class="me1">Net</span>.<span class="me1">XMLHttpSyncExecutor</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; Sys.<span class="me1">Net</span>.<span class="me1">XMLHttpSyncExecutor</span>.<span class="me1">initializeBase</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw2">var</span> _this = <span class="kw1">this</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._webRequest = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._responseAvailable = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._timedOut = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._timer = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._aborted = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._started = <span class="kw2">false</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw1">this</span>._responseData = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._statusCode = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._statusText = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._headers = <span class="kw2">null</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw1">this</span>._onReadyStateChange = <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>_this._xmlHttpRequest.<span class="me1">readyState</span> === <span class="nu0">4</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._clearTimer<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._responseAvailable = <span class="kw2">true</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._responseData = _this._xmlHttpRequest.<span class="me1">responseText</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._statusCode = _this._xmlHttpRequest.<span class="kw3">status</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._statusText = _this._xmlHttpRequest.<span class="me1">statusText</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._headers = _this._xmlHttpRequest.<span class="me1">getAllResponseHeaders</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._webRequest.<span class="me1">completed</span><span class="br0">&#40;</span>Sys.<span class="me1">EventArgs</span>.<span class="me1">Empty</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>_this._xmlHttpRequest != <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._xmlHttpRequest.<span class="me1">onreadystatechange</span> = <span class="kw2">Function</span>.<span class="me1">emptyMethod</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._xmlHttpRequest = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">this</span>._clearTimer = <span class="kw2">function</span> <span class="kw1">this</span>$_clearTimer<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>_this._timer != <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span class="me1">clearTimeout</span><span class="br0">&#40;</span>_this._timer<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._timer = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">this</span>._onTimeout = <span class="kw2">function</span> <span class="kw1">this</span>$_onTimeout<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!_this._responseAvailable<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._clearTimer<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._timedOut = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._xmlHttpRequest.<span class="me1">onreadystatechange</span> = <span class="kw2">Function</span>.<span class="me1">emptyMethod</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._xmlHttpRequest.<span class="me1">abort</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._webRequest.<span class="me1">completed</span><span class="br0">&#40;</span>Sys.<span class="me1">EventArgs</span>.<span class="me1">Empty</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this._xmlHttpRequest = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>This is very simple and clean, so I&#8217;ll just show you other methods of the <tt>XMLHttpSyncExecutor</tt>.</p>
<div class="codecolorer-container javascript" style="height:280px;"><div class="codecolorer" style="font-family: monospace;"><span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$get_timedOut<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;value type=&quot;Boolean&quot;&gt;&lt;/value&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>._timedOut;<br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$get_started<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;value type=&quot;Boolean&quot;&gt;&lt;/value&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>._started;<br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$get_responseAvailable<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;value type=&quot;Boolean&quot;&gt;&lt;/value&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>._responseAvailable;<br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$get_aborted<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;value type=&quot;Boolean&quot;&gt;&lt;/value&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>._aborted;<br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$executeRequest<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._webRequest = <span class="kw1">this</span>.<span class="me1">get_webRequest</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">this</span>._started<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> Error.<span class="me1">invalidOperation</span><span class="br0">&#40;</span>String.<span class="me1">format</span><span class="br0">&#40;</span>Sys.<span class="me1">Res</span>.<span class="me1">cannotCallOnceStarted</span>, <span class="st0">'executeRequest'</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">this</span>._webRequest === <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> Error.<span class="me1">invalidOperation</span><span class="br0">&#40;</span>Sys.<span class="me1">Res</span>.<span class="me1">nullWebRequest</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw2">var</span> body = <span class="kw1">this</span>._webRequest.<span class="me1">get_body</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw2">var</span> headers = <span class="kw1">this</span>._webRequest.<span class="me1">get_headers</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest = <span class="kw2">new</span> XMLHttpRequest<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest.<span class="me1">onreadystatechange</span> = <span class="kw1">this</span>._onReadyStateChange;<br />
&nbsp; &nbsp; <span class="kw2">var</span> verb = <span class="kw1">this</span>._webRequest.<span class="me1">get_httpVerb</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest.<span class="kw3">open</span><span class="br0">&#40;</span>verb, <span class="kw1">this</span>._webRequest.<span class="me1">getResolvedUrl</span><span class="br0">&#40;</span><span class="br0">&#41;</span>, <span class="kw2">false</span><span class="br0">&#41;</span>; <span class="co1">// False to call Synchronously</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>headers<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> header <span class="kw1">in</span> headers<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> val = headers<span class="br0">&#91;</span>header<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">typeof</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span> !== <span class="st0">&quot;function&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest.<span class="me1">setRequestHeader</span><span class="br0">&#40;</span>header, val<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>verb.<span class="me1">toLowerCase</span><span class="br0">&#40;</span><span class="br0">&#41;</span> === <span class="st0">&quot;post&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>headers === <span class="kw2">null</span><span class="br0">&#41;</span> || !headers<span class="br0">&#91;</span><span class="st0">'Content-Type'</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest.<span class="me1">setRequestHeader</span><span class="br0">&#40;</span><span class="st0">'Content-Type'</span>, <span class="st0">'application/x-www-form-urlencoded'</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!body<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body = <span class="st0">&quot;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw2">var</span> timeout = <span class="kw1">this</span>._webRequest.<span class="me1">get_timeout</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>timeout &gt; <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>._timer = window.<span class="me1">setTimeout</span><span class="br0">&#40;</span><span class="kw2">Function</span>.<span class="me1">createDelegate</span><span class="br0">&#40;</span><span class="kw1">this</span>, <span class="kw1">this</span>._onTimeout<span class="br0">&#41;</span>, timeout<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest.<span class="me1">send</span><span class="br0">&#40;</span>body<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">this</span>._started = <span class="kw2">true</span>;<br />
<span class="br0">&#125;</span><br />
<br />
&nbsp;<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$getAllResponseHeaders<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;returns type=&quot;String&quot;&gt;&lt;/returns&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="kw1">this</span>._responseAvailable<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> Error.<span class="me1">invalidOperation</span><span class="br0">&#40;</span>String.<span class="me1">format</span><span class="br0">&#40;</span>Sys.<span class="me1">Res</span>.<span class="me1">cannotCallBeforeResponse</span>, <span class="st0">'getAllResponseHeaders'</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>._headers;<br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$get_responseData<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;value type=&quot;String&quot;&gt;&lt;/value&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="kw1">this</span>._responseAvailable<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> Error.<span class="me1">invalidOperation</span><span class="br0">&#40;</span>String.<span class="me1">format</span><span class="br0">&#40;</span>Sys.<span class="me1">Res</span>.<span class="me1">cannotCallBeforeResponse</span>, <span class="st0">'get_responseData'</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>._responseData;<br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$get_statusCode<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;value type=&quot;Number&quot;&gt;&lt;/value&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="kw1">this</span>._responseAvailable<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> Error.<span class="me1">invalidOperation</span><span class="br0">&#40;</span>String.<span class="me1">format</span><span class="br0">&#40;</span>Sys.<span class="me1">Res</span>.<span class="me1">cannotCallBeforeResponse</span>, <span class="st0">'get_statusCode'</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>._statusCode;<br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$get_statusText<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;value type=&quot;String&quot;&gt;&lt;/value&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="kw1">this</span>._responseAvailable<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> Error.<span class="me1">invalidOperation</span><span class="br0">&#40;</span>String.<span class="me1">format</span><span class="br0">&#40;</span>Sys.<span class="me1">Res</span>.<span class="me1">cannotCallBeforeResponse</span>, <span class="st0">'get_statusText'</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>._statusText;<br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$get_xml<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;value&gt;&lt;/value&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="kw1">this</span>._responseAvailable<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> Error.<span class="me1">invalidOperation</span><span class="br0">&#40;</span>String.<span class="me1">format</span><span class="br0">&#40;</span>Sys.<span class="me1">Res</span>.<span class="me1">cannotCallBeforeResponse</span>, <span class="st0">'get_xml'</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw2">var</span> xml = <span class="kw1">this</span>._responseData;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>!xml<span class="br0">&#41;</span> || <span class="br0">&#40;</span>!xml.<span class="me1">documentElement</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xml = <span class="kw2">new</span> XMLDOM<span class="br0">&#40;</span><span class="kw1">this</span>._responseData<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>!xml<span class="br0">&#41;</span> || <span class="br0">&#40;</span>!xml.<span class="me1">documentElement</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>navigator.<span class="me1">userAgent</span>.<span class="me1">indexOf</span><span class="br0">&#40;</span><span class="st0">'MSIE'</span><span class="br0">&#41;</span> !== <span class="nu0">-1</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xml.<span class="me1">setProperty</span><span class="br0">&#40;</span><span class="st0">'SelectionLanguage'</span>, <span class="st0">'XPath'</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>xml.<span class="me1">documentElement</span>.<span class="me1">namespaceURI</span> === <span class="st0">&quot;http://www.mozilla.org/newlayout/xml/parsererror.xml&quot;</span><span class="br0">&#41;</span> &amp;&amp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>xml.<span class="me1">documentElement</span>.<span class="me1">tagName</span> === <span class="st0">&quot;parsererror&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>xml.<span class="me1">documentElement</span>.<span class="me1">firstChild</span> &amp;&amp; xml.<span class="me1">documentElement</span>.<span class="me1">firstChild</span>.<span class="me1">tagName</span> === <span class="st0">&quot;parsererror&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">return</span> xml;<br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">function</span> Sys$Net$XMLHttpSyncExecutor$abort<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>arguments.<span class="me1">length</span> !== <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">throw</span> Error.<span class="me1">parameterCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="kw1">this</span>._started<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> Error.<span class="me1">invalidOperation</span><span class="br0">&#40;</span>Sys.<span class="me1">Res</span>.<span class="me1">cannotAbortBeforeStart</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">this</span>._aborted || <span class="kw1">this</span>._responseAvailable || <span class="kw1">this</span>._timedOut<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw1">this</span>._aborted = <span class="kw2">true</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw1">this</span>._clearTimer<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">this</span>._xmlHttpRequest &amp;&amp; !<span class="kw1">this</span>._responseAvailable<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest.<span class="me1">onreadystatechange</span> = <span class="kw2">Function</span>.<span class="me1">emptyMethod</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest.<span class="me1">abort</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>._xmlHttpRequest = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> handler = <span class="kw1">this</span>._webRequest._get_eventHandlerList<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getHandler</span><span class="br0">&#40;</span><span class="st0">&quot;completed&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>handler<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler<span class="br0">&#40;</span><span class="kw1">this</span>, Sys.<span class="me1">EventArgs</span>.<span class="me1">Empty</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<br />
Sys.<span class="me1">Net</span>.<span class="me1">XMLHttpSyncExecutor</span>.<span class="me1">prototype</span> = <span class="br0">&#123;</span><br />
&nbsp; &nbsp; get_timedOut: Sys$Net$XMLHttpSyncExecutor$get_timedOut,<br />
&nbsp; &nbsp; get_started: Sys$Net$XMLHttpSyncExecutor$get_started,<br />
&nbsp; &nbsp; get_responseAvailable: Sys$Net$XMLHttpSyncExecutor$get_responseAvailable,<br />
&nbsp; &nbsp; get_aborted: Sys$Net$XMLHttpSyncExecutor$get_aborted,<br />
&nbsp; &nbsp; executeRequest: Sys$Net$XMLHttpSyncExecutor$executeRequest,<br />
&nbsp; &nbsp; getAllResponseHeaders: Sys$Net$XMLHttpSyncExecutor$getAllResponseHeaders,<br />
&nbsp; &nbsp; get_responseData: Sys$Net$XMLHttpSyncExecutor$get_responseData,<br />
&nbsp; &nbsp; get_statusCode: Sys$Net$XMLHttpSyncExecutor$get_statusCode,<br />
&nbsp; &nbsp; get_statusText: Sys$Net$XMLHttpSyncExecutor$get_statusText,<br />
&nbsp; &nbsp; get_xml: Sys$Net$XMLHttpSyncExecutor$get_xml,<br />
&nbsp; &nbsp; abort: Sys$Net$XMLHttpSyncExecutor$abort<br />
<span class="br0">&#125;</span><br />
Sys.<span class="me1">Net</span>.<span class="me1">XMLHttpSyncExecutor</span>.<span class="me1">registerClass</span><span class="br0">&#40;</span><span class="st0">'Sys.Net.XMLHttpSyncExecutor'</span>, Sys.<span class="me1">Net</span>.<span class="me1">WebRequestExecutor</span><span class="br0">&#41;</span>;</div></div>
<p>And finally we will notify ASP.NET AJAX that script have been loaded.</p>
<div class="codecolorer-container javascript"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">typeof</span><span class="br0">&#40;</span>Sys<span class="br0">&#41;</span> != <span class="st0">'undefined'</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; Sys.<span class="me1">Application</span>.<span class="me1">notifyScriptLoaded</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div></div>
<p>Usage is not so simple as wanted, but it&#8217;s still quite easy to understand:</p>
<div class="codecolorer-container javascript"><div class="codecolorer" style="font-family: monospace;"><span class="kw2">function</span> getServerTime<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">// Instantiate a WebRequest.</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> wRequest = <span class="kw2">new</span> Sys.<span class="me1">Net</span>.<span class="me1">WebRequest</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="co1">// Set the request URL.</span><br />
&nbsp; &nbsp; wRequest.<span class="me1">set_url</span><span class="br0">&#40;</span>PageMethods.<span class="me1">get_path</span><span class="br0">&#40;</span><span class="br0">&#41;</span> + <span class="st0">&quot;/GetServerTime&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="co1">// Set the request verb.</span><br />
&nbsp; &nbsp; wRequest.<span class="me1">set_httpVerb</span><span class="br0">&#40;</span><span class="st0">'POST'</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; wRequest.<span class="me1">get_headers</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="st0">'Content-Type'</span><span class="br0">&#93;</span> = <span class="st0">'application/json; charset=utf-8'</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw2">var</span> executor = <span class="kw2">new</span> Sys.<span class="me1">Net</span>.<span class="me1">XMLHttpSyncExecutor</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; wRequest.<span class="me1">set_executor</span><span class="br0">&#40;</span>executor<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="co1">// Execute the request.</span><br />
&nbsp; &nbsp; wRequest.<span class="me1">invoke</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>executor.<span class="me1">get_responseAvailable</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> executor.<span class="me1">get_object</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;<br />
<span class="br0">&#125;</span></div></div>
<p>When you are using <tt>ScriptService</tt>, you will not see these difficulties, because ASP.NET will generate wrappers by itself. But if you need synchronous AJAX call &#8212; sorry, but in this case you should do it manually. Sample solution could be found <a href="http://kpumuk.info/wp-content/uploads/2007/09/xmlhttpsyncexecutor.zip" title='XMLHttpSyncExecutor example'>here</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=zkLKWz98"><img src="http://feeds.feedburner.com/~f/kpumuk?i=zkLKWz98" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=2tg3UOOY"><img src="http://feeds.feedburner.com/~f/kpumuk?i=2tg3UOOY" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=1D4Qb8Zf"><img src="http://feeds.feedburner.com/~f/kpumuk?i=1D4Qb8Zf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=f0pFOZD"><img src="http://feeds.feedburner.com/~f/kpumuk?i=f0pFOZD" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/154729705" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/asp-net/synchronous-page-method-call-in-asp-net-ajax-library/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/asp-net/synchronous-page-method-call-in-asp-net-ajax-library/</feedburner:origLink></item>
		<item>
		<title>Human computations</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/150969116/</link>
		<comments>http://kpumuk.info/internet/human-computations/#comments</comments>
		<pubDate>Sat, 01 Sep 2007 16:12:22 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[artificial-intelligence]]></category>

		<category><![CDATA[captcha]]></category>

		<category><![CDATA[classification]]></category>

		<category><![CDATA[computations]]></category>

		<category><![CDATA[games]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[human-resources]]></category>

		<category><![CDATA[image-search]]></category>

		<category><![CDATA[object-detection]]></category>

		<guid isPermaLink="false">http://kpumuk.info/internet/human-computations/</guid>
		<description><![CDATA[Very cool video about free human resources usage I have found the other day. As you could see from my resume, I&#8217;m graduated from the Intelligent Decision Support Systems Department of the Kharkov National University of Radio-Electronics. I don&#8217;t remember too much from my courses (but I know where and what to search when some [...]]]></description>
			<content:encoded><![CDATA[<p>Very cool video about free human resources usage I have found the other day. As you could see from my <a href="http://kpumuk.info/curriculum-vitae/">resume</a>, I&#8217;m graduated from the Intelligent Decision Support Systems Department of the Kharkov National University of Radio-Electronics. I don&#8217;t remember too much from my courses (but I know where and what to search when some sort of knowledge will be necessary, be sure), but what had stuck in my memory is that there are tons of tasks which can&#8217;t be easily solved: images classification, object detection, automatic expert systems knowledge bases building, etc. Some of these tasks are partially solved and have satisfactory results (for example mathematical and statistical methods of objects detection), others have bypassing methods (for example, Google uses text from HTML links to classify images). The main reason is that computers are not so smart as humans (maybe it&#8217;s not so bad, just think of the &#8220;The Matrix&#8221; movie).</p>
<p><span id="more-177"></span></p>
<p>So, little more about the video. Luis von Ahn, an assistant professor in the Computer Science Department at Carnegie Mellon University, explains idea of how to use resources of millions people absolutely free, and get results unachievable by today&#8217;s high end computers. He is very smart, and I took a delight in watching his performance (yeah, performance, because his jokes were no worse than jokes of the best comic actors I&#8217;ve seen). I strongly recommend you to watch it, even if you hate artificial intelligence.</p>
<p>Here is an abstract:</p>
<blockquote><div>
Tasks like image recognition are trivial for humans, but continue to challenge even the most sophisticated computer programs. This talk introduces a paradigm for utilizing human processing power to solve problems that computers cannot yet solve. Traditional approaches to solving such problems focus on improving software. I advocate a novel approach: constructively channel human brainpower using computer games. For example, the ESP Game, described in this talk, is an enjoyable online game &#8212; many people play over 40 hours a week &#8212; and when people play, they help label images on the Web with descriptive keywords. These keywords can be used to significantly improve the accuracy of image search. People play the game not because they want to help, but because they enjoy it.</p>
<p>I describe other examples of &#8220;games with a purpose&#8221;: Peekaboom, which helps determine the location of objects in images, and Verbosity, which collects common-sense knowledge. I also explain a general approach for constructing games with a purpose.
</p></div>
</blockquote>
<p>And the video itself:</p>
<p><embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-8246463980976635143&#038;hl=en" flashvars="&#038;subtitle=on"> </embed></p>
<p>Stop playing solitaire! Help Google to grab the World!</p>
<p>BTW, &#8220;Peekaboom&#8221; is consonant to my current project name. No, I&#8217;m not developing another clone of the &#8220;game with a purpose&#8221;. No, I won&#8217;t tell you what the project is, at least now. Have other questions?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=6Awx99EM"><img src="http://feeds.feedburner.com/~f/kpumuk?i=6Awx99EM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=Lc8uToDG"><img src="http://feeds.feedburner.com/~f/kpumuk?i=Lc8uToDG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=KpfwLEKl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=KpfwLEKl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=UJsjTsD"><img src="http://feeds.feedburner.com/~f/kpumuk?i=UJsjTsD" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/150969116" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/internet/human-computations/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/internet/human-computations/</feedburner:origLink></item>
	</channel>
</rss>
