Пример #1
0
        public async Task <IList <Audit> > ReadAuditsAsync(AuditQueryBatch queryBatch, int auditArtifactTypeId, IList <int> actionChoiceIds)
        {
            return(await TimeSpan.FromSeconds(1).RetryCall(3, this.logger, async() =>
            {
                var queryStart = GetQueryStart(queryBatch);
                var queryRequest = new QueryRequest
                {
                    Condition = this.dataGridConditionBuilder.BuildActionTimeframeCondition(actionChoiceIds.ToArray(),
                                                                                            queryBatch.Query.StartTime, queryBatch.Query.EndTime),
                    Fields = new List <FieldRef>
                    {
                        new FieldRef {
                            Name = DataGridResourceConstants.DataGridFieldAuditId
                        },
                        new FieldRef {
                            Name = DataGridResourceConstants.DataGridFieldUserId
                        },
                        new FieldRef {
                            Name = DataGridResourceConstants.DataGridFieldAuditArtifactId
                        },
                        new FieldRef {
                            Name = DataGridResourceConstants.DataGridFieldDetails
                        },
                        new FieldRef {
                            Name = DataGridResourceConstants.DataGridFieldTimeStamp
                        },
                        new FieldRef {
                            Name = DataGridResourceConstants.DataGridFieldAction
                        },
                        new FieldRef {
                            Name = DataGridResourceConstants.DataGridFieldExecutionTime
                        }
                    },
                    ObjectType = new ObjectTypeRef()
                    {
                        ArtifactTypeID = auditArtifactTypeId
                    }
                };

                var auditQueryOptions = new AuditQueryOptions {
                    ReturnRawDetails = true
                };                                                                                         // Get Audit details

                using (var auditManagerProxy = this.auditLogObjectManagerFactory.GetManager())
                {
                    try
                    {
                        var result = await
                                     auditManagerProxy.QueryAsync(
                            queryBatch.Query.WorkspaceId,
                            queryRequest,
                            queryStart,
                            queryBatch.Size,
                            auditQueryOptions
                            );


                        return this.dataGridResponseAuditMapper.ResponseToAudits(result, queryBatch.Query.WorkspaceId);
                    }
                    catch (Exception e)
                    {
                        if (e.Message.Contains("StatusCode: 404"))
                        {
                            this.logger.LogWarning(
                                $"Endpoint not found when reading audits {e.Message} {this.DataGridServiceDetails(queryBatch.Query)}, retrying...");
                            throw new RetryException(e);
                        }
                        else
                        {
                            throw this.DataGridServiceException(e, queryBatch.Query,
                                                                $"Failed to read audits Size: {queryBatch.Size}, Start: {queryBatch.Start} || queryStart: {queryStart}, QueryParam: {queryRequest.ToJson()}");
                        }
                    }
                }
            }));
        }