Exemple #1
0
 public string[] SearchByUrl(string Url, bool CaseSensitive = true, UrlNamespace ArticleType = UrlNamespace.Articles, int Results = 5)
 {
     //TODO - plus handle some kind of entry cache
     return(new string[Results]);
 }
Exemple #2
0
 public Article GetArticleByTitle(string Title, UrlNamespace ArticleType = UrlNamespace.Articles)
 {
     //TODO
     return(new Article());
 }
Exemple #3
0
        public Article GetArticleByUrl(string Url, UrlNamespace ArticleType = UrlNamespace.Articles)
        {
            if (!UrlPointerPointers.ContainsKey(ArticleType))
            {
                throw new ArgumentException("File contains no Articles of type " + ArticleType.ToString());
            }

            Dictionary <string, int> DicToRef = UrlPointerPointers [ArticleType];
            int            UrlRef;
            StringComparer SC = StringComparer.InvariantCulture;

            if (DicToRef.ContainsKey(Url))
            {
                UrlRef = DicToRef [Url];
            }
            else
            {
                int LowerBound, UpperBound, TestValue, TestRes;

                var SortedKeys = DicToRef.Keys.ToList();
                SortedKeys.Sort();

                int i = 0;
                if (SC.Compare(Url, SortedKeys[i]) < 0)
                {
                    throw new ArgumentException("Cannot Find Article");
                }
                do
                {
                    LowerBound = DicToRef[SortedKeys[i++]];
                } while (SC.Compare(Url, SortedKeys[i]) > 0);

                i = SortedKeys.Count - 1;
                if (SC.Compare(Url, SortedKeys[i]) > 0)
                {
                    throw new ArgumentException("Cannot Find Article");
                }
                do
                {
                    UpperBound = DicToRef[SortedKeys[i--]];
                } while (SC.Compare(Url, SortedKeys[i]) < 0);

                while (true)
                {
                    TestValue = ((UpperBound - LowerBound) / 2) + LowerBound;
                    if (TestValue == LowerBound)
                    {
                        throw new ArgumentException("Cannot Find Article");
                    }
                    string tmpStr = ReadDirectoryEntryUrl(UrlPointers[TestValue]);
                    TestRes = SC.Compare(Url, tmpStr);
                    if (TestRes == 0)
                    {
                        //Found it - lets save its location in our quick reference kkv trips
                        UrlRef = TestValue;
                        UrlPointerPointers[ReadDirectoryEntryNamespace(UrlPointers[UrlRef])].Add(tmpStr, UrlRef);
                        break;
                    }
                    else if (TestRes < 0)
                    {
                        UpperBound = TestValue;
                    }
                    else
                    {
                        LowerBound = TestValue;
                    }
                }
            }
            return(GetArticle(ReadDirectoryEntry(UrlPointers[UrlRef])));
        }
Exemple #4
0
 public string[] SearchByUrl(string Url, bool CaseSensitive = true, UrlNamespace ArticleType = UrlNamespace.Articles, int Results = 5)
 {
     //TODO - plus handle some kind of entry cache
     return new string[Results];
 }
Exemple #5
0
        public Article GetArticleByUrl(string Url, UrlNamespace ArticleType = UrlNamespace.Articles)
        {
            if (!UrlPointerPointers.ContainsKey (ArticleType))
                throw new ArgumentException ("File contains no Articles of type " + ArticleType.ToString ());

            Dictionary<string, int> DicToRef = UrlPointerPointers [ArticleType];
            int UrlRef;
            StringComparer SC = StringComparer.InvariantCulture;

            if (DicToRef.ContainsKey (Url)) {
                UrlRef = DicToRef [Url];
            } else {

                int LowerBound,UpperBound,TestValue,TestRes;

                var SortedKeys = DicToRef.Keys.ToList();
                SortedKeys.Sort();

                int i = 0;
                if (SC.Compare(Url, SortedKeys[i]) < 0) throw new ArgumentException("Cannot Find Article");
                do {
                    LowerBound = DicToRef[SortedKeys[i++]];
                } while (SC.Compare(Url, SortedKeys[i]) > 0);

                i = SortedKeys.Count - 1;
                if (SC.Compare(Url, SortedKeys[i]) > 0) throw new ArgumentException("Cannot Find Article");
                do {
                    UpperBound = DicToRef[SortedKeys[i--]];
                } while (SC.Compare(Url, SortedKeys[i]) < 0);

                while (true)
                {
                    TestValue = ((UpperBound - LowerBound) / 2) + LowerBound;
                    if (TestValue == LowerBound) throw new ArgumentException("Cannot Find Article");
                    string tmpStr = ReadDirectoryEntryUrl(UrlPointers[TestValue]);
                    TestRes = SC.Compare(Url, tmpStr);
                    if (TestRes == 0)
                    {
                        //Found it - lets save its location in our quick reference kkv trips
                        UrlRef = TestValue;
                        UrlPointerPointers[ReadDirectoryEntryNamespace (UrlPointers[UrlRef])].Add (tmpStr, UrlRef);
                        break;
                    }
                    else if (TestRes < 0)
                    {
                        UpperBound = TestValue;
                    }
                    else
                    {
                        LowerBound = TestValue;
                    }
                }
            }
            return GetArticle(ReadDirectoryEntry(UrlPointers[UrlRef]));
        }
Exemple #6
0
 public Article GetArticleByTitle(string Title, UrlNamespace ArticleType = UrlNamespace.Articles)
 {
     //TODO
     return new Article();
 }