Why use serialization in .Net development?
I was curious to know why I should be using serialization in my development process and I came across an interesting use for it, I was writing a code development tool and was required to store each project for code generation so it could be retrieved later on. Initially I used a text file then an XML file. But the whole process of having to manage the saving and loading of the project files was tedious(Ok may be not as much as I am making it out to be!).
Then it flashed, why not just serialize the Project object. Wallah!! I reduced my code from a couple of classes to manage the XML iteration, file exceptions etc to a few lines of code.
Wow I was beginning to see the power of serialization....
A journey through the software development world can be interesting, exciting and quite daunting and Id like to share my own such experiences here.
Tuesday, March 31, 2009
Saturday, March 28, 2009
Finally my own Data Access Generator tool...
I’ve been struggling over the past few years in search of something that can reduce code development especially the unexciting Data Access Layer code, which is basically a wrapper to conform to a 3-tiered or n-tiered architecture.
I tried a few OR mappers and even gave the Table adapters from the .Net 2.0 Framework a fair shot. But I missed the bare code that I was so accustomed to seeing either due to the fear of performance issues or from hitting the wall down the road. I haven’t explored LINQ to justify my code generation tool and this is no LINQ killer I assure you.
But I did find that a simple code generation tool can achieve a great deal, especially restoring my confidence when it was rolled into production. For one thing the code was always debbugable. So I wrote my own little code generation tool that was based on text templates that you can hack at any time. It does the job and I used it for a couple of enterprise solutions successfully and would like to share the tool.
It’s based on stored procedures fro data access. It automatically generates select, update, insert and delete stored procedures and writes wrapper classes to access these stored procedures. Additionally you can write your custom stored procedures using a naming convention and it will generate the wrapper classes.
You can get a copy from here Click here!
In case anyone is interested in the source code you can email me.
I’ve been struggling over the past few years in search of something that can reduce code development especially the unexciting Data Access Layer code, which is basically a wrapper to conform to a 3-tiered or n-tiered architecture.
I tried a few OR mappers and even gave the Table adapters from the .Net 2.0 Framework a fair shot. But I missed the bare code that I was so accustomed to seeing either due to the fear of performance issues or from hitting the wall down the road. I haven’t explored LINQ to justify my code generation tool and this is no LINQ killer I assure you.
But I did find that a simple code generation tool can achieve a great deal, especially restoring my confidence when it was rolled into production. For one thing the code was always debbugable. So I wrote my own little code generation tool that was based on text templates that you can hack at any time. It does the job and I used it for a couple of enterprise solutions successfully and would like to share the tool.
It’s based on stored procedures fro data access. It automatically generates select, update, insert and delete stored procedures and writes wrapper classes to access these stored procedures. Additionally you can write your custom stored procedures using a naming convention and it will generate the wrapper classes.
You can get a copy from here Click here!
In case anyone is interested in the source code you can email me.
Thursday, August 28, 2008
The request failed with HTTP status 404: Not Found.
I was stuck on this issue for a week till I eventually found the solution and it was in bits and peaces all over the net. But I thought someone might benefit from getting the solution as a whole. Again I haven’t spent enough time to understand the solution but it worked and for now I have to be satisfied with that.
My hosting provider has reporting services installed on a separate machine to the actual website so this should work for most hosting setups. I wanted to embed the reports in my webpage using report viewer. The trick was trying to pass authentication information from my website to the reporting services.
To do this you need to create a ReportServerConnection class and register it in your web.config, along with this you need to add application key/value pairs to pass your report server credentials.
Web Config
Add the following code to a blank page and run then run the code to get the PublicKeyToken
Response.Write("
" +typeof(SportsDB.BLL.SimpleReportServerConnection).AssemblyQualifiedName);
Add the following in your webconfig. It goes under the assemblies tag.
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />
buildProviders>
<add key="MyReportServerUrl" value="https://XXXX"/>
<add key="MyReportViewerUser" value="XXX"/>
<add key="MyReportViewerPassword" value="XXX"/>
<add key="MyReportViewerDomain" value="XXX"/>
As for the code here is the full class – (Don’t you just luv to cut and paste!!)
using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Net;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Reporting.WebForms;
namespace XXXX
{
public interface IReportServerConnection2 : IReportServerConnection, IReportServerCredentials { }
public sealed class SimpleReportServerConnection : IReportServerConnection2
{
public WindowsIdentity ImpersonationUser
{
get
{
// Use the default Windows user. Credentials will be
// provided by the NetworkCredentials property.
return null;
}
}
public ICredentials NetworkCredentials
{
get
{
// Read the user information from the web.config file.
// By reading the information on demand instead of
// storing it, the credentials will not be stored in
// session, reducing the vulnerable surface area to the
// web.config file, which can be secured with an ACL.
// User name
string userName =
ConfigurationManager.AppSettings
["MyReportViewerUser"];
if (string.IsNullOrEmpty(userName))
throw new Exception(
"Missing user name from Web.config file");
// Password
string password =
ConfigurationManager.AppSettings
["MyReportViewerPassword"];
if (string.IsNullOrEmpty(password))
throw new Exception(
"Missing password from Web.config file");
// Domain
string domain =
ConfigurationManager.AppSettings
["MyReportViewerDomain"];
if (string.IsNullOrEmpty(domain))
throw new Exception(
"Missing domain from Web.config file");
return new NetworkCredential(userName, password, domain);
}
}
public bool GetFormsCredentials(out Cookie authCookie,
out string userName, out string password,
out string authority)
{
authCookie = null;
userName = null;
password = null;
authority = null;
// Not using form credentials
return false;
}
public Uri ReportServerUrl
{
get
{
string url =
ConfigurationManager.AppSettings[
"MyReportServerUrl"];
if (string.IsNullOrEmpty(url))
throw new Exception(
"Missing url from the Web.config file");
return new Uri(url);
}
}
public int Timeout
{
get
{
return 60000; // 60 seconds
}
}
public IEnumerable<Cookie> Cookies
{
get
{
// No custom cookies
return null;
}
}
public IEnumerable<string> Headers
{
get
{
// No custom headers
return null;
}
}
}
}
Subscribe to:
Posts (Atom)