Exemple #1
0
        /// <summary>
        /// Does issues' search by JQL.
        /// </summary>
        /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param>
        /// <param name="request">Searching request.</param>
        /// <param name="issueType">Type of an issue to return.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <exception cref="SimpleJira.Interface.JqlCompilationException">Throws exception when JQL is not valid.</exception>
        /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception>
        /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception>
        /// <returns>
        ///     Search response which contains issues, issues' count, additional information from request.
        /// </returns>
        public static async Task <JiraIssuesResponse> SelectIssuesAsync(this IJira jira,
                                                                        JiraIssuesRequest request, Type issueType, CancellationToken cancellationToken)
        {
            var response = await jira.SelectIssuesAsync(new JiraIssuesRequest
            {
                Expand        = request.Expand,
                Fields        = request.Fields,
                Jql           = request.Jql,
                MaxResults    = request.MaxResults,
                StartAt       = request.StartAt,
                ValidateQuery = request.ValidateQuery
            }, cancellationToken);

            if (issueType == typeof(JiraIssue))
            {
                return(response);
            }
            return(new JiraIssuesResponse
            {
                Expand = response.Expand,
                Total = response.Total,
                MaxResults = response.MaxResults,
                StartAt = response.StartAt,
                Issues = response.Issues.Select(x => x.Cast(issueType)).ToArray()
            });
        }
Exemple #2
0
        private JiraIssuesResponse SelectIssuesInfo(BuiltQuery builtQuery, Stopwatch stopwatch)
        {
            loggingSettings.Log(LogLevel.Debug,
                                $"Getting the count of issues is starting execution, query [{builtQuery.Query}] ");

            try
            {
                var request = new JiraIssuesRequest
                {
                    Jql        = builtQuery.Query?.ToString() ?? "",
                    StartAt    = 0,
                    MaxResults = 1,
                    Fields     = new[] { "created" }
                };

                var response = jira.SelectIssuesAsync(request, builtQuery.IssueType, CancellationToken.None)
                               .GetAwaiter().GetResult();
                if (stopwatch != null)
                {
                    stopwatch.Stop();
                    loggingSettings.Log(LogLevel.Trace,
                                        $"Getting the count of issues is finished, query [{builtQuery.Query}], took [{stopwatch.Elapsed.TotalMilliseconds}] ms");
                }

                return(response);
            }
            catch (Exception)
            {
                if (stopwatch != null)
                {
                    stopwatch.Stop();
                    loggingSettings.Log(LogLevel.Trace,
                                        $"Getting the count of issues is finished, query [{builtQuery.Query}]. Threw an exception, took [{stopwatch.Elapsed.TotalMilliseconds}] ms");
                }

                throw;
            }
        }
Exemple #3
0
        private IEnumerable ExecuteCollection(BuiltQuery builtQuery, Stopwatch stopwatch)
        {
            var keys   = new HashSet <string>();
            var fields = builtQuery.Projection?.fields
                         .Select(x => x.Expression)
                         .ToArray();
            var skip       = builtQuery.Skip ?? 0;
            var take       = builtQuery.Take ?? int.MaxValue;
            var projection = builtQuery.Projection != null
                ? ProjectionMapperFactory.GetMapper(builtQuery.Projection)
                : null;

            if (projection == null && loggingSettings.NeedLogging(LogLevel.Warning))
            {
                if (warnings.TryAdd(Environment.StackTrace, 0))
                {
                    loggingSettings.Log(LogLevel.Warning,
                                        $"Query [{builtQuery.Query}] doesn't have .Select(...) construction. It may be critical to the performance because Jira should return all fields of issues.");
                }
            }

            loggingSettings.Log(LogLevel.Debug, $"Query [{builtQuery.Query}] is starting execution");

            int got;
            int maxResults;

            do
            {
                maxResults = Math.Min(take, packetSize);

                Stopwatch partialStopwatch = null;
                if (loggingSettings.NeedLogging(LogLevel.Trace))
                {
                    partialStopwatch = Stopwatch.StartNew();
                    loggingSettings.Log(LogLevel.Trace,
                                        $"Query's part (startAt: [{skip}], maxResults: [{maxResults}], jql: [{builtQuery.Query}]) is starting execution");
                }

                var request = new JiraIssuesRequest
                {
                    Jql        = builtQuery.Query?.ToString() ?? "",
                    StartAt    = skip,
                    MaxResults = maxResults,
                    Fields     = fields
                };
                JiraIssuesResponse response;
                try
                {
                    response = jira.SelectIssues(request, builtQuery.IssueType);
                    if (partialStopwatch != null)
                    {
                        partialStopwatch.Stop();
                        loggingSettings.Log(LogLevel.Trace,
                                            $"Query's partial execution (startAt: [{skip}], maxResults: [{maxResults}], jql: [{builtQuery.Query}]) is finished. Returned [{response.Issues.Length}] issues, took [{partialStopwatch.Elapsed.TotalMilliseconds}] ms");
                    }
                }
                catch (Exception)
                {
                    if (partialStopwatch != null)
                    {
                        partialStopwatch.Stop();
                        loggingSettings.Log(LogLevel.Trace,
                                            $"Query's partial execution (startAt: [{skip}], maxResults: [{maxResults}], jql: [{builtQuery.Query}]) is finished. Threw an exception, took [{partialStopwatch.Elapsed.TotalMilliseconds}] ms");
                    }

                    stopwatch?.Stop();

                    throw;
                }

                got = response.Issues.Length;
                for (var i = 0; i < response.Issues.Length && take > 0; ++i)
                {
                    var issue = response.Issues[i];
                    if (keys.Add(issue.Key))
                    {
                        yield return(projection != null?projection(issue) : issue);

                        take--;
                    }
                }

                skip += packetSize;
            } while (take > 0 && got == maxResults);

            if (stopwatch != null)
            {
                stopwatch.Stop();
                loggingSettings.Log(LogLevel.Trace,
                                    $"Query's execution [{builtQuery.Query}] is finished. Returned [{keys.Count}] issues, took [{stopwatch.Elapsed.TotalMilliseconds}] ms");
            }
        }
Exemple #4
0
        /// <summary>
        /// Does issues' search by JQL.
        /// </summary>
        /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param>
        /// <param name="request">Searching request.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <exception cref="SimpleJira.Interface.JqlCompilationException">Throws exception when JQL is not valid.</exception>
        /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception>
        /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception>
        /// <returns>
        ///     Typified search response which contains typified issues, issues' count, additional information from request.
        /// </returns>
        public static async Task <JiraIssuesResponse <TIssue> > SelectIssuesAsync <TIssue>(this IJira jira,
                                                                                           JiraIssuesRequest request, CancellationToken cancellationToken) where TIssue : JiraIssue
        {
            var result = await jira.SelectIssuesAsync(request, typeof(TIssue), cancellationToken);

            return(new JiraIssuesResponse <TIssue>
            {
                Expand = result.Expand,
                Issues = result.Issues.Cast <TIssue>().ToArray(),
                Total = result.Total,
                MaxResults = result.MaxResults,
                StartAt = result.StartAt
            });
        }
Exemple #5
0
 /// <summary>
 /// Does issues' search by JQL.
 /// </summary>
 /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param>
 /// <param name="request">Searching request.</param>
 /// <exception cref="SimpleJira.Interface.JqlCompilationException">Throws exception when JQL is not valid.</exception>
 /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception>
 /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception>
 /// <returns>
 ///     Typified search response which contains typified issues, issues' count, additional information from request.
 /// </returns>
 public static Task <JiraIssuesResponse <TIssue> > SelectIssuesAsync <TIssue>(this IJira jira,
                                                                              JiraIssuesRequest request) where TIssue : JiraIssue
 {
     return(jira.SelectIssuesAsync <TIssue>(request, CancellationToken.None));
 }
Exemple #6
0
 /// <summary>
 /// Does issues' search by JQL.
 /// </summary>
 /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param>
 /// <param name="request">Searching request.</param>
 /// <exception cref="SimpleJira.Interface.JqlCompilationException">Throws exception when JQL is not valid.</exception>
 /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception>
 /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception>
 /// <returns>
 ///     Typified search response which contains typified issues, issues' count, additional information from request.
 /// </returns>
 public static JiraIssuesResponse <TIssue> SelectIssues <TIssue>(this IJira jira,
                                                                 JiraIssuesRequest request) where TIssue : JiraIssue
 {
     return(jira.SelectIssuesAsync <TIssue>(request, CancellationToken.None).GetAwaiter().GetResult());
 }
Exemple #7
0
 /// <summary>
 /// Does issues' search by JQL.
 /// </summary>
 /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param>
 /// <param name="request">Searching request.</param>
 /// <exception cref="SimpleJira.Interface.JqlCompilationException">Throws exception when JQL is not valid.</exception>
 /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception>
 /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception>
 /// <returns>
 ///     Search response which contains issues, issues' count, additional information from request.
 /// </returns>
 public static Task <JiraIssuesResponse> SelectIssuesAsync(this IJira jira, JiraIssuesRequest request)
 {
     return(jira.SelectIssuesAsync(request, CancellationToken.None));
 }
Exemple #8
0
 /// <summary>
 /// Does issues' search by JQL.
 /// </summary>
 /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param>
 /// <param name="request">Searching request.</param>
 /// <param name="issueType">Type of an issue to return.</param>
 /// <exception cref="SimpleJira.Interface.JqlCompilationException">Throws exception when JQL is not valid.</exception>
 /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception>
 /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception>
 /// <returns>
 ///     Search response which contains issues, issues' count, additional information from request.
 /// </returns>
 public static JiraIssuesResponse SelectIssues(this IJira jira, JiraIssuesRequest request, Type issueType)
 {
     return(jira.SelectIssuesAsync(request, issueType, CancellationToken.None).GetAwaiter().GetResult());
 }