public static Event ToMozuEvent(this AubEvent evt) { return(new Event { EntityId = evt.EntityId, Topic = evt.Topic, Id = evt.EventId }); }
public async Task UpdateEvent(int tenantId, AubEvent aubEvent) { try { _apiContext = new ApiContext(tenantId); var entityResource = new EntityResource(_apiContext); var entity = await entityResource.GetEntityAsync(_listFullName, aubEvent.Id); if (entity != null) { await entityResource.UpdateEntityAsync(JObject.FromObject(aubEvent), _listFullName, aubEvent.Id); } else { await AddEvent(tenantId, aubEvent); } } catch (ApiException ex) { _logger.Error(ex.Message, ex); } }
public async Task <bool> AddEvent(int tenantId, AubEvent aubEvent) { if (!aubEvent.IsApproved()) { return(false); } var correlationId = String.Empty; var errorCode = String.Empty; try { _apiContext = new ApiContext(tenantId); var entityResource = new EntityResource(_apiContext); var entity = await entityResource.GetEntityAsync(_listFullName, aubEvent.Id); if (entity == null) { // var aubEvnt = entity.ToObject<AubEvent>(); // if (aubEvnt.Status == EventStatus.Processed.ToString()) return false; // aubEvnt.Status = EventStatus.Pending.ToString(); // aubEvnt.QueuedDateTime = DateTime.UtcNow; // await entityResource.UpdateEntityAsync(JObject.FromObject(aubEvnt), _listFullName, aubEvnt.Id); //} //else //{ await entityResource.InsertEntityAsync(JObject.FromObject(aubEvent), _listFullName); } } catch (AggregateException ex) { ex.Handle(e => { var apiEx = e as ApiException; if (apiEx != null) { if (apiEx.ErrorCode.Trim() == "ITEM_ALREADY_EXISTS") { return(true); } _capturedException = ExceptionDispatchInfo.Capture(apiEx); correlationId = apiEx.CorrelationId; errorCode = apiEx.ErrorCode; } else { _capturedException = ExceptionDispatchInfo.Capture(e); } return(true); }); } catch (ApiException ex) { if (ex.ErrorCode.Trim() == "ITEM_ALREADY_EXISTS") { return(false); } _capturedException = ExceptionDispatchInfo.Capture(ex); correlationId = ex.CorrelationId; errorCode = ex.ErrorCode; } catch (Exception ex) { _capturedException = ExceptionDispatchInfo.Capture(ex); } if (_capturedException != null && _capturedException.SourceException.InnerException != null) { var message = String.Format("{0}. CorrId: {1}, ErrorCode: {2}", _capturedException.SourceException.Message, correlationId, errorCode); if (_capturedException.SourceException.InnerException != null) { _logger.Error(message, _capturedException.SourceException); } } return(false); }
public static bool IsApproved(this AubEvent evt) { return(!String.IsNullOrEmpty(evt.Topic) && (evt.Topic.StartsWith("customeraccount.") || evt.Topic.Equals("order.opened"))); }