Ejemplo n.º 1
0
 public TopicTick(int topicId, string symbol, IEventRegistration eventReg)
 {
     this.TopicID  = topicId;
     this.Changed  = false;
     this.symbol   = symbol;
     this.EventReg = eventReg;
 }
Ejemplo n.º 2
0
        public async Task <int> QueueDispatchesInternalEvents()
        {
            var services = new ServiceCollection();

            services.AddEvents();
            services.AddTransient <QueueConsumationStartedListener>();
            var provider = services.BuildServiceProvider();

            IEventRegistration registration = provider.ConfigureEvents();

            registration
            .Register <QueueConsumationStarted>()
            .Subscribe <QueueConsumationStartedListener>();


            int successfulTasks = 0;

            Queue queue = new Queue(provider.GetService <IServiceScopeFactory>(), provider.GetService <IDispatcher>());

            queue.QueueTask(() => successfulTasks++);
            queue.QueueTask(() => successfulTasks++);
            queue.QueueTask(() => successfulTasks++);

            await queue.ConsumeQueueAsync();

            // Should not throw due to null Dispatcher


            Assert.True(QueueConsumationStartedListener.Ran);

            return(successfulTasks); // Avoids "unused variable" warning ;)
        }
Ejemplo n.º 3
0
        //this method is called by Excel for every =RTD(...) execution
        //the topicID is a unique identifier for every cell in the excel, we use it to map where to notify back to
        public object ConnectData(int topicID, ref Array RTDparms, ref bool getNewValues)
        {
            string symbol = (string)RTDparms.GetValue(0);
            // Reading from the Space
            string tickInfo = ReadTick(symbol);

            // Registering for notifications using the space proxy
            TickInfo.TickInfo notifyTemplate = new TickInfo.TickInfo();
            notifyTemplate.Symbol = symbol;
            IEventRegistration eventReg = _proxy.DefaultDataEventSession.AddListener <TickInfo.TickInfo>(notifyTemplate, Space_TickChanged);

            //creating a new topic (which has a referance to the listner) and store it locally
            TopicTick tp = new TopicTick(topicID, symbol, eventReg);

            if (!_tickTable.ContainsKey(symbol))
            {
                _tickTable.Add(symbol, tp);
            }
            if (!_topicIDTable.ContainsKey(topicID))
            {
                _topicIDTable.Add(topicID, tp);
            }

            return((object)tickInfo);
        }
Ejemplo n.º 4
0
        public IEventRegistration AddHandler <T>(EventHandler <T> handler) where T : EventArgs
        {
            IEventRegistration eventRegistration = parentEventBus.AddHandler(handler);

            eventRegistrations.Add(eventRegistration);
            return(eventRegistration);
        }
Ejemplo n.º 5
0
        public async Task <bool> SchedulerDispatchesEvents()
        {
            var services = new ServiceCollection();

            services.AddEvents();
            services.AddTransient <ScheduledEventStartedListener>();
            var provider = services.BuildServiceProvider();

            IEventRegistration registration = provider.ConfigureEvents();

            registration
            .Register <ScheduledEventStarted>()
            .Subscribe <ScheduledEventStartedListener>();

            var  scheduler = new Scheduler(new InMemoryMutex(), provider.GetRequiredService <IServiceScopeFactory>(), provider.GetRequiredService <IDispatcher>());
            bool dummy     = true;

            scheduler.Schedule(() => dummy = true)
            .EveryMinute();

            await scheduler.RunAtAsync(DateTime.Parse("2018/06/07"));

            Assert.True(ScheduledEventStartedListener.Ran);

            return(dummy); // Avoids "unused variable" warning ;)
        }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            IEventRegistration registration = app.ApplicationServices.ConfigureEvents();

            registration.Register <DemoEvent>()
            .Subscribe <WriteMessageToConsoleListener>()
            .Subscribe <WriteStaticMessageToConsoleListener>();

            //添加定时任务1:每秒打印
            app.ApplicationServices.UseScheduler(scheduler =>
            {
                scheduler.Schedule(() => Console.WriteLine($"Runs every minute Ran at: {DateTime.UtcNow}")).Cron("* * * * *");//.EverySecond();
            });

            //添加队列

            app.ApplicationServices.ConfigureQueue().LogQueuedTaskProgress(app.ApplicationServices.GetService <ILogger <IQueue> >());
        }
Ejemplo n.º 7
0
 public EventController(IClubClient _club, IEventClient _repo,IEventRegistration _reg, UserManager<ApplicationUser> _user, IMapClient _rContext)
 {
     _context = _repo;
     _routeContext = _rContext;
     _userManager = _user;
     _clubContext = _club;
     _evntReg = _reg;
 }
Ejemplo n.º 8
0
 public EventController(IClubClient _club, IEventClient _repo, IEventRegistration _reg, UserManager <ApplicationUser> _user, IMapClient _rContext)
 {
     _context      = _repo;
     _routeContext = _rContext;
     _userManager  = _user;
     _clubContext  = _club;
     _evntReg      = _reg;
 }
Ejemplo n.º 9
0
        public void CreateEventRegistration(IEventRegistration eventRegistration)
        {
            var _eventRegistration = new EventRegistration()
            {
                EventID   = eventRegistration.EventID,
                AccountID = eventRegistration.AccountID
            };

            _eventRegistrationDataBaseHandler.CreateEventRegistration(_eventRegistration);
            _eventRegistrationDataBaseHandler.UpdateCapacity(eventRegistration.EventID);
        }
        /**
         * topicID - unique ID of the cell in the Excel
         * RTDparms - must have at least one parameter
         * getNewValues - used by the Excel, no need change 
         */
        public object ConnectData(int topicID, ref Array RTDparms, ref bool getNewValues)
        {
            // Registering for notifications on status "done"
            HelloMsg notifyTemplate = new HelloMsg();
            notifyTemplate.STATUS = "done";
            _eventReg = _proxy.DefaultDataEventSession.AddListener
                        <HelloMsg>(notifyTemplate, Space_DataChanged);

            //store the cell this RTD is written in
            _topicID = topicID;
            return "This cell is listening for msg with status 'done' ...";
        }
Ejemplo n.º 11
0
        /**
         * topicID - unique ID of the cell in the Excel
         * RTDparms - must have at least one parameter
         * getNewValues - used by the Excel, no need change
         */
        public object ConnectData(int topicID, ref Array RTDparms, ref bool getNewValues)
        {
            // Registering for notifications on status "done"
            HelloMsg notifyTemplate = new HelloMsg();

            notifyTemplate.STATUS = "done";
            _eventReg             = _proxy.DefaultDataEventSession.AddListener
                                    <HelloMsg>(notifyTemplate, Space_DataChanged);

            //store the cell this RTD is written in
            _topicID = topicID;
            return("This cell is listening for msg with status 'done' ...");
        }
Ejemplo n.º 12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json",
                                  "QueueJobsEvent v1");
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            IEventRegistration registration = app.ApplicationServices.ConfigureEvents();


            //app.ApplicationServices.UseScheduler(scheduler =>
            //{
            //    scheduler.OnWorker("CPUIntensiveTasks");
            //    scheduler
            //        .Schedule<RebuildStaticCachedData>().Hourly();

            //    scheduler.OnWorker("TestingSeconds");
            //    scheduler.Schedule(
            //        () => Console.WriteLine($"Runs every second. Ran at: {DateTime.UtcNow}")
            //    ).EverySecond();
            //    scheduler.Schedule(() => Console.WriteLine($"Runs every thirty seconds. Ran at: {DateTime.UtcNow}")).EveryThirtySeconds().Zoned(TimeZoneInfo.Local);
            //    scheduler.Schedule(() => Console.WriteLine($"Runs every ten seconds. Ran at: {DateTime.UtcNow}")).EveryTenSeconds();
            //    scheduler.Schedule(() => Console.WriteLine($"Runs every fifteen seconds. Ran at: {DateTime.UtcNow}")).EveryFifteenSeconds();
            //    scheduler.Schedule(() => Console.WriteLine($"Runs every thirty seconds. Ran at: {DateTime.UtcNow}")).EveryThirtySeconds();
            //    scheduler.Schedule(() => Console.WriteLine($"Runs every minute Ran at: {DateTime.UtcNow}")).EveryMinute();
            //    scheduler.Schedule(() => Console.WriteLine($"Runs every 2nd minute Ran at: {DateTime.UtcNow}")).Cron("*/2 * * * *");
            //});

            app.ApplicationServices
            .ConfigureQueue()
            .LogQueuedTaskProgress(app.ApplicationServices.GetService <ILogger <IQueue> >());

            app.ApplicationServices.ConfigureQueue()
            .LogQueuedTaskProgress(app.ApplicationServices.GetService <ILogger <IQueue> >());
        }
 //Update in CRUD
 public void UpdateEventRegistration(IEventRegistration E1)
 {
     using (MySqlConnection conn = new MySqlConnection(connectionString))
     {
         conn.Open();
         string query = "UPDATE eventregistration SET EventID = @EventID, AccountID = @AccountID WHERE ID=@ID; ";
         using (MySqlCommand command = new MySqlCommand(query, conn))
         {
             command.Parameters.AddWithValue("@EventID", E1.EventID);
             command.Parameters.AddWithValue("@AccountID", E1.AccountID);
             command.ExecuteNonQuery();
         }
     }
 }
 //GetById
 public IEventRegistration GetById(IEventRegistration eventRegistration)
 {
     using (MySqlConnection conn = new MySqlConnection(connectionString))
     {
         conn.Open();
         string query = "SELECT * FROM eventRegistration WHERE ID = @ID; ";
         using (MySqlCommand command = new MySqlCommand(query, conn))
         {
             command.Parameters.AddWithValue("@ID", eventRegistration.ID);
             command.Parameters.AddWithValue("@EventID", eventRegistration.EventID);
             command.Parameters.AddWithValue("@AccountID", eventRegistration.AccountID);
         }
     }
     return(eventRegistration);
 }
        //Create in CRUD
        public void CreateEventRegistration(IEventRegistration E1)
        {
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                conn.Open();
                string query = "INSERT INTO eventregistration(EventID,AccountID)VALUES(@EventID,@AccountID); ";

                using (MySqlCommand command = new MySqlCommand(query, conn))
                {
                    command.Parameters.AddWithValue("@EventID", E1.EventID);
                    command.Parameters.AddWithValue("@AccountID", E1.AccountID);

                    command.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 16
0
 private void clean()
 {
     try
     {
         //remove the event
         if (_eventReg != null)
         {
             _proxy.DefaultDataEventSession.RemoveListener(_eventReg);
             _eventReg = null;
         }
         // Clear the RTDUpdateEvent reference.
         _xlRTDUpdate = null;
     }
     catch (Exception ex)
     {
         System.Console.Write(ex);
     }
 }
Ejemplo n.º 17
0
        public async Task CanClickThroughMenus()
        {
            await TopMenuItem.LeftClick();

            await Task.Delay(100);

            var nestedMenuItem = await TopMenuItem.GetElement <MenuItem>("SubMenu");

            await using IEventRegistration registration = await nestedMenuItem.RegisterForEvent(nameof (MenuItem.Click));

            await nestedMenuItem.LeftClick(clickTime : TimeSpan.FromMilliseconds(100));

            await Wait.For(async() =>
            {
                var invocations = await registration.GetInvocations();
                Assert.AreEqual(1, invocations.Count);
            });
        }
Ejemplo n.º 18
0
        public async Task CanRightClickToShowContextMenu()
        {
            await Grid.RightClick();

            IVisualElement <ContextMenu>?contextMenu = await Grid.GetContextMenu();

            Assert.IsNotNull(contextMenu);
            var menuItem = await contextMenu.GetElement <MenuItem>("Context1");

            await Task.Delay(100);

            Assert.IsNotNull(menuItem);
            await using IEventRegistration registration = await menuItem.RegisterForEvent(nameof (MenuItem.Click));

            await menuItem.LeftClick(clickTime : TimeSpan.FromMilliseconds(100));

            await Wait.For(async() =>
            {
                var invocations = await registration.GetInvocations();
                Assert.AreEqual(1, invocations.Count);
            });
        }
Ejemplo n.º 19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            IEventRegistration registration = app.ApplicationServices.ConfigureEvents();

            registration.Register <DemoEvent>()
            .Subscribe <Listener1>()
            .Subscribe <Listener2>();
        }
 private void clean()
 {
     try
     {
         //remove the event
         if (_eventReg != null)
         {
             _proxy.DefaultDataEventSession.RemoveListener(_eventReg);
             _eventReg = null;
         }
         // Clear the RTDUpdateEvent reference.
         _xlRTDUpdate = null;
     }
     catch (Exception ex)
     {
         System.Console.Write(ex);
     }
 }
Ejemplo n.º 21
0
 public IEventRegistration UpdateEventRegistration(IEventRegistration eventRegistration)
 {
     EventRegistrationDataBaseHandler.UpdateEventRegistration(eventRegistration);
     return(eventRegistration);
 }
Ejemplo n.º 22
0
 public IEventRegistration GetById(IEventRegistration eventRegistration)
 {
     return(EventRegistrationDataBaseHandler.GetById(eventRegistration));
 }
Ejemplo n.º 23
0
 public Events(IEventRegistration eventRegistration)
 {
     _eventRegistration = eventRegistration;
 }
Ejemplo n.º 24
0
 public TopicTick(int topicId, string symbol, IEventRegistration eventReg)
 {
     this.TopicID = topicId;
     this.Changed = false;
     this.symbol = symbol;
     this.EventReg = eventReg;
 }
Ejemplo n.º 25
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            IEventRegistration registration = app.ApplicationServices.ConfigureEvents();

            registration.Register <DemoEvent>()
            .Subscribe <WriteMessageToConsoleListener>()
            .Subscribe <WriteStaticMessageToConsoleListener>();

            app.ApplicationServices.UseScheduler(scheduler =>
            {
                // scheduler.Schedule(() => Console.WriteLine($"Every minute (ran at ${DateTime.UtcNow}) on thread {Thread.CurrentThread.ManagedThreadId}"))
                //     .EveryMinute();

                // scheduler.Schedule(() => Console.WriteLine($"Every minute#2 (ran at ${DateTime.UtcNow}) on thread {Thread.CurrentThread.ManagedThreadId}"))
                //     .EveryMinute();

                // scheduler.ScheduleAsync(async () =>
                // {
                //     await Task.Delay(10000);
                //     Console.WriteLine($"Every minute#3 (ran at ${DateTime.UtcNow}) on thread {Thread.CurrentThread.ManagedThreadId}");
                // })
                // .EveryMinute();

                // scheduler.Schedule(() => Console.WriteLine($"Every five minutes (ran at ${DateTime.UtcNow}) on thread {Thread.CurrentThread.ManagedThreadId}"))
                //     .EveryFiveMinutes();

                // scheduler.Schedule<SendNightlyReportsEmailJob>()
                //     .Cron("* * * * *")
                //     .PreventOverlapping("SendNightlyReportsEmailJob");

                //     scheduler.ScheduleAsync(async () => {
                //         var dispatcher = app.ApplicationServices.GetRequiredService<IDispatcher>();
                //         await dispatcher.Broadcast(new DemoEvent("This event happens every minute!"));
                //     }).EveryMinute();

                scheduler.OnWorker("EmailTasks");
                scheduler
                .Schedule <SendNightlyReportsEmailJob>().Daily();
                scheduler
                .Schedule <SendPendingNotifications>().EveryMinute();

                scheduler.OnWorker("CPUIntensiveTasks");
                scheduler
                .Schedule <RebuildStaticCachedData>().Hourly();
            });

            app.ApplicationServices
            .ConfigureQueue()
            .LogQueuedTaskProgress(app.ApplicationServices.GetService <ILogger <IQueue> >());

            app.ApplicationServices.ConfigureQueue()
            .LogQueuedTaskProgress(app.ApplicationServices.GetService <ILogger <IQueue> >());
        }
Ejemplo n.º 26
0
 public Events(IEventRegistration eventRegistration, IEventQuery eventQuery, IFetchActiveEvents fetchActiveEvents)
 {
     _eventRegistration = eventRegistration;
     _eventQuery        = eventQuery;
     _fetchActiveEvents = fetchActiveEvents;
 }