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

<channel>
	<title>C-Pound.Net</title>
	<atom:link href="http://cpound.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://cpound.net/blog</link>
	<description>C# Code Snippets and Daily Programming Thoughts</description>
	<lastBuildDate>Wed, 30 Sep 2009 21:09:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using ActionFilters for Logging in ASP.Net MVC</title>
		<link>http://cpound.net/blog/using-actionfilters-for-logging-in-asp-net-mvc/</link>
		<comments>http://cpound.net/blog/using-actionfilters-for-logging-in-asp-net-mvc/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 21:09:13 +0000</pubDate>
		<dc:creator>Victor Boba</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://cpound.net/blog/?p=32</guid>
		<description><![CDATA[The ActionFilterAttribute is a great way to create a global logging procedure for entry and exit of an ActionResult method in your MVC Controllers.
Create a class that inherits from ActionFilterAttribute and implements IActionFilter.
    [AttributeUsage(AttributeTargets.Method)]
    public sealed class LogRequestAttribute : ActionFilterAttribute, IActionFilter
    {
     [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.actionfilterattribute.aspx">ActionFilterAttribute</a> is a great way to create a global logging procedure for entry and exit of an ActionResult method in your MVC Controllers.</p>
<p>Create a class that inherits from ActionFilterAttribute and implements IActionFilter.</p>
<pre class="prettyprint lang-cs">    [AttributeUsage(AttributeTargets.Method)]
    public sealed class LogRequestAttribute : ActionFilterAttribute, IActionFilter
    {
        ///
        /// Log exit of the ActionResult method
        ///
        ///
        void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext)
        {
            // Put code you want to log when the ActionResult has completed in here.
        }

        ///
        /// Log entry into the ActionResult method
        ///
        ///
        void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
        {
            // Put code you want to log when the ActionResult is entered in here.
        }
    }</pre>
<p>To implement in your code, all you do is add the attribute to the ActionResult method:</p>
<pre class="prettyprint lang-cs">        [LogRequestAttribute]
        public ActionResult ChangePasswordSuccess()
        {
            return View();
        }</pre>
<p>When the ActionResult executes, it will hit in this order:</p>
<ol>
<li>OnActionExecuting</li>
<li>OnActionExecuted</li>
</ol>
<p>Using the ActionFilterAttribute saves you from having to write the same code over and over for every method in your Controller.</p>
<p>Here&#8217;s an example of using the ActionFilterAttribute for rolling your own security from Adrew Siemer&#8217;s blog:</p>
<p><a href="http://geekswithblogs.net/AndrewSiemer/archive/2008/11/17/mvc-attributes-via-actionfilterattribute-again.aspx">http://geekswithblogs.net/AndrewSiemer/archive/2008/11/17/mvc-attributes-via-actionfilterattribute-again.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cpound.net/blog/using-actionfilters-for-logging-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Save/Restore Winforms Position on Start/Shutdown</title>
		<link>http://cpound.net/blog/saverestore-winforms-position-on-startshutdown/</link>
		<comments>http://cpound.net/blog/saverestore-winforms-position-on-startshutdown/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 04:09:15 +0000</pubDate>
		<dc:creator>Victor Boba</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[Winforms]]></category>

		<guid isPermaLink="false">http://cpound.net/blog/?p=14</guid>
		<description><![CDATA[Saving the form&#8217;s position and restoring it on startup is a simple process when using the Settings functionality that&#8217;s saved with each user of your application.
Create a few settings in your Settings tab for the project and set them as User scope. Use the below picture as your guide:
In the form you want to save [...]]]></description>
			<content:encoded><![CDATA[<p>Saving the form&#8217;s position and restoring it on startup is a simple process when using the Settings functionality that&#8217;s saved with each user of your application.</p>
<p>Create a few settings in your Settings tab for the project and set them as User scope. Use the below picture as your guide:</p>
<div id="attachment_12" class="wp-caption alignnone" style="width: 583px"><img class="size-full wp-image-12" title="Settings" src="http://cpound.net/blog/wp-content/uploads/2009/09/Settings.jpg" alt="Settings" width="573" height="114" /><p class="wp-caption-text">Settings</p></div>
<p>In the form you want to save add the following text to your FormClosing, and Load events:</p>
<pre class="prettyprint lang-cs">
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
    if (this.WindowState != FormWindowState.Minimized)
    {
        Properties.Settings.Default.MainForm_WindowState = this.WindowState;
        Properties.Settings.Default.MainForm_Location = this.Location;
        Properties.Settings.Default.MainForm_Size = this.Size;
    }
    Properties.Settings.Default.Save();
}

private void MainForm_Load(object sender, EventArgs e)
{
    if (Properties.Settings.Default.MainForm_WindowState == FormWindowState.Maximized)
    {
        this.WindowState = FormWindowState.Maximized;
    }
    else
    {
        this.WindowState = Properties.Settings.Default.MainForm_WindowState;
        this.Location = Properties.Settings.Default.MainForm_Location;
        if (Properties.Settings.Default.MainForm_Size.IsEmpty)
        {
            this.Width = Screen.GetWorkingArea(this).Width - 200;
            this.Height = Screen.GetWorkingArea(this).Height - 100;
        }
        else
       {
           this.Size = Properties.Settings.Default.MainForm_Size;
       }
       if (this.Top < 0)
           this.Top = 0;
   }
}
</pre>
<p>You'll notice that we're checking to only save when not minimized. We're also ensuring that the form is within view and is not somehow off the sceeen.</p>
]]></content:encoded>
			<wfw:commentRss>http://cpound.net/blog/saverestore-winforms-position-on-startshutdown/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
