public new Task InitializeAsync()
        {
            base.InitializeAsync().Wait(); // call base method initialization

            // set initial direction
            string initialDirection = deviceConfig.initialDirection;                     // use configuration value as default
            var    myTwin           = _DeviceClient.GetDynamicDigitalTwinAsync().Result; // get twin

            if (myTwin.Properties.Reported.Contains("GateDirection"))
            {         // if there is a diretion property
                // set the value direction, don't use the Set method so we don't trigger a device twin property udpate
                CurrentDirection = (GateDirection)Enum.Parse(typeof(GateDirection), initialDirection = myTwin.Properties.Reported["GateDirection"]);
            }
            else // direction wasn't already set
            {
                // set direction of device via the setter so we update the device twin
                this.SetDirectionAsync((GateDirection)Enum.Parse(typeof(GateDirection), initialDirection)).Wait();
            }

            TimedSimulatedEvent simulatedEvent = new TimedSimulatedEvent(2500, 1000, this.SimulatedTicketSwipeOccured);

            // set up any simulated events for this device
            this._EventScheduler.Add(simulatedEvent);

            // register any direct methods we're to recieve
            // receive ticket validation results
            this._DeviceClient.RegisterDirectMethodAsync(ReceiveTicketValidationResponse).Wait();
            // receive gate direction change commands
            this._DeviceClient.RegisterDirectMethodAsync(ReceiveCommandGateChange).Wait();

            _DeviceClient.RegisterDesiredPropertyUpdateCallbackAsync(OnGateDeviceDesiredPropertyChanged);

            return(Task.CompletedTask);
        }
예제 #2
0
        public void TestCreateBaseDevice()
        {
            FakeDeviceClient myClient = new FakeDeviceClient();

            TimedSimulatedEvent simulatedEvent1 = new TimedSimulatedEvent(2000, 1000, this.EmptyTimeEvent);
            TimedSimulatedEvent simulatedEvent2 = new TimedSimulatedEvent(2000, 1000, this.EmptyTimeEvent);

            EventScheduler myScheduler = new EventScheduler();

            myScheduler.Add(simulatedEvent1);
            myScheduler.Add(simulatedEvent2);

            BaseDevice device = new BaseDevice(deviceconfig, myClient, myScheduler);

            device.InitializeAsync().Wait(); // initialize the device
            device.StartAllEvents();
            // make sure the events have started
            Assert.IsTrue(simulatedEvent1.IsRunning);
            Assert.IsTrue(simulatedEvent2.IsRunning);
            // Testing that StopAllEvents actually stops the simulated events.
            device.StopAllEvents();
            Assert.IsFalse(simulatedEvent1.IsRunning);
            Assert.IsFalse(simulatedEvent2.IsRunning);
        }