示例#1
0
		public void Merge(BCQueryResult qr) {

			//if (qr.QueryResults != null && qr.QueryResults.Count > 0)
			//        QueryResults.Add(qr.QueryResults[qr.QueryResults.Count -1]);
			if (qr.Videos != null) Videos.AddRange(qr.Videos);
			if(qr.Playlists != null) Playlists.AddRange(qr.Playlists);
			PageNumber = qr.PageNumber;
			TotalCount = qr.TotalCount;
			PageSize = qr.PageSize;
		}
示例#2
0
		private static BCQueryResult MultipleQueryHandler(Dictionary<String, String> reqparams, BCObjectType itemType, BCAccount account) {

			//Get the JSon reader returned from the APIRequest
			BCQueryResult qr = new BCQueryResult();
			qr.TotalCount = 0;

			int defaultPageSize = 100;
			if (!reqparams.ContainsKey("page_size")) { // if page size is not set than set it
				reqparams.Add("page_size", defaultPageSize.ToString());
				qr.MaxToGet = -1;
			} else { // else parse it 
				qr.MaxToGet = Convert.ToInt32(reqparams["page_size"]);
				defaultPageSize = qr.MaxToGet;
			}

			
			MakeRequest(qr, reqparams, itemType, account);
			if (!reqparams.ContainsKey("page_number")) { // if page number is not set then pass make recursive calls
				reqparams.Add("page_number", "0");

				//make sure you get the correct page num
				int modifier = (qr.MaxToGet.Equals(-1)) ? qr.TotalCount : qr.MaxToGet;
				double maxPageNum = (qr.TotalCount > 0) ? Math.Ceiling((double)(modifier / defaultPageSize)) : 0;

				//if there are more to get move to next page and keep getting them
				for (int pageNum = 1; pageNum <= maxPageNum; pageNum++) {
					//update page each iteration
					reqparams["page_number"] = pageNum.ToString();
					MakeRequest(qr, reqparams, itemType, account);
				}

				if (itemType.Equals(BCObjectType.videos)) {
					//trim if specified
					if (qr.Videos.Count > qr.MaxToGet && !qr.MaxToGet.Equals(-1) && qr.MaxToGet < qr.TotalCount) {
						List<BCVideo> vidTemp = qr.Videos.GetRange(0, Convert.ToInt32(qr.MaxToGet));
						qr.Videos.Clear();
						qr.Videos.AddRange(vidTemp);
					}
				}
			}

			return qr;
		}
        public BCQueryResult GetResults(string query)
        {
            this._pageNumber = Util.ParseInt(Request.QueryString[Util.PagingKey]);

            if (this.bcApi != null)
            {
                if (string.IsNullOrEmpty(query))
                {
                    this.result = this.bcApi.FindAllVideos(this._itemsPerPage, BCSortByType.MODIFIED_DATE, BCSortOrderType.DESC, null, null, MediaDeliveryTypeEnum.DEFAULT, this._pageNumber, true);
                }
                else
                {
                    List<string> customFields = null;

                    if (!string.IsNullOrEmpty(CustomFields))
                    {
                        string[] fields = CustomFields.Split(",".ToCharArray());

                        customFields = new List<string>(fields.Length);

                        foreach (string field in fields)
                        {
                            customFields.Add(field);
                        }
                    }

                    //this.result = this.bcApi.SearchVideos(-1, null, Util.GetVideoSearchFields("*" + query + "*"), null, BCSortOrderType.DESC, false, 
                    //    null, null, MediaDeliveryTypeEnum.DEFAULT);
                    this.result = this.bcApi.FindVideosByText(query, this._itemsPerPage, BCSortByType.MODIFIED_DATE, BCSortOrderType.DESC, null, customFields, MediaDeliveryTypeEnum.DEFAULT, this._pageNumber, true);
                }

                if (this.result != null)
                {
                    this._itemCount = this.result.TotalCount;
                }
            }

            return this.result;
        }
示例#4
0
		private static void MakeRequest(BCQueryResult qr, Dictionary<string, string> reqparams, BCObjectType itemType, BCAccount account) {
			QueryResultPair qrp = BCAPIRequest.ExecuteRead(reqparams, account);
			qrp.JsonResult = qrp.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":");
			qr.QueryResults.Add(qrp);
			qr.Merge(JSON.Converter.Deserialize<BCQueryResult>(qrp.JsonResult));
		}
示例#5
0
		private static BCQueryResult MultipleQueryHandler(Dictionary<String, String> reqparams, BCObjectType itemType, AccountConfigElement account)
        {
			//Get the JSon reader returned from the APIRequest
			BCQueryResult qr = new BCQueryResult();
			qr.TotalCount = 0;

			try {

				//set some global request paramameters
                if (!reqparams.ContainsKey("page_number")) {
                    reqparams.Add("page_number", "0");
                }

				//set if not set or 
				if (!reqparams.ContainsKey("page_size")) {
					qr.MaxToGet = -1;
				}
				else {
					qr.MaxToGet = Convert.ToInt32(reqparams["page_size"]);
				}

				//get initial query
				double maxPageNum = 0;

				QueryResultPair qrp = BCAPIRequest.ExecuteRead(reqparams, account);
				//convert the result for deserialization
				qrp.JsonResult = qrp.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":");
				qr.QueryResults.Add(qrp);
                qr.Merge(JSON.Converter.Deserialize<BCQueryResult>(qrp.JsonResult));

                //make sure you get the correct page num
                if (qr.TotalCount > 0) {
                    //if you want all use the total count to calculate the number of pages
                    if (qr.MaxToGet.Equals(-1)) {
                        maxPageNum = Math.Ceiling((double)(qr.TotalCount / 100));
                    }
                    //or just use the max you want to calculate the number of pages
				    else {
					    maxPageNum = Math.Ceiling((double)(qr.MaxToGet / 100));
				    }
                }

				//if there are more to get move to next page and keep getting them
				for (int pageNum = 1; pageNum <= maxPageNum; pageNum++ ) {

					//update page each iteration
					reqparams["page_number"] = pageNum.ToString();
					
					QueryResultPair qrp2 = BCAPIRequest.ExecuteRead(reqparams, account);
					//convert the result for deserialization
					qrp2.JsonResult = qrp2.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":");
					qr.QueryResults.Add(qrp2);
					qr.Merge(JSON.Converter.Deserialize<BCQueryResult>(qrp2.JsonResult));				
				}

				//sorting on our end

				if (itemType.Equals(BCObjectType.videos) && reqparams.ContainsKey("sort_by")) {
					//PUBLISH_DATE, 
					if (reqparams["sort_by"].Equals("PUBLISH_DATE")) {
						qr.Videos.Sort(BCVideo.PublishDateComparison);
					}
					//PLAYS_TOTAL, 
					else if (reqparams["sort_by"].Equals("PLAYS_TOTAL")) {
						qr.Videos.Sort(BCVideo.TotalPlaysComparison);
					}
					//PLAYS_TRAILING_WEEK
					else if (reqparams["sort_by"].Equals("PLAYS_TRAILING_WEEK")) {
						qr.Videos.Sort(BCVideo.PlaysTrailingComparison);
					}
                    //MODIFIED_DATE,
                    else if (reqparams["sort_by"].Equals("MODIFIED_DATE")) {
						qr.Videos.Sort(BCVideo.ModifiedDateComparison);
					}
                    //CREATION_DATE, 
					else {
						qr.Videos.Sort(BCVideo.CreationDateComparison);
					}

					//if they want asc
					if (reqparams["sort_order"].Equals("DESC")) {
						qr.Videos.Reverse();
					}
					
					//trim if specified
					if (qr.Videos.Count > qr.MaxToGet && !qr.MaxToGet.Equals(-1) && qr.MaxToGet < qr.TotalCount) {
						List<BCVideo> vidTemp = qr.Videos.GetRange(0, Convert.ToInt32(qr.MaxToGet));

						qr.Videos.Clear();
						qr.Videos.AddRange(vidTemp);
					}
				}
			}
			catch(Exception ex){
				throw new Exception(ex.ToString());
			}

			return qr;
		}