Inheritance: MonoBehaviour
Beispiel #1
0
 private static void RegisterEvents(EventNotifier processingClass)
 {
     processingClass.DebugEvent   += DebugEventHandler;
     processingClass.StatusEvent  += StatusEventHandler;
     processingClass.ErrorEvent   += ErrorEventHandler;
     processingClass.WarningEvent += WarningEventHandler;
 }
Beispiel #2
0
 static void RegisterEvents(EventNotifier processor)
 {
     processor.DebugEvent   += Processor_DebugEvent;
     processor.ErrorEvent   += Processor_ErrorEvent;
     processor.StatusEvent  += Processor_StatusEvent;
     processor.WarningEvent += Processor_WarningEvent;
 }
Beispiel #3
0
    public void Init(EventNotifier notifier, int msg, int code, bool isAll, object onFire)
    {
        if (onFire is OnFire)
        {
            this.onFire = (OnFire)onFire; fireType = enFire.onFire;
        }
        else if (onFire is OnFire1)
        {
            this.onFire1 = (OnFire1)onFire; fireType = enFire.onFire1;
        }
        else if (onFire is OnFire2)
        {
            this.onFire2 = (OnFire2)onFire; fireType = enFire.onFire2;
        }
        else if (onFire is OnFire3)
        {
            this.onFire3 = (OnFire3)onFire; fireType = enFire.onFire3;
        }
        else if (onFire is OnFireOb)
        {
            this.onFireOb = (OnFireOb)onFire; fireType = enFire.onFireOb;
        }
        else if (onFire is OnVote)
        {
            this.onVote = (OnVote)onFire; fireType = enFire.onVote;
        }


        this.notifier = notifier;
        this.msg      = msg;
        this.code     = code;
        this.isAll    = isAll;
        removeCounter = 0;
    }
Beispiel #4
0
        public void EventsAreNotRedispatched()
        {
            EventNotifier notifier = new EventNotifier();

            int callCount = 0;

            notifier.OnEvent <TestEvent>(evnt => ++ callCount);

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);

            notifier.Submit(TestEvent.Create());
            notifier.DispatchEvents();
            Assert.Equal(1, callCount);
            callCount = 0;

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);

            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());
            notifier.DispatchEvents();
            Assert.Equal(3, callCount);
            callCount = 0;

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);
        }
Beispiel #5
0
    public static void setControlroomDoor(bool locked)
    {
        controlroomDoor = locked;

        //notify the event notifyer
        EventNotifier.NotifyOpenedControlRoom();
    }
        public void TimerTest()
        {
            //TimeListener.Append(PlanConfig.);
            int MaxRun = 100000;
            //int timeout = 60;
            int    errorCount = 0;
            double errorTime  = 0;
            double minTime    = 0;
            double maxTime    = 0;

            Trace.WriteLine("Thread creating...");
            var task = Task.Run(() =>
            {
                for (int i = 0; i < MaxRun; i++)
                {
                    var e       = new TimeoutNotifyEventArgs(60);
                    e.Callback += (p) =>
                    {
                        var t   = (DateTime.Now - p.ExpiredTime);
                        var sec = t.TotalSeconds;
                        //Trace.WriteLine(string.Format("Thread run:{0}ms", t.TotalMilliseconds));
                        errorTime += t.TotalMilliseconds;
                        if (minTime > t.TotalMilliseconds)
                        {
                            minTime = t.TotalMilliseconds;
                        }
                        if (maxTime < t.TotalMilliseconds)
                        {
                            maxTime = t.TotalMilliseconds;
                        }

                        if (sec > 1)
                        {
                            errorCount++;
                        }
                    };
                    EventNotifier.Put(e);
                }
            });

            task.Wait();
            var task1 = Task.Run(() =>
            {
                while (EventNotifier.WaitEventCount > 0 || EventNotifier.TimerNum < MaxRun)
                {
                    Trace.WriteLine(string.Format("Thread {3} wait: {0}, run: {1}, timeout num:{2}", EventNotifier.WaitEventCount, EventNotifier.TimerNum, errorCount, EventNotifier.ActiveThreadCount));
                    Thread.Sleep(500);
                }
            });

            task1.Wait();
            var avg = MathUtils.RoundCustom(errorTime / MaxRun, 4);

            Trace.WriteLine(string.Format("Thread wait: {0}, run: {1}, timeout num:{2}", EventNotifier.WaitEventCount, EventNotifier.TimerNum, errorCount));

            Trace.WriteLine(string.Format("Thread min: {0}ms, avg: {1}ms, max:{2}ms", minTime, avg, maxTime));

            EventNotifier.Dispose();
            Trace.WriteLine("Thread end.");
        }
Beispiel #7
0
    //删除一个发送者,这个时候连它的监听者也会被删除
    public static void Remove(EventNotifier notifier)
    {
        notifier.isRemove = true;
        if (m_fireCount > 0)
        {
            m_delayRemovesNotifiers.Add(notifier);//fire中的话,等到fire后才删除
            return;
        }

        if (notifier.observersById.Count != 0)//如果不加这一行,会导致foreach里有GC Alloc
        {
            foreach (EventObserver observer in notifier.observersById.Values)
            {
                AllFireNotifier.Remove(observer);
                if (!m_observersById.Remove(observer.Id))
                {
                    Debuger.LogError(string.Format("删除了不存在的监听者:{0}", observer.Id));
                }
                IdTypePool <EventObserver> .Put(observer);
            }
        }
        if (!m_notifiersById.Remove(notifier.Id))
        {
            Debuger.LogError(string.Format("删除了不存在的发送者:{0}", notifier.Id));
        }


        IdTypePool <EventNotifier> .Put(notifier);
    }
Beispiel #8
0
        public override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            this.clusterConnectionLostNotifier = this.HostedCluster.ServiceProvider.GetRequiredService <EventNotifier <EventArgs> >();
            this.gatewayCountChangedNotifier   = this.HostedCluster.ServiceProvider.GetRequiredService <EventNotifier <GatewayCountChangedEventArgs> >();
        }
Beispiel #9
0
 public async Task Book(FittingRoom fittingRoom)
 {
     this.FittingRoomBookingStatus = FittingRoomBookingStatusEnum.InUse;
     this.FittingRoomId            = fittingRoom.Id;
     fittingRoom.Book();
     await EventNotifier.Notify(this.UserNotificationId, fittingRoom.Localization);
 }
Beispiel #10
0
    public static EventNotifier Get()
    {
        EventNotifier notifier = IdTypePool <EventNotifier> .Get();

        notifier.Init();
        m_notifiersById.Add(notifier.Id, notifier);
        return(notifier);
    }
Beispiel #11
0
 // Sets the open/close-value of a door
 public static void setDoor(int door, bool open)
 {
     //notifies EventNotifier that a new door is open, if that door is not allready open
     if (open && !openDoors[door - 1])
     {
         EventNotifier.NotifyNewPuzzle(door);
     }
     openDoors[door - 1] = open;
 }
Beispiel #12
0
        static void Main(string[] args)
        {
            var path = args[0];

            if (!string.IsNullOrEmpty(path))
            {
                EventNotifier.SendDigest(path);
            }
        }
Beispiel #13
0
        public void Execute()
        {
            this.notifier = new EventNotifier();
            this.notifier.SimulationStartedForSeatingArrangement += this.OnSimulationStartedForSeatingArrangement;
            this.notifier.SimulationEndedForSeatingArrangement   += this.OnSimulationEndedForSeatingArrangement;

            new Launcher(this.notifier)
            .ExecuteSimulations(PerformanceTestSimulation.CreateSeatingArrangement());
        }
Beispiel #14
0
 public override void OnClear()
 {
     notifier = null;
     onFire   = null;
     onFire1  = null;
     onFire2  = null;
     onFire3  = null;
     onFireOb = null;
     onVote   = null;
 }
Beispiel #15
0
    // Resets all doors so that only the first one is open
    public static void resetOpenDoors()
    {
        openDoors    = new bool[3];
        openDoors[0] = true;

        //notify EventNotifier that the doors are reset
        EventNotifier.NotifyNewPuzzle(1);
        //Updates the notebook
        NotebookController.SetAccess(1, NotebookController.GetLevelKey(level));
    }
        /// <inheritdoc/>
        public override int GetHashCode()
        {
            var hashCode = base.GetHashCode();

            hashCode = (hashCode *
                        -1521134295) + EventNotifier.GetHashSafe();
            hashCode = (hashCode *
                        -1521134295) + ContainsNoLoops.GetHashSafe();
            return(hashCode);
        }
Beispiel #17
0
        public IEntity Instantiate()
        {
            int           id            = _gameEngine.EntityIdGenerator.Next();
            EventNotifier eventNotifier = _gameEngine.EventNotifier;

            RuntimeEntity entity = new RuntimeEntity(id, this, eventNotifier);

            _gameEngine.AddEntity(entity);

            return(entity);
        }
Beispiel #18
0
 public PassService(
     PlayerStateManager playerStateManager,
     AgentLookup agentLookup,
     TimerService timerService,
     EventNotifier notifier)
 {
     this.playerStateManager = playerStateManager;
     this.agentLookup        = agentLookup;
     this.timerService       = timerService;
     this.notifier           = notifier;
 }
 public async Task test()
 {
     try
     {
         await EventNotifier.Notify("dzrl-i1e64c:APA91bHt9h6162Dl6ds_xfed1J2PrUOXQLUvcFudA5pTh-hCan9M4nSdAw3qNip6d-H5rBkoz9av1Cgq6i9msv8rLzo6IV57Q-qsrbkIXYCOgfgkiapr0VIjGf4UTv6kESq8Hn0alwpZ", "1");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Beispiel #20
0
            public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
            {
                var clusterConnectionLostNotifier  = new EventNotifier <EventArgs>();
                var gatewayConnectionCountNotifier = new EventNotifier <GatewayCountChangedEventArgs>();

                clientBuilder.ConfigureServices(s => s.AddSingleton(clusterConnectionLostNotifier));
                clientBuilder.ConfigureServices(s => s.AddSingleton(gatewayConnectionCountNotifier));
                clientBuilder.Configure <GatewayOptions>(options => options.GatewayListRefreshPeriod = TimeSpan.FromSeconds(1));
                clientBuilder.AddClusterConnectionLostHandler((s, e) => clusterConnectionLostNotifier.Notify(e));
                clientBuilder.AddGatewayCountChangedHandler((s, e) => gatewayConnectionCountNotifier.Notify(e));
            }
        public FederationManager(NodeSettings nodeSettings, Network network, ILoggerFactory loggerFactory, IKeyValueRepository keyValueRepo)
        {
            this.settings     = Guard.NotNull(nodeSettings, nameof(nodeSettings));
            this.network      = Guard.NotNull(network as PoANetwork, nameof(network));
            this.keyValueRepo = Guard.NotNull(keyValueRepo, nameof(keyValueRepo));

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
            this.locker = new object();

            this.OnFedMemberAdded  = new EventNotifier <PubKey>();
            this.OnFedMemberKicked = new EventNotifier <PubKey>();
        }
        public static object AddSSLCertificate(object[] args)
        {
            byte[] accountAddress = (byte[])args[0];
            Logger.log(accountAddress);
            Logger.log("Checking Account Owner with CheckWitness");
            if (!Runtime.CheckWitness(accountAddress))
            {
                Logger.log("Invalid Account or Invalid Transaction");
                return(false);
            }

            Logger.log("Checked Account Owner with CheckWitness");

            Logger.log("Checking Account Cert Credit Balance");
            if (!PaymentManager.IsAccountBalanceSufficientCertificateOperation(accountAddress))
            {
                Logger.log("Account Cert Credit is Not Sufficient for Add SSL Certificate Operation");
                return(false);
            }

            Logger.log("Checked Account Cert Credit Balance");

            byte[] encodedCert     = (byte[])args[1];
            byte[] certificateHash = Sha256(encodedCert);
            Logger.log("Adding SSL Certificate");
            bool addSslCertificateResult = SslCertificateHandler.AddSslCertificate(certificateHash, encodedCert);

            if (addSslCertificateResult)
            {
                Logger.log("Charging Fee For Certificate Operation");
                if (!PaymentManager.ChargeFeeForCertificateOperation(accountAddress))
                {
                    Logger.log("Error while charging fee for Certificate Operation");
                    return(false);
                }

                Logger.log("Charge Fee For Certificate Operation success");

                EventNotifier.NotifyNewSSLCertificateAdded(encodedCert);
            }
            else
            {
                Logger.log(
                    "Because of error in add in SSL Certificate Not Fee will be charged For Certificate Operation");
            }

            Logger.log(addSslCertificateResult);
            Logger.log("SSL Certificate process completed");
            return(addSslCertificateResult);
        }
Beispiel #23
0
    // Open next puzzle
    public void FinishLevel()
    {
        NotebookController.SetAccess(1, NotebookController.GetPuzzleKey(level, puzzle));
        if (puzzle >= 0 && puzzle < 3)
        {
            Globals.setDoor(puzzle + 1, true);
        }
        else if (puzzle == 3)
        {
            Globals.nextLevelAvailable = true;

            //Alerts EventNotifier that one can now travel to a new location
            EventNotifier.NotifyNewLevel();
        }
    }
Beispiel #24
0
    //监听,onFire返回false表示否决(之后的监听者不执行)
    static int DoAdd(EventNotifier notifier, int msg, int code, object onFire)
    {
        if (notifier == null || !m_notifiersById.ContainsKey(notifier.Id))
        {
            Debuger.LogError(string.Format("观察对象找不到:{0}", msg + code));
            return(Invalid_Id);
        }

        EventObserver observer = IdTypePool <EventObserver> .Get();

        observer.Init(notifier, msg, code, false, onFire);
        notifier.Add(observer);
        AllFireNotifier.Add(observer);
        m_observersById.Add(observer.Id, observer);
        return(observer.Id);
    }
Beispiel #25
0
 public RoundManager(
     IEnumerable <Bot> bots,
     TimerService timerService,
     EventNotifier notifier,
     IControlledRandom random)
 {
     this.playerCircle       = new PlayerCircle();
     this.handEvaluator      = new HandWinEvaluator();
     this.rulesEngine        = new GameRulesEngine();
     this.playerStateManager = new PlayerStateManager();
     this.agentLookup        = new AgentLookup();
     this.notifier           = notifier;
     this.random             = random;
     this.timerService       = timerService;
     this.AddBots(bots);
     this.Reset();
 }
Beispiel #26
0
        public void EventsAreNotRedispatchedWithConcurrentDispatch()
        {
            EventNotifier notifier = new EventNotifier();

            int callCount = 0;

            notifier.OnEvent <TestEvent>(evnt => {
                notifier.Submit(TestEvent.Create());
                ++callCount;
            });

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);

            notifier.Submit(TestEvent.Create());
            notifier.DispatchEvents();
            Assert.Equal(1, callCount);

            for (int i = 0; i < 20; ++i)
            {
                callCount = 0;
                notifier.DispatchEvents();
                Assert.Equal(1, callCount);
            }

            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());

            for (int i = 0; i < 20; ++i)
            {
                callCount = 0;
                notifier.DispatchEvents();
                Assert.Equal(4, callCount);
            }
        }
Beispiel #27
0
 public static int AddVote(EventNotifier notifier, int msg, int code, EventObserver.OnVote onVote)
 {
     return(DoAdd(notifier, msg, code, onVote));
 }
Beispiel #28
0
 public Simulator(EventNotifier notifier)
 {
     this.notifier = notifier;
 }
Beispiel #29
0
 public Launcher(EventNotifier notifier)
 {
     this.notifier = notifier;
 }
Beispiel #30
0
    //广播事件,返回false表示有人否决
    public static bool Fire(EventNotifier notifier, int msg, int code, object param1 = null, object param2 = null, object param3 = null)
    {
        if (notifier != null && notifier.isRemove)//已经删除的要再发送的时候报个错
        {
            Debuger.LogError(string.Format("广播者已经被删除但是仍然fire:{0} {1} {2}", notifier.Id, msg, code));
            return(true);
        }

        ++m_fireCount;
        bool ret = true;

        try
        {
            int key = msg * 100000 + code;
            Dictionary <int, EventObserver> obs;
            if (AllNotifier.observersByMsgCode.TryGetValue(key, out obs))
            {
                if (obs.Count != 0)//如果不加这一行,会导致foreach里有GC Alloc
                {
                    foreach (EventObserver observer in obs.Values)
                    {
                        if (observer.removeCounter > 0)
                        {
                            ++observer.removeCounter;
                            if (observer.removeCounter > 10)
                            {
                                Debuger.LogError(string.Format("监听者者已经被删除但是仍然fire:{0} {1} {2} {3}", observer.Id, msg, code, Util.GetDelegateName(observer.GetDelegate())));
                            }
                            continue;
                        }

                        observer.notifier = notifier;//这里全局监听的notifier是动态变化的
                        if (!observer.OnHandleFire(param1, param2, param3))
                        {
                            ret = false;
                            goto Label_Break;
                        }
                    }
                }
            }

            if (notifier.observersByMsgCode.TryGetValue(key, out obs))
            {
                if (obs.Count != 0)//如果不加这一行,会导致foreach里有GC Alloc
                {
                    foreach (EventObserver observer in obs.Values)
                    {
                        if (observer.removeCounter > 0)
                        {
                            ++observer.removeCounter;
                            if (observer.removeCounter > 10)
                            {
                                Debuger.LogError(string.Format("监听者已经被删除但是仍然fire2:{0} {1} {2} {3}", observer.Id, msg, code, Util.GetDelegateName(observer.GetDelegate())));
                            }
                            continue;
                        }

                        if (!observer.OnHandleFire(param1, param2, param3))
                        {
                            ret = false;
                            goto Label_Break;
                        }
                    }
                }
            }

            Label_Break :;
        }
        //catch (System.Exception err)
        //{
        //    Debuger.LogError(err.StackTrace + ":" + err.Message);
        //}
        finally
        {
            --m_fireCount;
            if (m_fireCount <= 0 && m_delayRemovesObservers.Count != 0)
            {
                for (int i = 0; i < m_delayRemovesObservers.Count; ++i)
                {
                    Remove(m_delayRemovesObservers[i]);
                }

                m_delayRemovesObservers.Clear();
            }
            if (m_fireCount <= 0 && m_delayRemovesNotifiers.Count != 0)
            {
                for (int i = 0; i < m_delayRemovesNotifiers.Count; ++i)
                {
                    Remove(m_delayRemovesNotifiers[i]);
                }
                m_delayRemovesNotifiers.Clear();
            }
        }

        return(ret);
    }