Example #1
0
 public TimerTriggerBinding(ParameterInfo parameter, TimerTriggerAttribute attribute, TimersConfiguration config)
 {
     _attribute       = attribute;
     _parameter       = parameter;
     _config          = config;
     _bindingContract = CreateBindingDataContract();
 }
Example #2
0
        public async Task BindAsync_ReturnsExpectedTriggerData()
        {
            ParameterInfo parameter  = GetType().GetMethod("TestTimerJob").GetParameters()[0];
            MethodInfo    methodInfo = (MethodInfo)parameter.Member;
            string        timerName  = string.Format("{0}.{1}", methodInfo.DeclaringType.FullName, methodInfo.Name);

            Mock <ScheduleMonitor> mockScheduleMonitor = new Mock <ScheduleMonitor>(MockBehavior.Strict);
            ScheduleStatus         status = new ScheduleStatus();

            mockScheduleMonitor.Setup(p => p.GetStatusAsync(timerName)).ReturnsAsync(status);

            TimerTriggerAttribute attribute = parameter.GetCustomAttribute <TimerTriggerAttribute>();
            TimersConfiguration   config    = new TimersConfiguration();

            config.ScheduleMonitor = mockScheduleMonitor.Object;
            TestTraceWriter     trace   = new TestTraceWriter();
            TimerTriggerBinding binding = new TimerTriggerBinding(parameter, attribute, config, trace);

            // when we bind to a non-TimerInfo (e.g. in a Dashboard invocation) a new
            // TimerInfo is created, with the ScheduleStatus populated
            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, trace);
            ValueBindingContext    context         = new ValueBindingContext(functionContext, CancellationToken.None);
            TriggerData            triggerData     = (TriggerData)(await binding.BindAsync("", context));
            TimerInfo timerInfo = (TimerInfo)triggerData.ValueProvider.GetValue();

            Assert.Same(status, timerInfo.ScheduleStatus);

            // when we pass in a TimerInfo that is used
            TimerInfo expected = new TimerInfo(attribute.Schedule, status);

            triggerData = (TriggerData)(await binding.BindAsync(expected, context));
            timerInfo   = (TimerInfo)triggerData.ValueProvider.GetValue();
            Assert.Same(expected, timerInfo);
        }
 public TimerTriggerBinding(ParameterInfo parameter, TimerTriggerAttribute attribute, TimersConfiguration config, TraceWriter trace)
 {
     _attribute = attribute;
     _parameter = parameter;
     _config = config;
     _trace = trace;
     _bindingContract = CreateBindingDataContract();
 }
        /// <summary>
        /// Enables use of the Timer extensions
        /// </summary>
        /// <param name="config">The <see cref="JobHostConfiguration"/> to configure.</param>
        /// <param name="timersConfig">The <see cref="TimersConfiguration"/> to use.</param>
        public static void UseTimers(this JobHostConfiguration config, TimersConfiguration timersConfig)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            config.RegisterExtensionConfigProvider(new TimersExtensionConfig(timersConfig));
        }
 public TimerListener(TimerTriggerAttribute attribute, string timerName, TimersConfiguration config, ITriggeredFunctionExecutor executor, TraceWriter trace)
 {
     _attribute = attribute;
     _timerName = timerName;
     _config = config;
     _executor = executor;
     _trace = trace;
     _cancellationTokenSource = new CancellationTokenSource();
     _schedule = _attribute.Schedule;
     ScheduleMonitor = _attribute.UseMonitor ? _config.ScheduleMonitor : null;
 }
        public TimerTriggerBinding(ParameterInfo parameter, TimerTriggerAttribute attribute, TimersConfiguration config, TraceWriter trace)
        {
            _attribute = attribute;
            _parameter = parameter;
            _config = config;
            _trace = trace;
            _bindingContract = CreateBindingDataContract();

            MethodInfo methodInfo = (MethodInfo)parameter.Member;
            _timerName = string.Format("{0}.{1}", methodInfo.DeclaringType.FullName, methodInfo.Name);
        }
Example #7
0
 public TimerListener(TimerTriggerAttribute attribute, string timerName, TimersConfiguration config, ITriggeredFunctionExecutor executor, TraceWriter trace)
 {
     _attribute = attribute;
     _timerName = timerName;
     _config    = config;
     _executor  = executor;
     _trace     = trace;
     _cancellationTokenSource = new CancellationTokenSource();
     _schedule       = _attribute.Schedule;
     ScheduleMonitor = _attribute.UseMonitor ? _config.ScheduleMonitor : null;
 }
        public TimerTriggerBinding(ParameterInfo parameter, TimerTriggerAttribute attribute, TimersConfiguration config, TraceWriter trace)
        {
            _attribute       = attribute;
            _parameter       = parameter;
            _config          = config;
            _trace           = trace;
            _bindingContract = CreateBindingDataContract();

            MethodInfo methodInfo = (MethodInfo)parameter.Member;

            _timerName = string.Format("{0}.{1}", methodInfo.DeclaringType.FullName, methodInfo.Name);
        }
        private void CreateTestListener(string expression, bool useMonitor = true)
        {
            _attribute            = new TimerTriggerAttribute(expression);
            _attribute.UseMonitor = useMonitor;
            _config = new TimersConfiguration();
            _mockScheduleMonitor    = new Mock <ScheduleMonitor>(MockBehavior.Strict);
            _config.ScheduleMonitor = _mockScheduleMonitor.Object;
            _mockTriggerExecutor    = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            FunctionResult result = new FunctionResult(true);

            _mockTriggerExecutor.Setup(p => p.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>()))
            .Callback <TriggeredFunctionData, CancellationToken>((mockFunctionData, mockToken) =>
            {
                _triggeredFunctionData = mockFunctionData;
            })
            .Returns(Task.FromResult(result));
            _listener = new TimerListener(_attribute, _testTimerName, _config, _mockTriggerExecutor.Object);
        }
Example #10
0
        private void CreateTestListener(string expression, bool useMonitor = true, Action functionAction = null)
        {
            _attribute            = new TimerTriggerAttribute(expression);
            _schedule             = TimerSchedule.Create(_attribute, new TestNameResolver());
            _attribute.UseMonitor = useMonitor;
            _config = new TimersConfiguration();
            _mockScheduleMonitor    = new Mock <ScheduleMonitor>(MockBehavior.Strict);
            _config.ScheduleMonitor = _mockScheduleMonitor.Object;
            _mockTriggerExecutor    = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            FunctionResult result = new FunctionResult(true);

            _mockTriggerExecutor.Setup(p => p.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>()))
            .Callback <TriggeredFunctionData, CancellationToken>((mockFunctionData, mockToken) =>
            {
                _triggeredFunctionData = mockFunctionData;
                functionAction?.Invoke();
            })
            .Returns(Task.FromResult(result));
            JobHostConfiguration hostConfig = new JobHostConfiguration();

            hostConfig.HostId = "testhostid";
            _logger           = new TestLogger(null);
            _listener         = new TimerListener(_attribute, _schedule, _testTimerName, _config, _mockTriggerExecutor.Object, _logger);
        }
Example #11
0
 public TimerTriggerAttributeBindingProvider(TimersConfiguration config, INameResolver nameResolver, TraceWriter trace)
 {
     _config       = config;
     _nameResolver = nameResolver;
     _trace        = trace;
 }
 private void CreateTestListener(string expression, bool useMonitor = true)
 {
     _attribute = new TimerTriggerAttribute(expression);
     _attribute.UseMonitor = useMonitor;
     _config = new TimersConfiguration();
     _mockScheduleMonitor = new Mock<ScheduleMonitor>(MockBehavior.Strict);
     _config.ScheduleMonitor = _mockScheduleMonitor.Object;
     _mockTriggerExecutor = new Mock<ITriggeredFunctionExecutor>(MockBehavior.Strict);
     FunctionResult result = new FunctionResult(true);
     _mockTriggerExecutor.Setup(p => p.TryExecuteAsync(It.IsAny<TriggeredFunctionData>(), It.IsAny<CancellationToken>()))
         .Callback<TriggeredFunctionData, CancellationToken>((mockFunctionData, mockToken) =>
         {
             _triggeredFunctionData = mockFunctionData;
         })
         .Returns(Task.FromResult(result));
     _listener = new TimerListener(_attribute, _testTimerName, _config, _mockTriggerExecutor.Object, new TestTraceWriter());
 }
Example #13
0
 public Packet_04(TimersConfiguration timersConfiguration)
 {
     Command  = 4;
     b        = Utils.Create <body>(timersConfiguration);
     BodySize = getSize(b);
 }
 public TimersExtensionConfig(TimersConfiguration config)
 {
     _config = config;
 }
Example #15
0
 public TimerTriggerAttributeBindingProvider(TimersConfiguration config, INameResolver nameResolver, ILogger logger)
 {
     _config       = config;
     _nameResolver = nameResolver;
     _logger       = logger;
 }
 public TimerTriggerAttributeBindingProvider(TimersConfiguration config, TraceWriter trace)
 {
     _config = config;
     _trace  = trace;
 }
Example #17
0
 public TimerTriggerAttributeBindingProvider(TimersConfiguration config)
 {
     _config = config;
 }
Example #18
0
        private void buttonConfig_Click(object sender, RibbonControlEventArgs e)
        {
            TimersConfiguration timersConfig = new TimersConfiguration();

            Range range = Activesheet.Range["T6:U17"];


            try
            {
                int rowStart = range.Row;
                int colStart = range.Column;
                for (int rowIndex = 0; rowIndex < 12; rowIndex++)
                {
                    Range valueRange = Activesheet.Cells[rowStart + rowIndex, colStart];
                    int   value      = (int)valueRange.Value;

                    Range  keyRange = Activesheet.Cells[rowStart + rowIndex, colStart + 1];
                    String key      = keyRange.Value.ToString();

                    switch (key)
                    {
                    case "AZQ9":
                        timersConfig.periodCarrier = value;
                        break;

                    case "AZQ8":
                        timersConfig.periodGap = value;
                        break;

                    case "AZQ22":
                        timersConfig.onGap = value;
                        break;

                    case "AZQ23":
                        timersConfig.offGap = value;
                        break;

                    case "AZQ13":
                        timersConfig.periodBunch = value;
                        break;

                    case "AZQ16":
                        timersConfig.dutyBunch = value;
                        break;

                    case "AZQ27":
                        timersConfig.startGap = value;
                        break;

                    case "AZQ28":
                        timersConfig.stopGap = value;
                        break;

                    case "AZQ35":
                        timersConfig.startHigh = value;
                        break;

                    case "AZQ36":
                        timersConfig.stopHigh = value;
                        break;

                    case "AZQ43":
                        timersConfig.startLow = value;
                        break;

                    case "AZQ44":
                        timersConfig.stopLow = value;
                        break;
                    }
                }
                client.setTimersConfiguration(timersConfig);
            }
            catch (Exception ex)
            {
                showMessage(ex.ToString());
            }
        }
 public TimerTriggerAttributeBindingProvider(TimersConfiguration config, TraceWriter trace)
 {
     _config = config;
     _trace = trace;
 }