private void TaskStateChangingHandler(object sender, PropertyUpdateEventArgs <TaskState> e)
        {
            var er = new EventRecord(nameof(TestTask.StateChanging), sender, e);

            lock (EventRecords)
            {
                EventRecords.Add(er);
            }
        }
Esempio n. 2
0
        /// <inheritdoc />
        public async Task PopulariseEvent(CancellationToken cancellationToken, Guid eventId, DateTime created)
        {
            if (!cancellationToken.IsCancellationRequested)
            {
                Logger.LogInformation("Popularising event {Id}", eventId);

                var popularityRecord = EventRecords.FirstOrDefault(x => x.Record == eventId);

                using var scope = ServiceProvider.CreateScope();
                var context = scope.ServiceProvider.GetRequiredService <ApplicationContext>();

                var e = await context.Events
                        .Include(x => x.EventCategories)
                        .AsNoTracking().AsSplitQuery()
                        .FirstOrDefaultAsync(x => x.Id == eventId, cancellationToken);

                if (e == null)
                {
                    Logger.LogInformation("Event not found");
                    return;
                }

                // if the event is already popular
                if (popularityRecord != null)
                {
                    Logger.LogInformation("Event {Id} is already popular, making more popular", eventId);

                    popularityRecord.Updated = created;
                    popularityRecord.Score++;
                }
                else
                {
                    EventRecords.Add(new PopularityRecord
                    {
                        Added   = created,
                        Updated = created,
                        Record  = eventId,
                        Score   = 1
                    });
                }

                if (e.EventCategories.Any())
                {
                    foreach (var category in e.EventCategories)
                    {
                        await PopulariseCategory(cancellationToken, category.CategoryId, created);
                    }
                }

                // sends popular events to all web-socket clients
                await PopularityHubContext.Clients.All.SendAsync("events", await GetPopularEvents());

                Logger.LogInformation("Popularised event {Id}", eventId);
            }
        }
Esempio n. 3
0
 private void HandleRecordCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
 {
     // This method is multithreaded to demonstate the next marshalling stage for the UI update.
     // Synchronize it here to keep bad things from happening.
     lock (EventRecords)
     {
         if (args.NewItems != null)
         {
             foreach (var record in args.NewItems)
             {
                 var recordVM = new RecordViewModel()
                 {
                     Model = record as HandlerRecord, DelegateInvokeThreadId = _invokerThreadId
                 };
                 EventRecords.Add(recordVM);
             }
         }
     }
 }
Esempio n. 4
0
        public void Read(BinaryReader binaryReader)
        {
            EventRecords.Clear();
            IsNull = binaryReader.ReadBoolean();

            if (IsNull)
            {
                return;
            }
            else
            {
                var length = binaryReader.ReadInt32();

                for (var i = 0; length > i; i++)
                {
                    var eventRecord = new EventRecord();
                    eventRecord.Read(binaryReader);
                    EventRecords.Add(eventRecord);
                }
            }
        }
Esempio n. 5
0
 public EventRecordArray AddEventRecord(EventRecord eventRecord)
 {
     EventRecords.Add(eventRecord);
     return(this);
 }
Esempio n. 6
0
 public ROCMaster_EventRecordArray AddEventRecord(ROCMaster_EventRecord eventRecord)
 {
     EventRecords.Add(eventRecord);
     return(this);
 }