Gurtle.Providers.GoogleCode.GoogleCodeProject.DownloadIssues C# (CSharp) Method

DownloadIssues() public method

public DownloadIssues ( string project, int start, bool includeClosedIssues, Func onData, Action onProgress, Exception>.Action onCompleted ) : System.Action
project string
start int
includeClosedIssues bool
onData Func
onProgress Action
onCompleted Exception>.Action
return System.Action
        public Action DownloadIssues(string project, int start, bool includeClosedIssues,
            Func<IEnumerable<Issue>, bool> onData,
            Action<DownloadProgressChangedEventArgs> onProgress,
            Action<bool, Exception> onCompleted)
        {
            Debug.Assert(project != null);
            Debug.Assert(onData != null);

            var client = new WebClient();

            Action<int> pager = next => client.DownloadStringAsync(
                this.IssuesCsvUrl(next, includeClosedIssues));

            client.DownloadStringCompleted += (sender, args) =>
            {
                if (args.Cancelled || args.Error != null)
                {
                    if (onCompleted != null)
                        onCompleted(args.Cancelled, args.Error);

                    return;
                }

                var issues = IssueTableParser.Parse(new StringReader(args.Result)).ToArray();
                var more = onData(issues);

                if (more)
                {
                    start += issues.Length;
                    pager(start);
                }
                else
                {
                    if (onCompleted != null)
                        onCompleted(false, null);
                }
            };

            if (onProgress != null)
                client.DownloadProgressChanged += (sender, args) => onProgress(args);

            pager(start);

            return client.CancelAsync;
        }