Esempio n. 1
0
        public static void AddFreeSql(this IServiceCollection service)
        {
            var dbConfig      = GlobalContext.DefaultDbConfig;
            var freeSqlConfig = GlobalContext.FreeSqlConfig;

            service.AddSingleton <IFreeSql>(f =>
            {
                IFreeSql freeSql = DbInstanceFactory.GetInstance(dbConfig.DataType, dbConfig.MasterConnection);
                if (freeSqlConfig.LogSql)
                {
                    freeSql.Aop.CurdAfter += (s, e) => {
                        if (e.Table.DbName != "easy_log" && e.Table.DbName != "sys_sql_log")
                        {
                            LoggerHelper.Sql(e.Table.DbName, e.Sql, e.ElapsedMilliseconds);
                        }
                    };
                }

                return(freeSql);
            });


            //注入当前用户 利用了缓存查询当前用户信息
            //service.AddScoped<CurrentUser>(f => f.GetRequiredService<IHttpContextAccessor>().HttpContext?.User?.GetCurrentUser(f));
            //使用类库Scrutor做发现注入类库和服务
            //service.AddServer(typeof(IRepKey));
            //service.AddServer(typeof(IDeviceAppService));
            //service.TryAddScoped<IRequestHelper, RequestHelper>();
        }
Esempio n. 2
0
        /// <summary>
        /// 获取栏目
        /// </summary>
        /// <param name="channelId"></param>
        /// <returns></returns>
        public static cms_channel GetChannel(int channelId)
        {
            if (_channels.ContainsKey(channelId))
            {
                return(_channels[channelId]);
            }
            var sql   = DbInstanceFactory.GetInstance();
            var model = sql.Select <cms_channel>().Where(s => s.id == channelId).First();

            if (model != null)
            {
                AddChannel(model);
            }
            return(model);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取栏目
        /// </summary>
        /// <param name="template"></param>
        /// <returns></returns>
        public static cms_template GetTemplate(int template)
        {
            if (_templates.ContainsKey(template))
            {
                return(_templates[template]);
            }
            var sql   = DbInstanceFactory.GetInstance();
            var model = sql.Select <cms_template>().Where(s => s.id == template).First();

            if (model != null)
            {
                AddTemplate(model);
            }
            return(model);
        }
Esempio n. 4
0
        /// <summary>
        /// 加载模板文件,生成模板内容
        /// </summary>
        /// <param name="contentId"></param>
        public void CreateHtml(int contentId)
        {
            try
            {
                var sqlDb   = DbInstanceFactory.GetInstance();
                var content = sqlDb.Select <cms_content>().Where(s => s.id == contentId).First();
                if (content == null)
                {
                    return;
                }
                string contentFolder = $@"static/content/{content.channel_id}";
                string contentFile   = $@"static/content/{content.channel_id}/{ content.id}.html";

                string contentFolderPath = Path.Combine(GlobalContext.WebRootPath, contentFolder);
                string contentFilePath   = Path.Combine(GlobalContext.WebRootPath, contentFile);
                string templatePath      = Path.Combine(GlobalContext.WebRootPath, "Template/article.html");
                if (!File.Exists(templatePath))
                {
                    LoggerHelper.Exception("模板数据不存在");
                    return;
                }
                if (!Directory.Exists(contentFolderPath))
                {
                    Directory.CreateDirectory(contentFolderPath);
                }


                //加载模板
                //this.LoadTemplateFile(templatePath);
                //this.InitPageTemplate(content);
                //this.Document = new TemplateDocument(templatePath, fileName);

                using (var filestream = new FileStream(contentFilePath, FileMode.Create, FileAccess.ReadWrite))
                {
                    string renderHtml = this.Document.GetRenderText();

                    using (StreamWriter writer = new StreamWriter(filestream, Encoding.UTF8))
                    {
                        writer.WriteLine(renderHtml);
                        writer.Flush();
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Exception(ex);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 获取栏目
        /// </summary>
        /// <param name="channelId"></param>
        /// <returns></returns>
        public static cms_channel GetChannelByIndex(string channelIndex)
        {
            if (_indexChannels.ContainsKey(channelIndex))
            {
                return(_indexChannels[channelIndex]);
            }
            var sql   = DbInstanceFactory.GetInstance();
            var model = sql.Select <cms_channel>().Where(s => s.channel_index == channelIndex)
                        .OrderBy(s => s.id).First();

            if (model != null)
            {
                AddChannel(model);
            }
            return(model);
        }
Esempio n. 6
0
        public static void Init()
        {
            var sqlDb     = DbInstanceFactory.GetInstance();
            var templates = sqlDb.Select <cms_template>().ToList();
            var channels  = sqlDb.Select <cms_channel>().ToList();


            templates.ForEach(s =>
            {
                TemplateManagerCache.AddTemplate(s);
            });

            channels.ForEach(s =>
            {
                if (s.link_type == 1 && string.IsNullOrEmpty(s.channel_href))
                {
                    var firstId = sqlDb.Select <cms_content>().Where(a => a.channel_id == s.id).OrderByDescending(a => a.id).First(a => a.id);
                    if (firstId > 0)
                    {
                        s.channel_href = $"/news/{s.id}/{firstId}";
                    }
                }
                ChannelManagerCache.AddChannel(s);
            });

            ///站点设置
            var site = sqlDb.Select <cms_site>().OrderBy(s => s.id).First();

            if (site == null)
            {
                site              = new cms_site();
                site.site_name    = "EasyCMS内容发布系统";
                site.site_favicon = "/favicon.ico";
                site.site_logo    = "/static/images/logo.png";
            }
            SiteManagerCache.SetSiteInfo(site);
            //上传设置
            var uploadSet = sqlDb.Select <cms_upload_set>().OrderBy(s => s.id).First();

            if (uploadSet == null)
            {
                uploadSet = new cms_upload_set();
            }
            SiteManagerCache.SetUploadInfo(uploadSet);
        }
Esempio n. 7
0
 public void Excute(string wxAppId, string taskId)
 {
     try
     {
         var Sqldb = DbInstanceFactory.GetInstance();
         var log   = new easy_log();
         log.log_summary = "hangfireJob任务";
         log.log_message = DateTime.Now.ToString();
         log.log_type    = 1;
         log.log_time    = DateTime.Now;
         Sqldb.Insert(log).ExecuteAffrows();
         Sqldb.Update <hangfire_task>().Set(s => s.excute_time, DateTime.Now)
         .Where(s => s.id == taskId).ExecuteAffrows();
     }
     catch (Exception e)
     {
         LoggerHelper.Exception(e);
     }
 }
Esempio n. 8
0
 public GenerateAppService()
 {
     Sqldb = DbInstanceFactory.GetInstance();
 }