private void ProcessRefreshRequest(RecordedEvent recordedEvent)
 {
     Logger.Trace("Processing Refresh request");
     var payload = recordedEvent.Deserialize<RefreshContactsCommand>();
     var accountContacts = GetOrCreateAccountContacts(payload);
     accountContacts.RequestRefresh(payload.UserId);
 }
 private void OnEvent(RecordedEvent recordedEvent, Position position)
 {
     if (Event != null)
     {
         Event(this, new RecordedEventEventArgs(recordedEvent));
     }
 }
Exemplo n.º 3
0
        private void AddUserToCache(RecordedEvent recordedEvent)
        {
            var userCreatedEvent = recordedEvent.Deserialize<UserCreatedEvent>();
            var account = CreateAccount(userCreatedEvent.Account);
            var accounts = new[] { account };

            var user = new User(userCreatedEvent.Id, userCreatedEvent.DisplayName, accounts);
            _userCache.Add(user);
        }
        private void AddAccount(RecordedEvent userCreatedEvent)
        {
            var payload = userCreatedEvent.Deserialize<UserCreatedEvent>();
            var key = GetKey(payload.Account.Provider, payload.Account.AccountId);

            //TODO: What do I do if there are duplicates or it is missing? -LC
            var accountContacts = _accountContactsFactory.Create(payload.Account);
            _accounts.Add(key, accountContacts);
        }
Exemplo n.º 5
0
 private static string RecordDetailsString(RecordedEvent evnt)
 {
     var data = Encoding.UTF8.GetString(evnt.Data);
     return string.Format("[stream:{0}; eventNumber:{1}; type:{2}; data:{3}]",
                                                        evnt.EventStreamId,
                                                        evnt.EventNumber,
                                                        evnt.EventType,
                                                        data.Length > 12 ? (data.Substring(0, 12) + "...") : data);
 }
Exemplo n.º 6
0
        public CommittedEvent ToEvent(RecordedEvent eventData)
        {
            if (!_nameToType.ContainsKey(eventData.EventType))
            {
                _nameToType.Add(eventData.EventType, Type.GetType(eventData.EventType, true));
            }
            var type      = _nameToType[eventData.EventType];
            var eventBase = Deserialize(eventData.Data, type) as EventBase;

            return(new CommittedEvent(eventData.EventNumber, eventData.Created, eventBase, eventData.EventStreamId));
        }
Exemplo n.º 7
0
 public KnownEvent Get(RecordedEvent recordedEvent)
 {
     if (recordedEvent.EventType == "MeasurementRead")
     {
         return new KnownEvent<MeasurementRead>(ConsoleColor.Green, recordedEvent);
     }
     if (recordedEvent.EventType == "MeasurementAverageDay")
     {
         return new KnownEvent<MeasurementAverageDay>(ConsoleColor.Magenta, recordedEvent);
     }
     return new KnownEvent(ConsoleColor.Yellow);
 }
Exemplo n.º 8
0
 public static RecordedEvent ToRecordedEvent(this ES.RecordedEvent recordedEvent, long?eventNumber = null)
 {
     return(new RecordedEvent(
                recordedEvent.EventStreamId,
                recordedEvent.EventId,
                eventNumber ?? recordedEvent.EventNumber,
                recordedEvent.EventType,
                recordedEvent.Data,
                recordedEvent.Metadata,
                recordedEvent.IsJson,
                recordedEvent.Created,
                recordedEvent.CreatedEpoch));
 }
        public static bool Equal(EventData[] expected, RecordedEvent[] actual)
        {
            if (expected.Length != actual.Length)
                return false;

            for (var i = 0; i < expected.Length; i++)
            {
                if (!Equal(expected[i], actual[i]))
                    return false;
            }

            return true;
        }
        public static bool Equal(EventData expected, RecordedEvent actual)
        {
            if (expected.EventId != actual.EventId)
                return false;

            if (expected.Type != actual.EventType)
                return false;

            var expectedDataString = Helper.UTF8NoBom.GetString(expected.Data ?? new byte[0]);
            var expectedMetadataString = Helper.UTF8NoBom.GetString(expected.Metadata ?? new byte[0]);

            var actualDataString = Helper.UTF8NoBom.GetString(actual.Data ?? new byte[0]);
            var actualMetadataDataString = Helper.UTF8NoBom.GetString(actual.Metadata ?? new byte[0]);

            return expectedDataString == actualDataString && expectedMetadataString == actualMetadataDataString;
        }
        private void UpdateContact(RecordedEvent originalEvent)
        {
            var payload = originalEvent.Deserialize<AccountContactBatchUpdateRecord>();
            Logger.Trace("Updating {0} contact(s) for Account '{1}' on user '{2}'", payload.Contacts.Length, payload.AccountId, payload.UserId);
            var userContacts = GetUserContacts(payload);

            using (userContacts.TrackChanges())
            {
                foreach (var contact in payload.Contacts)
                {
                    userContacts.Add(contact);
                }

                SaveUpdates(userContacts);

                userContacts.CommitChanges();
            }
        }
Exemplo n.º 12
0
 public KnownEvent Get(RecordedEvent recordedEvent)
 {
     if (recordedEvent.EventType == "GameOver")
     {
         return new KnownEvent<GameOver>(ConsoleColor.Green, recordedEvent);
     }
     if (recordedEvent.EventType == "GameWon")
     {
         return new KnownEvent<GameWon>(ConsoleColor.Magenta, recordedEvent);
     }
     if (recordedEvent.EventType == "GameLost")
     {
         return new KnownEvent<GameLost>(ConsoleColor.Magenta, recordedEvent);
     }
     if (recordedEvent.EventType == "IrresponsibleGamblerDetected")
     {
         return new KnownEvent<IrresponsibleGamblerDetected>(ConsoleColor.Red, recordedEvent);
     }
     return new KnownEvent(ConsoleColor.Yellow);
 }
Exemplo n.º 13
0
        public static void VerifyIfMatched(RecordedEvent evnt)
        {
            if (evnt.EventType.StartsWith("TestEvent"))
            {
                var data = Encoding.UTF8.GetString(evnt.Data);
                var atoms = data.Split('-');
                if (atoms.Length != 3)
                    throw new ApplicationException(string.Format("Invalid TestEvent object: currupted data format: {0}",
                                                                 RecordDetailsString(evnt)));

                var expectedLength = int.Parse(atoms[1]);
                if (expectedLength != atoms[2].Length)
                    throw new ApplicationException(string.Format("Invalid TestEvent object: not expected data length: {0}",
                                                                 RecordDetailsString(evnt)));

                if (new string('#', expectedLength) != atoms[2])
                    throw new ApplicationException(string.Format("Invalid TestEvent object: currupted data: {0}",
                                                                 RecordDetailsString(evnt)));
            }
        }
        private static object DeserializeEvent(RecordedEvent @event)
        {
            var eventType = Type.GetType(@event.EventType);
            Debug.Assert(eventType != null, "Couldn't load type '{0}'. Are you missing an assembly reference?", @event.EventType);

            return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(@event.Data), eventType);
        }
Exemplo n.º 15
0
        static Event DeserializeEvent(RecordedEvent @event)
        {
            var eventType = Type.GetType(@event.EventType);
            Debug.Assert(eventType != null, "Couldn't load type '{0}'. Are you missing an assembly reference?", @event.EventType);

            var json = Encoding.UTF8.GetString(@event.Data);
            return (Event) JsonConvert.DeserializeObject(json, eventType, SerializerSettings);
        }
Exemplo n.º 16
0
 public RawEvent(RecordedEvent recordedEvent)
 {
     this.EventType = recordedEvent.EventType;
     this.Metadata = recordedEvent.Metadata;
     this.Data = recordedEvent.Data;
 }
Exemplo n.º 17
0
        private void AddAccountToCache(RecordedEvent recordedEvent)
        {
            var userCreatedEvent = recordedEvent.Deserialize<UserRegisteredAccountEvent>();
            var account = CreateAccount(userCreatedEvent.Account);

            var useridx = _userCache.FindIndex(u=>u.Id == userCreatedEvent.UserId);
            var cachedUser = _userCache[useridx];
            var newUser = cachedUser.AddAccount(account);
            _userCache[useridx] = newUser;
        }
Exemplo n.º 18
0
 private static string FormatStream(string linkedStream, RecordedEvent recordedEvent)
 {
     return linkedStream == null
         ? "stream: " + recordedEvent.EventStreamId
         : "link: " + linkedStream;
 }
Exemplo n.º 19
0
 internal ResolvedEvent(ClientMessage.ResolvedIndexedEvent evnt)
 {
     Event            = evnt.Event == null ? null : new RecordedEvent(evnt.Event);
     Link             = evnt.Link == null ? null : new RecordedEvent(evnt.Link);
     OriginalPosition = null;
 }
Exemplo n.º 20
0
 internal ResolvedEvent(ClientMessage.ResolvedEvent evnt)
 {
     Event            = evnt.Event == null ? null : new RecordedEvent(evnt.Event);
     Link             = evnt.Link == null ? null : new RecordedEvent(evnt.Link);
     OriginalPosition = new Position(evnt.CommitPosition, evnt.PreparePosition);
 }
 private void AddAccount(RecordedEvent accountRegisteredEvent)
 {
     var payload = accountRegisteredEvent.Deserialize<UserRegisteredAccountEvent>();
     LinkUserIdToAccountId(payload.UserId, payload.Account.AccountId);
 }
Exemplo n.º 22
0
 internal ResolvedEvent(ClientMessage.ResolvedEvent evnt)
 {
     Event = evnt.Event == null ? null : new RecordedEvent(evnt.Event);
     Link = evnt.Link == null ? null : new RecordedEvent(evnt.Link);
     OriginalPosition = new Position(evnt.CommitPosition, evnt.PreparePosition);
 }
 private void AddUser(RecordedEvent userCreatedEvent)
 {
     var payload = userCreatedEvent.Deserialize<UserCreatedEvent>();
     LinkUserIdToAccountId(payload.Id, payload.Account.AccountId);
 }
 public virtual IPersistentRepresentation GetRepresentation(Serializer serializer, RecordedEvent @event)
 {
     return (IPersistentRepresentation) serializer.FromBinary(@event.Data, typeof (IPersistentRepresentation));
 }
Exemplo n.º 25
0
 public object DeserializeEvent(RecordedEvent recordedEvent)
 {
     var metadata = recordedEvent.Metadata;
     var data = recordedEvent.Data;
     var eventClrTypeName = JObject.Parse(Encoding.UTF8.GetString(metadata)).Property(EventClrTypeHeader).Value;
     return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data), Type.GetType((string)eventClrTypeName));
 }
Exemplo n.º 26
0
 internal ResolvedEvent(ClientMessage.ResolvedIndexedEvent evnt)
 {
     Event = evnt.Event == null ? null : new RecordedEvent(evnt.Event);
     Link = evnt.Link == null ? null : new RecordedEvent(evnt.Link);
     OriginalPosition = null;
 }
Exemplo n.º 27
0
 public KnownEvent Get(RecordedEvent recordedEvent)
 {
     return new KnownEvent(ConsoleColor.Yellow);
 }