Пример #1
0
        public JsonResult RunTask(int id)
        {
            TaskDetail td = taskService.Get(id);

            if (td == null)
            {
                return(Json(new { status = true, message = "执行失败!" }));
            }

            if (Utility.IsDistributedDeploy() && (td.RunAtServer == RunAtServer.Master || td.RunAtServer == RunAtServer.Search))
            {
                try
                {
                    TaskServiceClient client = new TaskServiceClient("WCFTaskService");
                    client.RunTask(id);
                }
                catch (Exception e)
                {
                    return(Json(new { message = "执行失败!" }));
                }
            }
            else
            {
                TaskSchedulerFactory.GetScheduler().Run(id);
            }

            return(Json(new { success = true, message = "执行成功!" }));
        }
Пример #2
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var containerBuilder = new ContainerBuilder();

            //注册运行环境
            containerBuilder.Register(c => new DefaultRunningEnvironment()).As <IRunningEnvironment>().SingleInstance();

            //注册系统日志
            containerBuilder.Register(c => new Log4NetLoggerFactoryAdapter()).As <ILoggerFactoryAdapter>().SingleInstance();

            //注册缓存
            containerBuilder.Register(c => new DefaultCacheService(new MemcachedCache(), 1.0F)).As <ICacheService>().SingleInstance();

            //注册IStoreProvider
            string fileServerRootPath = ConfigurationManager.AppSettings["DistributedDeploy:FileServerRootPath"];
            string fileServerRootUrl  = ConfigurationManager.AppSettings["DistributedDeploy:FileServerRootUrl"];
            string fileServerUsername = ConfigurationManager.AppSettings["DistributedDeploy:FileServerUsername"];
            string fileServerPassword = ConfigurationManager.AppSettings["DistributedDeploy:FileServerPassword"];

            containerBuilder.Register(c => new DefaultStoreProvider(fileServerRootPath, fileServerRootUrl, fileServerUsername, fileServerPassword)).Named <IStoreProvider>("CommonStorageProvider").SingleInstance();
            containerBuilder.Register(c => new DefaultStoreProvider(fileServerRootPath, fileServerRootUrl, fileServerUsername, fileServerPassword)).As <IStoreProvider>().SingleInstance();

            //注册任务调度器
            containerBuilder.Register(c => new QuartzTaskScheduler(RunAtServer.Master)).As <ITaskScheduler>().SingleInstance();

            //通知提醒查询器
            containerBuilder.Register(c => new NoticeReminderAccessor()).As <IReminderInfoAccessor>().SingleInstance();

            IContainer container = containerBuilder.Build();

            DIContainer.RegisterContainer(container);

            //启动主控端定时任务
            TaskSchedulerFactory.GetScheduler().Start();
        }
Пример #3
0
        protected void Application_End(object sender, EventArgs e)
        {
            //保存定时任务状态
            TaskSchedulerFactory.GetScheduler().SaveTaskStatus();

            //关闭全文检索索引
            foreach (SearchEngine searchEngine in SearchEngineService.searchEngines.Values)
            {
                searchEngine.Close();
            }
        }
Пример #4
0
        /// <summary>
        /// 执行任务
        /// </summary>
        /// <param name="context">Quartz任务运行环境</param>
        /// <remarks>外部不需调用,仅用于任务调度组建内部</remarks>
        public void Execute(IJobExecutionContext context)
        {
            int        Id   = context.JobDetail.JobDataMap.GetInt("Id");
            TaskDetail task = TaskSchedulerFactory.GetScheduler().GetTask(Id);

            if (task == null)
            {
                throw new ArgumentException("Not found task :" + task.Name);
            }


            TaskService taskService = new TaskService();

            task.IsRunning = true;
            DateTime lastStart = DateTime.UtcNow;

            try
            {
                ITask excuteTask = (ITask)Activator.CreateInstance(Type.GetType(task.ClassType));
                excuteTask.Execute(task);

                task.LastIsSuccess = true;
            }
            catch (Exception ex)
            {
                LoggerFactory.GetLogger().Error(ex, string.Format("Exception while running job {0} of type {1}", context.JobDetail.Key, context.JobDetail.JobType.ToString()));
                task.LastIsSuccess = false;
            }

            task.IsRunning = false;

            task.LastStart = lastStart;
            if (context.NextFireTimeUtc.HasValue)
            {
                task.NextStart = context.NextFireTimeUtc.Value.UtcDateTime;
            }
            else
            {
                task.NextStart = null;
            }

            task.LastEnd = DateTime.UtcNow;
            taskService.SaveTaskStatus(task);
        }
Пример #5
0
 /// <summary>
 /// 执行定时任务
 /// </summary>
 /// <param name="taskId">定时任务的Id</param>
 public void RunTask(int taskId)
 {
     TaskSchedulerFactory.GetScheduler().Run(taskId);
 }
Пример #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime, IServiceProvider svp)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            HttpContextCore.ServiceProvider = svp;

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            string urlSuffix = string.Empty;
            var    setting   = Configuration["UseSuffix"];

            if (setting.Equals("true", StringComparison.CurrentCultureIgnoreCase))
            {
                urlSuffix = ".aspx";
            }

            app.UseStaticFiles();
            app.UseSession();
            app.UseTimedJob();
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme  = "Sexy.Cookie",
                AutomaticAuthenticate = true,
                LoginPath             = new PathString("/System/ManageLogin" + urlSuffix),
                AccessDeniedPath      = new PathString("/Error/GlobalError" + urlSuffix),
                AutomaticChallenge    = true,
                CookieHttpOnly        = true,
                ExpireTimeSpan        = TimeSpan.FromMinutes(30),
                SlidingExpiration     = true,
                ClaimsIssuer          = "http://www.sexy.com",
                CookiePath            = "/"
            });
            TaskSchedulerFactory.GetScheduler().Start();
            app.UseMvc(routes =>
            {
                //routes.MapRoute(
                //   name: "Route",
                //   template: "{*path}",
                //   defaults: new { controller = "Manage", action = "Login" } );

                routes.MapRoute(
                    name: "Error",
                    template: "Error/{action}" + urlSuffix,
                    defaults: new { controller = "Error" });

                routes.MapRoute(
                    name: "System",
                    template: "System/{action}" + urlSuffix,
                    defaults: new { controller = "System", action = "ManageLogin" });

                routes.MapRoute(
                    name: "Default",
                    template: "",
                    defaults: new { controller = "System", action = "ManageLogin" });

                routes.MapRoute(
                    name: "SystemUser",
                    template: "System/User/{action}" + urlSuffix,
                    defaults: new { controller = "SystemUser", action = "ManageUser" });

                routes.MapRoute(
                    name: "SystemPermissions",
                    template: "System/Permissions/{action}" + urlSuffix,
                    defaults: new { controller = "SystemPermissions", action = "ManagePermission" });

                routes.MapRoute(
                    name: "SystemGoods",
                    template: "System/Goods/{action}" + urlSuffix,
                    defaults: new { controller = "SystemGoods", action = "ManagerGoods" });

                routes.MapRoute(
                    name: "SystemBasics",
                    template: "System/Basics/{action}" + urlSuffix,
                    defaults: new { controller = "SystemBasics", action = "ManageOperation" });

                routes.MapRoute(
                    name: "SystemSettings",
                    template: "System/Settings/{action}" + urlSuffix,
                    defaults: new { controller = "SystemSettings", action = "SiteSettings" });

                routes.MapRoute(
                    name: "SystemPoint",
                    template: "System/Point/{action}" + urlSuffix,
                    defaults: new { controller = "SystemPoint", action = "ManagerPoint" });

                routes.MapRoute(
                    name: "SystemOrder",
                    template: "System/Order/{action}" + urlSuffix,
                    defaults: new { controller = "SystemOrder", action = "ManagerOrder" });
            });
            appLifetime.ApplicationStopped.Register(() => this.ApplicationContainer.Dispose());
        }