예제 #1
0
        public static void DeleteProgram(AMSQueueItem message, CancellationToken cancellationToken)
        {
            TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60015, "Delete expired programs");

            int count = LiveChannelManager.DeleteAllExpiredPrograms(AMSWorkerSettings.GetConfig().Durations.GetDuration("programExpireTime", TimeSpan.FromDays(1)));

            TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60015, "{0} programs deleted", count);
        }
예제 #2
0
        public static void StartAllTasks(CancellationToken cancellationToken)
        {
            AMSWorkerSettings settings = AMSWorkerSettings.GetConfig();

            DoLoopTask(StartEventsInTimeFrame, DefaultDelayTime, cancellationToken);
            DoLoopTask(StopEventsInTimeFrame, DefaultDelayTime, cancellationToken);
            DoLoopTask(ReadQueue, DefaultDelayTime, cancellationToken);

            DoLoopTask(GenerateSyncChannelInfoMessages, settings.Durations.GetDuration("syncChannelInfoInterval", DefaultDelayTime), cancellationToken);
            DoLoopTask(GenerateStopChannelMessages, settings.Durations.GetDuration("stopChannelInterval", DefaultDelayTime), cancellationToken);
            DoLoopTask(GenerateDeleteProgramMessages, settings.Durations.GetDuration("deleteProgamInterval", DefaultDelayTime), cancellationToken);
        }
예제 #3
0
        private static void SimulateOrExecuteAction(Action action, TimeSpan delay, Action afterDelayAction = null)
        {
            if (AMSWorkerSettings.GetConfig().EnableSimulation == false)
            {
                action();
            }
            else
            {
                Task.Delay(delay).Wait();

                if (afterDelayAction != null)
                {
                    afterDelayAction();
                }
            }
        }
예제 #4
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());
        }
예제 #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 void ReadQueue(CancellationToken cancellationToken)
        {
            AMSQueueItem message = GetQueue().GetMessages(string.Empty).SingleOrDefault();

            if (message != null)
            {
                //Trace.TraceInformation("Message: ID={0}, ResourceID={1}, Name={2}, ItemType={3}",
                //    message.ID, message.ResourceID, message.ResourceID, message.ItemType);

                if (AMSWorkerSettings.GetConfig().ItemTypes.IsEnabled(message.ItemType))
                {
                    switch (message.ItemType)
                    {
                    case AMSQueueItemType.StartEvent:
                        RunQueueTask(message, cancellationToken, AMSOperations.StartEvent);
                        break;

                    case AMSQueueItemType.StopEvent:
                        RunQueueTask(message, cancellationToken, AMSOperations.StopEvent);
                        break;

                    case AMSQueueItemType.SyncChannelInfo:
                        RunQueueTask(message, cancellationToken, AMSOperations.SyncChannelInfo);
                        break;

                    case AMSQueueItemType.StopChannel:
                        RunQueueTask(message, cancellationToken, AMSOperations.StopChannel);
                        break;

                    case AMSQueueItemType.DeleteProgram:
                        RunQueueTask(message, cancellationToken, AMSOperations.DeleteProgram);
                        break;
                    }
                }
            }
        }