Beispiel #1
0
        private Action DownloadIssues(
            string project,
            int start,
            bool includeClosedIssues,
            Func <IEnumerable <Bug>, bool> onDownloaded,
            Action <int> onProgress,
            Action <bool, Exception> onCompleted)
        {
            Debug.Assert(project != null);
            Debug.Assert(onDownloaded != null);

            var client     = new RestJsonClient(Url + BugzillaAPI.BUG, HttpVerb.GET);
            var resolution = includeClosedIssues ? "" : "---";

            Action <int> pager = next => client.SendRequestAsync(string.Format("api_key={0}&product={1}&offset={2}&limit=20&resolution={3}", APIKey, Product, next, resolution));

            client.DownloadCompleted += (sender, args) =>
            {
                var data = args.Serialize <Bugzilla>();
                var more = onDownloaded(data.bugs);

                if (more)
                {
                    start += data.bugs.Count;
                    pager(start);
                }
                else
                {
                    onCompleted?.Invoke(false, null);
                }
            };

            if (onProgress != null)
            {
                client.ProgressChanged += (sender, args) => onProgress(args);
            }

            pager(start);

            return(client.Abort);
        }