Ejemplo n.º 1
0
        /// <summary>
        /// Request switch.
        /// </summary>
        /// <param name="singleSwitch">Command.</param>
        public void RequestSwitch(FunctionSwitch singleSwitch)
        {
            try
            {
                loggerPool.Log(singleSwitch.ServiceType.ServiceType, new LogContentEntity()
                {
                    Message = singleSwitch.Command.ToString()
                });

                commandInvoker.Invoke <ExecuteResult>(singleSwitch);

                callback.Notify(MessageEntity.NormalInfo(singleSwitch.ServiceType, singleSwitch.Command.ToString()));
            }
            catch (Exception ex)
            {
                var fex = new FaultException(new FaultReason(ex.Message), new FaultCode("002"), "RequestSwitch");

                loggerPool.Log(singleSwitch.ServiceType.ServiceType, new LogContentEntity(fex.Message + fex.StackTrace)
                {
                    Level = "Error"
                });

                throw fex;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Execute the <see cref="ECommand.Pause"/> command.
 /// </summary>
 /// <param name="input">The input parameter.</param>
 /// <param name="output">The execute result.</param>
 protected override void ExecuteCore(FunctionSwitch input, ExecuteResult output)
 {
     if (input.Command == ECommand.Pause)
     {
         Scheduler.PauseTrigger(Scheduler.GetTrigger(input.ServiceType).Key);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Execute the <see cref="ECommand.RunImmediately"/> command.
        /// </summary>
        /// <param name="input">The input parameter.</param>
        /// <param name="output">The execute result.</param>
        protected override void ExecuteCore(FunctionSwitch input, ExecuteResult output)
        {
            if (input.Command == ECommand.RunImmediately)
            {
                if (GetStatus(input.ServiceType) == EServiceStatus.Running)
                {
                    return;
                }

                var serviceTypeKey = input.ServiceType.GetFullString();
                if (RunOnce.Exist(serviceTypeKey))
                {
                    return;
                }

                RunOnce.Add(serviceTypeKey);

                var job = Scheduler.GetJobDetail(input.ServiceType.ToJobKey());
                if (job != null)
                {
                    Scheduler.TriggerJob(job.Key, ConvertToJobDataMap(input.RequestParameterList));
                }

                RunOnce.Remove(serviceTypeKey);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Execute the <see cref="ECommand.Interrupt"/> command.
        /// </summary>
        /// <param name="input">The input parameter.</param>
        /// <param name="output">The execute result.</param>
        protected override void ExecuteCore(FunctionSwitch input, ExecuteResult output)
        {
            if (input.Command == ECommand.Interrupt)
            {
                if (GetStatus(input.ServiceType) != EServiceStatus.Running)
                {
                    return;
                }

                var job = Scheduler.GetCurrentlyExecutingJobs().FirstOrDefault(zw => zw.JobDetail.Key.Equals(input.ServiceType.ToJobKey()));
                if (job == null)
                {
                    return;
                }

                if (Defaults.IsIsolatedJob)
                {
                    var interrupt = job.JobInstance as IsolatedJob;
                    interrupt?.Interrupt();
                }
                else
                {
                    var interrupt = job.JobInstance as IInterruptableJob;
                    interrupt?.Interrupt();
                }
            }
        }
Ejemplo n.º 5
0
        //public static bool OpDeleteBottle(string id, int throwBackType = 0)
        //{
        //    DeleteBottle.Builder builder = DeleteBottle.CreateBuilder();
        //    builder.BottleId = id;
        //    builder.ThrowBackType = throwBackType;
        //    return add(new OpLog(0x20, builder.Build().ToByteArray()));
        //}

        public static bool opFunctionSwitch(FunctionID f, bool enable)
        {
            FunctionSwitch.Builder builder = FunctionSwitch.CreateBuilder();
            builder.FunctionId  = (uint)f;
            builder.SwitchValue = enable ? (uint)1 : (uint)2;
            return(add(new OpLog(0x17, builder.Build().ToByteArray())));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Execute the <see cref="ECommand.GetServiceInfo"/> command.
        /// </summary>
        /// <param name="input">The input parameter.</param>
        /// <param name="output">The execute result.</param>
        protected override void ExecuteCore(FunctionSwitch input, GetServiceInfoOutput output)
        {
            if (input.Command == ECommand.GetServiceInfo)
            {
                var serviceInfo = new ServiceInfo();

                serviceInfo.EServiceStatus = GetStatus(input.ServiceType);
                serviceInfo.Enable         = serviceInfo.EServiceStatus != EServiceStatus.Pause;

                var trigger = Scheduler.GetTrigger(input.ServiceType);
                if (trigger != null)
                {
                    var cronBuilder = trigger as ICronTrigger;
                    serviceInfo.ScheduleInfo = JobCronExpressionConfig.GetCronExpression(trigger);
                    var prev = trigger.GetPreviousFireTimeUtc();
                    if (prev.HasValue)
                    {
                        serviceInfo.PrevFiredTime = prev.Value.LocalDateTime;
                    }

                    var next = trigger.GetNextFireTimeUtc();
                    if (next.HasValue)
                    {
                        serviceInfo.NextFiredTime = next.Value.LocalDateTime;
                    }
                }
                else
                {
                    serviceInfo.ScheduleInfo = string.Empty;
                }

                output.ServiceInfo = serviceInfo;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Execute the <see cref="ECommand.Continue"/> command.
 /// </summary>
 /// <param name="input">The input parameter.</param>
 /// <param name="output">The execute result.</param>
 protected override void ExecuteCore(FunctionSwitch input, ExecuteResult output)
 {
     if (input.Command == ECommand.Continue)
     {
         if (Scheduler != null && Scheduler.IsStarted)
         {
             Scheduler.ResumeTrigger(Scheduler.GetTrigger(input.ServiceType).Key);
         }
     }
 }
Ejemplo n.º 8
0
        protected override void ExecuteCore(FunctionSwitch input, ExecuteResult output)
        {
            if (input.Command == ECommand.Pause)
            {
                var serviceName = input.ServiceType.ServiceType;

                Scheduler.PauseTrigger(serviceName.GetTriggerKey());
                bool yes = Scheduler.IsJobGroupPaused(serviceName + "Trigger");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Execute the invoke.
        /// </summary>
        /// <typeparam name="TOutput">The execute result.</typeparam>
        /// <param name="functionSwitch">The command.</param>
        /// <returns>return the execute result.</returns>
        public TOutput Invoke <TOutput>(FunctionSwitch functionSwitch)
        {
            if (!dict.ContainsKey(functionSwitch.Command))
            {
                var     type     = GetCommandClass(functionSwitch.Command);
                dynamic instance = Activator.CreateInstance(type, new object[] { scheduleProvider.Schedule });
                dict[functionSwitch.Command] = instance;
            }

            dynamic ret = dict[functionSwitch.Command].Execute(functionSwitch);

            return((TOutput)ret);
        }
Ejemplo n.º 10
0
        protected override void ExecuteCore(FunctionSwitch input, ExecuteResult output)
        {
            if (input.Command == ECommand.Interrupt)
            {
                var serviceName = input.ServiceType.ServiceType;

                if (GetStatus(serviceName) != EServiceStatus.Running)
                    return;

                var job = Scheduler.GetCurrentlyExecutingJobs().FirstOrDefault(zw => zw.JobDetail.Key.Name == serviceName);
                if (job == null)
                {
                    return;
                }

                var interrupt = job.JobInstance as IsolatedJob;
                interrupt.Interrupt();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Execute the <see cref="ECommand.ModifySchedule"/> command.
        /// </summary>
        /// <param name="input">The input parameter.</param>
        /// <param name="output">The execute result.</param>
        protected override void ExecuteCore(FunctionSwitch input, ExecuteResult output)
        {
            if (input.Command == ECommand.ModifySchedule)
            {
                var cronExpresion = input.ScheduleFormat;

                var trigger = Scheduler.GetTrigger(input.ServiceType);
                if (trigger != null)
                {
                    var cronBuilder = trigger as ICronTrigger;
                    JobCronExpressionConfig.SetCronExpression(trigger, cronExpresion);
                    cronBuilder.CronExpressionString = cronExpresion;
                    var newTrigger = cronBuilder.GetTriggerBuilder().Build();
                    Scheduler.PauseTrigger(trigger.Key);
                    Scheduler.RescheduleJob(trigger.Key, newTrigger);
                    Scheduler.ResumeTrigger(trigger.Key);
                }
            }
        }
Ejemplo n.º 12
0
        protected override void ExecuteCore(FunctionSwitch input, ExecuteResult output)
        {
            if (input.Command == ECommand.ModifySchedule)
            {
                var serviceName = input.ServiceType.ServiceType;
                var cronExpresion = input.ScheduleFormat;

                var triggerKey = serviceName.GetTriggerKey();
                var triggerName = serviceName + "Trigger";
                var trigger = Scheduler.GetTrigger(triggerKey);
                if (trigger != null)
                {
                    var cronBuilder = trigger as ICronTrigger;
                    JobCronExpressionConfig.SetCronExpression(triggerName, cronExpresion);
                    cronBuilder.CronExpressionString = cronExpresion;
                    var newTrigger = cronBuilder.GetTriggerBuilder().Build();
                    Scheduler.PauseTrigger(triggerKey);
                    Scheduler.RescheduleJob(triggerKey, newTrigger);
                    Scheduler.ResumeTrigger(triggerKey);
                }
            }
        }
Ejemplo n.º 13
0
 public void RequestSwitch(FunctionSwitch singleSwitch)
 {
     ClientConnector.RequestSwitch(singleSwitch);
 }
Ejemplo n.º 14
0
 public void RequestSwitch(FunctionSwitch singleSwitch)
 {
     ClientConnector.RequestSwitch(singleSwitch);
 }