搏客 Winning
After three days without programming, life becomes meaningless
posts - 46,  comments - 41,  trackbacks - 21

我的评论

对MSMQ 的一个简单封装 搏客 Winning 2006-07-03 11:27  
using System;
using System.IO;
using System.Messaging;

using Util;

namespace MQ
{
public class MSMQ
{
private Type m_type = null;
private string m_queuepath = null;


public MSMQ(string QueuePath)
{
this.m_queuepath = QueuePath;
if (!MessageQueue.Exists(this.m_queuepath)) MessageQueue.Create(this.m_queuepath);
}

public void Send(object obj)
{
try
{
MessageQueue mq = new MessageQueue(m_queuepath);
mq.Send(new Message(obj));
if (m_type == null) m_type = obj.GetType();
}
catch (Exception exc)
{
LogWriter.WriteLog("MSMQ.Send", exc.Message);
}
}

public object Receive(Type type)
{
MessageQueue mq = new MessageQueue(m_queuepath);
mq.Formatter = new XmlMessageFormatter(new Type[] { type });
try
{
Message msg = mq.Receive();
return msg.Body;
}
catch (Exception exc)
{
LogWriter.WriteLog("MSMQ.Receive", exc.Message);
return null;
}
}

public object Receive()
{
return Receive(this.m_type);
}

}
}
re: 解UrlPathEncode的字符串的噩梦 搏客 Winning 2005-05-10 09:27  
我们做项目的时候几乎不用Querystring传输中文
re: 随笔一 搏客 Winning 2005-05-09 12:54  
why 没有文字 only 两幅图片
工厂模式的一个应用---统一数据库差异 搏客 Winning 2005-04-29 10:52  
    在我们的项目中做到跨数据库是常有的需求,基本的思想是创建不同数据库统一的访问接口,然后为每一种数据库提供不同的实现,然后用工厂方法创建指定的数据库访问类,用接口访问数据库而不是具体的类。例如下面的Demo实现了用Web.Config中指定的类型和连接串创建数据库连接。
 
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Data.SqlClient;

namespace Demo
{
    
//定义数据库管理的相同接口
    public interface IDBDialect
    
{    
        IDbConnection CreateConnection();
    }


    
//默认的数据库管理类,包含一个不同数据库管理类的共同接口成员
    
//实现接口成员实例化为指定的类型后始终用这个类型执行数据库操作

    
public class DefaultDB
    
{
        
private static IDBDialect idd=null;
        
private static string connStr=null;

        
//静态初始化保证对数据库类型的判断只做一次
        static DefaultDB()
        
{
            connStr
=ConfigurationSettings.AppSettings["ConnStr"];
        

            
switch(ConfigurationSettings.AppSettings["DBType"])
            
{
                
case "SqlServer":
                    idd
=new SqlDialect();
                    
break;
                
case "OleDb":
                
default:
                    idd
=new OleDbDialect();
                    
break;
            }

        }


        
public static string ConnStr
        
{
            
get{return connStr;}
        }


        
public static IDbConnection CreateConnection()
        
{
            
return idd.CreateConnection();
        }

    }


    
//SqlServer管理类
    public class SqlDialect : IDBDialect
    
{
        
public IDbConnection CreateConnection()
        
{
            
return new SqlConnection(DefaultDB.ConnStr);
        }

    }


    
//OleDb管理类
    public class OleDbDialect : IDBDialect
    
{
        
public IDbConnection CreateConnection()
        
{
            
return new OleDbConnection(DefaultDB.ConnStr);
        }

    }

}
re: [ASP.net]未解的疑惑! 搏客 Winning 2005-04-12 09:50  
当然是Open()和Close()一次来得要快,但是方法的细粒度带来的
灵活性和性能是矛盾的。这需要权衡一下。
不错,以前看过国外一个小公司做的类似产品。好象要$90

与我联系

搜索

 

常用链接

随笔分类

随笔档案

积分与排名

  • 积分 - 30421
  • 排名 - 1312

最新评论

阅读排行榜