Пример #1
0
        public IActionResult GetSensors()
        {
            var request   = new GetSensorsProcessorRequestVersionOne();
            var processor = _processorFactory.Create(request);

            var result = processor.Execute();

            return(result);
        }
Пример #2
0
        public IActionResult GetRelayState([FromQuery] GetRelayStateRequest request)
        {
            var processorRequest = new GetRelayStateProcessorRequestVersionOne()
            {
                GpioPin = request.GpioPin
            };
            var processor = _processorFactory.Create(processorRequest);

            var result = processor.Execute();

            return(result);
        }
Пример #3
0
        private static void TestGreaterThan(IProcessorFactory factory, object superImportantReference)
        {
            const int FILTER_VALUE = 10;
            var processor = factory.Create(
                ProcessorType.GreaterThan, 
                superImportantReference, 
                FILTER_VALUE);

            if (processor.TryProcess(FILTER_VALUE - 5))
            {
                throw new InvalidOperationException("This should not have been greater than.");
            }

            if (!processor.TryProcess(FILTER_VALUE + 5))
            {
                throw new InvalidOperationException("This should have been greater than.");
            }

            if (processor.TryProcess("This isn't a number."))
            {
                throw new InvalidOperationException("This should have failed because the input is invalid.");
            }

            if (processor.TryProcess(new object()))
            {
                throw new InvalidOperationException("This should have failed because the input is invalid.");
            }
        }
Пример #4
0
        public IActionResult UpdateHumidifierTask(UpdateHumidifierTaskRequest request)
        {
            var processorRequest = new UpdateHumidifierTaskProcessorRequestVersionOne
            {
                CheckInterval      = request?.CheckInterval,
                HumiditySensorGpio = request?.HumiditySensorGpio,
                TargetHumidity     = request?.TargetHumidity,
                RelayGpio          = request?.RelayGpio,
                JobName            = request.JobName
            };

            var processor = _processorFactory.Create(processorRequest);
            var result    = processor.Execute();

            return(result);
        }
Пример #5
0
        private static void TestLessThan(IProcessorFactory factory, object superImportantReference)
        {
            const int FILTER_VALUE = 10;
            var       processor    = factory.Create(
                ProcessorType.LessThan,
                superImportantReference,
                FILTER_VALUE);

            if (!processor.TryProcess(FILTER_VALUE - 5))
            {
                throw new InvalidOperationException("This should have been less than.");
            }

            if (processor.TryProcess(FILTER_VALUE + 5))
            {
                throw new InvalidOperationException("This should not have been less than.");
            }

            if (processor.TryProcess("This isn't a number."))
            {
                throw new InvalidOperationException("This should have failed because the input is invalid.");
            }

            if (processor.TryProcess(new object()))
            {
                throw new InvalidOperationException("This should have failed because the input is invalid.");
            }
        }
Пример #6
0
        private static void TestStringEqual(IProcessorFactory factory, object superImportantReference)
        {
            const string FILTER_VALUE = "Hello, World!";
            var          processor    = factory.Create(
                ProcessorType.StringEqual,
                superImportantReference,
                FILTER_VALUE);

            if (!processor.TryProcess(FILTER_VALUE))
            {
                throw new InvalidOperationException("This should have matched.");
            }

            if (processor.TryProcess("Goodbye, Cruel World!"))
            {
                throw new InvalidOperationException("This should not have matched.");
            }

            if (processor.TryProcess(10))
            {
                throw new InvalidOperationException("This should not have matched.");
            }

            if (processor.TryProcess(new object()))
            {
                throw new InvalidOperationException("This should not have matched.");
            }
        }
Пример #7
0
        public MessageDispatcher(int numberOfProcessors, IProcessorFactory processorFactory)
        {
            _processors = Enumerable
                          .Range(0, numberOfProcessors)
                          .Select(i => processorFactory.Create(i.ToString(), this))
                          .ToList();

            foreach (var processor in _processors)
            {
                processor.OnDone += Done;
            }
        }
Пример #8
0
        private void StartThreads()
        {
            var i = 0;

            while (i++ < _threadCount)
            {
                var thread = new ProcessorThread($"{_name} / {i}", _processorFactory.Create());

                _threads.Add(thread);

                thread.Start();
            }
        }
        private void StartThreads()
        {
            var i = 0;

            while (i++ < threadCount)
            {
                var thread = new ProcessorThread(processorFactory.Create());

                threads.Add(thread);

                thread.Start();
            }
        }
Пример #10
0
        private static void RunRequest(RequestType requestType)
        {
            IProcessor internalProcessor = _processorFactory.Create(requestType);

            Console.WriteLine(internalProcessor.GetResponse());
        }
Пример #11
0
        private void StartThreads()
        {
            var i = 0;

            while (i++ < _threadCount)
            {
                var thread = new ProcessorThread(string.Format("{0} / {1}", _name, i), _processorFactory.Create());

                _threads.Add(thread);

                thread.Start();
            }
        }
Пример #12
0
        private static void TestStringEqual(IProcessorFactory factory, object superImportantReference)
        {
            const string FILTER_VALUE = "Hello, World!";
            var processor = factory.Create(
                ProcessorType.StringEqual,
                superImportantReference,
                FILTER_VALUE);

            if (!processor.TryProcess(FILTER_VALUE))
            {
                throw new InvalidOperationException("This should have matched.");
            }

            if (processor.TryProcess("Goodbye, Cruel World!"))
            {
                throw new InvalidOperationException("This should not have matched.");
            }

            if (processor.TryProcess(10))
            {
                throw new InvalidOperationException("This should not have matched.");
            }

            if (processor.TryProcess(new object()))
            {
                throw new InvalidOperationException("This should not have matched.");
            }
        }