Пример #1
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (optionsBuilder == null)
            {
                throw new ArgumentNullException(nameof(optionsBuilder));
            }

            optionsBuilder.EnableSensitiveDataLogging(false);
            optionsBuilder.EnableDetailedErrors();

            if (loggerFactory != null)
            {
                optionsBuilder.UseLoggerFactory(loggerFactory);
            }

            if (dataSource != null)
            {
                var connectionString = dataSource.GetConnectionString();

                if (connectionString.IsNullOrEmpty())
                {
                    throw new ConnectionStringException(
                              $"Connection string for datasource {dataSource.Name} is empty.");
                }

                switch (dataSource.Provider)
                {
                case Provider.PostgreSqL:
                    optionsBuilder.UseNpgsql(connectionString, postOptions =>
                    {
                        if (MaxRetryCount != null && MaxRetryDelay != null)
                        {
                            postOptions.EnableRetryOnFailure(MaxRetryCount.GetValueOrDefault(),
                                                             MaxRetryDelay.GetValueOrDefault(), null);
                        }
                    });
                    break;

                case Provider.Oracle:
                    optionsBuilder.UseOracle(connectionString);
                    break;

                default:
                    optionsBuilder.UseSqlServer(connectionString, sqlOptions =>
                    {
                        if (MaxRetryCount != null && MaxRetryDelay != null)
                        {
                            sqlOptions.EnableRetryOnFailure(MaxRetryCount.GetValueOrDefault(),
                                                            MaxRetryDelay.GetValueOrDefault(), null
                                                            );
                        }
                    });
                    break;
                }
            }

            base.OnConfiguring(optionsBuilder);
        }
Пример #2
0
        public XmlNode GenerateXML()
        {
            // Create XML Node and Attributes
            XmlDocument  d             = new XmlDocument();
            XmlNode      output        = d.CreateNode("element", "Action", null);
            XmlAttribute type          = d.CreateAttribute("Type");
            XmlAttribute showBack      = d.CreateAttribute("ShowBack");
            XmlAttribute disableCancel = d.CreateAttribute("DisableCancel");
            XmlAttribute attributes    = d.CreateAttribute("Attributes");
            XmlAttribute domain        = d.CreateAttribute("Domain");
            XmlAttribute group         = d.CreateAttribute("Group");
            XmlAttribute title         = d.CreateAttribute("Title");
            XmlAttribute maxRetryCount = d.CreateAttribute("MaxRetryCount");
            XmlAttribute condition     = d.CreateAttribute("Condition");

            // Assign attribute values
            type.Value          = "UserAuth";
            showBack.Value      = ShowBack.ToString();
            disableCancel.Value = DisableCancel.ToString();
            attributes.Value    = Attributes;
            domain.Value        = Domain;
            group.Value         = Group;
            title.Value         = Title;
            maxRetryCount.Value = MaxRetryCount.ToString();
            condition.Value     = Condition;

            // Append Attributes
            output.Attributes.Append(type);
            output.Attributes.Append(showBack);
            output.Attributes.Append(disableCancel);
            if (null != MaxRetryCount)
            {
                output.Attributes.Append(maxRetryCount);
            }
            if (!string.IsNullOrEmpty(Attributes))
            {
                output.Attributes.Append(attributes);
            }
            if (!string.IsNullOrEmpty(Domain))
            {
                output.Attributes.Append(domain);
            }
            if (!string.IsNullOrEmpty(Group))
            {
                output.Attributes.Append(group);
            }
            if (!string.IsNullOrEmpty(Title))
            {
                output.Attributes.Append(title);
            }
            if (!string.IsNullOrEmpty(Condition))
            {
                output.Attributes.Append(condition);
            }

            return(output);
        }
Пример #3
0
        /// <summary>
        /// 스케쥴러에 의해 주기적으로 호출되는 작업의 본체
        /// </summary>
        /// <param name="context"></param>
        public virtual void Execute(JobExecutionContext context)
        {
            var jobName = context.JobDetail.FullName;

            if (IsDebugEnabled)
            {
                log.Debug(@"Job[{0}]을 실행합니다...", jobName);
            }

            if (Enabled == false)
            {
                if (IsDebugEnabled)
                {
                    log.Debug(@"작업[{0}]이 사용가능 상태가 아니기 때문에, 작업을 수행하지 않습니다. Enabled=[{1}]", jobName, Enabled);
                }
                return;
            }

            var dataMap    = context.JobDetail.JobDataMap;
            var retryCount = dataMap.GetJobData(JobTool.RetryCountKey).AsInt(0);

            try {
                DoExecute(context, CancellationTokenSource.Token);

                // 작업이 성공했으면, 재실행횟수를 0으로 리셋합니다.
                dataMap.SetJobData(JobTool.RetryCountKey, 0);

                if (IsDebugEnabled)
                {
                    log.Debug(@"Job [{0}]을 완료했습니다!!!", jobName);
                }
            }
            catch (Exception ex) {
                retryCount++;

                if (log.IsWarnEnabled)
                {
                    log.Warn(@"작업[{0}] 실행 중 예외가 발생했습니다. 재실행 횟수=[{1}]", jobName, retryCount);
                    log.Warn(ex);
                }

                if (CancellationTokenSource.Token.IsCancellationRequested)
                {
                    return;
                }

                //! 최대 재실행 횟수가 존재한다면, 재실행을 즉시 실행하도록 하고, JobExecutionException을 발생시키면, Quartz가 Job을 즉시 재실행시킵니다.
                //
                var maxRetryCount = Math.Max(0, MaxRetryCount.AsInt(0));
                var canRetry      = (maxRetryCount > 0 && retryCount < maxRetryCount);

                if (canRetry)
                {
                    Thread.Sleep(Math.Max(10, RetryInterval.AsInt(10)));
                    dataMap.SetJobData(JobTool.RetryCountKey, retryCount);
                    throw new JobExecutionException(ex)
                          {
                              RefireImmediately = true
                          };
                }
            }
        }