コード例 #1
0
ファイル: QueryCategoryTest.cs プロジェクト: Zelxin/RPiKeg
 public void OperatorTest()
 {
     AtomCategory category = new AtomCategory("term");
     QueryCategory target = new QueryCategory(category); // TODO: Initialize to an appropriate value
     QueryCategoryOperator expected = QueryCategoryOperator.AND;
     QueryCategoryOperator actual;
     target.Operator = expected;
     actual = target.Operator;
     Assert.AreEqual(expected, actual);
 }
コード例 #2
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>[Test] public QueryObjectTest()</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void QueryObjectTest()
        {
            Tracing.TraceInfo("Entering QueryObject Test"); 

            FeedQuery query = new FeedQuery();
            query.Uri = new Uri(this.defaultHost);

            AtomCategory aCat = new AtomCategory("Test", new AtomUri("urn:test.com")); 
            QueryCategory qCat = new QueryCategory(aCat);
            query.Categories.Add(qCat);

            aCat = new AtomCategory("TestNotAndOr", new AtomUri("urn:test.com")); 
            qCat = new QueryCategory(aCat);
            qCat.Operator = QueryCategoryOperator.OR; 
            qCat.Excluded = true; 

            query.Categories.Add(qCat);


            aCat = new AtomCategory("ANDTHISONE", new AtomUri("")); 
            qCat = new QueryCategory(aCat);
            query.Categories.Add(qCat);

            aCat = new AtomCategory("AnotherOrWithoutCategory"); 
            qCat = new QueryCategory(aCat);
            qCat.Operator = QueryCategoryOperator.OR; 
            qCat.Excluded = true; 
            query.Categories.Add(qCat);

            query.Query = "Hospital";
            query.NumberToRetrieve = 20; 
            Tracing.TraceInfo("query: "  + query.Uri);  

            Uri uri =  query.Uri; 
            Tracing.TraceInfo("Uri: query= " + uri.Query); 
            query.Uri = uri; 
            Tracing.TraceInfo("Parsed Query URI: " + query.Uri); 
            Assert.IsTrue(uri.AbsolutePath.Equals(query.Uri.AbsolutePath), "both query URIs should be identical, uri: " + uri.AbsolutePath + " compared to query: " + query.Uri.AbsolutePath); 

            query.CategoryQueriesAsParameter = true;

            uri = query.Uri;
            Tracing.TraceInfo("Uri: query= " + uri.Query); 
            query.Uri = uri; 
            Tracing.TraceInfo("Parsed Query URI: " + query.Uri.AbsoluteUri); 
            Assert.IsTrue(uri.AbsolutePath.Equals(query.Uri.AbsolutePath), "both query URIs should be identical, uri: " + uri.AbsolutePath + " compared to query: " + query.Uri.AbsolutePath); 

        }
コード例 #3
0
 public IEnumerable<Video> Search(string videoQuery, int start = 0, int count = 20)
 {
     var author = "";
     var orderby = "";
     var time = "All Time";
     var category = "";
     var query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
     if (!string.IsNullOrEmpty(videoQuery))
     {
         query.Query = videoQuery;
     }
     if (!string.IsNullOrEmpty(author))
     {
         query.Author = author;
     }
     if (!string.IsNullOrEmpty(orderby))
     {
         query.OrderBy = orderby;
     }
     query.SafeSearch = YouTubeQuery.SafeSearchValues.None;
     if (String.IsNullOrEmpty(time) != true)
     {
         if (time == "All Time")
             query.Time = YouTubeQuery.UploadTime.AllTime;
         else if (time == "Today")
             query.Time = YouTubeQuery.UploadTime.Today;
         else if (time == "This Week")
             query.Time = YouTubeQuery.UploadTime.ThisWeek;
         else if (time == "This Month")
             query.Time = YouTubeQuery.UploadTime.ThisMonth;
     }
     if (String.IsNullOrEmpty(category) != true)
     {
         QueryCategory q = new QueryCategory(new AtomCategory(category));
         query.Categories.Add(q);
     }
     var res = GetVideos(query);
     return res.Skip(start).Take(count);
 }
コード例 #4
0
        /// <summary>
        /// this will take one category part and parse it
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        private void ParseCategoryString(string category)
        {
            // take the string, and create some category objects out of it...

            // replace the curly braces and the or operator | so that we can tokenize better
            category = category.Replace("%7B", "{");
            category = category.Replace("%7D", "}");
            category = category.Replace("%7C", "|");
            category = Utilities.UrlDecodedValue(category);

            // let's see if it's the only one...
            TokenCollection tokens = new TokenCollection(category, new char[1] {
                '|'
            });
            QueryCategoryOperator op = QueryCategoryOperator.AND;

            foreach (String token in tokens)
            {
                // each one is a category
                QueryCategory cat = new QueryCategory(token, op);
                this.Categories.Add(cat);
                op = QueryCategoryOperator.OR;
            }
        }
コード例 #5
0
        /// <summary>
        /// this will take one category part and parse it
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        private void ParseCategoryString(string category)
        {
            // take the string, and create some category objects out of it...

            // replace the curly braces and the or operator | so that we can tokenize better
            category = category.Replace("%7B", "{"); 
            category = category.Replace("%7D", "}");
            category = category.Replace("%7C", "|");
            category = Utilities.UrlDecodedValue(category);

            // let's see if it's the only one...
            TokenCollection tokens = new TokenCollection(category, new char[1] {'|'}); 
            QueryCategoryOperator op = QueryCategoryOperator.AND; 
            foreach (String token in tokens)
            {
                // each one is a category
                QueryCategory cat = new QueryCategory(token, op); 
                this.Categories.Add(cat);
                op = QueryCategoryOperator.OR; 
            }
        }
コード例 #6
0
ファイル: ListVideos.cs プロジェクト: Zelxin/RPiKeg
 public static IEnumerable<Video> Search(string videoQuery, string author, string orderby, bool racy, string time, string category)
 {
     YouTubeQuery query = new YouTubeQuery(YouTubeQuery.TopRatedVideo);
     if (String.IsNullOrEmpty(videoQuery) != true)
     {
         query.Query = videoQuery;
     }
     if (String.IsNullOrEmpty(author) != true)
     {
         query.Author = author;
     }
     if (String.IsNullOrEmpty(orderby) != true)
     {
         query.OrderBy = orderby;
     }
     if (racy == true)
     {
         query.SafeSearch = YouTubeQuery.SafeSearchValues.None;
     }
     if (String.IsNullOrEmpty(time) != true)
     {
         if (time == "All Time")
             query.Time = YouTubeQuery.UploadTime.AllTime;
         else if (time == "Today")
             query.Time = YouTubeQuery.UploadTime.Today;
         else if (time == "This Week")
             query.Time = YouTubeQuery.UploadTime.ThisWeek;
         else if (time == "This Month")
             query.Time = YouTubeQuery.UploadTime.ThisMonth;
     }
     if (String.IsNullOrEmpty(category) != true)
     {
         QueryCategory q  = new QueryCategory(new AtomCategory(category));
         query.Categories.Add(q);
     }
     return ListVideos.GetVideos(query);
 }
コード例 #7
0
ファイル: collections.cs プロジェクト: mintwans/cpsc483
 /// <summary>standard typed accessor method </summary> 
 public bool Contains( QueryCategory value )  
 {
     // If value is not of type AtomPerson, this will return false.
     return( List.Contains( value ) );
 }
コード例 #8
0
ファイル: collections.cs プロジェクト: mintwans/cpsc483
 /// <summary>standard typed accessor method </summary> 
 public void Remove( QueryCategory value )  
 {
     List.Remove( value );
 }
コード例 #9
0
ファイル: collections.cs プロジェクト: mintwans/cpsc483
 /// <summary>standard typed accessor method </summary> 
 public void Insert( int index, QueryCategory value )  
 {
     List.Insert( index, value );
 }
コード例 #10
0
ファイル: collections.cs プロジェクト: mintwans/cpsc483
 /// <summary>standard typed accessor method </summary> 
 public int IndexOf( QueryCategory value )  
 {
     return( List.IndexOf( value ) );
 }
コード例 #11
0
ファイル: collections.cs プロジェクト: mintwans/cpsc483
 /// <summary>standard typed accessor method </summary> 
 public int Add( QueryCategory value )  
 {
     return( List.Add( value ) );
 }
コード例 #12
0
ファイル: QueryCategoryTest.cs プロジェクト: Zelxin/RPiKeg
 public void ExcludedTest()
 {
     AtomCategory category = new AtomCategory("term");
     QueryCategory target = new QueryCategory(category); // TODO: Initialize to an appropriate value
     bool expected = false; // TODO: Initialize to an appropriate value
     bool actual;
     target.Excluded = expected;
     actual = target.Excluded;
     Assert.AreEqual(expected, actual);
 }
コード例 #13
0
ファイル: QueryCategoryTest.cs プロジェクト: Zelxin/RPiKeg
 public void QueryCategoryConstructorTest()
 {
     string strCategory = "TestValue"; // TODO: Initialize to an appropriate value
     QueryCategoryOperator op = QueryCategoryOperator.OR;
     QueryCategory target = new QueryCategory(strCategory, op);
     Assert.IsNotNull(target);
     Assert.AreEqual(target.Operator, op);
 }
コード例 #14
0
ファイル: QueryCategoryTest.cs プロジェクト: Zelxin/RPiKeg
 public void QueryCategoryConstructorTest1()
 {
     AtomCategory category = new AtomCategory("term");
     QueryCategory target = new QueryCategory(category);
     Assert.IsNotNull(target);
     Assert.AreEqual(target.Category, category);
 }
コード例 #15
0
ファイル: QueryCategoryTest.cs プロジェクト: Zelxin/RPiKeg
 public void CategoryTest()
 {
     AtomCategory category = new AtomCategory("term");
     QueryCategory target = new QueryCategory(category); // TODO: Initialize to an appropriate value
     AtomCategory actual;
     target.Category = category;
     actual = target.Category;
     Assert.AreEqual(category, actual);
 }
コード例 #16
0
ファイル: feedquery.cs プロジェクト: mintwans/cpsc483
        /////////////////////////////////////////////////////////////////////////////

#if WindowsCE || PocketPC
#else
        //////////////////////////////////////////////////////////////////////
        /// <summary>protected void ParseUri</summary> 
        /// <param name="targetUri">takes an incoming Uri string and parses all the properties out of it</param>
        /// <returns>throws a query exception when it finds something wrong with the input, otherwise returns a baseuri</returns>
        //////////////////////////////////////////////////////////////////////
        protected virtual Uri ParseUri(Uri targetUri)
        {
            Reset(); 
            StringBuilder newPath = null;
            UriBuilder newUri = null; 

            if (targetUri != null)
            {
                TokenCollection tokens; 
                // want to check some basic things on this guy first...
                ValidateUri(targetUri);
                newPath = new StringBuilder("", 2048);  
                newUri = new UriBuilder(targetUri);
                newUri.Path = null; 
                newUri.Query = null; 

                // now parse the query string and take the properties out
                string [] parts = targetUri.Segments;
                bool fCategory = false;

                foreach (string part in parts)
                {
                    string segment = CleanPart(part);
                    if (segment.Equals("-") == true)
                    {
                        // found the category simulator
                        fCategory = true; 
                    }
                    else if (fCategory == true)
                    {
                        // take the string, and create some category objects out of it...
                        
                        // replace the curly braces and the or operator | so that we can tokenize better
                        segment = segment.Replace("%7B", "{"); 
                        segment = segment.Replace("%7D", "}");
                        segment = segment.Replace("%7C", "|");

                        // let's see if it's the only one...
                        tokens = new TokenCollection(segment, new char[1] {'|'}); 
                        QueryCategoryOperator op = QueryCategoryOperator.AND; 
                        foreach (String token in tokens)
                        {
                            // each one is a category
                            QueryCategory category = new QueryCategory(token, op); 
                            this.Categories.Add(category);
                            op = QueryCategoryOperator.OR; 
                        }
                    }
                    else
                    {
                        newPath.Append(part);
                    }
                }

                char [] deli = {'?','&'}; 

                tokens = new TokenCollection(targetUri.Query, deli); 
                foreach (String token in tokens )
                {
                    if (token.Length > 0)
                    {
                        char [] otherDeli = {'='};
                        String [] parameters = token.Split(otherDeli,2); 
                        switch (parameters[0])
                        {
                            case "q":
                                this.Query = parameters[1];
                                break;
                            case "author":
                                this.Author = parameters[1];
                                break;
                            case "start-index":
                                this.StartIndex = int.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            case "max-results":
                                this.NumberToRetrieve = int.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            case "updated-min":
                                this.StartDate = DateTime.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            case "updated-max":
                                this.EndDate = DateTime.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            case "published-min":
                                this.MinPublication = DateTime.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            case "published-max":
                                this.MaxPublication = DateTime.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }

            if (newPath != null)
            {
                if (newPath[newPath.Length-1] == '/')
                    newPath.Length = newPath.Length -1 ;

                newUri.Path = newPath.ToString(); 
                this.baseUri = newUri.Uri.AbsoluteUri;

            }
            return null; 
        }