BugzillaInterface.Query.Execute C# (CSharp) Method

Execute() public method

Runs the Query and returns the number of results
public Execute ( ) : int
return int
        public int Execute()
        {
            Source = SplatterCore.Instance.Sources[SourceID];
            try {
                List<BugReport> results;

                try
                {
                    results = Generator.GetQueryResults ();
                }
                catch
                {
                    return -1;
                }
                if(Bugs == null || BugIds == null)
                {
                    BugIds = new List<int>();
                    Bugs = new List<BugReport>();
                }
                foreach (var bug in results) {

                    if(BugIds.Contains(bug.id))
                    {
                        //Console.WriteLine ("Found old bug: " + bug.ToString());
                        BugReport toMerge = Bugs[BugIds.IndexOf(bug.id)];

                        List<Comment> oldComments, newComments;
                        if(toMerge.last_change_time != bug.last_change_time)
                        {
                            // Case 1: The bug has been modified
                            Console.WriteLine ("Bug has been modified");

                            // back up the old comments
                            oldComments = new List<Comment>();
                            oldComments.AddRange(toMerge.Comments);

                            // assign to the bug
                            BugReport newBugReport = bug; // Try to avoid any late binding issues
                            Bugs[BugIds.IndexOf(bug.id)] = newBugReport;

                            // Set the old comments back
                            int targetBugId = BugIds.IndexOf(bug.id);

                            Bugs[targetBugId].setComments( oldComments );
                            Bugs[targetBugId].BugChangedFlag = true;
                        }
                        else
                        {
                            newComments = bug.Comments;
                            //Console.WriteLine ("Bug has not been modified");
                        }

                        toMerge = Bugs[BugIds.IndexOf(bug.id)];
                        //toMerge.MergeComments(newComments);
                    }
                    else
                    {
                        Console.WriteLine ("Found new bug");
                        Bugs.Add(bug);
                        BugIds.Add(bug.id);
                    }
                }
                return Bugs.Count;
            } finally {
            }
            return -1;
        }

Usage Example

Example #1
0
        protected virtual void TestQueryButtonClicked(object sender, System.EventArgs e)
        {
            // we're assuming that the source is a valid one.
            buttonOk.Sensitive = false;
            Candidate = null; // Erase any previous successful query candidate
            Query target = new Query();

            // Set the global source ID of the target's source
            target.SourceID = sourceSelector.Active - 1;

            // Start setting the parameters that will be set via the filters
            SearchParams queryParams = new SearchParams();

            // iterate over all the filters and get the filters
            foreach(Widget filterWidget in filterWidgets)
            {
                IFilterWidget filter = (IFilterWidget)filterWidget;
                if(filter != null)
                {
                    // modify the query parameters
                    filter.SetFilterParams(ref queryParams);
                }
            }

            target.Generator.queryParameters = queryParams;
            target.Generator.Title = bugTitleEntry.Text;

            // now try to run the query
            testQueryButton.Sensitive = false;
            int output = target.Execute();
            if(output == -1)
            {
                // the connection failed or something
                testQueryOutputLabel.Text = "The request to the server failed. Please try later";
                testQueryButton.Sensitive = true;
            }
            else
            {
                testQueryOutputLabel.Text = String.Format("The query returned {0} results", output);

                // Allow user to press OK button
                buttonOk.Sensitive = true;

                // Set the new candidate
                Candidate = target;

                testQueryButton.Sensitive = true;

            }
        }