<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Calisto Mind</title>
	<atom:link href="http://www.calistomind.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.calistomind.com</link>
	<description></description>
	<pubDate>Thu, 26 Jun 2008 03:54:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>ASP.NET Inline Tags</title>
		<link>http://www.calistomind.com/2008/06/25/aspnet-inline-tags/</link>
		<comments>http://www.calistomind.com/2008/06/25/aspnet-inline-tags/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 03:54:18 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/?p=92</guid>
		<description><![CDATA[There are all sorts of different inline tags, and I haven&#8217;t found a place that explains them all in one place, so here is the quick and dirty&#8230;
&#60;% &#8230; %&#62;
The most basic inline tag, basically runs normal code:
&#60;% if (User.IsInRole(&#8221;admin&#8221;)) { %&#62;
You can see this
&#60;% } else { %&#62;
You are no admin fool!
&#60;%} %&#62;
http://msdn2.microsoft.com/en-us/library/ms178135(vs.80).aspx
&#60;%= &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>There are all sorts of different inline tags, and I haven&#8217;t found a place that explains them all in one place, so here is the quick and dirty&#8230;</p>
<h1 style="text-align: center;">&lt;% &#8230; %&gt;</h1>
<p>The most basic inline tag, basically runs normal code:</p>
<blockquote><p>&lt;% if (User.IsInRole(&#8221;admin&#8221;)) { %&gt;<br />
You can see this<br />
&lt;% } else { %&gt;<br />
You are no admin fool!<br />
&lt;%} %&gt;</p></blockquote>
<p><a href="http://msdn2.microsoft.com/en-us/library/ms178135%28vs.80%29.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/ms178135(vs.80).aspx</a></p>
<h1 style="text-align: center;">&lt;%= &#8230; %&gt;</h1>
<p>Used for small chunks of information, usually from objects and single pieces of information like a single string or int variable:</p>
<blockquote><p>The Date is now &lt;%= DateTime.Now.ToShortDateString() %&gt;<br />
The value of string1 is &lt;%= string1 %&gt;</p></blockquote>
<p><a href="http://msdn2.microsoft.com/en-us/library/6dwsdcf5%28VS.71%29.aspx">http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx</a></p>
<p>*note: &lt;%= is the equivalent of Response.Write() -  Courtesy of Adam from the US,thanks!</p>
<h1 style="text-align: center;">&lt;%# .. %&gt;</h1>
<p>Used for Binding Expressions; such as Eval and Bind, most often found in data controls like GridView, Repeater, etc.:</p>
<blockquote><p>&lt;asp:Repeater ID=&#8221;rptMeetings&#8221; DataSourceID=&#8221;meetings&#8221; runat=&#8221;server&#8221;&gt;<br />
&lt;ItemTemplate&gt;<br />
&lt;%# Eval(&#8221;MeetingName&#8221;) %&gt;<br />
&lt;/ItemTemplate&gt;<br />
&lt;/asp:Repeater&gt;</p></blockquote>
<p><a href="http://msdn2.microsoft.com/en-us/library/ms178366.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/ms178366.aspx</a></p>
<h1 style="text-align: center;">&lt;%$ &#8230; %&gt;</h1>
<p>Used for expressions, not code; often seen with DataSources:</p>
<blockquote><p>&lt;asp:SqlDataSource ID=&#8221;party&#8221; runat=&#8221;server&#8221; ConnectionString=&#8221;&lt;%$ ConnectionStrings:letsParty %&gt;&#8221; SelectCommand=&#8221;SELECT * FROM [table]&#8221; /&gt;</p></blockquote>
<p><a href="http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx</a></p>
<h1 style="text-align: center;">&lt;%@ &#8230; %&gt;</h1>
<p>This is for directive syntax; basically the stuff you see at the top your your aspx pages like control registration and page declaration:</p>
<blockquote><p>&lt;%@ Page Language=&#8221;C#&#8221; MasterPageFile=&#8221;~/MasterPage.master&#8221; AutoEventWireup=&#8221;true&#8221; CodeFile=&#8221;Default.aspx.cs&#8221; Inherits=&#8221;_Default&#8221; Title=&#8221;Untitled Page&#8221; %&gt;<br />
&lt;%@ Register TagPrefix=&#8221;wp&#8221; Namespace=&#8221;CustomWebParts&#8221; %&gt;</p></blockquote>
<p><a href="http://msdn2.microsoft.com/en-us/library/xz702w3e%28VS.80%29.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx</a></p>
<h1 style="text-align: center;">&lt;%&#8211; &#8230; &#8211;%&gt;</h1>
<p>This is a server side comment, stuff  you don&#8217;t want anyone without code access to see:</p>
<blockquote><p>&lt;asp:Label ID=&#8221;lblAwesome&#8221; runat=&#8221;server&#8221; /&gt;<br />
&lt;%&#8211; sometimes end users make me angry &#8211;%&gt;<br />
&lt;asp:LinkButton ID=&#8221;lbEdit&#8221; Text=&#8221;Edit&#8221; OnClick=&#8221;Edit_Click&#8221; runat=&#8221;server&#8221; /&gt;</p></blockquote>
<p><a href="http://msdn2.microsoft.com/en-us/library/4acf8afk.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/4acf8afk.aspx</a></p>
<p>And that&#8217;s that.</p>
<p>Source: <a href="http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx" target="_blank">Naspinski</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/06/25/aspnet-inline-tags/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to easily parse HTML without RegEx</title>
		<link>http://www.calistomind.com/2008/05/06/how-to-easily-parse-html-without-regex/</link>
		<comments>http://www.calistomind.com/2008/05/06/how-to-easily-parse-html-without-regex/#comments</comments>
		<pubDate>Tue, 06 May 2008 16:50:04 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/?p=91</guid>
		<description><![CDATA[I recently discovered an absolutely amazing HTML parsing library for .NET called HtmlAgilityPack. It completely takes away the pain of parsing complicated HTML with regular expressions.
Here&#8217;s a very simple example of what you could do with it - I&#8217;m just extracting inner HTML from any element inside a HTML file which has a css class [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered an absolutely amazing HTML parsing library for .NET called <a href="http://www.codeplex.com/htmlagilitypack" target="_blank">HtmlAgilityPack</a>. It completely takes away the pain of parsing complicated HTML with regular expressions.</p>
<p>Here&#8217;s a very simple example of what you could do with it - I&#8217;m just extracting inner HTML from any element inside a HTML file which has a css class called &#8220;scrape&#8221; assigned to it:<br />
<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">using</span> HtmlAgilityPack;

<span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> _Default : System.Web.UI.Page
{
    <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
    {
        HtmlDocument doc = <span class="kwrd">new</span> HtmlDocument();
        doc.Load(Server.MapPath(filePath));
        Parse(doc.DocumentNode);
    }
    <span class="kwrd">private</span> <span class="kwrd">void</span> Parse(HtmlNode n)
    {
        <span class="kwrd">foreach</span> (HtmlAttribute atr <span class="kwrd">in</span> n.Attributes)
        {
            <span class="kwrd">if</span> (atr.Name == <span class="str">&#8220;class&#8221;</span> &amp;&amp; atr.Value == <span class="str">&#8220;scrape&#8221;</span>)
            {
                Response.Write(n.InnerHtml);
            }
        }

        <span class="kwrd">if</span> (n.HasChildNodes)
        {
            <span class="kwrd">foreach</span> (HtmlNode cn <span class="kwrd">in</span> n.ChildNodes)
            {
                Parse(cn);
            }
        }
    }
}
</pre>
<p>
That&#8217;s just a very small part of what it could do. I&#8217;ll expand upon this and post a few more examples in the future showing some interesting things you could do with this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/05/06/how-to-easily-parse-html-without-regex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How To Create A Random Fact Generator Using XML</title>
		<link>http://www.calistomind.com/2008/04/23/how-to-create-a-random-fact-generator-using-xml/</link>
		<comments>http://www.calistomind.com/2008/04/23/how-to-create-a-random-fact-generator-using-xml/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 00:03:19 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/?p=90</guid>
		<description><![CDATA[This is a simple little random fact generator which will show a new fact every time the page loads. After the initial load it will store the XML in the cache until the file is changed again.
XML: (Facts.xml)


&#60;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243; ?&#62;
&#60;facts&#62;
  &#60;fact&#62;
    The numbers &#8216;172&#8242; can be found on the back [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple little random fact generator which will show a new fact every time the page loads. After the initial load it will store the XML in the cache until the file is changed again.</p>
<p><b>XML: (Facts.xml)</b></p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">=&#8221;1.0&#8243;</span> <span class="attr">encoding</span><span class="kwrd">=&#8221;utf-8&#8243;</span> ?<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">facts</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">fact</span><span class="kwrd">&gt;</span>
    The numbers &#8216;172&#8242; can be found on the back of the U.S. $5 dollar
    bill in the bushes at the base of the Lincoln Memorial.
  <span class="kwrd">&lt;/</span><span class="html">fact</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">fact</span><span class="kwrd">&gt;</span>
    President Kennedy was the fastest random speaker in the world
    with upwards of 350 words per minute.
  <span class="kwrd">&lt;/</span><span class="html">fact</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">fact</span><span class="kwrd">&gt;</span>
    In the average lifetime, a person will walk the equivalent of 5
    times around the equator.
  <span class="kwrd">&lt;/</span><span class="html">fact</span><span class="kwrd">&gt;</span>
    .
    .
    .
<span class="kwrd">&lt;/</span><span class="html">facts</span><span class="kwrd">&gt;</span></pre>
<p><b>Code: (RandomFact.ascx.cs)</b></p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">using</span> System;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Data;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Configuration;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Collections;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.Caching;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.Security;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.UI;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.UI.WebControls;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.UI.WebControls.WebParts;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.UI.HtmlControls;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Xml;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.IO;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.ComponentModel;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Drawing.Design;
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_controls_RandomFact</span> : System.Web.UI.<span style="color: #2b91af;">UserControl</span>
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: blue;">string</span> _xmlDataSource;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">UrlProperty</span>()]
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">string</span> XMLDataSource
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">get</span> { <span style="color: blue;">return</span> _xmlDataSource; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">set</span> { _xmlDataSource = <span style="color: blue;">value</span>; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; litFact.Text = getRandomFact();
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: blue;">string</span> getRandomFact()
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Random</span> rndIndex = <span style="color: blue;">new</span> <span style="color: #2b91af;">Random</span>();
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">XmlDocument</span> xmlDocFacts = <span style="color: blue;">new</span> <span style="color: #2b91af;">XmlDocument</span>();
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">string</span> strFact = <span style="color: blue;">string</span>.Empty;
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">try</span>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (Cache[<span style="color: #a31515;">&#8220;xmlDocFacts&#8221;</span>] != <span style="color: blue;">null</span>)
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xmlDocFacts = (<span style="color: #2b91af;">XmlDocument</span>)Cache[<span style="color: #a31515;">&#8220;xmlDocFacts&#8221;</span>];
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xmlDocFacts.Load(Server.MapPath(XMLDataSource));
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Cache.Insert(<span style="color: #a31515;">&#8220;xmlDocFacts&#8221;</span>, xmlDocFacts, <span style="color: blue;">new</span> <span style="color: #2b91af;">CacheDependency</span>(Server.MapPath(XMLDataSource)));
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">XmlNodeList</span> xmlNodesMessage = xmlDocFacts.SelectNodes(<span style="color: #a31515;">&#8220;//fact&#8221;</span>);
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">int</span> rnd = rndIndex.Next(0, xmlNodesMessage.Count);
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; strFact = Server.HtmlEncode(xmlNodesMessage[rnd].InnerText);
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; strFact = <span style="color: blue;">string</span>.Format(<span style="color: #a31515;">&#8220;&lt;b&gt;Error:&lt;/b&gt; {0}&#8221;</span>, ex.Message);
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> strFact;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">}
</div>
</pre>
<p><b>Usage: (Default.aspx)</b><br />
<br/></p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">uc1</span><span style="color: blue;">:</span><span style="color: #a31515;">RandomFact</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;RandomFact1&#8243;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">XMLDataSource</span><span style="color: blue;">=&#8221;App_Data/Facts.xml&#8221;</span> <span style="color: blue;">/&gt;</span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/04/23/how-to-create-a-random-fact-generator-using-xml/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to manipulate video in .NET using ffmpeg (updated)</title>
		<link>http://www.calistomind.com/2008/04/22/how-to-manipulate-video-in-net-using-ffmpeg-updated/</link>
		<comments>http://www.calistomind.com/2008/04/22/how-to-manipulate-video-in-net-using-ffmpeg-updated/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 18:25:55 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/?p=86</guid>
		<description><![CDATA[Based on the reader comments on my previous entry on this topic I was able to fix some of the issues that others were experiencing.
I changed how the output is read, instead of reading the entire stream at once, its now read line-by-line as ErrorDataReceived and OutputDataReceived events are raised. Also added an extra option [...]]]></description>
			<content:encoded><![CDATA[<p>Based on the reader comments on my <a href="http://www.calistomind.com/2008/03/12/how-to-manipulate-video-in-net-using-ffmpeg/">previous entry</a> on this topic I was able to fix some of the issues that others were experiencing.</p>
<p>I changed how the output is read, instead of reading the entire stream at once, its now read line-by-line as ErrorDataReceived and OutputDataReceived events are raised. Also added an extra option in the command line (-ar 44100) to explicitly set the audio frequency to default since it wasn&#8217;t being applied to some video formats resulting in an error. And lastly, the console window is now set as hidden.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">private</span> <span class="kwrd">void</span> ConvertVideo(<span class="kwrd">string</span> srcURL, <span class="kwrd">string</span> destURL)
{
    <span class="kwrd">string</span> ffmpegURL = “~/project/tools/ffmpeg.exe”;
    DirectoryInfo directoryInfo = <span class="kwrd">new</span> DirectoryInfo(Path.GetDirectoryName(Server.MapPath(ffmpegURL)));

    ProcessStartInfo startInfo = <span class="kwrd">new</span> ProcessStartInfo();
    startInfo.FileName = Server.MapPath(ffmpegURL);
    startInfo.Arguments = <span class="kwrd">string</span>.Format(“-i \”{0}\” -aspect 1.7777 -ar 44100 -f flv \”{1}\”&#8221;, srcURL, destURL);
    startInfo.WorkingDirectory = directoryInfo.FullName;
    startInfo.UseShellExecute = <span class="kwrd">false</span>;
    startInfo.RedirectStandardOutput = <span class="kwrd">true</span>;
    startInfo.RedirectStandardInput = <span class="kwrd">true</span>;
    startInfo.RedirectStandardError = <span class="kwrd">true</span>;
    startInfo.CreateNoWindow = <span class="kwrd">true</span>;
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;

    <span class="kwrd">using</span> (Process process = <span class="kwrd">new</span> Process())
    {
        process.StartInfo = startInfo;
        process.EnableRaisingEvents = <span class="kwrd">true</span>;
        process.ErrorDataReceived += <span class="kwrd">new</span> DataReceivedEventHandler(process_ErrorDataReceived);
        process.OutputDataReceived += <span class="kwrd">new</span> DataReceivedEventHandler(process_OutputDataReceived);
        process.Exited += <span class="kwrd">new</span> EventHandler(process_Exited);

        <span class="kwrd">try</span>
        {
            process.Start();
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            process.WaitForExit();
        }
        <span class="kwrd">catch</span> (Exception ex)
        {
            lblError.Text = ex.ToString();
        }
        <span class="kwrd">finally</span>
        {
            process.ErrorDataReceived -= <span class="kwrd">new</span> DataReceivedEventHandler(process_ErrorDataReceived);
            process.OutputDataReceived -= <span class="kwrd">new</span> DataReceivedEventHandler(process_OutputDataReceived);
            process.Exited -= <span class="kwrd">new</span> EventHandler(process_Exited);
        }
    }
}
<span class="kwrd">void</span> process_OutputDataReceived(<span class="kwrd">object</span> sender, DataReceivedEventArgs e)
{
    <span class="kwrd">if</span> (e.Data != <span class="kwrd">null</span>)
    {
        lblStdout.Text += e.Data.ToString() + “&lt;br /&gt;”;
    }
}
<span class="kwrd">void</span> process_ErrorDataReceived(<span class="kwrd">object</span> sender, DataReceivedEventArgs e)
{
    <span class="kwrd">if</span> (e.Data != <span class="kwrd">null</span>)
    {
        lblStderr.Text += e.Data.ToString() + “&lt;br /&gt;”;
    }
}
<span class="kwrd">void</span> process_Exited(<span class="kwrd">object</span> sender, EventArgs e)
{
    <span class="rem">//Post-processing code goes here</span>
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/04/22/how-to-manipulate-video-in-net-using-ffmpeg-updated/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Three quick ways optimize AJAX driven websites in ASP.NET</title>
		<link>http://www.calistomind.com/2008/04/18/three-quick-ways-optimize-ajax-driven-websites-in-aspnet/</link>
		<comments>http://www.calistomind.com/2008/04/18/three-quick-ways-optimize-ajax-driven-websites-in-aspnet/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 22:02:17 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/?p=84</guid>
		<description><![CDATA[Recently I was involved in a project where I had to make heavy use of AJAX. I realized there are a few simple things you could do to improve performance.
1) Combine scripts



&#60;ajaxToolkit:ToolkitScriptManager ID=&#8221;TSM1&#8221; runat=&#8221;Server&#8221;
EnablePartialRendering=&#8221;true&#8221;
CombineScriptsHandlerUrl=&#8221;~/CombineScriptsHandler.ashx&#8221; /&#62;

As the name of the property suggests, it will pretty much combine all the needed JS files into one which in [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was involved in a project where I had to make heavy use of AJAX. I realized there are a few simple things you could do to improve performance.</p>
<p><strong>1) Combine scripts<br />
</strong></p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red0\green0\blue0;\red255\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 ajaxToolkit\cf1 :\cf3 ToolkitScriptManager\cf0  \cf5 ID\cf1 ="ScriptManager1"\cf0  \cf5 runat\cf1 ="Server"\cf0  \cf5 EnablePartialRendering\cf1 ="true"\par ??\cf0     \cf5 CombineScriptsHandlerUrl\cf1 ="~/CombineScriptsHandler.ashx"\cf0  \cf1 /&amp;gt;}<br />
--></p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<pre style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">ajaxToolkit</span><span style="color: blue;">:</span><span style="color: #a31515;">ToolkitScriptManager</span> <span style="color: red;">ID</span><span style="color: red;">=&#8221;</span><span><span style="color: blue;">TSM1</span></span><span style="color: red;">&#8221; runat</span><span style="color: blue;">=&#8221;Server&#8221;</span>
<span style="color: red;">EnablePartialRendering</span><span style="color: blue;">=&#8221;true&#8221;</span>
<strong><span style="color: red;">CombineScriptsHandlerUrl</span><span style="color: blue;">=&#8221;~/CombineScriptsHandler.ashx&#8221;</span></strong> <span style="color: blue;">/&gt;</span></pre>
</div>
<p>As the name of the property suggests, it will pretty much combine all the needed JS files into one which in turn will reduce the number of requests sent to the server. You can find a detailed discussion about this <a href="http://blogs.msdn.com/delay/archive/2007/06/20/script-combining-made-better-overview-of-improvements-to-the-ajax-control-toolkit-s-toolkitscriptmanager.aspx" target="_blank">here</a>.</p>
<p>It is pretty easy to implement; instead of using the regular ScriptManager, just switch to the ToolkitScriptManager which comes with the AjaxToolkit and then set its CombineScriptsHandlerUrl property as shown above and throw the CombineScriptsHandler.ashx (included in the &#8220;SampleWebSite&#8221; directory of AjaxControlToolkit&#8217;s <a href="http://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx" target="_blank">release package</a>) into the root.</p>
<p><strong>2) Run in release mode</strong></p>
<p>The debug versions of the AJAX library have their source formatting preserved, as well as some debug asserts. By running it in release mode you can shave off some bytes off your requests.</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red0\green0\blue0;\red255\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 ajaxToolkit\cf1 :\cf3 ToolkitScriptManager\cf0  \cf5 ID\cf1 ="ToolkitScriptManager1"\cf0  \cf5 runat\cf1 ="Server"\cf0  \cf5 EnablePartialRendering\cf1 ="true"\par ??\cf0     \cf5 ScriptMode\cf1 ="Release"\cf0  \cf5 CombineScriptsHandlerUrl\cf1 ="~/CombineScriptsHandler.ashx"\cf0  \cf1 /&amp;gt;\par ??}<br />
--></p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<pre style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">ajaxToolkit</span><span style="color: blue;">:</span><span style="color: #a31515;">ToolkitScriptManager</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;TSM1&#8243;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;Server&#8221;</span> <span style="color: red;">
EnablePartialRendering</span><span style="color: blue;">=&#8221;true&#8221; </span><strong><span style="color: red;">ScriptMode</span><span style="color: blue;">=&#8221;Release&#8221;</span></strong> <span style="color: blue;">/&gt;</span></pre>
</div>
<p>Although, its important to note that some versions of Safari don&#8217;t seem to be compatible with this and could cause many strange side effects as <a href="http://blog.tatham.oddie.com.au/2007/05/31/aspnet-ajax-is-a-pos-designed-by-naive-microsoft-universe-programmers/" target="_blank">this person</a> and I have experienced in the past.</p>
<p>On a side note, ASP.NET AJAX Control Toolkit officially <a href="http://msdn2.microsoft.com/en-us/library/bb470452.aspx" target="_blank">does not support </a><span class="m2"><span class="m2"><a href="http://msdn2.microsoft.com/en-us/library/bb470452.aspx" target="_blank">Macs with PowerPC processors</a>, its good to know that piece of information if a client ever demands an explanation as for why AJAX powered functionality seems to be broken or not functioning as expected in that environment.<br />
</span></span></p>
<p><strong>3) Enable script caching and compression in web.config</strong><br />
<!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 system.web.extensions\cf1 &amp;gt;\par ??\tab &amp;lt;\cf3 scripting\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 scriptResourceHandler\cf1  \cf4 enableCompression\cf1 =\cf0 "\cf1 true\cf0 "\cf1  \cf4 enableCaching\cf1 =\cf0 "\cf1 true\cf0 "\cf1 /&amp;gt;\par ??\tab &amp;lt;/\cf3 scripting\cf1 &amp;gt;\par ??&amp;lt;/\cf3 system.web.extensions\cf1 &amp;gt;}<br />
--></p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<pre style="margin: 0px;"><span style="color: blue;">
&lt;</span><span style="color: #a31515;">system.web.extensions</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">  &lt;</span><span style="color: #a31515;">scripting</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">    &lt;</span><span style="color: #a31515;">scriptResourceHandler</span><span style="color: blue;"> </span><span style="color: red;">enableCompression</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">true</span>&#8220;<span style="color: blue;">
</span><span style="color: red;">     enableCaching</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">true</span>&#8220;<span style="color: blue;">/&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">  &lt;/</span><span style="color: #a31515;">scripting</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">system.web.extensions</span><span style="color: blue;">&gt;</span></pre>
</div>
<p>This will compress and cache all the script files which are embedded as resources in an assembly, localization objects, and scripts that are served by the script resource handler.</p>
<p>But like the previous tip, there is a exception to this one too. Some versions of IE6 have a bug where they cant&#8217;t handle GZIP&#8217;d script files correctly. The RTM version of ASP.NET AJAX works around this by explicitly not compressing files for these versions of IE. Although if you are still having a problem, it just might be a safe bet to explicitly set the enableCompression property to false in the web.config.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/04/18/three-quick-ways-optimize-ajax-driven-websites-in-aspnet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Request.Browser.Crawler</title>
		<link>http://www.calistomind.com/2008/04/08/requestbrowsercrawler/</link>
		<comments>http://www.calistomind.com/2008/04/08/requestbrowsercrawler/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 17:02:03 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/?p=83</guid>
		<description><![CDATA[In my previous post about exception logging, I show how to log several different parameters related to the exception in the database. Request.Browser.Crawler is one of them and its used to track browser crawlers. It warrants its own separate entry since it requires some extra bit of setup in the web.config to get it to [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post about exception logging, I show how to log several different parameters related to the exception in the database. Request.Browser.Crawler is one of them and its used to track browser crawlers. It warrants its own separate entry since it requires some extra bit of setup in the web.config to get it to work correctly.</p>
<p>You&#8217;ll have to add the following code in the  section of your web.config file:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="rem">&lt;!&#8211; This section is used by Request.Browser.Crawler property to detect search engine crawlers &#8211;&gt;</span>
<span class="kwrd">&lt;</span><span class="html">browserCaps</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">filter</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; SEARCH ENGINES GROUP &#8211;&gt;</span>
    <span class="rem">&lt;!&#8211; check Google (Yahoo uses this as well) &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;^Googlebot(\-Image)?/(?&#8217;version&#8217;(?&#8217;major&#8217;\d+)(?&#8217;minor&#8217;\.\d+)).*&#8221;</span><span class="kwrd">&gt;</span>
      browser=Google
      version=${version}
      majorversion=${major}
      minorversion=${minor}
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; check Alta Vista (Scooter) &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;^Scooter(/|-)(?&#8217;version&#8217;(?&#8217;major&#8217;\d+)(?&#8217;minor&#8217;\.\d+)).*&#8221;</span><span class="kwrd">&gt;</span>
      browser=AltaVista
      version=${version}
      majorversion=${major}
      minorversion=${minor}
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; check Alta Vista (Mercator) &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;Mercator&#8221;</span><span class="kwrd">&gt;</span>
      browser=AltaVista
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; check Slurp (Yahoo uses this as well) &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;Slurp&#8221;</span><span class="kwrd">&gt;</span>
      browser=Slurp
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; check MSN &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;MSNBOT&#8221;</span><span class="kwrd">&gt;</span>
      browser=MSN
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; check Northern Light &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;^Gulliver/(?&#8217;version&#8217;(?&#8217;major&#8217;\d+)(?&#8217;minor&#8217;\.\d+)).*&#8221;</span><span class="kwrd">&gt;</span>
      browser=NorthernLight
      version=${version}
      majorversion=${major}
      minorversion=${minor}
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; check Excite &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;ArchitextSpider&#8221;</span><span class="kwrd">&gt;</span>
      browser=Excite
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; Lycos &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;Lycos_Spider&#8221;</span><span class="kwrd">&gt;</span>
      browser=Lycos
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; Ask Jeeves &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;Ask Jeeves&#8221;</span><span class="kwrd">&gt;</span>
      browser=AskJeaves
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; check Fast &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;^FAST-WebCrawler/(?&#8217;version&#8217;(?&#8217;major&#8217;\d+)(?&#8217;minor&#8217;\.\d+)).*&#8221;</span><span class="kwrd">&gt;</span>
      browser=Fast
      version=${version}
      majorversion=${major}
      minorversion=${minor}
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; IBM Research Web Crawler &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">case</span> <span class="attr">match</span><span class="kwrd">=&#8221;http\:\/\/www\.almaden.ibm.com\/cs\/crawler&#8221;</span><span class="kwrd">&gt;</span>
      browser=IBMResearchWebCrawler
      crawler=true
    <span class="kwrd">&lt;/</span><span class="html">case</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">filter</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">browserCaps</span><span class="kwrd">&gt;</span></pre>
<p>Now what does it all mean? Well, IIS uses that information in the &lt;browserCaps&gt; section of your config file to detect whether the client browser is a crawler or not. If you look at it closely, its basically a regular expression filter. I presume you could add more filters in a similar format to detect other kinds of crawlers.</p>
<p><strong>Update</strong>: For the most accurate and updated version of browserCaps and other useful browser testing/detection resources you can go to one of these sites:</p>
<p><a href="http://slingfive.com/pages/code/browserCaps/" target="_blank">http://slingfive.com/pages/code/browserCaps/</a></p>
<p><a href="http://ocean.accesswa.net/browsercaps/" target="_blank">http://ocean.accesswa.net/browsercaps/</a></p>
<p><a href="http://browsers.garykeith.com/downloads.asp" target="_blank">http://browsers.garykeith.com/downloads.asp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/04/08/requestbrowsercrawler/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Exception Logging Using The Database</title>
		<link>http://www.calistomind.com/2008/04/08/exception-logging-using-the-database/</link>
		<comments>http://www.calistomind.com/2008/04/08/exception-logging-using-the-database/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 16:25:26 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/?p=82</guid>
		<description><![CDATA[This is a simple technique I use to log exceptions in all my web applications.
First lets start by adding the following to the web.config:


&#60;appSettings&#62;
&#60;add key=&#8221;LogUnhandledExceptions&#8221; value=&#8221;true&#8221;/&#62;
&#60;/appSettings&#62;

Second, we add the following bit inside the Application_Error event of the Global.asax file. This will capture all the unhandled exceptions and log them into the database:


private static bool logUnhandledExceptions [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple technique I use to log exceptions in all my web applications.</p>
<p>First lets start by adding the following to the web.config:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">&lt;</span><span class="html">appSettings</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">key</span><span class="kwrd">=&#8221;LogUnhandledExceptions&#8221;</span> <span class="attr">value</span><span class="kwrd">=&#8221;true&#8221;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">appSettings</span><span class="kwrd">&gt;</span>
</pre>
<p>Second, we add the following bit inside the Application_Error event of the Global.asax file. This will capture all the unhandled exceptions and log them into the database:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">bool</span> logUnhandledExceptions = Convert.ToBoolean(ConfigurationManager.AppSettings[<span class="str">&#8220;LogUnhandledExceptions&#8221;</span>]);
.
.
.
<span class="kwrd">void</span> Application_Error(<span class="kwrd">object</span> sender, EventArgs e)
{
    <span class="kwrd">if</span> (logUnhandledExceptions)
    {
        <span class="kwrd">if</span> (Context != <span class="kwrd">null</span>)
        {
            <span class="kwrd">if</span> (Server.GetLastError() != <span class="kwrd">null</span>)
            {
                <span class="rem">//Get reference to the source of the exception chain</span>
                Exception ex = Context.Server.GetLastError().GetBaseException();

                YourCompany.Helpers.ExceptionHandler.Log(ex);
            }
        }
    }
}
</pre>
<p>And now finally the main part. This is the class which will log all the relavent information related to the exception in the DB.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Data;
<span class="kwrd">using</span> System.Configuration;
<span class="kwrd">using</span> System.Web;
<span class="kwrd">using</span> System.Web.Security;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> System.Web.UI.WebControls;
<span class="kwrd">using</span> System.Web.UI.WebControls.WebParts;
<span class="kwrd">using</span> System.Web.UI.HtmlControls;
<span class="kwrd">using</span> System.Diagnostics;
<span class="kwrd">using</span> System.Data.SqlClient;
<span class="kwrd">using</span> System.Web.Configuration;

<span class="kwrd">namespace</span> YourCompany.Helpers
{
    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> ExceptionHandler
    {
        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Log(Exception ex)
        {
            <span class="kwrd">if</span> (ex.GetBaseException() != <span class="kwrd">null</span>)
            {
                <span class="kwrd">try</span>
                {
                    HttpContext context = HttpContext.Current;
                    HttpBrowserCapabilities browser = context.Request.Browser;

                    <span class="kwrd">string</span> referer = String.Empty;

                    <span class="kwrd">if</span> (context.Request.UrlReferrer != <span class="kwrd">null</span>)
                    {
                        referer = context.Request.UrlReferrer.ToString();
                    }

                    <span class="kwrd">using</span> (SqlConnection sqlConnection = <span class="kwrd">new</span> SqlConnection(WebConfigurationManager.ConnectionStrings[<span class="str">&#8220;ConnectionString&#8221;</span>].ConnectionString))
                    {
                        <span class="kwrd">using</span> (SqlCommand sqlCommand = <span class="kwrd">new</span> SqlCommand())
                        {
                            sqlCommand.Connection = sqlConnection;
                            sqlCommand.CommandType = CommandType.StoredProcedure;
                            sqlCommand.CommandText = <span class="str">&#8220;EventLog_Insert&#8221;</span>;

                            sqlCommand.Parameters.Add(<span class="str">&#8220;@Source&#8221;</span>, SqlDbType.NVarChar).Value = ex.Source;
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@Message&#8221;</span>, SqlDbType.NVarChar).Value = ex.Message;
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@Form&#8221;</span>, SqlDbType.NVarChar).Value = context.Request.Form.ToString();
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@Path&#8221;</span>, SqlDbType.NVarChar).Value = context.Request.Path.ToString();
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@QueryString&#8221;</span>, SqlDbType.NVarChar).Value = context.Request.QueryString.ToString();
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@TargetSite&#8221;</span>, SqlDbType.NVarChar).Value = ex.TargetSite.ToString();
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@StackTrace&#8221;</span>, SqlDbType.NVarChar).Value = ex.StackTrace.ToString();
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@Referer&#8221;</span>, SqlDbType.NVarChar).Value = referer;
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@MachineName&#8221;</span>, SqlDbType.NVarChar).Value = context.Server.MachineName.ToString();
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@IPAddress&#8221;</span>, SqlDbType.NVarChar).Value = context.Request.UserHostAddress;
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@BrowserType&#8221;</span>, SqlDbType.NVarChar).Value = browser.Type;
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@BrowserName&#8221;</span>, SqlDbType.NVarChar).Value = browser.Browser;
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@BrowserVersion&#8221;</span>, SqlDbType.NVarChar).Value = browser.Version;
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@BrowserPlatform&#8221;</span>, SqlDbType.NVarChar).Value = browser.Platform;
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@SupportsCookies&#8221;</span>, SqlDbType.Bit).Value = browser.Cookies;
                            sqlCommand.Parameters.Add(<span class="str">&#8220;@IsCrawler&#8221;</span>, SqlDbType.Bit).Value = browser.Crawler;

                            sqlConnection.Open();

                            sqlCommand.ExecuteNonQuery();
                        }
                    }
                }
                <span class="kwrd">catch</span>
                {
                    <span class="rem">// database error, not much you can do here except logging the error in the windows event log</span>
                    EventLog.WriteEntry(ex.Source, <span class="str">&#8220;Database Error From Exception Handler!&#8221;</span>, EventLogEntryType.Error);
                }
            }
        }
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/04/08/exception-logging-using-the-database/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Mysterious &#8220;Invalid Parameter Used&#8221; Error</title>
		<link>http://www.calistomind.com/2008/03/29/the-mysterious-invalid-parameter-used-error/</link>
		<comments>http://www.calistomind.com/2008/03/29/the-mysterious-invalid-parameter-used-error/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 07:37:47 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/2008/03/29/the-mysterious-invalid-parameter-used-error/</guid>
		<description><![CDATA[Recently I was trying to write a little C# function for cropping images. I expected it to be a quick 5 minute task but I ended up spending a huge amount of time getting it to work correctly. I kept getting a very stubborn and mysterious error - &#8220;Invalid Parameter Used&#8221; - whenever I tried [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was trying to write a little C# function for cropping images. I expected it to be a quick 5 minute task but I ended up spending a huge amount of time getting it to work correctly. I kept getting a very stubborn and mysterious error - &#8220;Invalid Parameter Used&#8221; - whenever I tried to save my newly cropped image by doing bitmap.Save(). I tried various suggestions I found on forums and blogs to no avail.</p>
<p>Finally I figured out what the problem was. I was encapulatning the Bitmap and Graphics objects inside a &#8220;using&#8221; statement. So the Bitmap object was being prematurely disposed before I returned it back to the caller.</p>
<p>So in the end my solution looked like this. I just god rid of the &#8220;usings&#8221;.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode"><span class="kwrd">public</span> Bitmap CropImage(Image image, Rectangle cropRect)
{
    Bitmap bitmap = <span class="kwrd">new</span> Bitmap(cropRect.Width, cropRect.Height, PixelFormat.Format24bppRgb);
    bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
    Graphics graphics = Graphics.FromImage(bitmap);
    graphics.DrawImage(image, 0, 0, cropRect, GraphicsUnit.Pixel);
    <span class="kwrd">return</span> bitmap;
}</pre>
<p>Usage -<br />
<span class="csharpcode"><br />
Bitmap croppedBmp = CropImage(<span class="str">&#8220;~/uploads/test.jpg&#8221;</span>, <span class="kwrd">new</span> Rectangle(x, y, width, height));<br />
croppedBmp.Save();</span></p>
<p>Moral of the story: If you are getting this error while calling Bitmap.Save() then make sure you are not disposing your Bitmap object prematurely. Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/03/29/the-mysterious-invalid-parameter-used-error/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to unzip files in .NET using SharpZipLib</title>
		<link>http://www.calistomind.com/2008/03/12/how-to-unzip-files-in-net-using-sharpziplib/</link>
		<comments>http://www.calistomind.com/2008/03/12/how-to-unzip-files-in-net-using-sharpziplib/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 06:30:22 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/2008/03/12/how-to-unzip-files-in-net-using-sharpziplib/</guid>
		<description><![CDATA[SharpZipLib is a great open source library for handeling all kinds of gzip/zip compression/decompression. More Info - http://www.icsharpcode.net/OpenSource/SharpZipLib/
In the following example I&#8217;m passing the HtmlInputFile object directly into the ZipInputStream to decompress the PostedFile and save its contents on the server.


.
.
using System.IO;
using ICSharpCode.SharpZipLib.Zip
.
.
private void UnzipAndSave(HtmlInputFile objFileUpload)
{
    ZipInputStream s = new ZipInputStream(objFileUpload.PostedFile.InputStream);

    ZipEntry theEntry;
 [...]]]></description>
			<content:encoded><![CDATA[<p>SharpZipLib is a great open source library for handeling all kinds of gzip/zip compression/decompression. More Info - <a href="http://www.icsharpcode.net/OpenSource/SharpZipLib/">http://www.icsharpcode.net/OpenSource/SharpZipLib/</a></p>
<p>In the following example I&#8217;m passing the HtmlInputFile object directly into the ZipInputStream to decompress the PostedFile and save its contents on the server.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
.
.
<span class="kwrd">using</span> System.IO;
<span class="kwrd">using</span> ICSharpCode.SharpZipLib.Zip
.
.
<span class="kwrd">private</span> <span class="kwrd">void</span> UnzipAndSave(HtmlInputFile objFileUpload)
{
    ZipInputStream s = <span class="kwrd">new</span> ZipInputStream(objFileUpload.PostedFile.InputStream);

    ZipEntry theEntry;
    <span class="kwrd">string</span> virtualPath = <span class="str">&#8220;~/uploads/&#8221;</span>;
    <span class="kwrd">string</span> fileName = <span class="kwrd">string</span>.Empty;
    <span class="kwrd">string</span> fileExtension = <span class="kwrd">string</span>.Empty;
    <span class="kwrd">string</span> fileSize = <span class="kwrd">string</span>.Empty;

    <span class="kwrd">while</span> ((theEntry = s.GetNextEntry()) != <span class="kwrd">null</span>)
    {
        fileName = Path.GetFileName(theEntry.Name);
        fileExtension = Path.GetExtension(fileName);

        <span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(fileName))
        {
            <span class="kwrd">try</span>
            {
                FileStream streamWriter = File.Create(Server.MapPath(virtualPath + fileName));
                <span class="kwrd">int</span> size = 2048;
                <span class="kwrd">byte</span>[] data = <span class="kwrd">new</span> <span class="kwrd">byte</span>[2048];

                <span class="kwrd">do</span>
                {
                    size = s.Read(data, 0, data.Length);
                    streamWriter.Write(data, 0, size);
                } <span class="kwrd">while</span> (size &gt; 0);

                fileSize = Convert.ToDecimal(streamWriter.Length / 1024).ToString() + ” KB”;

                streamWriter.Close();

                <span class="rem">//Add custom code here to add each file to the DB, etc.</span>
            }
            <span class="kwrd">catch</span> (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
    }

    s.Close();
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/03/12/how-to-unzip-files-in-net-using-sharpziplib/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to manipulate video in .NET using ffmpeg</title>
		<link>http://www.calistomind.com/2008/03/12/how-to-manipulate-video-in-net-using-ffmpeg/</link>
		<comments>http://www.calistomind.com/2008/03/12/how-to-manipulate-video-in-net-using-ffmpeg/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 06:02:04 +0000</pubDate>
		<dc:creator>J</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.calistomind.com/2008/03/12/how-to-manipulate-video-in-net-using-ffmpeg/</guid>
		<description><![CDATA[In this case I&#8217;m resizing the video and converting it to FLV format. For more ffmpeg commandline options - http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html


private void ConvertVideo(string srcURL, string destURL)
{
    string ffmpegURL = &#8220;~/project/tools/ffmpeg.exe&#8221;;
    DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(Server.MapPath(ffmpegURL)));

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = Server.MapPath(ffmpegURL);
    [...]]]></description>
			<content:encoded><![CDATA[<p>In this case I&#8217;m resizing the video and converting it to FLV format. For more ffmpeg commandline options - <a href="http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html">http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html</a></p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">private</span> <span class="kwrd">void</span> ConvertVideo(<span class="kwrd">string</span> srcURL, <span class="kwrd">string</span> destURL)
{
    <span class="kwrd">string</span> ffmpegURL = <span class="str">&#8220;~/project/tools/ffmpeg.exe&#8221;</span>;
    DirectoryInfo directoryInfo = <span class="kwrd">new</span> DirectoryInfo(Path.GetDirectoryName(Server.MapPath(ffmpegURL)));

    ProcessStartInfo startInfo = <span class="kwrd">new</span> ProcessStartInfo();
    startInfo.FileName = Server.MapPath(ffmpegURL);
    startInfo.Arguments = <span class="kwrd">string</span>.Format(<span class="str">&#8220;-i \&#8221;{0}\&#8221; -s 368&#215;216 -aspect 1.7777 \&#8221;{1}\&#8221;"</span>, srcURL, destURL);
    startInfo.WorkingDirectory = directoryInfo.FullName;
    startInfo.UseShellExecute = <span class="kwrd">false</span>;
    startInfo.RedirectStandardOutput = <span class="kwrd">true</span>;
    startInfo.RedirectStandardInput = <span class="kwrd">true</span>;
    startInfo.RedirectStandardError = <span class="kwrd">true</span>;

    <span class="kwrd">using</span> (Process process = <span class="kwrd">new</span> Process())
    {
        process.StartInfo = startInfo;

        <span class="kwrd">try</span>
        {
            process.Start();
            StreamReader standardOutput = process.StandardOutput;
            StreamWriter standardInput = process.StandardInput;
            StreamReader standardError = process.StandardError;
            process.WaitForExit();

            lblError.Text = standardError.ReadToEnd();
            lblOutput.Text = standardOutput.ReadToEnd();
        }
        <span class="kwrd">catch</span> (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.calistomind.com/2008/03/12/how-to-manipulate-video-in-net-using-ffmpeg/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
