コード例 #1
0
        public void TestShiftingIndex(int index, TextIndex.IndexState state, int shifting, int actualIndex, TextIndex.IndexState actualState)
        {
            var textIndex       = new TextIndex(index, state);
            var actualTextIndex = new TextIndex(actualIndex, actualState);

            Assert.AreEqual(TextIndexUtils.ShiftingIndex(textIndex, shifting), actualTextIndex);
        }
コード例 #2
0
        }//登录

        public object GetIndex(int?page)
        {
            var models = new List <TextIndex>();
            List <BlogModel.BlogText> TextList = repository.GetTextsAll();

            foreach (var item in TextList)
            {
                var temp = new TextIndex
                {
                    TextID      = item.TextID,
                    CommitCount = repository.GetCommitsByTextID(item.TextID).Count(),
                    Text        = item.Text,
                    FirstView   = item.FirstView
                };
                if (item.CategoryName == null)
                {
                    item.CategoryName = "未分类";
                }
                temp.CategoryName   = item.CategoryName;
                temp.TextTitle      = item.TextTitle;
                temp.TextChangeDate = item.TextChangeDate;
                temp.Hot            = item.Hot;
                models.Add(temp);
            }
            models.Reverse();
            int pageSize   = 10;//每页显示的文章数
            int pageNumber = (page ?? 1);

            return(models.ToPagedList(pageNumber, pageSize));
        }//首页,page实现分页
コード例 #3
0
        public void ClearID(int ID, bool unindex, bool setBackCursor)
        {
            TextIndex index = GetIndex(ID);

            OverwriteOrAppend(index._index, new string(' ', index._length));

            if (unindex)
            {
                indices.Remove(index);
            }

            int    rememberConsoleLeft = System.Console.CursorLeft;
            int    rememberConsoleTop  = System.Console.CursorTop;
            Coords seekedCoords        = TextIndexToConsoleCoords(index._index);

            System.Console.SetCursorPosition(seekedCoords.x, seekedCoords.y);
            System.Console.Write(new string(' ', index._length));

            if (setBackCursor)
            {
                System.Console.SetCursorPosition(rememberConsoleLeft, rememberConsoleTop);
            }
            else
            {
                System.Console.SetCursorPosition(seekedCoords.x, seekedCoords.y);
            }
        }
コード例 #4
0
        public List <TextIndex> SearchBlogBycate(string categroyname)
        {
            var blog        = repository.GetTextsAll();
            var search_list = new List <TextIndex>();

            if (!string.IsNullOrEmpty(categroyname))
            {
                var c_blogs = blog.Where(m => m.CategoryName.Equals(categroyname)).ToList();
                foreach (var item in c_blogs)
                {
                    if (item.CategoryName == null)
                    {
                        item.CategoryName = "未分类";
                    }
                    var temp = new TextIndex
                    {
                        TextID         = item.TextID,
                        CommitCount    = repository.GetCommitsByTextID(item.TextID).Count(),
                        Text           = item.Text,
                        TextTitle      = item.TextTitle,
                        CategoryName   = item.CategoryName,
                        TextChangeDate = item.TextChangeDate,
                        FirstView      = item.FirstView,
                        Hot            = item.Hot
                    };
                    search_list.Add(temp);
                }
            }
            return(search_list);
        }
コード例 #5
0
        protected virtual TextIndex GetNextIndex(TextIndex currentIndex)
        {
            var nextIndex = TextIndexUtils.ToStringIndex(currentIndex);
            var nextState = TextIndexUtils.ReverseState(currentIndex.State);

            return(new TextIndex(nextIndex, nextState));
        }
コード例 #6
0
ファイル: LyricManager.cs プロジェクト: karaoke-dev/karaoke
        public bool AddTimeTagByPosition(Lyric lyric, TextIndex index)
        {
            if (!beatmap.HitObjects.Contains(lyric))
            {
                return(false);
            }

            var timeTags      = lyric.TimeTags.ToList();
            var targetTimeTag = timeTags.FirstOrDefault(x => x.Index >= index) ?? timeTags.LastOrDefault();

            if (targetTimeTag == null)
            {
                return(false);
            }

            changeHandler?.BeginChange();

            var insertIndex = timeTags.IndexOf(targetTimeTag);

            timeTags.Insert(insertIndex, new TimeTag(index));
            lyric.TimeTags = timeTags.ToArray();

            changeHandler?.EndChange();

            return(false);
        }
コード例 #7
0
        public ActionResult MIndex(int?page) //移动端主页
        {
            var currentLoginUser = Session["loginuser"] == null ? null : (User)Session["loginuser"];

            ViewBag.currentLoginInfo = currentLoginUser;
            var models   = new List <TextIndex>();
            var TextList = new List <TextList>();

            TextList = db.TextLists.ToList();
            foreach (var item in TextList)
            {
                var temp = new TextIndex
                {
                    TextID      = item.TextID,
                    CommitCount = db.CommitLists.Count(c => c.TextID == item.TextID),
                    Text        = item.Text,
                    FirstView   = item.FirstView
                };
                if (item.CategoryName == null)
                {
                    item.CategoryName = "未分类";
                }
                temp.CategoryName   = item.CategoryName;
                temp.TextTitle      = item.TextTitle;
                temp.TextChangeDate = item.TextChangeDate;
                temp.Hot            = item.Hot;
                models.Add(temp);
            }
            models.Reverse();
            int pageSize   = 4;          //每页显示的文章数
            int pageNumber = (page ?? 1);

            return(View(models.ToPagedList(pageNumber, pageSize)));
        }
コード例 #8
0
        public List <TextIndex> SearchBlog(string searchthing)//搜索博文
        {
            var blog        = repository.GetTextsAll();
            var search_list = new List <TextIndex>();

            if (!string.IsNullOrEmpty(searchthing))
            {
                var s_blogs = blog.Where(m => m.TextTitle.Contains(searchthing) || m.Text.Contains(searchthing)).ToList();
                foreach (var item in s_blogs)
                {
                    var temp = new TextIndex();
                    temp.TextID      = item.TextID;
                    temp.CommitCount = repository.GetCommitsByTextID(item.TextID).Count();
                    temp.Text        = item.Text;
                    if (item.CategoryName == null)
                    {
                        item.CategoryName = "未分类";
                    }
                    temp.CategoryName   = item.CategoryName;
                    temp.FirstView      = item.FirstView;
                    temp.TextTitle      = item.TextTitle.Replace(searchthing, "<font color='red'>" + searchthing + "</font>");
                    temp.TextChangeDate = item.TextChangeDate;
                    temp.Hot            = item.Hot;
                    search_list.Add(temp);
                }
            }
            return(search_list);
        }
コード例 #9
0
        public void AddsItems()
        {
            var idx = new TextIndex("test", new RamMnemonic());

            idx.Add("123");
            Assert.True(idx.Has("123"));
        }
コード例 #10
0
        public ActionResult CategroyBlog(string categroyname)
        {
            var currentLoginUser = Session["loginuser"] == null ? null : (User)Session["loginuser"];

            ViewBag.currentLoginInfo = currentLoginUser;
            var blog = from m in db.TextLists
                       select m;
            //搜索
            var search_list = new List <TextIndex>();

            if (!string.IsNullOrEmpty(categroyname))
            {
                var c_blogs = blog.Where(m => m.CategoryName.Equals(categroyname)).ToList();
                foreach (var item in c_blogs)
                {
                    var temp = new TextIndex();
                    temp.TextID      = item.TextID;
                    temp.CommitCount = db.CommitLists.Count(c => c.TextID == item.TextID);
                    temp.Text        = item.Text;
                    temp.TextTitle   = item.TextTitle;
                    if (item.CategoryName == null)
                    {
                        item.CategoryName = "未分类";
                    }
                    temp.CategoryName   = item.CategoryName;
                    temp.TextChangeDate = item.TextChangeDate;
                    temp.FirstView      = item.FirstView;
                    temp.Hot            = item.Hot;
                    search_list.Add(temp);
                }
                ViewBag.searchRes = search_list;
            }
            return(View(search_list));
        }
コード例 #11
0
        public ActionResult SearchResult(string searchthing)
        {
            var currentLoginUser = Session["loginuser"] == null ? null : (User)Session["loginuser"];

            ViewBag.searching        = searchthing;
            ViewBag.currentLoginInfo = currentLoginUser;
            var blog = from m in db.TextLists
                       select m;
            //搜索
            var search_list = new List <TextIndex>();

            if (!string.IsNullOrEmpty(searchthing))
            {
                var s_blogs = blog.Where(m => m.TextTitle.Contains(searchthing) || m.Text.Contains(searchthing)).ToList();
                foreach (var item in s_blogs)
                {
                    var temp = new TextIndex();
                    temp.TextID      = item.TextID;
                    temp.CommitCount = db.CommitLists.Count(c => c.TextID == item.TextID);
                    temp.Text        = item.Text;
                    if (item.CategoryName == null)
                    {
                        item.CategoryName = "未分类";
                    }
                    temp.CategoryName   = item.CategoryName;
                    temp.FirstView      = item.FirstView;
                    temp.TextTitle      = item.TextTitle.Replace(searchthing, "<font color='red'>" + searchthing + "</font>");
                    temp.TextChangeDate = item.TextChangeDate;
                    temp.Hot            = item.Hot;
                    search_list.Add(temp);
                }
                ViewBag.searchRes = search_list;
            }
            return(View(search_list));
        }
コード例 #12
0
        /// <summary>
        /// Display string with position format
        /// </summary>
        /// <example>
        /// 3
        /// 4(end)
        /// </example>
        /// <param name="textIndex"></param>
        /// <returns></returns>
        public static string PositionFormattedString(TextIndex textIndex)
        {
            var index = textIndex.Index;
            var state = textIndex.State == TextIndex.IndexState.End ? "(end)" : "";

            return($"{index}{state}");
        }
コード例 #13
0
        public void RemovesFromIndex()
        {
            var idx = new TextIndex("test", new RamMnemonic());

            idx.Add("123");
            idx.Remove("123");
            Assert.False(idx.Has("123"));
        }
コード例 #14
0
        public TextIndex <T> CreateIndex(IEnumerable <Phrase <T> > phrases)
        {
            var index = new TextIndex <T>();

            LoadPhrasesIntoTheIndex(phrases, index);

            return(index);
        }
コード例 #15
0
        public void RemovesXmls()
        {
            var mem = new RamMnemonic();
            var idx = new TextIndex("test", mem);

            idx.Add("123").Xocument("xunit-test").Modify(new Directives().Xpath("/xunit-test").Add("content").Set("boo"));
            idx.Remove("123");
            Assert.DoesNotContain($"test/123/xunit-test", mem.Contents().Knowledge());
        }
コード例 #16
0
        public void RejectsUnknownSingleItem()
        {
            var mem = new RamMnemonic();
            var idx = new TextIndex("test", mem);

            Assert.Throws <ArgumentException>(() =>
                                              idx.Comb("123")
                                              );
        }
コード例 #17
0
        public static int ToStringIndex(TextIndex index)
        {
            if (index.State == TextIndex.IndexState.Start)
            {
                return(index.Index);
            }

            return(index.Index + 1);
        }
コード例 #18
0
        public static bool OutOfRange(TextIndex index, string lyric)
        {
            if (string.IsNullOrEmpty(lyric))
            {
                return(true);
            }

            return(index.Index < 0 || index.Index >= lyric.Length);
        }
コード例 #19
0
        public void RemovesCells()
        {
            var mem = new RamMnemonic();
            var idx = new TextIndex("test", mem);

            idx.Add("123").Cell("xunit-test").Update(new InputOf("content"));
            idx.Remove("123");
            Assert.DoesNotContain($"test/123/xunit-test", mem.Contents().Knowledge());
        }
コード例 #20
0
        public override TextIndexList Ranges(string text)
        {
            TextIndexList ranges = new TextIndexList();

            TextIndex t = new TextIndex(Start, Length);

            ranges.Add(t);
            return(ranges);
        }
コード例 #21
0
ファイル: Compiler.cs プロジェクト: h3tch/ProtoFX
 /// <summary>
 /// Search for and process all object blocks in the file.
 /// </summary>
 /// <returns></returns>
 private IEnumerable <Block> ProcessBlocks()
 {
     // process found block strings
     foreach (Match match in RegexBlock.Matches(Text))
     {
         yield return(new Block(this,
                                TextIndex.Skip(match.Index).Take(match.Length).ToList(),
                                Text.LineFromPosition(match.Index), match.Value));
     }
 }
コード例 #22
0
        private void LoadPhrasesIntoTheIndex(IEnumerable <Phrase <T> > phrases, TextIndex <T> index)
        {
            var row = 0;

            foreach (var phrase in phrases)
            {
                AddPhrase(index, phrase);
                row++;
                FireRowInsertedEvent(row);
            }
        }
コード例 #23
0
        public override TimeTagIndexCaretPosition MoveToFirst()
        {
            var lyric = Lyrics.FirstOrDefault(l => !string.IsNullOrEmpty(l.Text));

            if (lyric == null)
            {
                return(null);
            }

            var index = new TextIndex();

            return(new TimeTagIndexCaretPosition(lyric, index));
        }
コード例 #24
0
        public override TimeTagIndexCaretPosition MoveToLast()
        {
            var lyric = Lyrics.LastOrDefault(l => !string.IsNullOrEmpty(l.Text));

            if (lyric == null)
            {
                return(null);
            }

            var textLength = lyric?.Text.Length ?? 0;
            var index      = new TextIndex(textLength - 1, TextIndex.IndexState.End);

            return(new TimeTagIndexCaretPosition(lyric, index));
        }
コード例 #25
0
        public List <WordReference <T> > SearchTheIndex(TextIndex <T> index, string frontString)
        {
            var binarySearcher = new BinarySearch <T>((str1, str2) => str2.StartsWith(str1) ? 0 : str1.CompareTo(str2));
            var words          = binarySearcher.Search(index, frontString);

            var results = new List <WordReference <T> >();

            foreach (var word in words)
            {
                results.AddRange(index[word]);
            }

            return(results);
        }
コード例 #26
0
        [TestCase(0, TextIndex.IndexState.Start, 3, 1, null)] // test switch value.
        public void TestClamp(int index, TextIndex.IndexState state, int minIndex, int maxIndex, int?actualIndex)
        {
            var textIndex = new TextIndex(index, state);

            if (actualIndex != null)
            {
                var actualTextIndex = new TextIndex(actualIndex.Value, state);
                Assert.AreEqual(TextIndexUtils.Clamp(textIndex, minIndex, maxIndex), actualTextIndex);
            }
            else
            {
                Assert.Throws <ArgumentException>(() => TextIndexUtils.Clamp(textIndex, minIndex, maxIndex));
            }
        }
コード例 #27
0
        public void CachesItems()
        {
            var mem = new RamMnemonic();
            var idx = new TextIndex("test", mem);

            idx.Add("123");

            new MemorizedXocument(
                $"test/hq/catalog.xml",
                mem
                ).Modify(
                new Directives().Xpath("/catalog/*").Remove()
                );
            Assert.True(idx.Has("123"));
        }
コード例 #28
0
        public void IsThreadSafe()
        {
            var idx = new TextIndex("test", new RamMnemonic());

            Parallel.For(0, 100, i =>
            {
                idx.Add(i.ToString());
                idx.List().ToArray();
            });

            Assert.Equal(
                100,
                idx.List().Count
                );
        }
コード例 #29
0
 // 1) Load Table
 // 2) Add items to index
 // 3) Save Index
 public void CreateIndex(string Name, string Directory, IDataReader reader, CultureInfo culture, string keyField, string textField)
 {
     int row = 0;
     TextIndex index = new TextIndex(Name, culture);
     index.IndexFolder = Directory;
     index.Initialize();
     while (reader.Read()) {
         int key = (int)reader[keyField];
         string text = (string)reader[textField];
         index.AddPhrase(key, text);
         row++;
         if (OnRowInserted != null)
             OnRowInserted(row);
     }
     index.SaveIndex();
 }
コード例 #30
0
        private List <WordReference <T> > GetTheSearchResultsForThisWord(TextIndex <T> textIndex, Synonym word)
        {
            var resultsForThisWord = textIndexSearcher.SearchTheIndex(textIndex, word.OriginalWord);

            foreach (var suggestedWord in word.SuggestedWords)
            {
                if (suggestedWord == word.OriginalWord)
                {
                    continue;
                }

                var subResults = GetTheSearchResultsForTheSynonyms(textIndex, suggestedWord);
                resultsForThisWord.AddRange(subResults);
            }
            return(resultsForThisWord);
        }
コード例 #31
0
        public static PreparedDecorationCollection Merge(PreparedDecorationCollection previous, PreparedDecorationCollection current, TextDelta td)
        {
            if (previous.mDecorations.Count == 0)
            {
                current.mDifferenceRange = current.Bounds();
                return(current);
            }
            if (AreDecorationsSame(previous, current))
            {
                PreparedDecorationCollection merged = new PreparedDecorationCollection();
                TextIndexList differenceRanges      = new TextIndexList();
                for (int i = 0; i < previous.Count; i++)
                {
                    TextIndexList previousIndex   = previous.Index(i);
                    TextIndexList currentIndex    = current.Index(i);
                    TextIndex     differenceRange = currentIndex.RangeDifferentFrom(previousIndex);
                    if (differenceRange != null && differenceRange.Length > 0)
                    {
                        differenceRanges.Add(differenceRange);
                    }
                }
                differenceRanges.Add(td.TextIndex);

                merged.mDifferenceRange = differenceRanges.Bounds;
                TextIndex activeArea = differenceRanges.Bounds;
                if (activeArea != null)
                {
                    for (int i = 0; i < previous.Count; i++)
                    {
                        TextIndexList currentIndex = current.Index(i);
                        TextIndexList projected    = currentIndex.Projection(activeArea);

                        if (projected.IndexLengthUpperBound() > 0)// Are there and textindexes in projected that have a length > 0
                        {
                            merged.Add(current.Decoration(i), projected);
                        }
                    }
                }

                return(merged);
            }
            else
            {
                current.mAreDecorationsChanged = true;
                return(current);
            }
        }
コード例 #32
0
 /// <remarks>This method assumes a reader lock has already been acquired before calling this method</remarks>
 private static TextIndex GetTextIndex(string catalog, CultureInfo culture)
 {
     string indexKey = catalog + culture.ToString();
     if (Indexes.Keys.Contains(indexKey))
         return Indexes[indexKey];
     else {
         // Load the index!
         TextIndex index = new TextIndex(catalog, culture);
         index.IndexFolder = DatabasePath;
         index.Initialize();
         index.LoadIndex();
         LockCookie lc = readerLock.UpgradeToWriterLock(1000 * 60); // 60 seconds!
         Indexes.Add(indexKey, index);
         readerLock.DowngradeFromWriterLock(ref lc);
         return index;
     }
 }