private void LoadEventInfoFromStorage <T>(EMEvent <T> eMEvent) where T : IEMEvent { try { string eventPropJson = GeneretePropertiesJson(eMEvent.EventData); var checkResult = _eventInfoLoader.GetOrAddEMEventInfo(eMEvent, eventPropJson); if (checkResult != null) { if (checkResult.EventPropertiesJson != eventPropJson)//if event has different properties .Throw Exception { throw new EMEventInvalidPropertyException($"{eMEvent.EventName} named event has different properties. Registered properties: {checkResult.EventPropertiesJson}, Sended properties {eventPropJson}"); } var dict = GetAllEventsDic(); if (dict == null) { dict = new Dictionary <string, EMEventInfoDto>(); } dict.Add(checkResult.EventName, checkResult); _cacheManager.Set(_options.RegisteredEventsMemoryCacheKey, dict, TimeSpan.FromMilliseconds(_options.CacheExpireTimeMinute)); } } catch (EMEventInvalidPropertyException e) { // event property is wrong. don't let event publishing. throw new Exception("Error while checking event property on storage. Your event properties are wrong.See inner exception for more information.", e); } catch (Exception e) { throw new Exception("Error while checkng event propert on storage.See inner exception for more information.", e); } }
public void CheckEvent <T>(EMEvent <T> eMEvent) where T : IEMEvent { var propJson = GeneretePropertiesJson(eMEvent.EventData); // generate properties json to check its same with registered one var dict = GetAllEventsDic(); // get registered events if (dict.ContainsKey(eMEvent.EventName)) //if event exists { if (dict[eMEvent.EventName].EventPropertiesJson == propJson) //and properties are same { return; // its ok do nothing } else { throw new Exception($"Registered event has different properties.Event Name: {eMEvent.EventName}, Registered Prop:{dict[eMEvent.EventName].EventPropertiesJson}, Sended Props: {propJson}"); } } else { LoadEventInfoFromStorage(eMEvent); // if event dont exist go and query it (we may dont have it in our cache) dict = GetAllEventsDic(); // get registered events if (dict[eMEvent.EventName].EventPropertiesJson == propJson) //after { return; // its ok do nothing } else { throw new Exception($"Registered event has different properties.Event Name: {eMEvent.EventName}, Registered Prop:{dict[eMEvent.EventName].EventPropertiesJson}, Sended Props: {propJson}"); } } }
//------------------ same functions but async public async Task CheckEventAsync <T>(EMEvent <T> eMEvent) where T : IEMEvent { var propJson = GeneretePropertiesJson(eMEvent.EventData); var dict = await GetAllEventsDicAsync(); if (dict.ContainsKey(eMEvent.EventName)) { if (dict[eMEvent.EventName].EventPropertiesJson == propJson) { return;// its ok do nothing } else { throw new Exception($"Registered event has different properties.Event Name: {eMEvent.EventName}, Registered Prop:{dict[eMEvent.EventName].EventPropertiesJson}, Sended Props: {propJson}"); } } else { await LoadEventInfoFromStorageAsync(eMEvent); dict = await GetAllEventsDicAsync(); if (dict[eMEvent.EventName].EventPropertiesJson == propJson) { return;// its ok do nothing } else { throw new Exception($"Registered event has different properties.Event Name: {eMEvent.EventName}, Registered Prop:{dict[eMEvent.EventName].EventPropertiesJson}, Sended Props: {propJson}"); } } }
public EMEventInfoDto GetOrAddEMEventInfo <T>(EMEvent <T> data, string propertiesJson) where T : IEMEvent { //if event exist if (_context.EMEventInfos.Any(x => x.EventName == data.EventName)) { var dbResult = _context.EMEventInfos.FirstOrDefault(x => x.EventName == data.EventName); return(new EMEventInfoDto { EventName = dbResult.EventName, EventPropertiesJson = dbResult.EventPropertiesJson }); } else // event not exist. Create it { var eventInfo = new EMEventInfo { CreationTime = DateTime.Now, //TODO: Change it CreatorClientName = "", EventName = data.EventName, EventPropertiesJson = propertiesJson }; _context.EMEventInfos.Add(eventInfo); _context.SaveChanges(); return(new EMEventInfoDto { EventName = data.EventName, EventPropertiesJson = propertiesJson }); } }
public async Task <EMEventInfoDto> GetOrAddEMEventInfoAsync <T>(EMEvent <T> data, string propertiesJson) where T : IEMEvent { //if event exist if (await _context.EMEventInfos.AnyAsync(x => x.EventName == data.EventName)) { var dbResult = await _context.EMEventInfos.FirstOrDefaultAsync(x => x.EventName == data.EventName); return(new EMEventInfoDto { EventName = dbResult.EventName, EventPropertiesJson = dbResult.EventPropertiesJson });//Return event info } else // event not exist. Create it { var eventInfo = new EMEventInfo { CreationTime = DateTime.Now, //TODO: Change it CreatorClientName = "", EventName = data.EventName, EventPropertiesJson = propertiesJson }; await _context.EMEventInfos.AddAsync(eventInfo); await _context.SaveChangesAsync(); return(new EMEventInfoDto { EventName = data.EventName, EventPropertiesJson = propertiesJson }); } }
public virtual EMEvent <T> GetEvent <T>(T e) where T : IEMEvent { string eventName = GetEventName(e.GetType()); var newEvent = new EMEvent <T>() { EventData = e, EventName = eventName }; return(newEvent); }
public Task <EMEventInfoDto> GetOrAddEMEventInfoAsync <T>(EMEvent <T> data, string propertiesJson) where T : IEMEvent { throw new NotImplementedException(); }