예제 #1
0
        public async void Run()
        {
            // check allow scheduler
            if ((bool)AppSettingHelper.GetAppSetting(typeof(bool), "AllowScheduler", true, false))
            {
                // construct a scheduler factory
                var props = new NameValueCollection
                {
                    { "quartz.serializer.type", "binary" }
                };
                // init schedule
                var schedFact = new StdSchedulerFactory(props);
                // get a scheduler
                _sched = await schedFact.GetScheduler();

                // job scheduler
                // init job
                var jobScheduler = JobBuilder.Create <JobScheduler>()
                                   .WithIdentity("jobScheduler", "scheduler").Build();

                var triggerScheduler = TriggerBuilder.Create()
                                       .WithIdentity("triggerScheduler", "scheduler")
                                       .WithCronSchedule((string)AppSettingHelper.GetAppSetting(typeof(string), "CronExpression",
                                                                                                CronExpression, false))
                                       .WithSimpleSchedule(x => x.WithIntervalInSeconds(60).RepeatForever().WithMisfireHandlingInstructionFireNow())
                                       .ForJob(jobScheduler)
                                       .Build();

                // add to schedule
                await _sched.ScheduleJob(jobScheduler, triggerScheduler);

                // start
                await _sched.Start();
            }
        }
예제 #2
0
        /// <summary>
        /// 获取预置模型及模板数据
        /// </summary>
        /// <returns></returns>
        public JsonResult GetDataCodeFirst()
        {
            DataInfoForJson model = new DataInfoForJson();

            try
            {
                string nameSpace = AppSettingHelper.GetAppSetting("NameSpaceCodeFirst");
                var    types     = Assembly.GetExecutingAssembly().GetTypes().Where(u => u.Namespace == nameSpace).ToList();

                model.DataTable = new List <DataItem>();
                model.Data      = new List <DataItem>();

                var files = context.TempInfo.Where(u => u.TP_Type == (int)Data.TemplateType.ModelFirst).OrderBy(u => u.TP_Order).ToList();


                foreach (var item in files)
                {
                    model.Data.Add(new DataItem()
                    {
                        Key  = item.TP_ID.ToString(),
                        Name = item.TP_Name
                    });
                }

                foreach (var typeInfo in types)
                {
                    DataItem item = new DataItem();

                    item.Key = typeInfo.FullName;

                    var attribute = TemplateGenerator.CodeFirstGenerator.CodeFirstHelper.GetModelAttribute <TemplateGenerator.CodeFirstGenerator.ModelAttributes.ItemDisplayNameAttribute>(typeInfo);

                    if (attribute != null)
                    {
                        item.Name = attribute.DisplayName;
                    }
                    else
                    {
                        item.Name = typeInfo.Name;
                    }

                    model.DataTable.Add(item);
                }

                model.Status = 1;
            }
            catch (Exception ex)
            {
                model.Status = 0;
                model.Desc   = ex.Message;
            }



            return(Json(model));
        }
예제 #3
0
        /// <summary>
        /// 根据模板生成代码
        /// </summary>
        /// <param name="tempID"></param>
        /// <param name="tablename"></param>
        /// <param name="forceChange"></param>
        /// <returns></returns>
        public JsonResult GeneratorData(int tempID, string tablename, bool forceChange)
        {
            ModelForJson data = new ModelForJson();

            try
            {
                string localURL = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["tempLocation"]);

                string dllLocation = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["dllLocation"]);

                string nameSpace = AppSettingHelper.GetAppSetting("NameSpaceCodeFirst");

                var model = context.TempInfo.Find(tempID);

                if (model != null)
                {
                    var dataModel = Assembly.GetExecutingAssembly().GetTypes().Where(u => u.Namespace == nameSpace && u.FullName == tablename).ToList();



                    if (dataModel.Count == 1)
                    {
                        var modelData = TemplateGenerator.CodeFirstGenerator.CodeFirstHelper.GetModelData(dataModel[0]);

                        string dataString = JsonHelper.ToJson(modelData);

                        string result = TemplateGenerator.RazorGenerator.DomainHelper.GenetatorCodeFirst(dllLocation, Server.MapPath(model.TP_URL), forceChange, dataString);
                        data.Status = 1;
                        data.Result = result;
                    }
                    else
                    {
                        data.Status = 0;
                        data.Result = "错误的模型全称!";
                    }
                }
                else
                {
                    data.Status = 0;
                    data.Desc   = "模板信息不存在!";
                }
            }
            catch (Exception ex)
            {
                data.Status = 0;
                data.Desc   = ex.Message;
            }
            return(Json(data, JsonRequestBehavior.AllowGet));
        }
예제 #4
0
파일: Resource.cs 프로젝트: war-man/HRM
        public static bool IsHJM()
        {
            try
            {
                // get application type
                var application = AppSettingHelper.GetAppSetting(typeof(string), "Application", true).ToString();

                // return is hjm
                return(application.ToLower() == "hjm");
            }
            catch
            {
                return(false);
            }
        }
예제 #5
0
        public void Configuration(IAppBuilder app)
        {
            AuthenticationConfigurator.ConfigureAuth(app);
            var hubConfiguration = new HubConfiguration();

            hubConfiguration.EnableDetailedErrors = true;
            app.MapSignalR(hubConfiguration);

            string hangfireDBName = AppSettingHelper.GetAppSetting <string>(Constants.AppSetting.HangfireDBName);

            GlobalConfiguration.Configuration.UseMongoStorage("mongodb://localhost", hangfireDBName);

            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                Authorization = new[] { new AuthorizationFilter() }
            });

            app.UseHangfireServer();
        }
예제 #6
0
        /// <summary>
        /// 批量生成代码
        /// </summary>
        /// <param name="tempIDs"></param>
        /// <param name="tablenames"></param>
        /// <param name="forceChange"></param>
        /// <returns></returns>
        public ActionResult GeneratorDataBatch(int[] tempIDs, string[] tablenames, bool forceChange = false)
        {
            string newFolder = "";

            try
            {
                string dllLocation = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["dllLocation"]);
                string connectStr  = System.Configuration.ConfigurationManager.AppSettings["DbConnString"];

                string TemporaryFolder = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["TemporaryFolder"]);

                string nameSpace = AppSettingHelper.GetAppSetting("NameSpaceCodeFirst");

                if (!FileHelper.IsExistDirectory(TemporaryFolder))
                {
                    FileHelper.CreateDirectory(TemporaryFolder);
                }

                newFolder = TemporaryFolder + "/" + (tempIDs.Length > 0 ? tempIDs[0].ToString() : "Temp") + "_" + (int)(random.NextDouble() * 10000);

                if (tablenames.Length > 0)
                {
                    var tempList = context.TempInfo.Where(u => tempIDs.Contains(u.TP_ID)).ToList();

                    FileHelper.CreateDirectory(newFolder);
                    foreach (var temp in tempList)
                    {
                        FileHelper.CreateDirectory(newFolder + "/" + temp.TP_FolderName);



                        foreach (string tableName in tablenames)
                        {
                            var dataModel = Assembly.GetExecutingAssembly().GetTypes().Where(u => u.Namespace == nameSpace && u.FullName == tableName).ToList();



                            if (dataModel.Count == 1)
                            {
                                var modelData = TemplateGenerator.CodeFirstGenerator.CodeFirstHelper.GetModelData(dataModel[0]);

                                string dataString = JsonHelper.ToJson(modelData);

                                string result = TemplateGenerator.RazorGenerator.DomainHelper.GenetatorCodeFirst(dllLocation, Server.MapPath(temp.TP_URL), forceChange, dataString);


                                string filePath = newFolder + "/" + temp.TP_FolderName + "/" + tableName + "." + temp.TP_Extention;

                                FileHelper.CreateFile(filePath);
                                FileHelper.WriteText(filePath, result);
                            }
                        }
                    }

                    //生成压缩包
                    ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
                    fz.CreateZip(newFolder + ".zip", newFolder, true, "");

                    #region  除文件及文件夹
                    FileHelper.ClearDirectory(newFolder);
                    FileHelper.DeleteDirectory(newFolder);
                    #endregion

                    MemoryStream memStream = new MemoryStream();
                    using (FileStream fs = new FileStream(newFolder + ".zip", FileMode.Open))
                    {
                        memStream.SetLength(fs.Length);
                        fs.Read(memStream.GetBuffer(), 0, (int)fs.Length);
                    }

                    //删除压缩包
                    FileHelper.DeleteFile(newFolder + ".zip");

                    return(File(memStream, "application/octet-stream", "批量生成代码" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".zip"));
                }
                else
                {
                    Response.Write("没有数据");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                if (!string.IsNullOrEmpty(newFolder))
                {
                    if (FileHelper.IsExistDirectory(newFolder))
                    {
                        #region  除文件及文件夹
                        FileHelper.ClearDirectory(newFolder);
                        FileHelper.DeleteDirectory(newFolder);
                        FileHelper.DeleteFile(newFolder + ".zip");
                        #endregion
                    }
                }

                Response.Write(ex.Message);
                return(null);
            }
        }