- enterprisedlinq_demo_vsbeta2.zip
- EnterpriseDlinq_demo_VSBeta2
- BusinessLayer
- DataAccessLayer
- MVPWeb
- App_Code
- App_Data
- Bin
- Northwind.Business.dll
- Northwind.Business.pdb
- Northwind.Data.dll
- Northwind.Data.DTO.dll
- Northwind.Data.DTO.pdb
- Northwind.Data.pdb
- Northwind.Presentation.dll
- Northwind.Presentation.pdb
- Northwind.Service.dll
- Northwind.Service.pdb
- CustomerListing.aspx
- CustomerListing.aspx.cs
- Images
- first.gif
- last.gif
- next.gif
- prev.gif
- Thumbs.db
- web.config
- NWClient.sln
- PrecompiledWeb
- MVPWeb
- bin
- App_Code.compiled
- App_Code.dll
- App_Web_jhhzcwwg.dll
- Northwind.Business.dll
- Northwind.Business.pdb
- Northwind.Data.dll
- Northwind.Data.DTO.dll
- Northwind.Data.DTO.pdb
- Northwind.Data.pdb
- Northwind.Presentation.dll
- Northwind.Presentation.pdb
- Northwind.Service.dll
- Northwind.Service.pdb
- CustomerListing.aspx
- Images
- first.gif
- last.gif
- next.gif
- prev.gif
- PrecompiledApp.config
- web.config
- Web
- Presentation
- ServiceLayer
- Thumbs.db
- TransferObjects
- Web
- enterprisedlinq_demo.zip
- EnterpriseDlinq_demo
- BusinessLayer
- DataAccessLayer
- MVPWeb
- App_Code
- App_Data
- Bin
- Northwind.Business.dll
- Northwind.Business.pdb
- Northwind.Data.dll
- Northwind.Data.DTO.dll
- Northwind.Data.DTO.pdb
- Northwind.Data.pdb
- Northwind.Presentation.dll
- Northwind.Presentation.pdb
- Northwind.Service.dll
- Northwind.Service.pdb
- CustomerListing.aspx
- CustomerListing.aspx.cs
- Images
- first.gif
- last.gif
- next.gif
- prev.gif
- Thumbs.db
- web.config
- NWClient.sln
- Presentation
- ServiceLayer
- Thumbs.db
- TransferObjects
- Web
- enterprisedlinq_dbscripts.zip
- EnterpriseDlinq_DBScripts
- enterprisedlinq_test.zip
- EnterpriseDlinq_test
- enterprisedlinq_stats.zip
- Performance Stats.xls
|
using System;
using System.Data;
using System.Configuration;
using System.Linq;
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 Northwind.Business;
using Northwind.Business.DataInterfaces;
using Northwind.Data.DTO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Reflection;
/*
**************************************************************
* Author: Rohit Gadagkar (rohit.gadagkar@gmail.com)
* Copyright � 2007 Rohit Gadagkar
* License:
* Free without any restrictions whatsoever
*
* Created: 9/1/2007
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
* OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE.
**************************************************************
*/
/// <summary>
/// Summary description for Util
/// </summary>
public static class Util
{
class Constants
{
public const string DAO_FACTORY_KEY = "daoFactoryType";
public const string DEFAULT_FACTORY_TYPE = "Northwind.Data.DLinqDAOFactory";
public const string FACTORY_ASSEMBLY = "Northwind.Data";
public const string CACHED_PROP_PREFIX = "__$DTOProperty_";
}
public static T MarshalObject<T>(FormView f) where T:new()
{
T dto = new T();
Type type = dto.GetType();
for (int i = 0; i < f.Row.Cells[0].Controls.Count; i += 2)
{
Control label = f.Row.Cells[0].Controls[i];
if (label is LiteralControl)
{
string propName = (label as LiteralControl).Text;
propName = Regex.Replace(propName, "([\\s:-]*(<br[ ]*/>)*)(\\w+)([\\s:-])+", "$3");
if (!String.IsNullOrEmpty(propName))
{
PropertyInfo prop = GetProperty(propName, type);
if (prop != null)
{
Control valueCell = f.Row.Cells[0].Controls[i + 1];
object value = (valueCell is TextBox)
? (valueCell as TextBox).Text
: null;
prop.SetValue(dto, value, null);
}
}
}
}
return dto;
}
public static IDaoFactory CreateFactoryInstance()
{
string typeStr = ConfigurationManager.AppSettings[Constants.DAO_FACTORY_KEY];
if (String.IsNullOrEmpty(typeStr)) typeStr = Constants.DEFAULT_FACTORY_TYPE;
IDaoFactory f = null;
try {
Assembly a = Assembly.Load(Constants.FACTORY_ASSEMBLY);
if (a != null) {
Type fType = a.GetType(typeStr);
if (fType == null) fType = a.GetType(String.Format("{0}.{1}",
Constants.FACTORY_ASSEMBLY, typeStr));
f = Activator.CreateInstance(fType) as IDaoFactory;
}
}
catch (Exception ex) {
throw new Exception(String.Format("Unable to load {0} from Northwind.Data",
typeStr), ex);
}
return f;
}
internal static PropertyInfo GetProperty(string propName, Type type)
{
System.Web.Caching.Cache c = HttpRuntime.Cache;
PropertyInfo prop = c[GetKey(propName)] as PropertyInfo;
if (prop == null) {
prop = type.GetProperty(propName);
if(prop != null) c[GetKey(propName)] = prop;
}
return prop;
}
internal static string GetKey(string propName)
{
return Constants.CACHED_PROP_PREFIX + propName;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
I am a tech lead working for Cap Gemini. Although I primarily work with the Microsoft technology stack (including .NET and legacy technologies) I like to keep myself informed about developments in the Java world.