/// <summary>
        /// Returns a Service.GoogleSearchResult data set that is valid
        /// according to web service guidelines
        /// </summary>
        /// <param name="pageSize">page size of the Service.GoogleSearchResult set</param>
        /// <returns>Service.GoogleSearchResult instance with Service.resultElement
        /// entries present according to page size</returns>
        public static Service.GoogleSearchResult GetGoogleSearchResults(int pageSize)
        {
            Service.GoogleSearchResult result = new Service.GoogleSearchResult();

            result.estimatedTotalResultsCount = TotalResultsCount;
            result.estimateIsExact            = true;
            result.documentFiltering          = false;
            result.startIndex             = 1;
            result.endIndex               = pageSize;
            result.searchTime             = 0.09;
            result.searchQuery            = "Result Control";
            result.searchComments         = "";
            result.searchTips             = "";
            result.directoryCategories    = new Service.DirectoryCategory[1];
            result.directoryCategories[0] = ResultDummyDataSource.GetDirectoryCategory();

            // fill up 10 result elements
            result.resultElements = new Service.ResultElement[pageSize];
            for (int i = 0; i < pageSize; i++)
            {
                result.resultElements[i] = GetResultElement(i);
            }

            return(result);
        }
        private void HandleSearch()
        {
            Service.GoogleSearchResult result =
                Service.SearchUtil.SearchGoogleService(
                    Query, StartIndex, PageSize, Filtering);

            OnGoogleSearched(new GoogleSearchedEventArgs(result));

            this.DataSource = result;
            this.DataBind();
        }
        private void HandleSearch()
        {
            // check to see if search was handled on this postback
            // (this prevents TextChanged and ButtonClicked from
            // double-tapping Google web service for the same query)
            if (searchHandled == true)
            {
                return;
            }

            // check for redirect of query processing to Google web site
            if (RedirectToGoogle == true)
            {
                this.Page.Response.Redirect(
                    GoogleWebSearchUrl + "?q=" +
                    HttpContext.Current.Server.UrlEncode(Query), true);
            }

            if (ResultControl.Length != 0)
            {
                // lookup the Result control we are linked to
                // and get the PageSize and Filtering property values
                Result resControl = (Result)Page.FindControl(ResultControl);
                int    pageSize   = resControl.PageSize;
                bool   filtering  = resControl.Filtering;

                // get search results from Google web service proxy
                Service.GoogleSearchResult result =
                    Service.SearchUtil.SearchGoogleService(
                        Query, 0, pageSize, filtering);

                // raise search results for any interested parties as well
                OnGoogleSearched(new GoogleSearchedEventArgs(result));

                // databind search results with the Result control
                // we are linked with
                resControl.DataSource = result;
                resControl.DataBind();
            }


            // set bool that tells us the search has been handled on this
            // postback
            searchHandled = true;
        }
示例#4
0
        private void BindResultHeader(object source, EventArgs e)
        {
            Label  header        = (Label)source;
            Result resultControl = GetResultControl(header);

            Service.GoogleSearchResult result = GetResult(header.NamingContainer);

            StringBuilder section = new StringBuilder();

            // get ResouceManager for localized format strings
            ResourceManager rm = ResourceFactory.Manager;

            // Searched for: <searchQuery>
            section.Append(
                String.Format(
                    rm.GetString("ResultStatusTemplate.SearchFor"),
                    result.searchQuery));
            section.Append("<br>");

            // Result <StartIndex+1> - <EndIndex+1> of about
            // <TotalResultsCount> records
            // (accounting for zero based index)
            section.Append(
                String.Format(
                    rm.GetString("ResultStatusTemplate.ResultAbout"),
                    resultControl.StartIndex + 1,
                    resultControl.EndIndex + 1,
                    resultControl.TotalResultsCount));
            section.Append("&nbsp&nbsp");

            // Query took about <searchTime> seconds.
            section.Append(
                String.Format(
                    rm.GetString("ResultStatusTemplate.QueryTook"),
                    System.Math.Round(result.searchTime, 2)));
            section.Append("<br>");

            header.Text = section.ToString();
        }
 /// <summary>
 /// Constructor for GoogleSearchEventArgs
 /// </summary>
 /// <param name="result">Results from search of Google web service</param>
 public GoogleSearchedEventArgs(Service.GoogleSearchResult result)
 {
     this.result = result;
 }
        private void CreateControlHierarchy(bool dataBind)
        {
            Service.GoogleSearchResult result = null;

            // Result items
            items = new ArrayList();

            int count = 0;

            if (dataBind == true)
            {
                if (DataSource == null)
                {
                    return;
                }
                result     = (Service.GoogleSearchResult)DataSource;
                Query      = result.searchQuery;
                StartIndex = result.startIndex - 1;

                // set ViewState values for read-only props
                ViewState["TotalResultsCount"] =
                    result.estimatedTotalResultsCount;
                ViewState["EndIndex"] = result.endIndex - 1;

                count = result.resultElements.Length;
            }
            else
            {
                object temp = ViewState["ResultItemCount"];
                if (temp != null)
                {
                    count = (int)temp;
                }
            }

            if (HeaderTemplate != null)
            {
                ResultItem headerItem = CreateResultItem(-1,
                                                         ResultItemType.Header, false, null);
                items.Add(headerItem);
            }

            ResultItem statusItem = CreateResultItem(-1, ResultItemType.Status,
                                                     dataBind, result);

            items.Add(statusItem);

            // loop through and create ResultItem controls for each of the
            // result elements from the Google web service result
            ResultItemType itemType = ResultItemType.Item;

            for (int i = 0; i < count; i++)
            {
                if (separatorTemplate != null)
                {
                    ResultItem separator =
                        CreateResultItem(-1, ResultItemType.Separator, false, null);
                    items.Add(separator);
                }

                Service.ResultElement resultElem = null;
                if (dataBind == true)
                {
                    resultElem = result.resultElements[i];
                }

                ResultItem item = CreateResultItem(i, itemType, dataBind,
                                                   resultElem);
                items.Add(item);

                // swap between item and alternatingitem types
                if (itemType == ResultItemType.Item)
                {
                    itemType = ResultItemType.AlternatingItem;
                }
                else
                {
                    itemType = ResultItemType.Item;
                }
            }

            // display pager if allowed by user and if results
            // are greater than a page in length
            if (DisplayPager == true && TotalResultsCount > PageSize)
            {
                ResultItem pager = CreatePagerResultItem(dataBind, result);
                items.Add(pager);
            }

            if (FooterTemplate != null)
            {
                ResultItem footer = CreateResultItem(-1, ResultItemType.Footer,
                                                     false, null);
                items.Add(footer);
            }
            if (dataBind)
            {
                ViewState["ResultItemCount"] = count;
            }
        }