Example #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);
        }
Example #2
0
        private void buttonTest_Click(object sender, EventArgs e)
        {
            try
            {
                var endPoint = textWebAddress.Text.Trim().TrimEnd('/');
                var apiKey   = textApiKey.Text.Trim();
                var client   = new RestJsonClient(endPoint + BugzillaAPI.VERSION, HttpVerb.GET);
                var data     = client.SendRequest(string.Format("api_key={0}", apiKey)).Serialize <Bugzilla>();
                var version  = data.version;

                client = new RestJsonClient(endPoint + BugzillaAPI.PRODUCT + "/" + Parameters.Product, HttpVerb.GET);
                data   = client.SendRequest(string.Format("api_key={0}", apiKey)).Serialize <Bugzilla>();

                var productStatus = "";
                if (data.products.Count == 0)
                {
                    productStatus = string.Format("Product '{0}' is not found. Please make sure the product has been created.", Parameters.Product);
                }
                else
                {
                    productStatus = string.Format("Product '{0}' is {1}.", Parameters.Product, data.products[0].is_active ? "active" : "inactive");
                }

                var message = string.Format("The Bugzilla version is {0}.{1}{2}{3}",
                                            version,
                                            Environment.NewLine,
                                            Environment.NewLine,
                                            productStatus);

                MessageBox.Show(message, "Test Passed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (WebException we)
            {
                MessageBox.Show(we.Message, "Test Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }