Nero

Node.js的并发性远没有传言的那么好,回调的机制.NET中的async和await能达到一样的效果,哼。

博客园 首页 新随笔 联系 订阅 管理

Pet Shop 4.0 个人版 :解析
 
功能需求:

(1)    用户帐号的管理功能:包括帐号创建,帐号登录,帐号维护;

(2)    产品浏览功能:类别浏览,具体产品浏览,详细信息,库存信息等等;

(3)    用户购物功能:添加购物,计算总价,下订单等等。

项目列表:

序号  项目名称    描述
---------------------------------------------------------------------------------------------
1  WEB     表示层
2  Model     业务实体
3  BLL     业务逻辑层
4  DALFactory --- --------  数据层的抽象工厂
5  IDAL     数据访问层接口定义
6  SQLServerDAL    SQLServer数据访问层
7 OracleDAL    Oracle数据访问层
8  DBUtility    数据库访问组件基础类
---------------------------------------------------------------------------------------------
9  CacheDependencyFactory --------  缓存依赖类的工厂类
10  ICacheDependency   缓存依赖类接口
11  TableCacheDependency  缓存依赖实现类
---------------------------------------------------------------------------------------------
12  IBLLStrategy    同步/异步处理策略接口(实现在bll根据配置反射选择)
13  MessagingFactory ----------  异时处理消息队列的抽象工厂
14  IMessaging    异时处理消息队列接口定义
15  MSMQMessaging    异时处理消息队列的实现
---------------------------------------------------------------------------------------------
16  Profile    Profile的数据访问层
17  ProfileDALFactory ---------  ProfileDAL的工厂类(反射创建ProfileDAL)
18  IProfileDAL    Profile的数据访问层接口定义
19  OracleProfileDAL   Oracle的Profile Providers 做用户状态管理
20  SQLProfileDAL    SQL Server 的Profile Providers 做用户状态管理
----------------------------------------------------------------------------------------------
21  Membership    Membership认证和授权管理
----------------------------------------------------------------------------------------------
22  OrderProcessor    后台处理进程,处理订单队列

数据库  ---表名      

MSPetShop4
        dbo.AspNet_SqlCacheTablesForChangeNotification
 dbo.Category    宠物的类别目录表
 dbo.Inventory 宠物产品的存货信息
 dbo.Item 单个产品的详细信息
 dbo.Product 宠物的产品列表,一条Product可能包括多个Item
 dbo.Supplier 供应商信息

MSPetShop4Orders
 dbo.LineItem 订单的每一项的详细信息,包括产品名称和数量,价格等
 dbo.Orders 用户购物的订单,一个订单可以包括多项LineItem
 dbo.OrderStatus 订单的状态

MSPetShop4Profile
 dbo.Account     基本用户信息
 dbo.Cart 购物车
 dbo.Profiles 用户配置表,用于记录他们的favorites

MSPetShop4Services
 dbo.aspnet_Membership
 dbo.aspnet_Paths
 dbo.aspnet_PersonalizationAllUsers
 dbo.aspnet_PersonalizationPerUser
 dbo.aspnet_Profile
 dbo.aspnet_Roles
 dbo.aspnet_SchemaVersions
 dbo.aspnet_Users
 dbo.aspnet_UsersInRoles
 dbo.aspnet_WebEvent_Events

存储过程一大堆的 .都在 MSPetShop4Services 里面,安装之后.你自己看吧...
看下面之前 最好先把页面运行一遍,看看具体的流程..
------------------------------------------------------------------------------------------------------
  现在就一个 起始页面的 目录绑定介绍第一部分//// 按照这个框架自己先做一个小例子吧...
         ★ WEB  表示层
 private void BindCategories() {
            Category category = new Category();
            repCategories.DataSource = category.GetCategories(); // 将 IList<CategoryInfo> 作为数据源
            repCategories.DataBind();           
       
         ★ BLL  业务逻辑层
namespace PetShop.BLL {   
    public class Category {
        private static readonly ICategory dal = PetShop.DALFactory.DataAccess.CreateCategory();   
        public IList<CategoryInfo> GetCategories() {
            return dal.GetCategories();
        }      
    }
}
        ★ DALFactory  数据层的抽象工厂
namespace PetShop.DALFactory {
    public sealed class DataAccess {    
        private static readonly string path = "PetShop.SQLServerDAL";      
        private DataAccess() { }
        public static PetShop.IDAL.ICategory CreateCategory() {
            string className = path + ".Category";
            return (PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className); ------这几个方法原来没有接触过...

 说明 : 通过 SQLServer数据访问层 和 数据库访问组件基础类 已经从数据库中得到了数据.此时表示层直接调用 SQLServerDAL 就可以了.
但是 却没有这么做..而是通过 BLL---->.DALFactory----> 才将数据引用进来.

        }
    }
}
        ★ IDAL  数据访问层接口定义
namespace PetShop.IDAL{
 public interface ICategory {     
  IList<CategoryInfo> GetCategories();    
 }
}
        ★ Model 业务实体
namespace PetShop.Model {

    [Serializable]
    public class CategoryInfo {     
        private string id;
        private string name;
        private string description;
        public CategoryInfo() { }
        public CategoryInfo(string id, string name, string description) {
            this.id = id;
            this.name = name;
            this.description = description;
        }
        public string Id {
            get { return id; }
        }
        public string Name {
            get { return name; }
        }
        public string Description {
            get { return description; }
        }
    }
}
     
      ★ SQLServerDAL  SQLServer数据访问层     
namespace PetShop.SQLServerDAL {
    public class Category : ICategory {    
        private const string SQL_SELECT_CATEGORIES = "SELECT CategoryId, Name, Descn FROM Category";
        public IList<CategoryInfo> GetCategories() {
   IList<CategoryInfo> categories = new List<CategoryInfo>();          
   using(SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CATEGORIES, null)) {
                while (rdr.Read()) {
                    CategoryInfo cat = new CategoryInfo(rdr.GetString(0), rdr.GetString(1), rdr.GetString(2));
                    categories.Add(cat);
                }
            } 
            return categories;
        }  
     }
}
      ★ DBUtility  数据库访问组件基础类
namespace PetShop.DBUtility {   
    public abstract class SqlHelper { 
        public static readonly string ConnectionStringLocalTransaction ="Server=.;Database=master;uid=sa;pwd=sa";       
        public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) {
            SqlCommand cmd = new SqlCommand();
            SqlConnection conn = new SqlConnection(connectionString);         
            try {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                return rdr;
            }
            catch {
                conn.Close();
                throw;
            }
        }   
   
        private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms) {
            if (conn.State != ConnectionState.Open)
                conn.Open();
            cmd.Connection = conn;
            cmd.CommandText = cmdText;
            if (trans != null)
                cmd.Transaction = trans;
            cmd.CommandType = cmdType;
            if (cmdParms != null) {
                foreach (SqlParameter parm in cmdParms)
                    cmd.Parameters.Add(parm);
            }
        }
    }
}
--------------以下 就一个起始页面的缓存进行说明---------------

 this.CachePolicy.Dependency = DependencyFacade.GetItemDependency(); // 过一会 就写一个 100W 的数据试一下.

让我 再来看一下关于缓存的类库
9  CacheDependencyFactory --------  缓存依赖类的工厂类
10  ICacheDependency   缓存依赖类接口
11  TableCacheDependency  缓存依赖实现类

页面直接调用了 缓存依赖类的工厂类

 public static class DependencyFacade {
        private static readonly string path ="PetShop.TableCacheDependency";
      
        public static AggregateCacheDependency GetItemDependency() {
            if (!string.IsNullOrEmpty(path))
                return DependencyAccess.CreateItemDependency().GetDependency();
            else
                return null;
        }
    }
----------------------缓存依赖类的工厂类
public static class DependencyAccess {
      
        public static IPetShopCacheDependency CreateItemDependency() {
            return LoadInstance("Item");
        }

        private static IPetShopCacheDependency LoadInstance(string className) {

            string path = "PetShop.TableCacheDependency";
            string fullyQualifiedClass = path + "." + className;

            return (IPetShopCacheDependency)Assembly.Load(path).CreateInstance(fullyQualifiedClass);---又碰到前面遇到的了
        }
    }
--------------------------缓存依赖类接口
namespace PetShop.ICacheDependency {
   
    public interface IPetShopCacheDependency {

        AggregateCacheDependency GetDependency();

        AggregateCacheDependency: 关键字解释:组合ASP.NET 应用程序的.System.Web.Caching.cache 对象中存储的项和 System.Web.Caching.cacheDependency 对象数组之间的多个依赖项.无法继承此类..
        
    }
}

--------------------------缓存依赖实现类 -----还是和数据访问层那样.此时的工作已经完成. 等待工厂来引用
    public class Item : TableDependency {

        public Item() : base("ItemTableDependency") { }
    }
}

 public abstract class TableDependency : PetShop.ICacheDependency.IPetShopCacheDependency {
      
        protected char[] configurationSeparator = new char[] { ',' };

        protected AggregateCacheDependency dependency = new AggregateCacheDependency();

        protected TableDependency(string configKey) {

            string dbName ="MSPetShop4";

  <add key="CategoryTableDependency" value="Category"/>
  <add key="ProductTableDependency" value="Product,Category"/>
  <add key="ItemTableDependency" value="Product,Category,Item"/>

            string tableConfig = ConfigurationManager.AppSettings[configKey];

            string[] tables = tableConfig.Split(configurationSeparator);

            foreach (string tableName in tables)
                dependency.Add(new SqlCacheDependency(dbName, tableName));
        }

        public AggregateCacheDependency GetDependency() {
            return dependency;
        }
    }
-------缓存 就这样做好了...代码很简单..关键是 好多 关键字没有用过...不知道具体的含义..

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lovesnow1573/archive/2007/08/27/1760101.aspx

posted on 2010-04-15 23:55  强盗罗吉  阅读(224)  评论(0编辑  收藏  举报