Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the Event3 class.
 /// </summary>
 /// <arg name="handler"></arg>
 /// <arg name="arg1"></arg>
 /// <arg name="arg2"></arg>
 /// <arg name="arg3"></arg>
 public Event3(int evenId, Handler3 <TArg1, TArg2, TArg3> handler, TArg1 arg1, TArg2 arg2, TArg3 arg3)
     : base(evenId)
 {
     this.handler = handler;
     this.arg1    = arg1;
     this.arg2    = arg2;
     this.arg3    = arg3;
 }
Ejemplo n.º 2
0
        static void Main()
        {
            MyStopWatch stopwatch = new MyStopWatch();
            Handler1    handler1  = new Handler1();
            Handler2    handler2  = new Handler2();
            Handler3    handler3  = new Handler3();

            stopwatch.Event += handler1.OnTimer;
            stopwatch.Event += handler2.OnTimer;
            stopwatch.Event += handler3.OnTimer;
            stopwatch.Start(new TimeSpan(0, 0, 5));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            WriteArguments(args);

            Handler1 handler1 = new Handler1();
            Handler2 handler2 = new Handler2();
            Handler3 handler3 = new Handler3();

            MyServiceNormal myServiceNormal = new MyServiceNormal(handler1, handler2, handler3);

            myServiceNormal.DoSomething();

            WriteSeparator();

            HandlerMediator       handlerMediator       = new HandlerMediator(handler1, handler2, handler3);
            MyServiceWithMediator myServiceWithMediator = new MyServiceWithMediator(handlerMediator);

            myServiceWithMediator.DoSomething();
        }
Ejemplo n.º 4
0
            public bool TryGetHandler(out IHttpHandler handler)
            {
                var count = _collection.Count;

                if (count == 0)
                {
                    handler = null;
                    return(true);
                }
                else if (count == 1)
                {
                    handler = _collection[0];
                    return(true);
                }
                else if (count == 2)
                {
                    handler = new Handler2(_collection[0], _collection[1]);
                    return(true);
                }
                else if (count == 3)
                {
                    handler = new Handler3(_collection[0], _collection[1], _collection[2]);
                    return(true);
                }
                else if (count == 4)
                {
                    handler = new Handler4(_collection[0], _collection[1], _collection[2], _collection[3]);
                    return(true);
                }
                else if (count == 5)
                {
                    handler = new Handler5(_collection[0], _collection[1], _collection[2], _collection[3], _collection[4]);
                    return(true);
                }
                else
                {
                    handler = null;
                    return(false);
                }
            }
Ejemplo n.º 5
0
        /// <summary>
        /// 异步调用
        /// </summary>
        public void DoAsynAction()
        {
            Handler1 handler1 = new Handler1(AsynDemo1);

            handler1.BeginInvoke(null, null);

            Handler2 handler2 = new Handler2(AsynDemo2);

            handler2.BeginInvoke("string", null, null);

            Handler3 handler3 = new Handler3(AsynDemo3);
            //handler3.BeginInvoke(null, null);
            IAsyncResult result3 = handler3.BeginInvoke(null, null);

            Handler4 handler4 = new Handler4(AsynDemo4);
            //handler4.BeginInvoke("string", null, null);
            IAsyncResult result4 = handler4.BeginInvoke("string", null, null);

            Handler5 handler5 = new Handler5(AsynDemo5);
            //handler5.BeginInvoke("", 0, null, null);
            IAsyncResult result5 = handler5.BeginInvoke("string", 0, null, null);
        }
Ejemplo n.º 6
0
 public RequestHandler3 <T, R, U>?Handle(Handler3 handler)
 {
     _executor = (request, param1, param2, param3, mediaTypeMapper1, errorHandler1, logger1)
                 => RequestExecutor.ExecuteRequest(() => handler.Invoke(param1, param2, param3), errorHandler1, logger1);
     return(this);
 }
Ejemplo n.º 7
0
 public MyServiceNormal(Handler1 handler1, Handler2 handler2, Handler3 handler3)
 {
     _handler1 = handler1;
     _handler2 = handler2;
     _handler3 = handler3;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Create an event with 3 arguments.
 /// </summary>
 /// <typearg name="TArg1"></typearg>
 /// <typearg name="TArg2"></typearg>
 /// <typearg name="TArg3"></typearg>
 /// <arg name="handler"></arg>
 /// <arg name="arg1"></arg>
 /// <arg name="arg2"></arg>
 /// <arg name="arg3"></arg>
 /// <returns></returns>
 public static EventBase CreateEvent <TArg1, TArg2, TArg3>(int eventId, Handler3 <TArg1, TArg2, TArg3> handler, TArg1 arg1, TArg2 arg2, TArg3 arg3)
 {
     return(new Event3 <TArg1, TArg2, TArg3>(eventId, handler, arg1, arg2, arg3));
 }
Ejemplo n.º 9
0
 public HandlerMediator(Handler1 handler1, Handler2 handler2, Handler3 handler3)
 {
     _handler1 = handler1;
     _handler2 = handler2;
     _handler3 = handler3;
 }