Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.CancelKeyPress += (sender, eventArgs) => { Environment.Exit(0); };

                Console.Write("String 1: ");
                string str1 = Console.ReadLine();
                Console.Write("String 2: ");
                string str2 = Console.ReadLine();
                Console.WriteLine("Score   : " + StringSimilarity.Calculate(str1, str2));
            }
        }
Ejemplo n.º 2
0
        public static UwcWindow FindMatchingWindow(string title)
        {
            if (UwcManager.windows.Count <= 0)
            {
                Debug.LogError("No windows!");
                return(null);
            }

            //TODO: option to prioritize starting charcters and use start of window title
            //We reverse the string so priority is on the last characters, most likely part of the app name
            //string reverseTitle = new string(title.ToCharArray().Reverse().ToArray());


            foreach (UwcWindow window in UwcManager.windows.Values)
            {
                if (window.title == "")
                {
                    continue;
                }
                if (window.title.Contains("DISPLAY"))
                {
                    continue;
                }

                string testTitle;

                //If the title is long enough, store the last characters
                if (window.title.Length > I.partialWindowTitleCharacters)
                {
                    testTitle = window.title.Substring(window.title.Length - I.partialWindowTitleCharacters);
                }
                else
                {
                    testTitle = window.title;
                }

                //string reverseTestTitle = new string(testTitle.ToCharArray().Reverse().ToArray());


                decimal accuracy = StringSimilarity.Calculate(title, testTitle);

                //It's a match!
                if (accuracy >= allowedAccuracyTitleMatch)
                {
                    return(window);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 文章详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> Detail(int id)
        {
            if (id == 0)
            {
                return(new NotFoundViewResult());
            }

            Article article = await _dbContext.Article.Where(s => s.Status == (int)CommonStatus.Valid)
                              .Include(s => s.Remarks).ThenInclude(s => s.User)
                              .Include(s => s.Remarks).ThenInclude(s => s.RemarkReplys).ThenInclude(s => s.User)
                              .Include(s => s.Remarks).ThenInclude(s => s.RemarkReplys).ThenInclude(s => s.TargetUser)
                              .Include(s => s.ArticleMusics).ThenInclude(s => s.Music)
                              .FirstOrDefaultAsync(s => s.Id == id);

            if (article == null)
            {
                return(new NotFoundViewResult());
            }

            ArticleDetailModel detailModel = new ArticleDetailModel();

            detailModel.Article = article;

            detailModel.ArticleCategorys = await _dbContext.Set <ArticleCategory>().ToListAsync();

            detailModel.RandomArticles = await _dbContext.Article
                                         .Where(s => s.Status == (int)CommonStatus.Valid)
                                         .Select(s => new Article()
            {
                Id         = s.Id,
                CreateTime = s.CreateTime,
                Title      = s.Title
            })
                                         .OrderBy(s => Guid.NewGuid())
                                         .Take(8)
                                         .ToListAsync();

            var similarArticles = await _dbContext.Article
                                  .Where(s => s.Status == (int)CommonStatus.Valid && s.Id != article.Id)
                                  .Select(s => new Article()
            {
                Id         = s.Id,
                CreateTime = s.CreateTime,
                Title      = s.Title
            })
                                  .ToListAsync();

            //筛选相似数据
            similarArticles = similarArticles.Where(s => StringSimilarity.Calculate(article.Title, s.Title) > 0.3m).OrderBy(s => Guid.NewGuid()).Take(8).ToList();

            detailModel.SimilarArticles = similarArticles;

            string viewCountStr = await _cache.GetStringAsync($"article{id}");

            if (viewCountStr.IsNullOrEmpty())
            {
                viewCountStr = "0";
            }
            int viewCount = int.Parse(viewCountStr) + 1;
            await _cache.SetStringAsync($"article{id}", viewCount.ToString());

            article.ReadCount += viewCount;
            if (viewCount == int.Parse(Configuration["AppSettings:Threshold"]))
            {
                _dbContext.Set <Article>().Update(article);
                if (await _dbContext.SaveChangesAsync() <= 0)
                {
                    _logger.LogWarning($"更新文章浏览量失败,ID:{article.Id}");
                }
                await _cache.RemoveAsync($"article{id}");
            }

            return(View(detailModel));
        }