Пример #1
0
        public async Task <object> Get(int id, int page = 1, string bcategory = "技术博文")
        {
            int intTotalCount = 6;
            int Total         = 0;
            int TotalCount    = 1;
            List <BlogArticle> blogArticleList = new List <BlogArticle>();

            using (MiniProfiler.Current.Step("开始加载数据:"))
            {
                if (redisCacheManager.Get <object>("Redis.Blog") != null)
                {
                    MiniProfiler.Current.Step("从Redis服务器中加载数据:");
                    blogArticleList = redisCacheManager.Get <List <BlogArticle> >("Redis.Blog");
                }
                else
                {
                    MiniProfiler.Current.Step("从MSSQL服务器中加载数据:");
                    blogArticleList = await blogArticleServices.Query(a => a.bcategory == bcategory);

                    redisCacheManager.Set("Redis.Blog", blogArticleList, TimeSpan.FromHours(2));
                }
            }

            Total      = blogArticleList.Count();
            TotalCount = blogArticleList.Count() / intTotalCount;

            using (MiniProfiler.Current.Step("获取成功后,开始处理最终数据"))
            {
                blogArticleList = blogArticleList.OrderByDescending(d => d.bID).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList();

                foreach (var item in blogArticleList)
                {
                    if (!string.IsNullOrEmpty(item.bcontent))
                    {
                        item.bRemark = (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Length >= 200 ? (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Substring(0, 200) : (HtmlHelper.ReplaceHtmlTag(item.bcontent));
                        int totalLength = 500;
                        if (item.bcontent.Length > totalLength)
                        {
                            item.bcontent = item.bcontent.Substring(0, totalLength);
                        }
                    }
                }
            }

            return(Ok(new
            {
                success = true,
                page = page,
                total = Total,
                pageCount = TotalCount,
                data = blogArticleList
            }));
        }
Пример #2
0
        public async void Delete_Blog_Test()
        {
            Add_Blog_Test();

            var deleteModel = (await blogArticleServices.Query(d => d.btitle == "xuint test title")).FirstOrDefault();

            Assert.NotNull(deleteModel);

            var IsDel = await blogArticleServices.Delete(deleteModel);

            Assert.True(IsDel);
        }
Пример #3
0
        public async Task <object> TestMutiDBAPI()
        {
            // 从主库(Sqlite)中,操作blogs
            var blogs = await _blogArticleServices.Query(d => d.bID == 1);

            // 从从库(Sqlserver)中,获取pwds
            var pwds = await _passwordLibServices.Query(d => d.PLID > 0);

            return(new
            {
                blogs,
                pwds
            });
        }
Пример #4
0
        //[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
        //[ResponseCache(Duration = 600)]
        public async Task <MessageModel <PageModel <BlogArticle> > > Get(int id, int page = 1, string bcategory = "技术博文", string key = "")
        {
            int intTotalCount = 6;
            int total;
            int totalCount = 1;
            List <BlogArticle> blogArticleList = new List <BlogArticle>();

            if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                key = "";
            }

            blogArticleList = await _blogArticleServices.Query(a => a.bcategory == bcategory && a.IsDeleted == false);

            blogArticleList = blogArticleList.Where(d => (d.btitle != null && d.btitle.Contains(key)) || (d.bcontent != null && d.bcontent.Contains(key))).ToList();

            total      = blogArticleList.Count();
            totalCount = (Math.Ceiling(total.ObjToDecimal() / intTotalCount.ObjToDecimal())).ObjToInt();

            using (MiniProfiler.Current.Step("获取成功后,开始处理最终数据"))
            {
                blogArticleList = blogArticleList.OrderByDescending(d => d.bID).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList();

                foreach (var item in blogArticleList)
                {
                    if (!string.IsNullOrEmpty(item.bcontent))
                    {
                        item.bRemark = (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Length >= 200 ? (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Substring(0, 200) : (HtmlHelper.ReplaceHtmlTag(item.bcontent));
                        int totalLength = 500;
                        if (item.bcontent.Length > totalLength)
                        {
                            item.bcontent = item.bcontent.Substring(0, totalLength);
                        }
                    }
                }
            }

            return(new MessageModel <PageModel <BlogArticle> >()
            {
                success = true,
                msg = "获取成功",
                response = new PageModel <BlogArticle>()
                {
                    page = page,
                    dataCount = total,
                    data = blogArticleList,
                    pageCount = totalCount,
                }
            });
        }
Пример #5
0
        public async Task <List <BlogArticle> > GetBlogs()
        {
            List <BlogArticle> blogs = new List <BlogArticle>();

            if (_redisCacheManager.Get <object>("Redis.Blog") != null)
            {
                blogs = _redisCacheManager.Get <List <BlogArticle> >("Redis.Blog");
            }
            else
            {
                blogs = await _blogArticleServices.Query(d => d.BId > 5);

                _redisCacheManager.Set("Redis.Blog", blogs, TimeSpan.FromHours(2));//缓存2小时
            }
            return(blogs);
        }
Пример #6
0
        public async Task <List <BlogArticle> > GetBlogs()
        {
            //var connect = Appsettings.app(new string []{ "AppSettings", "RedisCaching", "ConnectionString"});//按照层级的顺序,依次写出来
            List <BlogArticle> blogArticlesList = new List <BlogArticle>();

            //if (redisCacheManager.Get<object>("Redis.Blog") != null)
            //{
            //    blogArticlesList = redisCacheManager.Get<List<BlogArticle>>("Redis.Blog");
            //}
            //else
            //{
            blogArticlesList = await blogArticleServices.Query(d => d.bID < 5);

            redisCacheManager.Set("Redis.Blog", blogArticlesList, TimeSpan.FromHours(2));    //缓存2小时
            //}
            return(blogArticlesList);
        }
Пример #7
0
        public async Task <object> Page(int page, string bcategory = "技术博文", string key = "")
        {
            //// 读取json数据文件,把文件转换为实体类
            //string filePath = $"{AppContext.BaseDirectory}book.json";
            //var objJson = FileHelper.ReadFile(filePath, System.Text.Encoding.Default);
            //List<Book> bookList = JsonConvert.DeserializeObject<List<Book>>(objJson);


            int intTotalCount = 6;
            int total;
            int totalCount = 1;

            List <BlogArticle> blogArticleList = new List <BlogArticle>();

            blogArticleList = await _blogArticleServices.Query(a => a.bcategory == bcategory && a.IsDeleted == false);

            total      = blogArticleList.Count();
            totalCount = (Math.Ceiling(total.ObjToDecimal() / intTotalCount.ObjToDecimal())).ObjToInt();

            using (MiniProfiler.Current.Step("获取成功后,开始处理最终数据"))
            {
                blogArticleList = blogArticleList.OrderByDescending(d => d.bID).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList();

                foreach (var item in blogArticleList)
                {
                    if (!string.IsNullOrEmpty(item.bcontent))
                    {
                        item.bRemark = (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Length >= 200 ? (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Substring(0, 200) : (HtmlHelper.ReplaceHtmlTag(item.bcontent));
                        int totalLength = 500;
                        if (item.bcontent.Length > totalLength)
                        {
                            item.bcontent = item.bcontent.Substring(0, totalLength);
                        }
                    }
                }
            }

            return(Ok(new
            {
                success = true,
                page,
                total,
                pageCount = totalCount,
                data = blogArticleList
            }));
        }
Пример #8
0
        public async Task <MessageModel <List <BlogArticle> > > GetBlogsByTypesForMVP(string types = "", int id = 0)
        {
            if (types.IsNotEmptyOrNull())
            {
                var blogs = await _blogArticleServices.Query(d => d.bcategory != null && types.Contains(d.bcategory) && d.IsDeleted == false);

                return(new MessageModel <List <BlogArticle> >()
                {
                    msg = "获取成功",
                    success = true,
                    response = blogs
                });
            }

            return(new MessageModel <List <BlogArticle> >()
            {
            });
        }
Пример #9
0
        public async Task <List <BlogArticle> > GetBlogs()
        {
            var connect = Appsettings.app(new string[] { "AppSettings", "RedisCaching", "ConnectionString" });

            var blogArticleList = new List <BlogArticle>();

            if (redisCacheManager.Get <object>("Redis.Blog") != null)
            {
                blogArticleList = redisCacheManager.Get <List <BlogArticle> >("Redis.Blog");
            }
            else
            {
                blogArticleList = await blogArticleServices.Query(s => s.bID > 5);

                redisCacheManager.Set("Redis.Blog", blogArticleList, TimeSpan.FromHours(2));
            }

            return(blogArticleList);
        }
Пример #10
0
        public async Task <object> Get(int id, int page = 1, string bcategory = "技术博文")
        {
            int intTotalCount = 6;
            int TotalCount    = 1;
            List <BlogArticle> blogArticleList = new List <BlogArticle>();

            if (redisCacheManager.Get <object>("Redis.Blog") != null)
            {
                blogArticleList = redisCacheManager.Get <List <BlogArticle> >("Redis.Blog");
            }
            else
            {
                blogArticleList = await blogArticleServices.Query(a => a.bcategory == bcategory);

                redisCacheManager.Set("Redis.Blog", blogArticleList, TimeSpan.FromHours(2));
            }


            TotalCount = blogArticleList.Count() / intTotalCount;

            blogArticleList = blogArticleList.OrderByDescending(d => d.bID).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList();

            foreach (var item in blogArticleList)
            {
                if (!string.IsNullOrEmpty(item.bcontent))
                {
                    //item.bcontent = Tools.ReplaceHtmlTag(item.bcontent);
                    int totalLength = 500;
                    if (item.bcontent.Length > totalLength)
                    {
                        item.bcontent = item.bcontent.Substring(0, totalLength);
                    }
                }
            }

            var data = new { success = true, page = page, pageCount = TotalCount, data = blogArticleList };


            return(data);
        }
Пример #11
0
        public async Task Run(IJobExecutionContext context, int jobid)
        {
            var list = await _blogArticleServices.Query();

            if (jobid > 0)
            {
                var model = await _tasksQzServices.QueryById(jobid);

                if (model != null)
                {
                    model.RunTimes += 1;
                    var separator = "<br>";
                    model.Remark =
                        $"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】【执行成功】:博客数{list.Count}{separator}"
                        + string.Join(separator, StringHelper.GetTopDataBySeparator(model.Remark, separator, 9));

                    await _tasksQzServices.Update(model);
                }
            }

            await Console.Out.WriteLineAsync("博客总数量" + list.Count.ToString());
        }
Пример #12
0
        public async Task <object> TestMutiDBAPI()
        {
            // 从主库中,操作blogs
            var blogs = await _blogArticleServices.Query(d => d.bID == 1);

            var addBlog = await _blogArticleServices.Add(new BlogArticle()
            {
            });

            // 从从库中,操作pwds
            var pwds = await _passwordLibServices.Query(d => d.PLID > 0);

            var addPwd = await _passwordLibServices.Add(new PasswordLib()
            {
            });

            return(new
            {
                blogs,
                pwds
            });
        }
Пример #13
0
        public async Task <object> Get(int id, int page = 1, string bcategory = "技术博客", string key = "")
        {
            int inTotalCount = 6;
            int total;
            int totalCount = 1;
            List <BlogArticle> blogArticleList = new List <BlogArticle>();

            if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                key = "";
            }
            using (MiniProfiler.Current.Step("开始加载数据:"))
            {
                try
                {
                    if (_redisCacheManager.Get <object>("Redis.Blog") != null)
                    {
                        MiniProfiler.Current.Step("从Redis服务器中加载数据:");
                        blogArticleList = _redisCacheManager.Get <List <BlogArticle> >("Redis.Blog");
                    }
                    else
                    {
                        MiniProfiler.Current.Step("从MSSQL服务器中加载数据:");
                        blogArticleList = await _blogArticleServices.Query(a => a.bcategory ==
                                                                           bcategory && a.IsDeleted == false);

                        _redisCacheManager.Set("Redis.Blog", blogArticleList, TimeSpan.FromHours(2));
                    }
                }
                catch (Exception e)
                {
                    MiniProfiler.Current.CustomTiming("Errors:", "Redis服务未启用,请开启该服务,并且请注意端口号,本项目使用的的6319," +
                                                      "而且我的是没有设置密码。" + e.Message);
                    blogArticleList = await _blogArticleServices.Query(a => a.bcategory == bcategory && a.IsDeleted == false);
                }
            }
            blogArticleList = blogArticleList.Where(d => (d.btitle != null && d.btitle.Contains(key)) ||
                                                    (d.bcontent != null && d.bcontent.Contains(key))).ToList();

            total      = blogArticleList.Count();
            totalCount = blogArticleList.Count() / inTotalCount;

            using (MiniProfiler.Current.Step("开始处理最终数据"))
            {
                blogArticleList = blogArticleList.OrderByDescending(d => d.bID).Skip((page - 1) * inTotalCount).Take(inTotalCount).ToList();

                foreach (var item in blogArticleList)
                {
                    if (!string.IsNullOrEmpty(item.bcategory))
                    {
                        item.bRemark = (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Length >= 200 ?
                                       (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Substring(0, 200)
                            : (HtmlHelper.ReplaceHtmlTag(item.bcontent));
                        int totalLength = 500;
                        if (item.bcontent.Length > totalLength)
                        {
                            item.bcontent = item.bcontent.Substring(0, totalLength);
                        }
                    }
                }
            }
            return(Ok(new
            {
                success = true,
                page,
                total,
                pageCount = totalCount,
                data = blogArticleList
            }));
        }
Пример #14
0
        public async Task <MessageModel <ResponseEnum> > Get()
        {
            var data = new MessageModel <ResponseEnum>();

            /*
             *  测试 sql 查询
             */
            var queryBySql = await _blogArticleServices.QuerySql("SELECT bsubmitter,btitle,bcontent,bCreateTime FROM BlogArticle WHERE bID>5");

            /*
             *  测试按照指定列查询
             */
            var queryByColums = await _blogArticleServices
                                .Query <BlogViewModels>(it => new BlogViewModels()
            {
                btitle = it.btitle
            });

            /*
             *  测试按照指定列查询带多条件和排序方法
             */
            Expression <Func <BlogArticle, bool> > registerInfoWhere = a => a.btitle == "xxx" && a.bRemark == "XXX";
            var queryByColumsByMultiTerms = await _blogArticleServices
                                            .Query <BlogArticle>(it => new BlogArticle()
            {
                btitle = it.btitle
            }, registerInfoWhere, "bID Desc");

            /*
             *  测试 sql 更新
             *
             * 【SQL参数】:@bID:5
             *  @bsubmitter:laozhang619
             *  @IsDeleted:False
             * 【SQL语句】:UPDATE `BlogArticle`  SET
             *  `bsubmitter`=@bsubmitter,`IsDeleted`=@IsDeleted  WHERE `bID`=@bID
             */
            var updateSql = await _blogArticleServices.Update(new { bsubmitter = $"laozhang{DateTime.Now.Millisecond}", IsDeleted = false, bID = 5 });


            // 测试模拟异常,全局异常过滤器拦截
            var i = 0;
            var d = 3 / i;


            // 测试 AOP 缓存
            var blogArticles = await _blogArticleServices.GetBlogs();


            // 测试多表联查
            var roleModulePermissions = await _roleModulePermissionServices.QueryMuchTable();


            // 测试多个异步执行时间
            var roleModuleTask = _roleModulePermissionServices.Query();
            var listTask       = _advertisementServices.Query();
            var ad             = await roleModuleTask;
            var list           = await listTask;


            // 测试service层返回异常
            _advertisementServices.ReturnExp();

            return(data);
        }
Пример #15
0
        public async Task Run(IJobExecutionContext context)
        {
            var list = await _blogArticleServices.Query();

            await Console.Out.WriteLineAsync("博客总数量" + list.Count.ToString());
        }