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

            lock (EventRecords)
            {
                EventRecords.Add(er);
            }
        }
Exemplo 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);
            }
        }
        public void BasicEvent2()
        {
            Assert.NotNull(_metaData);

            var eventStr     = "0x08000000000000005095a20900000000020000000100000000000000000000000000020000";
            var eventRecords = new EventRecords(_metaData);

            eventRecords.Create(eventStr);

            // TODO add asserts
            Assert.True(true);
        }
Exemplo n.º 4
0
        private static async Task TestAsync(string[] args)
        {
            //Console.WriteLine(Utils.GetPublicKeyFrom("5CxW5DWQDpXi4cpACd62wzbPjbYrx4y67TZEmRXBcvmDTNaM").Length);
            using var client = new SubstrateClient(new Uri(Websocketurl));
            client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>());
            await client.ConnectAsync(CancellationToken.None);

            var eventStr = "0x14" +
                           "00" +                                                               // ******************* EVENT 1 begin
                           "00000000" +                                                         // phase {ApplyExtrinsic: 0 u32}
                           "0000" +                                                             // event { index: 0x0000
                           "482d7c0900000000" +                                                 // weight: 159,133,000
                           "02" +                                                               // class: Mandatory
                           "00" +                                                               // paysFee: Yes
                           "00" +                                                               // ******************* EVENT 1 end
                           "00" +                                                               // ******************* EVENT 2 begin
                           "01000000" +                                                         // phase {ApplyExtrinsic: 1 u32}
                           "0000" +                                                             // event { index: 0x0000
                           "0000000000000000" +                                                 // weight: 0,
                           "02" +                                                               // class: Mandatory,
                           "00" +                                                               // paysFee: Yes
                           "00" +                                                               // ******************* EVENT 2 end
                           "00" +                                                               // ******************* EVENT 3 begin
                           "02000000" +                                                         // phase {ApplyExtrinsic: 1 u32}
                           "2002" +                                                             // event { index: 0x2002
                           "4d2b23d27e1f6e3733d7ebf3dc04f3d5d0010cd18038055f9bbbab48f460b61e" + // public-key
                           "87a1395e8b61d529e7684d80373d52a23dd5de84061ab0a980ecbbcb3364457b" + // mogwai-id
                           "00" +                                                               // ******************* EVENT 3 end
                           "00" +                                                               // ******************* EVENT 4 begin
                           "02000000" +                                                         // phase {ApplyExtrinsic
                           "1106" +                                                             // event { index:
                           "2e6bb353c70000000000000000000000" +
                           "00" +                                                               // ******************* EVENT 4 end
                           "00" +                                                               // ******************* EVENT 5 begin
                           "02000000" +                                                         // phase {ApplyExtrinsic
                           "0000" +                                                             // event { index:
                           "1008f60500000000" +
                           "00" +                                                               // class: Mandatory,
                           "00" +                                                               // paysFee: Yes
                           "00";                                                                // ******************* EVENT 4 begin

            ;


            var eventRecords = new EventRecords(client.MetaData);

            eventRecords.Create(eventStr);
            Console.WriteLine(eventRecords);
        }
        public void BasicEvent3()
        {
            Assert.NotNull(_metaData);

            var eventStr = "0x1802130100020800bc0000007f9267dfabb62a000000000000000000ac9baa9c3eff7f000000" +
                           "00000000000000021006ac9baa9c3eff7f000000000000000000000209006e0400000000000000000000" +
                           "5095a20900000000020000010f00087c932416d1f140d6351d3b6b09ff6fee66ff240bdb92976d36c2ef" +
                           "5b13d83c7f0100000000000000490b83057d01d315d27e2b607c31754419bce23df85e39db096abce127" +
                           "16470b010000000000000000";
            var eventRecords = new EventRecords(_metaData);

            eventRecords.Create(eventStr);

            // TODO add asserts
            Assert.True(true);
        }
Exemplo n.º 6
0
        private static async Task EventDecodeAsync(string[] args)
        {
            using var client = new SubstrateClient(new Uri(Websocketurl));
            client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>());
            await client.ConnectAsync(CancellationToken.None);

            //var eventStr = "0x1802130100020800bc0000007f9267dfabb62a000000000000000000ac9baa9c3eff7f00000000000000000000021006ac9baa9c3eff7f000000000000000000000209006e04000000000000000000005095a20900000000020000010f00087c932416d1f140d6351d3b6b09ff6fee66ff240bdb92976d36c2ef5b13d83c7f0100000000000000490b83057d01d315d27e2b607c31754419bce23df85e39db096abce12716470b010000000000000000";
            //var eventStr = "0x08000000000000005095a20900000000020000000100000000000000000000000000020000";
            var eventStr = "0x04000000000000005095a20900000000020000";

            //var eventRecord = EventRecords.Decode(eventStr, client.MetaData);

            var eventRecord = new EventRecords(client.MetaData);

            eventRecord.Create(eventStr);

            Console.WriteLine(eventRecord.ToString());
        }
Exemplo n.º 7
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);
             }
         }
     }
 }
Exemplo n.º 8
0
        private static async Task EventhandlingTestAsync(string[] args)
        {
            using var client = new SubstrateClient(new Uri(Websocketurl));
            client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>());
            await client.ConnectAsync(CancellationToken.None);

            Action <string, StorageChangeSet> callBackSubscribeStorage = (subscriptionId, eventObject) =>
            {
                if (eventObject.Changes == null)
                {
                    return;
                }

                try
                {
                    Console.WriteLine($"OldEventRecord: {eventObject.Changes[0][1]}");
                    var eventRecords = new EventRecords(client.MetaData);
                    eventRecords.Create(eventObject.Changes[0][1].ToString());
                    Console.WriteLine(eventRecords.ToString());
                }
                catch (NotImplementedException e)
                {
                    Console.WriteLine($"##### {e}");
                }
            };

            // GetStorageKeyBytesHash
            var systemEventsKeys = Utils.Bytes2HexString(RequestGenerator.GetStorageKeyBytesHash("System", "Events"));

            var jArray = new JArray(systemEventsKeys);

            Console.WriteLine($"Key: {systemEventsKeys}");

            var subscriptionId = await client.State.SubscribeStorageAsync(jArray,
                                                                          callBackSubscribeStorage
                                                                          );


            Console.WriteLine("Press any key!");
            Console.ReadKey();

            //var reqResult = await client.State.UnsubscribeStorageAsync(subscriptionId, CancellationToken.None);
        }
Exemplo n.º 9
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);
                }
            }
        }
        public void BasicEvent1()
        {
            Assert.NotNull(_metaData);

            var eventStr     = "0x04000000000000005095a20900000000020000";
            var eventRecords = new EventRecords(_metaData);

            eventRecords.Create(eventStr);

            Assert.AreEqual(1, eventRecords.Value.Count);
            Assert.AreEqual(PhaseState.None, eventRecords.Value[0].Phase.PhaseState.Value);
            Assert.AreEqual(0, eventRecords.Value[0].Phase.ApplyExtrinsic.Value);

            Assert.AreEqual("System", eventRecords.Value[0].BaseEvent.ModuleName);
            Assert.AreEqual("ExtrinsicSuccess", eventRecords.Value[0].BaseEvent.EventName);
            Assert.AreEqual(1, eventRecords.Value[0].BaseEvent.EventArgs.Length);
            Assert.AreEqual("DispatchInfo", eventRecords.Value[0].BaseEvent.EventArgs[0].GetType().Name);
            var dispetchInfo = (DispatchInfo)eventRecords.Value[0].BaseEvent.EventArgs[0];

            Assert.AreEqual(161650000, dispetchInfo.Weight.Value);
        }
Exemplo n.º 11
0
        /// <inheritdoc />
        public async Task <List <PopularEventViewModel> > GetPopularEvents()
        {
            using var scope = ServiceProvider.CreateScope();
            var context = scope.ServiceProvider.GetRequiredService <ApplicationContext>();

            var eventsEnumerable = context.Events.Include(x => x.Promos).AsSplitQuery().AsNoTracking().AsEnumerable();

            var events = eventsEnumerable.Where(x => EventRecords.Any(e => x.Id == e.Record)).ToList();

            // If there are no popular events just get the first lot.
            if (!events.Any())
            {
                return((await context.Events
                        .Include(x => x.Promos)
                        .AsSplitQuery().AsNoTracking().Take(10).Where(x => !x.isCanceled)
                        .OrderBy(x => x.StartLocal).ToListAsync()).Select(x =>
                {
                    var e = Mapper.Map <PopularEventViewModel>(x);
                    var promoViewModel = e.Promos.Where(x => x.Active && x.Start < DateTime.Now && DateTime.Now < x.End).Select(promo => Mapper.Map <PromoViewModel>(promo)).FirstOrDefault();
                    e.Promos = new List <PromoViewModel> {
                        promoViewModel
                    };
                    return e;
                })
                       .ToList());
            }

            // Promos.Where(x => x.Active && x.Start < DateTime.Now && DateTime.Now < x.End).Select(promo => Mapper.Map<PromoViewModel>(promo)).First()

            return(events.Select(x =>
            {
                var mapped = Mapper.Map <PopularEventViewModel>(x);
                mapped.Score = EventRecords.Find(e => x.Id == e.Record).Score;
                var promoViewModel = mapped.Promos.Where(x => x.Active && x.Start < DateTime.Now && DateTime.Now < x.End).Select(promo => Mapper.Map <PromoViewModel>(promo)).FirstOrDefault();
                mapped.Promos = new List <PromoViewModel> {
                    promoViewModel
                };
                return mapped;
            }).OrderBy(x => x.StartLocal).ToList());
        }
Exemplo n.º 12
0
 /// <summary>
 /// Returns an enumerator that iterates through a collection.
 /// </summary>
 /// <returns>
 /// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
 /// </returns>
 public IEnumerator GetEnumerator()
 {
     return(EventRecords.GetEnumerator());
 }
Exemplo n.º 13
0
 public EventRecordArray AddEventRecord(EventRecord eventRecord)
 {
     EventRecords.Add(eventRecord);
     return(this);
 }
Exemplo n.º 14
0
 public override string ToString()
 {
     return(string.Join("|", EventRecords.Select(parameter => parameter.ToString())));
 }
Exemplo n.º 15
0
 public ROCMaster_EventRecordArray AddEventRecord(ROCMaster_EventRecord eventRecord)
 {
     EventRecords.Add(eventRecord);
     return(this);
 }