Log4net: simple way to use in your Asp.net application

Log the actions of your applications is very important especially when you develop new features or develop very difficult logical business.
But it is also important when users use your applications to understand the critical issues or problems.
To implement quickly the log operations Apache developed an opensource library for .Net developers.

Emanuele’s Blog: Log4net: simple way to use in your Asp.net application

Rhino Mocks Quick Reference

Last week I gave a presentation on mock objects for Software Professionals of Alaska. Once the PowerPointy hand-waving was out of the way, I illustrated the concepts with code examples using Rhino Mocks. I thought I was well-versed in Rhino Mocks before I started, but in the process of preparing the presentation I realized there was a lot that I didn’t know or had forgotten. So I distilled all the main facts and features down into a 3-page quick reference of tables and example usage. You might argue that 3 pages makes it a ‘slow reference,’ but regardless I still think it’s useful to see all the basics stripped down to the bare minimum. Much of the content came from the Rhino Mocks Documentation Wiki, so look there first if you need more details on a particular feature.

Oran DennisonRhino Mocks Quick Reference

Copy project files to another location after build

For a (web-)project I am working on, I needed to copy the content of 1 website to a sub-folder of another website after the project was built. This enables the 2 projects being separately developed and deployed, but also allows the one project being deployed as a sub-site of the other one. Got it? 🙂

This is how I did this:
In the project file of the sub-project:

  1. In the project file I defined a few variables to make things easier
    <PropertyGroup>
    <MyOutputFolder>C:ProjectOutputFolder</MyOutputFolder>
    <OutputSubFolder>SubFolder</OutputSubFolder>
    </PropertyGroup>
  2. I defined what files to copy, with the binary output (dll) separately from the website content:
    <ItemGroup>
    <MyCopyItems Include="$(MSBuildProjectDirectory)***.aspx" />
    <MyCopyItems Include="$(MSBuildProjectDirectory)***.htm?" />
    <MyCopyItems Include="$(MSBuildProjectDirectory)***.js" />
    <MyCopyItems Include="$(MSBuildProjectDirectory)***.gif" />
    <MyCopyItems Include="$(MSBuildProjectDirectory)***.jp?g" />
    <MyCopyItems Include="$(MSBuildProjectDirectory)***.png" />
    <MyCopyBin Include="$(MSBuildProjectDirectory)bin***.dll" />
    </ItemGroup>
  3. I created a new target that performs 2 copy commands, one for the binaries and one for the content:
    <Target Name="MyPostBuildTarget">
    <Copy SourceFiles="@(MyCopyItems)"
    DestinationFiles="@(MyCopyItems->'$(MyOutputFolder)$(OutputSubFolder)%(RecursiveDir)%(Filename)%(Extension)')" />
    <Copy SourceFiles="@(MyCopyBin)"
    DestinationFolder="$(MyOutputFolder)bin" />
    </Target>
  4. I added this target to the BuildDependsOn property so that it is executed everytime the project is built:
    <BuildDependsOn>$(BuildDependsOn);MyPostBuildTarget</BuildDependsOn>

This gives something like:

<!-- Copy project output to defined folder -->
<PropertyGroup>
<BuildDependsOn>$(BuildDependsOn);MyPostBuildTarget</BuildDependsOn>
<MyOutputFolder>C:ProjectOutputFolder</MyOutputFolder>
<OutputSubFolder>SubFolder</OutputSubFolder>
</PropertyGroup>
<ItemGroup>
<MyCopyItems Include="$(MSBuildProjectDirectory)***.aspx" />
<MyCopyItems Include="$(MSBuildProjectDirectory)***.htm?" />
<MyCopyItems Include="$(MSBuildProjectDirectory)***.js" />
<MyCopyItems Include="$(MSBuildProjectDirectory)***.gif" />
<MyCopyItems Include="$(MSBuildProjectDirectory)***.jp?g" />
<MyCopyItems Include="$(MSBuildProjectDirectory)***.png" />
<mycopybin include="$(MSBuildProjectDirectory)bin***.dll" />
</ItemGroup>
<Target Name="MyPostBuildTarget">
<Copy SourceFiles="@(MyCopyItems)"
DestinationFiles="@(MyCopyItems->'$(MyOutputFolder)$(OutputSubFolder)%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="@(MyCopyBin)"
DestinationFolder="$(MyOutputFolder)bin" />
</Target>

Some references on copying project files with MSBuild:
MSDN MSBuild Reference – Copy Task
Channel 9 Wiki: Copy Built Output Of A Visual Studio Project
SharpDevelop Community – Copy config post build
How To: Insert Custom Process at Specific Points During Build
How To: Add Custom Process at Specific Points During Build (Method #2)

[Build Knowledge] Versioning

Today I’ll show you how to use NAnt and Cruise Control.Net to Version your application.
What you’ll need
1. NAnt A .Net Build tool. We’re going to use this to compile our Hello World Application and set the version number.
2. Cruise Control.Net A Continious Integration Server that lets us start NAnt and makes our version number.

Sleep Overrated – Scott Cowan[Build Knowledge] Versioning

UML TOOLBOX: 20+ UML Tools & Tutorials

UML is a globally accepted standard for software modeling in the technology community. Visualization with UML gives a punch to the whole development process. We’ve gathered over 20 Tools & Tutorials to help you get going with UML.

Mashable.comUML TOOLBOX: 20+ UML Tools & Tutorials

How To Create A Custom Control

  1. Create a new ASP.NET Web Application, Windows Forms Control Library or Class Library project
  2. Create a new class and inherit from System.Web.UI.WebControls.WebControl or from a specific control (like TextBox)
  3. Override the Render method and call writer.write() to write raw HTML to the page. ASP.Net server tags won’t work
  4. Use WriteBeginTag(), WriteEndTag(), RenderBeginTag(), RenderEndTag(), AddAttribute(), AddStyleAttribute() and WriteAttribute() to create HTML tags and attributes
  5. Add design-time attributes to properties, like:
    [Category(“Appearance”)]
    [Description(“The text to be shown in the control”)]
  6. Define a tagprefix attribute:
    [assembly: System.Web.UI.TagPrefix(“Anthoro.WebControls”, “awc”)]
    namespace Anthoro.WebControls
    { …
  7. Add a toolbox icon:
    1. Create a 16×16 pixel bitmap (BMP 16 colors) with the same name as the control.
    2. Add it to the root of your project
    3. Set its Build Action to “Embedded Resource”
  8. Add additional resources (stylesheet, images, text files, …) and mark them as “Embedded Resource” also
  9. Add an Assembly attribute for each resource to your AssemblyInfo.cs:
    [assembly: WebResource(“Anthoro.Controls.style.css”, “text/css”, PerformSubstitution = true)]
    When the PerformSubstitution parameter is set to true, the resource will be processed and other webresource URL’s inside it will be parsed and replaced (works only for text-based resources:
    background-image: url(‘<%= WebResource("Anthoro.Controls.back.png")%>‘);
  10. Pay attention to the full namespace and folder structure where your resources are stored. The resource name is build as: Namespace + Subfolders + filename
  11. At design-time, the control is displayed by running the rendering logic. To override this, use the GetDesignTimeHtml(), GetEmptyDesignTimeHtml() and GetErrorDesignTimeHtml() methods

Update: Unlike in C#, in VB.Net the subfolders are not taken into account with the namespace. So the example above in point 10 will be: Namespace + filename

C# MYSQLWrapper Class and PHPWrapper-Script

The MYSQLWrapper Class is a small and simple to use solution for accessing serverside MySQL Databases at a standard webspace that supports php and mysql.
I thought it would be useful because many of you have got those cheep php/mysql supported sites and want to use data at client side.
SQL queries and non query commands proceed as follows:

  1. The client side c# programm passes the needed sql command to the serversided script using http request.
  2. The serversided script performs sql statement an returns the result, if there is any, back to the client
  3. Now the client parses returned data and creates a Resultset that behaves simliar to the sqlDataReader

The Code Project C# MYSQLWrapper Class and PHPWrapper-Script

Powered by ScribeFire.

Particletree » Ranked Searches with SQL

A handy trick to add some sort of ranking to SQL search results:

Creating some sort of search functionality is something we all have to do at one point or another. For the good cases, we have fulltext search or an external program available to us. But sometimes, getting down and dirty with plain SQL is the only option.

SELECT
SUM(((LENGTH(Body) - LENGTH(REPLACE(Body, 'term', '')))/4))
AS Occurrences

Particletree: Ranked Searches with SQL

Cutting Edge: AJAX Application Architecture, Part 1 — MSDN Magazine, September 2007

MSDN Magazine – Cutting Edge: “AJAX Application Architecture, Part 1 & 2”

Cutting Edge: AJAX Application Architecture, Part 1 — MSDN Magazine, September 2007:
AJAX to the Rescue
The AJAX Architecture
What’s an AJAX Framework?
ASP.NET AJAX Extensions
A Look at Partial Rendering
Anatomy of an AJAX Postback
Optimization Techniques for Partial Rendering
Weighing Partial Rendering

Cutting Edge: AJAX Application Architecture, Part 2 — MSDN Magazine, October 2007:
Logging In with AJAX
Flavors of Services
What Do AJAX Services Return?
JSON Versus XML
Security Concerns
Services in ASP.NET AJAX
ASP.NET AJAX Services and SOAP
Invoking AJAX Services
Building the User Interface
What It All Means

Learn to Love Complaining Clients [Work Smarter]

You’ll face moments of truth every day of your life. You’ll make decisions and take the consequences. The consequences can be good, they can be bad, but they are there for every action you take. Moments of truth can have a profound effect on your business, and complaints have enormous significance, so we’ll consider client complaints in this chapter.

Sitepoint: Learn to Love Complaining Clients [Work Smarter]