[实例研究Duwamish]SystemFramework和Common命名空间

研究Duwamish,运用Duwamish,按照其架构,本人尝试开发一家以农资信息为主,外加网上购物的小型商业站点(请大家按照Duwamish四层架构的思想给与建议与意见)

设计SystemFramework以及Common命名空间的类型

Duwamish的SystemFramework的作用是:
记录日志以及直接读取Web.config.这里,我们只是设计Common命名空间,舍弃SystemFramwork

(1)New3ney.Common.New3neyConfiguration

None.gif
None.gif
namespace  Common
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
using System;
InBlock.gif    
using System.Configuration;
InBlock.gif    
using System.Collections;
InBlock.gif    
using System.Xml;
InBlock.gif    
using System.Collections.Specialized;  

InBlock.gif    public class New3neyConfiguration:IConfigurationSectionHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private static String DbPath;

            private const string DBPATH="DbPath";
InBlock.gif        
private const string DBPATH_DEFAULT="data/data.mdb";

InBlock.gif
        public Object Create(Object parent,Object configContext,XmlNode section)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            NameValueCollection settings;
InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                NameValueSectionHandler baseHandler 
= new NameValueSectionHandler();
InBlock.gif                settings 
= (NameValueCollection)baseHandler.Create(parent, configContext, section);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                settings 
= null;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(settings==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DbPath
=DBPATH_DEFAULT;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DbPath
=ReadSetting(settings,DBPATH,DBPATH_DEFAULT);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return settings;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//获得DataPath
InBlock.gif
        public static string DataPath
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return DbPath;}
ExpandedSubBlockEnd.gif        }

InBlock.gif      //这个方法在Duwamish里面被放置在SystemFramwork里面
InBlock.gif        
public static String ReadSetting(NameValueCollection settings, String key, String defaultValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Object setting 
= settings[key];
InBlock.gif                
InBlock.gif                
return (setting == null? defaultValue : (String)setting;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return defaultValue;
ExpandedSubBlockEnd.gif            }

InBlock.gif        
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

其具体作用:
读取Web.Config里面的设置,如果没有设置就返回默认设置,这一点正是我们创建自己的配置节类型的原因.

(2)从Duwamish里面的Common.Data定义的类型继承于DataSet,而且加上了[SerializableAttribute] 可以看出其主要为利用Remoting技术部署提供可以序列化为Binary或者SOPA的数据类型.另外,也为程序更少的依赖数据库而更好地控制数据提供了方便.

这里,我们由于架构没有用到DotNetRemoting技术,没有设计这个类型.

接下来就是独立实现DataAccess层了,对数据进行一系列的操作返回类型基本上用DataSet,Bool,String.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值