Exemplo n.º 1
0
        /// <summary>
        /// The set recalculated.
        /// </summary>
        /// <param name="calculateJobInfo">
        /// The job info.
        /// </param>
        private void SetRecalculated(CalculateKeysJobInfo calculateJobInfo)
        {
            var session = ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession();

            if (calculateJobInfo.IsStandard)
            {
                if (CalculateKeysPool.Instance.ExecutingList.All(x => !x.IsStandard) &&
                    CalculateKeysPool.Instance.Queue.All(x => !x.IsStandard))
                {
                    var searchKeyTypes = ObjectFactory.GetInstance <ISearchKeyTypeManager>().GetAll().Where(x => x.Tfoms == null);
                    foreach (var type in searchKeyTypes)
                    {
                        type.Recalculated = true;
                        session.SaveOrUpdate(type);
                    }

                    session.Flush();
                }
            }
            else
            {
                if (CalculateKeysPool.Instance.ExecutingList.All(x => x.SearchKeyType.Id != calculateJobInfo.SearchKeyType.Id) &&
                    CalculateKeysPool.Instance.Queue.All(x => x.SearchKeyType.Id != calculateJobInfo.SearchKeyType.Id))
                {
                    calculateJobInfo.SearchKeyType.Recalculated = true;
                    session.SaveOrUpdate(calculateJobInfo.SearchKeyType);
                    session.Flush();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///   The add jobs for all keys.
        /// </summary>
        public void AddJobsForAllKeys()
        {
            var session    = ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession();
            var keyManager = ObjectFactory.GetInstance <ISearchKeyTypeManager>();

            var count    = session.QueryOver <Statement>().RowCount();
            var countJob = (count / CountInJob) + 1;

            // задачи для стандартных ключей
            if (keyManager.GetBy(x => !x.Recalculated && x.IsActive).Any(x => x.Tfoms == null))
            {
                for (var i = 0; i < countJob; i++)
                {
                    var jobInfo = new CalculateKeysJobInfo
                    {
                        IsStandard = true,
                        From       = (i * CountInJob) + 1,
                        To         = (i + 1) * CountInJob,
                        IsDeleted  = false
                    };

                    Queue.Enqueue(jobInfo);
                }
            }

            // задачи для пользовательских ключей
            var keyTypes = keyManager.GetBy(x => !x.Recalculated && x.IsActive).Where(x => x.Tfoms != null);

            countJob = (count / CountInJob) + 1;
            foreach (var keyType in keyTypes)
            {
                for (var i = 0; i < countJob; i++)
                {
                    var jobInfo = new CalculateKeysJobInfo
                    {
                        IsStandard    = false,
                        From          = (i * CountInJob) + 1,
                        To            = (i + 1) * CountInJob,
                        SearchKeyType = keyType,
                        IsDeleted     = false
                    };

                    Queue.Enqueue(jobInfo);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Добавляет в очередь расчет пользователького ключа
        /// </summary>
        /// <param name="keyType">
        /// The key Type.
        /// </param>
        public void AddJobForUserKey(SearchKeyType keyType)
        {
            // Получаем фабрику
            var schedulerFactory = ObjectFactory.TryGetInstance <ISchedulerFactory>();

            if (schedulerFactory == null)
            {
                return;
            }

            // Получаем шедулер
            var scheduler = schedulerFactory.AllSchedulers.FirstOrDefault();

            if (scheduler == null)
            {
                return;
            }

            // Считаем сколько надо посчитать ключей
            var session  = ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession();
            var count    = session.QueryOver <Statement>().RowCount();
            var countJob = (count / CountInJob) + 1;

            lock (LockObject)
            {
                // Ставим на паузу тригер пересчета ключей
                var key = ObjectFactory.GetInstance <IQuartzInfoProvider>()
                          .GetTriggerKey(JobGroupNames.Service, JobNames.CalculatingKeys);
                if (key != null)
                {
                    scheduler.PauseTrigger(key);
                }

                try
                {
                    // очищаем очередь задач на расчет ключей этого типа
                    var list = instance.Queue.Where(x => x.SearchKeyType.Id != keyType.Id).ToList();
                    instance.Queue.Clear();
                    foreach (var calculateJobInfo in list)
                    {
                        instance.Queue.Enqueue(calculateJobInfo);
                    }

                    // останавливаем все работы, выполняемые для указанного ключа
                    var executingJobs = scheduler.GetCurrentlyExecutingJobs();
                    foreach (var executionContext in
                             executingJobs.Where(
                                 x =>
                                 x.JobDetail.JobDataMap.Contains(
                                     new KeyValuePair <string, object>(
                                         "Имя ключа",
                                         keyType.Code))))
                    {
                        scheduler.Interrupt(executionContext.FireInstanceId);
                    }

                    for (var i = 0; i < countJob; i++)
                    {
                        var jobInfo = new CalculateKeysJobInfo
                        {
                            IsStandard    = false,
                            From          = (i * CountInJob) + 1,
                            To            = (i + 1) * CountInJob,
                            SearchKeyType = keyType,
                            IsDeleted     = false
                        };
                        instance.Queue.Enqueue(jobInfo);
                    }
                }
                finally
                {
                    scheduler.ResumeTrigger(key);
                }
            }
        }