刚's profile旭克狂飙 C# .Net And More..PhotosBlogListsMore Tools Help

Blog


    January 29

    2009 kick off

    2009 could be a nice year!
    Let's wish something amazing would happen.
    August 22

    厦门小游

    厦门不愧是中国最适合人类居住的城市。
    清山绿岛,碧海环绕。
    整个城市几乎被绿茵覆盖。
    G2
    (鼓浪屿一瞥)
    October 29

    A friend from Mauritius

    Yesterday, I made a friend in Mauritius.
    It is really nice! We chat for more than 5 hours. I have never been chatting with someone for such a long time.
     
    Mauritius is a island country in Africa. The major economy incoming is travel.
    I made a wish to go travel to Mauritius some day.
    To enjoy the sunshine, the beach, to see the huge amazon lotus and the 7 colors mud.
    That will be wonderful.
    August 17

    龚青来访

    好久没见的老朋友老同学。这小子最爽了:悠长假期携家属四处旅游。 哥们真的很羡慕。
    October 28

    Sample code for the usage of LocalDataStoreSlot

    /* Introduction:
        1. The two DoWork methods  will be invoked in the same thread. A LocaDatStoreSlot is used to share data between them.
        2. In the DoWork method of BusinessLogicClass,  a LocalDataStoreSlot is created and the instance of ApplicationSession is stored in the slot.
        3. In the DoWork method of AnotheBusinessLogicClass, the data stored in the named LocalDataStoreSlot is retrieved.
     */

    using System;
    using System.Threading;
    using System.Diagnostics;
    using System.Text; 

    namespace SUnit
    {

        /// <summary>
        /// A test client.
        /// </summary>
        public class Client
        {
            /// <summary>
            /// The main method.
            /// </summary>
            public static void Start()
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork));
                Thread.Sleep(2000);
            } 

            /// <summary>
            /// A thread method.
            /// </summary>
            /// <param name="data">N/A</param>
            private static void DoWork(object data)
            {

                SomeBusinessLogicClass businessObject1 = new SomeBusinessLogicClass();
                businessObject1.DoWork(); 
                // Some Operation Here.
                AnotherBusinessLogicClass businessObject2 = new AnotherBusinessLogicClass();
                businessObject2.DoWork();
            }      
        } 

        /// <summary>
        /// Some business logic class.
        /// </summary>
        public class SomeBusinessLogicClass
        {

            /// <summary>
            /// Performs some business logic operation.
            /// <remarks>
            /// In this operation, the session data is stored in 
            /// the <see cref="LocalDataStoreSlot"/> named 'SampleSlot'.
            /// </remarks>
            /// </summary>
            public void DoWork()
            {

                ApplicationSession session = new ApplicationSession();
                session.UserName = Environment.UserName;
                session.Password = "eva";
                Thread.FreeNamedDataSlot(DataSlotSampleConstant.SlotName);
                LocalDataStoreSlot slot = Thread.AllocateNamedDataSlot(DataSlotSampleConstant.SlotName);
                Thread.SetData(slot, session);
            }
        } 

        /// <summary>
        /// Some business logic class.
        /// </summary>
        public class AnotherBusinessLogicClass
        {

            /// <summary>
            /// Performs some business logic operation.
            /// <remarks>
            /// In this operation, the session data can be retrieved from 
            /// the <see cref="LocalDataStoreSlot"/> named 'SampleSlot'.
            /// </remarks>
            /// </summary>
            public void DoWork()
            {

                LocalDataStoreSlot slot = Thread.GetNamedDataSlot(DataSlotSampleConstant.SlotName);
                ApplicationSession session = Thread.GetData(slot) as ApplicationSession; 
                Debug.Assert(null != session);            
                if (null != session)
                {
                    Console.WriteLine("Session Info:{0}", session.ToString());
                    Debug.Assert(session.UserName == Environment.UserName);
                }            
            }
        } 

        /// <summary>
        /// Represents a container of constants.
        /// </summary>
        public class DataSlotSampleConstant
        {

            /// <summary>
            /// The slot name.
            /// </summary>
            public const string SlotName = "SampleSlot";      

        } 

        /// <summary>
        /// A data structure.
        /// </summary>
        public class ApplicationSession
        {

            /// <summary>
            /// The user name.
            /// </summary>
            private string userName;

            /// <summary>
            /// The password.
            /// </summary>
            private string password;       

            /// <summary>
            /// Gets or sets the user name.
            /// </summary>
            public string UserName
            {
                get { return this.userName; }
                set { this.userName = value; }
            } 

            /// <summary>
            /// Gets or sets the password.
            /// </summary>
            public string Password
            {
                get { return this.password; }
                set { this.password = value; }
            } 

            /// <summary>
            /// Returns a <see cref="System.String"/> represent this <see cref="System.Object"/>.
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {

                StringBuilder builder = new StringBuilder();
                builder.Append("UserName:");
                builder.Append(userName);
                builder.Append("Password:");
                builder.Append(password);
                return builder.ToString();
            }       
        }
    }

    /* If you want to share data in different thread (in the same domain), see the sample code below.
     */

    /// <summary>
    /// Share data in a domain.
    /// <remarks>
    /// Data can be shared in different threads of the same domain.
    /// </remarks>
    /// </summary>
    public class Client2
    {
        /// <summary>
        /// The main method.
        /// </summary>
        public static void Start()
        {
            AppDomain appDomain = AppDomain.CurrentDomain;
            appDomain.SetData("SomeDataName", "Hello! App Domain!");
            ThreadPool.QueueUserWorkItem(new WaitCallback(GetData));
            Thread.Sleep(2000);
        } 

        /// <summary>
        /// A thread method.
        /// </summary>
        /// <param name="data">N/A</param>
        private static void GetData(object data)
        {
            Console.WriteLine(AppDomain.CurrentDomain.GetData("SomeDataName"));
        }

    }

     
    October 23

    MM 爱心短信

    MM让我很感到的一些短信:
     
    1. 我总是无端的想起你,总也想不够似的。。
    [寒假]
    2. 很乖呢,扫地拖地擦桌子,还不喊累呢!
    [新年伊始]
    3. 你爱我总有条件的。。哼, 不过我还是会乖乖的。
    [当我说"只要你怎样怎样我就怎样"时]
    4. 我想你的时候总也记得你对我的凶呢,不过我会越来越乖,你就舍不得了!
    [相思时]
    5. 亲爱的,生日快乐!
    [生日时]
    6. 七夕因为有你,才让我幸福而又感伤。
    [七夕]
     

    变了

    MM走了,剩下的半个柚子,没吃,居然长出了飞禽走兽。
    还有一个柿子,也变味了!
    October 22

    苗苗走了,茫然地在电脑前坐了一下午。

    这次没有送她到上火车时,因此也没有泪眼汪汪的场面。
     
    她快乐地走了。留下了不知所措的我。

    回来后,打扫了一下房间,茫然地在电脑前坐了一下午。
    September 24

    SUnit--朦胧

    Strephon的本意是做一个NHibernate的Wrapper.
    他在尝试NHibernate的时候,有过痛苦的经历。
     
    但我想NHibernate已经在逐渐成熟, 而且其本身使用已经比较简单。
    Wrapper不会让它再简单多少。
     
    想起最近在看的NMock, 觉得挺有意思。
    随着软件业的不断发展,企业对软件的质量要求越来越高, Unit Test成了软件开发过程中不可或缺的一部分。
    Microsoft在它的VS 2005中就集成了Unit Test功能。

    目前Unit Test的工具不是很多,我们何不来实现一套呢?
     
    我称我们要做的东西为SUnit.

    SUnit--催生

    最初是strephon(家栋)提出来要做一个OpenSource的Project。
    他总是有专业意识的。
     
    可我想到的是, 这是一个锻炼我们远程协作能力的好机会。
    Strephon在长沙, Scordeity在北京,而我在上海。
    现在Team成员散布全国各地, 正好让我们有机会实施这样的锻炼。
     
    把想法跟春华(Scordeity)说了,他很是赞同。
    很欣慰他还是象以前一样很积极。
    催着我写计划。
    September 16

    信用

    今天领到了浦发银行的信用卡奖品:捷安特(Giant)自行车一辆。
    感觉很满足。乘着手机有点,赶紧打电话跟MM分享了一下。

    每次打浦发客服电话,对方态度都很好。
    目前我所接触的所有银行中浦发银行客服做的最好。

    September 15

    专业

    今天看了镇上的两小伙子打桌球。
    那水平叫一个专业!!!
    想想自己,似乎从来没有把什么事情做到专业的地步!
    汗!
    September 12

    腐朽

    某日,突然发现自己穿的牛仔裤屁股上已经破了好大一块。
    心情格外复杂。
    September 03

    今天看了苗苗的Space


    今天看了苗苗的Space。(苗苗是她逼我给她取的名字, 她说自己是一颗可造之苗) 被她的点滴言语感动了。
    好久没尝到眼泪的味道。
    想给她发短信。
    手机上已有好些按键不灵了,老早就有,一直没拿去修,也没打算去修。我想我是被程序员的惰性惯怀了。
    就像有些事,你明明知道是要去做的, 可你就是不愿去面对, 去解决。
    我知道我欠她很多事情没去做,但是总是不愿去面对,去弥补。
    对待朋友,只要条件允许,我不会让自己吝啬。对她,我却总是情不自禁地有所保留。
    我不知道我以前坚定的信念都躲到那里去了。
    她总说我不欣赏她。每当这时我总是连连说欣赏欣赏。可总也找不出欣赏她的哪些东西。

    她总是憧憬着我们美好的未来。
    而根本不知道身边这个人却是一个连想象的勇气都没有的懦夫。

    昨天送走了她。
    她在车窗里强忍着眼泪。从男人的角度讲,我从来没有想过,分别是需要眼泪的。但我却还连自称男人的资格都没有。
    不说肩负起责任,反倒是总是企图从她身上夺走某个东西。
    现在她走了,以前触手可及的东西,现在都变的遥远了。
    送走她,回来的地铁上我看到了玻璃中的自己, 那么的渺小, 那么孤立无援。

    那一刻我才深深的感觉到她在我的生活中是多么的重要。
    无论是她把MSN的个人形象照片换成了我和她的合照,
    还是离别时她落下的眼泪,
    还是她喜欢双手抱着我的一只手睡觉,
    还是她喜欢用额头帮我扶镜框,
    ....
    这一切都会深深留在我的心中。
     
    January 03

    C#相关点滴知识

    1、根据线程安全的相关知识,分析以下代码,当调用test方法时i>10时是否会引起死锁?并简要说明理由。

     

            public void test(int i)

            {

                lock (this)

                {

                    if (i > 10)

                    {

                        i--;

                        test(i);

                    }

                }

            }

     

    答:不会发生死锁,(但有一点int是按值传递的,所以每次改变的都只是一个副本,因此不会出现死锁。但如果把int换做一个object,那么死锁会发生)

     

    2、分析以下代码。

     

            public static void test(string ConnectString)

            {

                System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();

                conn.ConnectionString = ConnectString;

                try

                {

                    conn.Open();

                }

                catch (Exception Ex)

                {

                    MessageBox.Show(Ex.ToString());

                }

                finally

                {

                    if (!conn.State.Equals(ConnectionState.Closed))

                        conn.Close();

                }

            }

     

    请问

    1)以上代码可以正确使用连接池吗?

     

    答:回答:如果传入的connectionString是一模一样的话,可以正确使用连接池。不过一模一样的意思是,连字符的空格数,顺序完全一致。

     

     

    2)以上代码所使用的异常处理方法,是否所有在test方法内的异常都可以被捕捉并显示出来?

     

    答:只可以捕捉数据库连接中的异常吧. finally中,catch中,如果有别的可能引发异常的操作,也应该用try,catch。所以理论上并非所有异常都会被捕捉。)

     

    3、简要谈一下您对微软.NET 构架下remotingwebservice两项技术的理解以及实际中的应用。

     

    答:WS主要是可利用HTTP,穿透防火墙。而Remoting可以利用TCP/IP,二进制传送提高效率。

    December 11

    WebHelper Team Live 架构初想

    WebHelper Team Live : 通过ProjectMission的形式将Member联系起来.增强软件过程,提高开发效率.

    Message : 促进TeamMember沟通交流

    ProjectLog : 记录经验 供回顾 供业绩评估

    MemberLog : 积累个人开发经验, 可供自己或者其他成员日后参阅.
    December 01

    隐秘的微软企业级数据中心系统架构图

    近日在观看MS WebCast视频后,发现一同下载的PDF中有些奇怪的DD.
     
    1.原图

     2.初露端倪


    3.犹抱琵琶


    4.真相大白

    原来在原图后面有一张微软企业级数据中心系统架构图,正常情况下看不出来,只有在拖动或者页面切换的瞬间可以看出.(后来还发现,还有一张扬声器状物体的图,在图3中可以看出)通过瞬时拷屏技术,将它弄了出来,不过这些东东实的不是很懂.迎大家转载讨论.

    VS2005系统架构设计图二例

    声明:本案例,属个人假象图,若与真实图有雷同,纯属巧合.
    JobSky应用图

    JobSky逻辑数据中心图

    JobSky部署图
    November 30

    VS2005系统架构设计图一例


    WebHelper ApplicationDiagram V1.0

    WebHelper 应用视图
    描述WebHelper解决方案中的所有Project以及他们之间的依赖关系

     WebHelper LogicDataCenter Diagram V1.0
    (逻辑数据中心)
    描述应用的部署环境的一种逻辑图



    WebHelper DeployDiagram V1.0

    WebHelper部署视图
    校验应用和逻辑环境的兼容性.
     

    November 23

    基于泛型重构和设计模式技术的数据访问层设计

    主要变化:
    1.引入范型(C#2.0)
    2.引入空对象(重构)
    3.引入抽象工厂(设计模式)
     
    1)主图


    2)DAO
     


    3)数据访问支持



    4)数据访问工厂