Example #1
0
 public async Task WriteDbLog(LogEntity logEntity)
 {
     logEntity.F_Id   = Utils.GuId();
     logEntity.F_Date = DateTime.Now;
     try
     {
         if (currentuser == null || string.IsNullOrEmpty(currentuser.UserId))
         {
             logEntity.F_IPAddress = WebHelper.Ip;
             if (GlobalContext.SystemConfig.LocalLAN != false)
             {
                 logEntity.F_IPAddressName = "本地局域网";
             }
             else
             {
                 logEntity.F_IPAddressName = WebHelper.GetIpLocation(logEntity.F_IPAddress);
             }
             logEntity.F_CompanyId = GlobalContext.SystemConfig.SysemMasterProject;
         }
         else
         {
             logEntity.F_IPAddress     = currentuser.LoginIPAddress;
             logEntity.F_IPAddressName = currentuser.LoginIPAddressName;
             logEntity.F_CompanyId     = currentuser.CompanyId;
         }
         logEntity.Create();
         if (HandleLogProvider != Define.CACHEPROVIDER_REDIS)
         {
             uniwork.Rollback();
             await repository.Insert(logEntity);
         }
         else
         {
             await HandleLogHelper.HSetAsync(logEntity.F_CompanyId, logEntity.F_Id, logEntity);
         }
     }
     catch (Exception)
     {
         logEntity.F_IPAddress = WebHelper.Ip;
         if (GlobalContext.SystemConfig.LocalLAN != false)
         {
             logEntity.F_IPAddressName = "本地局域网";
         }
         else
         {
             logEntity.F_IPAddressName = WebHelper.GetIpLocation(logEntity.F_IPAddress);
         }
         logEntity.F_CompanyId = GlobalContext.SystemConfig.SysemMasterProject;
         logEntity.Create();
         if (HandleLogProvider != Define.CACHEPROVIDER_REDIS)
         {
             await repository.Insert(logEntity);
         }
         else
         {
             await HandleLogHelper.HSetAsync(logEntity.F_CompanyId, logEntity.F_Id, logEntity);
         }
     }
 }
Example #2
0
        public async Task WriteDbLog(bool result, string resultLog)
        {
            LogEntity logEntity = new LogEntity();

            logEntity.F_Id            = Utils.GuId();
            logEntity.F_Date          = DateTime.Now;
            logEntity.F_Account       = currentuser.UserCode;
            logEntity.F_NickName      = currentuser.UserName;
            logEntity.F_IPAddress     = currentuser.LoginIPAddress;
            logEntity.F_IPAddressName = currentuser.LoginIPAddressName;
            logEntity.F_CompanyId     = currentuser.CompanyId;
            logEntity.F_Result        = result;
            logEntity.F_Description   = resultLog;
            logEntity.Create();
            if (HandleLogProvider != Define.CACHEPROVIDER_REDIS)
            {
                await repository.Insert(logEntity);
            }
            else
            {
                await HandleLogHelper.HSetAsync(currentuser.CompanyId, logEntity.F_Id, logEntity);
            }
        }
Example #3
0
 public Task Execute(IJobExecutionContext context)
 {
     return(Task.Run(async() =>
     {
         string jobId = "";
         JobDataMap jobData = null;
         OpenJobEntity dbJobEntity = null;
         DateTime now = DateTime.Now;
         try
         {
             jobData = context.JobDetail.JobDataMap;
             jobId = jobData["F_Id"].ToString();
             using (IDbContext _context = DBContexHelper.Contex())
             {
                 OpenJobsService autoJobService = new OpenJobsService(_context, _schedulerFactory, _iocJobfactory);
                 // 获取数据库中的任务
                 dbJobEntity = await autoJobService.GetForm(jobId);
                 if (dbJobEntity != null)
                 {
                     if (dbJobEntity.F_EnabledMark == true)
                     {
                         CronTriggerImpl trigger = context.Trigger as CronTriggerImpl;
                         if (trigger != null)
                         {
                             if (trigger.CronExpressionString != dbJobEntity.F_CronExpress)
                             {
                                 // 更新任务周期
                                 trigger.CronExpressionString = dbJobEntity.F_CronExpress;
                                 await _scheduler.RescheduleJob(trigger.Key, trigger);
                                 return;
                             }
                             #region 执行任务
                             _context.Session.BeginTransaction();
                             //反射执行就行
                             var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
                             //反射取指定前后缀的dll
                             var referencedAssemblies = Directory.GetFiles(path, "HaotianCloud.*.dll").Select(Assembly.LoadFrom).ToArray();
                             var types = referencedAssemblies
                                         .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces()
                                                                             .Contains(typeof(IJobTask)))).ToArray();
                             string filename = dbJobEntity.F_FileName;
                             var implementType = types.Where(x => x.IsClass && x.FullName == filename).FirstOrDefault();
                             var obj = System.Activator.CreateInstance(implementType, _context);   // 创建实例(带参数)
                             MethodInfo method = implementType.GetMethod("Start", new Type[] { }); // 获取方法信息
                             object[] parameters = null;
                             var temp = (Task <AlwaysResult>)method.Invoke(obj, parameters);       // 调用方法,参数为空
                             #endregion
                             //需要同步,不然数据库连接会断开
                             _context.Update <OpenJobEntity>(t => t.F_Id == jobId, a => new OpenJobEntity
                             {
                                 F_LastRunTime = now
                             });
                             OpenJobLogEntity log = new OpenJobLogEntity();
                             log.F_Id = Utils.GuId();
                             log.F_JobId = jobId;
                             log.F_JobName = dbJobEntity.F_JobName;
                             log.F_CreatorTime = now;
                             if (temp.Result.state.ToString() == ResultType.success.ToString())
                             {
                                 log.F_EnabledMark = true;
                                 log.F_Description = "执行成功," + temp.Result.message.ToString();
                             }
                             else
                             {
                                 log.F_EnabledMark = false;
                                 log.F_Description = "执行失败," + temp.Result.message.ToString();
                             }
                             string HandleLogProvider = GlobalContext.SystemConfig.HandleLogProvider;
                             if (HandleLogProvider != Define.CACHEPROVIDER_REDIS)
                             {
                                 _context.Insert(log);
                             }
                             else
                             {
                                 await HandleLogHelper.HSetAsync(log.F_JobId, log.F_Id, log);
                             }
                             _context.Session.CommitTransaction();
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             LogHelper.WriteWithTime(ex);
         }
     }));
 }