示例#1
0
        public AgentEventRectifier(IEnumerable <Type> types, INotifierQueryable agent_instance)
        {
            this._Types     = types.ToArray();
            _RemoveHandlers = new List <System.Action>();


            Type agentType = typeof(INotifierQueryable);

            System.Reflection.MethodInfo agentQueryNotifier = agentType.GetMethod(nameof(INotifierQueryable.QueryNotifier));

            foreach (Type type in _Types)
            {
                if (!type.IsInterface)
                {
                    continue;
                }
                System.Reflection.MethodInfo agentQueryNotifierT = agentQueryNotifier.MakeGenericMethod(type);


                object notifyInstance = agentQueryNotifierT.Invoke(agent_instance, new object[0]);

                Type notifyTypeT = typeof(INotifier <>).MakeGenericType(type);


                System.Reflection.EventInfo notifySupply   = notifyTypeT.GetEvent(nameof(INotifier <object> .Supply));
                System.Reflection.EventInfo notifyUnsupply = notifyTypeT.GetEvent(nameof(INotifier <object> .Unsupply));

                Utility.Reflection.TypeMethodCatcher catcherSupply       = new Regulus.Utility.Reflection.TypeMethodCatcher((System.Linq.Expressions.Expression <Action <AgentEventRectifier> >)(ins => ins._Supply <object>(null)));
                System.Reflection.MethodInfo         supplyGenericMethod = catcherSupply.Method.GetGenericMethodDefinition();
                System.Reflection.MethodInfo         supplyMethod        = supplyGenericMethod.MakeGenericMethod(type);

                Utility.Reflection.TypeMethodCatcher catcherUnsupply       = new Regulus.Utility.Reflection.TypeMethodCatcher((System.Linq.Expressions.Expression <Action <AgentEventRectifier> >)(ins => ins._Unsupply <object>(null)));
                System.Reflection.MethodInfo         unsupplyGenericMethod = catcherUnsupply.Method.GetGenericMethodDefinition();
                System.Reflection.MethodInfo         unsupplyMethod        = unsupplyGenericMethod.MakeGenericMethod(type);

                Type actionT1 = typeof(System.Action <>);
                Type actionT  = actionT1.MakeGenericType(type);



                Delegate delegateSupply   = Delegate.CreateDelegate(actionT, this, supplyMethod);
                Delegate delegateUnsupply = Delegate.CreateDelegate(actionT, this, unsupplyMethod);
                notifySupply.AddEventHandler(notifyInstance, delegateSupply);
                notifyUnsupply.AddEventHandler(notifyInstance, delegateUnsupply);
                _RemoveHandlers.Add(() =>
                {
                    notifySupply.RemoveEventHandler(notifyInstance, delegateSupply);
                    notifyUnsupply.RemoveEventHandler(notifyInstance, delegateUnsupply);
                });
            }
        }
示例#2
0
        public System.Guid Bind(INotifierQueryable notifier)
        {
            AgentEventRectifier rectifier = new AgentEventRectifier(_WatchTypes, notifier);
            RectifierBinder     user      = new RectifierBinder(rectifier);

            _Users.Add(user);
            foreach (Tuple <Type, object> g in user.Ghosts)
            {
                _Register.Regist(g.Item1, g.Item2);
            }
            rectifier.SupplyEvent   += _Register.Regist;
            rectifier.UnsupplyEvent += (type, obj) => { _Register.Unregist(obj); };

            return(user.Id);
        }
示例#3
0
        public TestEnv(T entry)
        {
            Entry = entry;
            IProtocol protocol = Regulus.Remote.Protocol.ProtocolProvider.Create(typeof(T2).Assembly).Single();

            _Service = new Regulus.Remote.Standalone.Service(entry, protocol);
            _Agent   = new Regulus.Remote.Ghost.Agent(protocol);
            _Service.Join(_Agent);


            Queryable = _Agent;

            _AgentUpdater = new ThreadUpdater(_Update);
            _AgentUpdater.Start();
        }
示例#4
0
文件: Console.cs 项目: bmjoy/Regulus
        public User CreateUser(INotifierQueryable notifier)
        {
            AgentEventRectifier rectifier = new AgentEventRectifier(_WatchTypes, notifier);
            User user = new User(rectifier);

            _Users.Add(user);
            // todo _Updater.Add(user.Agent);
            foreach (Tuple <Type, object> g in user.Ghosts)
            {
                _Register.Regist(g.Item1, g.Item2);
            }
            rectifier.SupplyEvent   += _Register.Regist;
            rectifier.UnsupplyEvent += (type, obj) => { _Register.Unregist(obj); };

            return(user);
        }
示例#5
0
        public ChatRoomPlayStatus(INotifierQueryable queryer, UIComponent room, UILibrary library)
        {
            _ReleaseHelper = new ReleaseHelper();
            room.Page.RootElement.Visibility = Visibility.Visible;

            _ReleaseHelper.Actions.Add(() => {
                room.Page.RootElement.Visibility = Visibility.Hidden;
            });


            var messageContol = room.Page.RootElement.FindName("Message") as global::Stride.UI.Controls.EditText;
            var targetContol  = room.Page.RootElement.FindName("Target") as global::Stride.UI.Controls.EditText;
            var sendControl   = room.Page.RootElement.FindName("Send") as global::Stride.UI.Controls.Button;
            var quitControl   = room.Page.RootElement.FindName("Quit") as global::Stride.UI.Controls.Button;
            var listPanel     = room.Page.RootElement.FindName("List") as global::Stride.UI.Panels.Grid;



            var sendObs = from handler in sendControl.TouchUpObs()
                          where messageContol.Text.Length > 0 && string.IsNullOrWhiteSpace(targetContol.Text)
                          from player in queryer.QueryNotifier <Regulus.Samples.Chat1.Common.IPlayer>().SupplyEvent()
                          from unit in new System.Action(() => player.Send(messageContol.Text)).ReturnVoid()
                          select unit;

            var sendObsDispose = sendObs.Subscribe(_ => messageContol.Text = "");

            _ReleaseHelper.Actions.Add(() => {
                sendObsDispose.Dispose();
            });

            var privateSendObs = from handler in sendControl.TouchUpObs()
                                 where messageContol.Text.Length > 0 && !string.IsNullOrWhiteSpace(targetContol.Text)
                                 from player in queryer.QueryNotifier <Regulus.Samples.Chat1.Common.IPlayer>().SupplyEvent()
                                 from target in player.Chatters.SupplyEvent()
                                 where target.Name.Value == targetContol.Text
                                 from unit in new System.Action(() => target.Whisper(messageContol.Text)).ReturnVoid()
                                 select unit;

            var privateSendObsDispose = privateSendObs.Subscribe(_ => messageContol.Text = "");

            _ReleaseHelper.Actions.Add(() => {
                privateSendObsDispose.Dispose();
            });


            var quitObs = from handler in quitControl.TouchUpObs().Take(1)
                          from player in queryer.QueryNotifier <Regulus.Samples.Chat1.Common.IPlayer>().SupplyEvent()
                          from unit in new System.Action(() => player.Quit()).ReturnVoid()
                          select unit;

            var quitObsDispose = quitObs.Subscribe(unit => DoneEvent());

            _ReleaseHelper.Actions.Add(() => {
                quitObsDispose.Dispose();
            });


            var publicMessageObs =
                from player in queryer.QueryNotifier <Regulus.Samples.Chat1.Common.IPlayer>().SupplyEvent()
                from message in Regulus.Remote.Reactive.Extensions.EventObservable <Common.Message>(h => player.PublicMessageEvent += h, h => player.PublicMessageEvent -= h)
                select message;

            var publicMessageObsDispose = publicMessageObs.Subscribe(msg => _ReceiveMessage(listPanel, $"{msg.Name}:{msg.Context}"));

            _ReleaseHelper.Actions.Add(() => {
                publicMessageObsDispose.Dispose();
            });

            var privateMessageObs =
                from player in queryer.QueryNotifier <Regulus.Samples.Chat1.Common.IPlayer>().SupplyEvent()
                from message in Regulus.Remote.Reactive.Extensions.EventObservable <Common.Message>(h => player.PrivateMessageEvent += h, h => player.PrivateMessageEvent -= h)
                select message;

            var privateMessageObsDispose = privateMessageObs.Subscribe(msg => _ReceiveMessage(listPanel, $"<private>{msg.Name}:{msg.Context}"));

            _ReleaseHelper.Actions.Add(() => {
                privateMessageObsDispose.Dispose();
            });
            this.library = library;
        }