コード例 #1
0
        private async Task <SubnavLink> AddUpdateSubNavLink(IApiContext apiContext, SubnavLink subnavLink)
        {
            var     entityResource = new EntityResource(apiContext);
            JObject jObject        = null;

            if (subnavLink.Path == null || !subnavLink.Path.Any())
            {
                return(null);
            }

            var existing = await GetExistingLink(apiContext, subnavLink);

            jObject = FromObject(subnavLink);

            if (existing == null)
            {
                jObject = await entityResource.InsertEntityAsync(jObject, SubnavLinkEntityName);
            }
            else
            {
                jObject = await entityResource.UpdateEntityAsync(jObject, SubnavLinkEntityName, existing.Id);
            }

            return(jObject.ToObject <SubnavLink>());
        }
コード例 #2
0
        public async Task <T> AddEntityAsync <T>(IApiContext apiContext, String listName, T obj)
        {
            var entityResource = new EntityResource(apiContext);
            var jobject        = JObject.FromObject(obj, SerializerSettings);
            var listFQN        = ValidateListName(listName);

            jobject = await entityResource.InsertEntityAsync(jobject, listFQN);

            return(jobject.ToObject <T>());
        }
コード例 #3
0
        public void AddEvent()
        {
            var eventItem = new EventItem
            {
                EntityId = "567",
                EventId = "def",
                Id = "PK123",
                Topic = "order.opened",
                QueuedDateTime = DateTime.Now,
                Status = EventStatus.Pending.ToString()
            };


            var listFullName = $"EventQueue@{_appSetting.Namespace}";

            try
            {
                var entityResource = new EntityResource(_apiContext);

                var entity = entityResource.GetEntityAsync(listFullName, eventItem.Id).Result;
                if (entity == null)
                {

                    var result = entityResource.InsertEntityAsync(JObject.FromObject(eventItem), listFullName).Result;
                }
            }
            catch (ApiException ex)
            {
                if (ex.ErrorCode.Trim() == "ITEM_ALREADY_EXISTS")
                {
                    throw new Exception("Item exists");
                }
                throw;
            }

        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public async Task Log(int tenantId, AppLog appAppLog)
        {
            var correlationId = String.Empty;
            var errorCode     = String.Empty;

            try
            {
                var apiContext     = new ApiContext(tenantId);
                var entityResource = new EntityResource(apiContext);
                await entityResource.InsertEntityAsync(JObject.FromObject(appAppLog), _listFullName);
            }
            catch (AggregateException ex)
            {
                ex.Flatten().Handle(e =>
                {
                    var apiEx = e as ApiException;
                    if (apiEx != null)
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(apiEx);
                        correlationId      = apiEx.CorrelationId;
                        errorCode          = apiEx.ErrorCode;
                    }
                    else if (e is HttpRequestException || e is TaskCanceledException)
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(ex);
                    }
                    else
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(ex);
                    }
                    return(true);
                });
            }
            catch (ApiException ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
                correlationId      = ex.CorrelationId;
                errorCode          = ex.ErrorCode;
            }
            catch (HttpRequestException ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
            }
            catch (TaskCanceledException ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
            }
            catch (Exception ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
            }
            if (_capturedException != null)
            {
                var message = String.Format("{0}. CorrId: {1}, ErrorCode: {2}",
                                            _capturedException.SourceException.Message, correlationId,
                                            errorCode);
                if (_capturedException.SourceException.InnerException != null)
                {
                    _log.Error(message, _capturedException.SourceException);
                }
            }
        }