Пример #1
0
        /// <summary>
        /// 发送停止事件的消息。只有状态允许停止的消息才会执行。
        /// </summary>
        /// <param name="eventIDs"></param>
        /// <returns></returns>
        public int SendStopEventMessages(params string[] eventIDs)
        {
            AMSEventCollection events = PrepareCanStopEvents(eventIDs);

            AMSQueueItemCollection messages = new AMSQueueItemCollection();

            events.ForEach(e => messages.Add(e.ToQueueMessage(AMSQueueItemType.StopEvent)));

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                this.ForceStopEvents(events);
                AMSQueueSqlAdapter.Instance.AddMessages(string.Empty, messages.ToArray());

                scope.Complete();
            }

            return(events.Count);
        }
Пример #2
0
        public static void GenerateStopChannelMessages(CancellationToken cancellationToken)
        {
            AMSWorkerSettings settings = AMSWorkerSettings.GetConfig();

            AMSChannelCollection channels =
                AMSChannelSqlAdapter.Instance.LoadNeedStopChannels(settings.Durations.GetDuration("stopChannelLeadTime", TimeSpan.FromHours(1)));

            AMSQueueItemCollection messages = new AMSQueueItemCollection();

            foreach (AMSChannel channel in channels)
            {
                AMSQueueItem message = new AMSQueueItem();

                message.ItemType = AMSQueueItemType.StopChannel;
                message.ResourceID = channel.ID;
                message.ResourceName = channel.Name;

                messages.Add(message);
            }

            GetQueue().AddMessages(string.Empty, messages.ToArray());
        }
Пример #3
0
        public static void GenerateStopChannelMessages(CancellationToken cancellationToken)
        {
            AMSWorkerSettings settings = AMSWorkerSettings.GetConfig();

            AMSChannelCollection channels =
                AMSChannelSqlAdapter.Instance.LoadNeedStopChannels(settings.Durations.GetDuration("stopChannelLeadTime", TimeSpan.FromHours(1)));

            AMSQueueItemCollection messages = new AMSQueueItemCollection();

            foreach (AMSChannel channel in channels)
            {
                AMSQueueItem message = new AMSQueueItem();

                message.ItemType     = AMSQueueItemType.StopChannel;
                message.ResourceID   = channel.ID;
                message.ResourceName = channel.Name;

                messages.Add(message);
            }

            GetQueue().AddMessages(string.Empty, messages.ToArray());
        }
Пример #4
0
        /// <summary>
        /// 停止需要停止的任务
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static void StopEventsInTimeFrame(CancellationToken cancellationToken)
        {
            AMSEventCollection events = AMSEventSqlAdapter.Instance.LoadNeedStopEvents();

            AMSQueueItemCollection messages = new AMSQueueItemCollection();

            foreach (AMSEvent eventData in events)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                if (LockHelper.IsLockAvailable(eventData))
                {
                    messages.Add(eventData.ToQueueMessage(AMSQueueItemType.StopEvent));
                    TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60012, "Add stop new event {0} to queue.", eventData.ID);
                }
            }

            GetQueue().AddMessages(string.Empty, messages.ToArray());
        }
Пример #5
0
        /// <summary>
        /// 检查需要启动的事件
        /// </summary>
        /// <returns></returns>
        public static void StartEventsInTimeFrame(CancellationToken cancellationToken)
        {
            AMSWorkerSettings  settings = AMSWorkerSettings.GetConfig();
            AMSEventCollection events   = AMSEventSqlAdapter.Instance.LoadNeedStartEvents(settings.Durations.GetDuration("createChannelWarmup", TimeSpan.FromMinutes(20)));

            AMSQueueItemCollection messages = new AMSQueueItemCollection();

            foreach (AMSEvent eventData in events)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                if (LockHelper.IsLockAvailable(eventData))
                {
                    messages.Add(eventData.ToQueueMessage(AMSQueueItemType.StartEvent));

                    TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60011, "Add start new event {0} to queue.", eventData.ID);
                }
            }

            GetQueue().AddMessages(string.Empty, messages.ToArray());
        }
Пример #6
0
        public static AMSEventCollection StartAllPrograms()
        {
            AMSEventCollection events = AMSEventSqlAdapter.Instance.Load(builder => builder.AppendItem("State", AMSEventState.Starting.ToString()));

            AMSQueueItemCollection messages = new AMSQueueItemCollection();

            foreach (AMSEvent eventData in events)
            {
                AMSQueueItem message = new AMSQueueItem();

                message.ResourceID = eventData.ID;
                message.ItemType = AMSQueueItemType.StartProgram;

                messages.Add(message);
            }

            IQueue<AMSQueueItem> queue = QueueManager.GetQueue<AMSQueueItem>("amsQueue");

            queue.AddMessages(string.Empty, messages.ToArray());

            return events;
        }
Пример #7
0
        /// <summary>
        /// 停止需要停止的任务
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static void StopEventsInTimeFrame(CancellationToken cancellationToken)
        {
            AMSEventCollection events = AMSEventSqlAdapter.Instance.LoadNeedStopEvents();

            AMSQueueItemCollection messages = new AMSQueueItemCollection();

            foreach (AMSEvent eventData in events)
            {
                if (cancellationToken.IsCancellationRequested)
                    break;

                if (LockHelper.IsLockAvailable(eventData))
                {
                    messages.Add(eventData.ToQueueMessage(AMSQueueItemType.StopEvent));
                    TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60012, "Add stop new event {0} to queue.", eventData.ID);
                }
            }

            GetQueue().AddMessages(string.Empty, messages.ToArray());
        }
Пример #8
0
        /// <summary>
        /// 检查需要启动的事件
        /// </summary>
        /// <returns></returns>
        public static void StartEventsInTimeFrame(CancellationToken cancellationToken)
        {
            AMSWorkerSettings settings = AMSWorkerSettings.GetConfig();
            AMSEventCollection events = AMSEventSqlAdapter.Instance.LoadNeedStartEvents(settings.Durations.GetDuration("createChannelWarmup", TimeSpan.FromMinutes(20)));

            AMSQueueItemCollection messages = new AMSQueueItemCollection();

            foreach (AMSEvent eventData in events)
            {
                if (cancellationToken.IsCancellationRequested)
                    break;

                if (LockHelper.IsLockAvailable(eventData))
                {
                    messages.Add(eventData.ToQueueMessage(AMSQueueItemType.StartEvent));

                    TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60011, "Add start new event {0} to queue.", eventData.ID);
                }
            }

            GetQueue().AddMessages(string.Empty, messages.ToArray());
        }