Esempio n. 1
0
        public void DispatchEvent <T>(ref T e) where T : EventBase
        {
            //Get the event's class
            Type eventClass = e.GetType();

            //Loop through the attributes
            foreach (Attribute classAttrib in eventClass.GetCustomAttributes())
            {
                //if the attribute is an event header
                if (classAttrib is EventHeader)
                {
                    EventHeader header = classAttrib as EventHeader;
                    //Get the callbacks
                    List <MethodInfo> callbacks = GetItem(header.eventName);
                    //Check that the callbacks are null/bad
                    if (callbacks == null)
                    {
                        continue;
                    }
                    if (callbacks.Count == 0)
                    {
                        continue;
                    }
                    //Call the callbacks
                    foreach (MethodInfo callback in callbacks)
                    {
                        callback.Invoke(null, new object[] { e });
                    }
                    return;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Parses <see cref="RotateEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            var binlogPosition = reader.ReadInt64LittleEndian();
            var binlogFilename = reader.ReadStringToEndOfFile();

            return(new RotateEvent(header, binlogFilename, binlogPosition));
        }
Esempio n. 3
0
        public async Task Create(CreateEventHeaderDto input)
        {
            var @eventHeader = input.MapTo <EventHeader>();

            @eventHeader = EventHeader.Create(AbpSession.GetTenantId(), input.Name, input.Description, input.Type, input.Date.Value, input.Frequency, input.ExpectedDate.Value, input.Department, input.Venue);
            await _eventHeaderRepository.InsertAsync(@eventHeader);
        }
Esempio n. 4
0
 /// <summary>
 /// Creates a new <see cref="XaPrepareEvent"/>.
 /// </summary>
 public XaPrepareEvent(EventHeader header, bool onePhase, int formatId, string gtrid, string bqual) : base(header)
 {
     OnePhase = onePhase;
     FormatId = formatId;
     Gtrid    = gtrid;
     Bqual    = bqual;
 }
Esempio n. 5
0
        /// <summary>
        /// Parses <see cref="IntVarEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            var type  = reader.ReadByte();
            var value = reader.ReadInt64LittleEndian();

            return(new IntVarEvent(header, type, value));
        }
 public static EventHeader Insert(this IDbConnection conn, EventHeader input)
 {
     return(conn.GetReader("insert into [EventHeaders] " +
                           "([EventId],[Name],[Value]) values (@p0,@p1,@p2);" +
                           " select [EventId],[Name],[Value] from [EventHeaders] where [EventId]=@p0 and [Name]=@p1;",
                           input.EventId, input.Name, input.Value).Select(x => x.ToEventHeader()).First());
 }
Esempio n. 7
0
        public void Main()
        {
            var eventHeader = new EventHeader();

            var student = new Student()
            {
                Name      = "Grace Hopper",
                StartYear = 1952
            };

            var course = new Course()
            {
                Name   = "Assembly Programming",
                Length = 40
            };


            var studentHistoryService = new StudentHistoryService();
            var studentHistoryResult  = studentHistoryService.AddHistoryEvent(eventHeader, student);

            Console.WriteLine(studentHistoryResult);

            var courseHistoryService = new CourseHistoryService();
            var courseHistoryResult  = courseHistoryService.AddHistoryEvent(eventHeader, course);

            Console.WriteLine(courseHistoryResult);
            Console.ReadLine();
        }
Esempio n. 8
0
        public static Event Deserialize(List <byte[]> envelope, byte[] data)
        {
            MessagePackObject           payloadData = Unpacking.UnpackObject(data).Value;
            IList <MessagePackObject>   parts;
            MessagePackObjectDictionary header;

            if (!payloadData.IsArray || (parts = payloadData.AsList()).Count != 3)
            {
                throw new Exception("Expected array of size 3");
            }
            if (!parts[0].IsMap || !(header = parts[0].AsDictionary()).ContainsKey("message_id"))
            {
                throw new Exception("Bad header");
            }
            if (parts[1].AsString() == null)
            {
                throw new Exception("Bad name");
            }

            var headerObj = new EventHeader
            {
                Version    = header["v"].AsInt32(),
                MessageId  = ProcessUuid(header, "message_id"),
                ResponseTo = ProcessUuid(header, "response_to")
            };

            var msg = new Event {
                Envelope = envelope, Header = headerObj, Name = parts[1].AsString(), Args = parts[2].AsList()
            };

            return(msg);
        }
Esempio n. 9
0
 public bool SaveEvents(IEnumerable <object> events)
 {
     foreach (var evt in events)
     {
         var evtblob = new EventBlob {
             TypeFullName = evt.GetType().FullName,
             TypeName     = evt.GetType().Name,
         };
         serializer.Serialize(evt, ref evtblob);
         var headers = new List <EventHeader>();
         foreach (var p in evt.GetType().GetProperties().Where(x => x.Name.EndsWith("Id")))
         {
             var val = p.GetValue(evt, null);
             if (val == null)
             {
                 continue;
             }
             var hdr = new EventHeader {
                 Name  = p.Name,
                 Value = val.ToString()
             };
             headers.Add(hdr);
         }
         adapter.SaveEvent(evtblob, headers);
     }
     return(true);
 }
Esempio n. 10
0
        /// <summary>
        /// Parses <see cref="TableMapEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            var tableId = reader.ReadLongLittleEndian(6);

            // Reserved bytes and database name length
            reader.Advance(3);
            var databaseName = reader.ReadNullTerminatedString();

            // Table name length
            reader.Advance(1);
            var tableName = reader.ReadNullTerminatedString();

            var columnsNumber = (int)reader.ReadLengthEncodedNumber();
            var columnTypes   = reader.ReadByteArraySlow(columnsNumber);

            var metadataLength = (int)reader.ReadLengthEncodedNumber();
            var metadata       = ParseMetadata(ref reader, columnTypes);

            var nullBitmap = reader.ReadBitmapLittleEndian(columnsNumber);

            TableMetadata tableMetadata = null;

            if (!reader.IsEmpty())
            {
                // Table metadata is supported in MySQL 5.6+ and MariaDB 10.5+.
                tableMetadata = new TableMetadata(ref reader, columnTypes);
            }

            return(new TableMapEvent(header, tableId, databaseName, tableName, columnTypes, metadata, nullBitmap, tableMetadata));
        }
Esempio n. 11
0
        public void HasKeyfound()
        {
            EventHeader sut = GetSut();

            sut.Set("foo", "dfsdf");
            Assert.True(sut.HasKey("foo"));
        }
Esempio n. 12
0
        public void GetEventType()
        {
            EventHeader sut  = GetSut();
            Type        type = sut.ResolveEventType();

            Assert.Equal(type, typeof(SampleEvent));
        }
Esempio n. 13
0
        public void ItResolvesAggregateId()
        {
            EventHeader sut = GetSut();
            string      id  = sut.AggregateId;

            Assert.Equal(id, expectedId);
        }
Esempio n. 14
0
        /// <summary>
        /// Parses <see cref="RowsQueryEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            reader.Advance(1);
            var query = reader.ReadStringToEndOfFile();

            return(new RowsQueryEvent(header, query));
        }
Esempio n. 15
0
 public void CreateBlankEvent()
 {
     EventToAdd                  = new EventHeader();
     EventToAdd.VersionNo        = 1;
     EventToAdd.PropertyChanged += OnTargetUpdated;
     EventToAdd.TenantId         = TenantId;
 }
Esempio n. 16
0
        public WhenSettingDefaults()

        {
            EventHeader sut = GetSut();

            sut.SetDetaults("123");
            this.sut = sut;
        }
Esempio n. 17
0
 /// <summary>
 /// HeaderNamespace and Name can be left null. Namespaces.Alexa and HeaderNames.Response will be used
 /// </summary>
 /// <param name="h"></param>
 /// <param name="source"></param>
 /// <param name="headerNamespace"></param>
 /// <param name="headerName"></param>
 public static void CheckResponseCreatedBaseHeader(EventHeader h, DirectiveHeader source, string headerNamespace = Namespaces.ALEXA, string headerName = HeaderNames.RESPONSE)
 {
     Assert.NotNull(h);
     Assert.Equal(headerNamespace, h.Namespace);
     Assert.Equal(headerName, h.Name);
     Assert.Equal("3", h.PayloadVersion);
     Assert.Equal(source.CorrelationToken, h.CorrelationToken);
 }
Esempio n. 18
0
        protected EventHeader GetSut()
        {
            var sut = new EventHeader();

            sut.Set(EventHeaderKeys.EventType, typeof(SampleEvent).AssemblyQualifiedName);
            sut.Set(EventHeaderKeys.AggregateId, expectedId);
            return(sut);
        }
Esempio n. 19
0
        public static ReadonlyEvent Parse(EventHeader head, string tail, IServiceProvider service)
        {
            var eventData = tail.Split('/');

            //This looks kinda wonky, but is O(n) and handles better than a switch.
            return(Categories[head.Category]
                   [head.Action]
                       (eventData, service));
        }
        public void TestConstructor()
        {
            var expectedEventId = "eventId";

            var subject = new EventHeader (expectedEventId);

            subject.EventId.Should ().NotBeNullOrEmpty ();
            subject.EventId.Should ().Be (expectedEventId);
        }
Esempio n. 21
0
        /// <summary>
        /// Parses <see cref="DeleteRowsEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            var shared = ParseHeader(ref reader);

            var columnsPresent = reader.ReadBitmapLittleEndian(shared.columnsNumber);
            var rows           = ParseDeleteRows(ref reader, shared.tableId, columnsPresent);

            return(new DeleteRowsEvent(header, shared.tableId, shared.flags, shared.columnsNumber, columnsPresent, rows));
        }
Esempio n. 22
0
        /// <summary>
        /// Parses <see cref="GtidEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            var flags         = reader.ReadByte();
            var sourceId      = new Uuid(reader.ReadByteArraySlow(16));
            var transactionId = reader.ReadInt64LittleEndian();
            var gtid          = new Gtid(sourceId, transactionId);

            return(new GtidEvent(header, gtid, flags));
        }
Esempio n. 23
0
        static EventHeader ToEventHeader(this IDataReader dr)
        {
            var bl = new EventHeader();

            bl.EventId = dr.GetInt32(0);
            bl.Name    = dr.GetString(1);
            bl.Value   = dr.GetString(2);
            return(bl);
        }
Esempio n. 24
0
        /// <summary>
        /// Parses <see cref="GtidEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            long sequence = reader.ReadInt64LittleEndian();
            long domainId = reader.ReadUInt32LittleEndian();
            var  gtid     = new Gtid(domainId, header.ServerId, sequence);

            byte flags = reader.ReadByte();

            return(new GtidEvent(header, gtid, flags));
        }
Esempio n. 25
0
        public void GettingStringAsDatetimeThrows()
        {
            EventHeader sut = GetSut();

            var expected = "sdmnfö2342ütäerfd";

            sut.Set("foo", expected);

            Assert.Throws <InvalidCastException>(() => sut.GetDateTime("foo"));
        }
Esempio n. 26
0
        /// <summary>
        /// Parses <see cref="GtidEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            var  sequence = reader.ReadInt64LittleEndian();
            long domainId = (uint)reader.ReadInt32LittleEndian();
            var  gtid     = $"{domainId}-{header.ServerId}-{sequence}";

            var flags = reader.ReadByte();

            return(new GtidEvent(header, gtid, flags));
        }
Esempio n. 27
0
        public string AddHistoryEvent <THistoryData>(EventHeader eventHeader, THistoryData historyData)
        {
            var historyEvent = CreateEvent();

            historyEvent.EventHeader = eventHeader;

            var result = "HistoryService: " + historyEvent.InsertRecord <THistoryData>(historyData);

            return(result);
        }
Esempio n. 28
0
        public IEvent DeserializeEvent(Dictionary <string, string> headerData, string eventData)
        {
            var  header = new EventHeader(headerData);
            Type type   = eventTypeResolver.ResolveType(header);

            var result = JsonConvert.DeserializeObject(eventData, type, SerializerSettings) as IEvent;

            result?.Headers.ApplyEventHeader(header);

            return(result);
        }
Esempio n. 29
0
        /// <summary>
        /// Parses <see cref="XaPrepareEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            bool   onePhase    = reader.ReadByte() != 0x00;
            int    formatId    = (int)reader.ReadUInt32LittleEndian();
            int    gtridLength = (int)reader.ReadUInt32LittleEndian();
            int    bqualLength = (int)reader.ReadUInt32LittleEndian();
            string gtrid       = reader.ReadString(gtridLength);
            string bqual       = reader.ReadString(bqualLength);

            return(new XaPrepareEvent(header, onePhase, formatId, gtrid, bqual));
        }
Esempio n. 30
0
        public virtual IEvent DeserializeEvent(Dictionary <string, string> headerData, string eventData)
        {
            var  header = new EventHeader(headerData);
            Type type   = eventTypeResolver.ResolveType(header);

            IEvent result = DeserializeEventInternal(eventData, type);

            result?.Headers.ApplyEventHeader(header);

            return(result);
        }
Esempio n. 31
0
        public virtual IEvent DeserializeEvent(string headerData, string eventData)
        {
            EventHeader header = DeserializeHeader(headerData);

            Type   type   = eventTypeResolver.ResolveType(header);
            IEvent result = DeserializeEventInternal(eventData, type);

            result?.Headers.ApplyEventHeader(header);

            return(result);
        }
Esempio n. 32
0
 public EventEnvelope(EventHeader header, object @event)
 {
     Header = header;
     Event = @event;
 }