/// <summary> /// Creates the pin device and start listening. This is useful when the device also manages pins /// </summary> /// <returns>The pin device and start listening.</returns> /// <param name="pinDevice">Pin device.</param> /// <param name="channel">Channel.</param> public MTuple <PinDevice, IMatchMonitor> CreatePinDeviceAndStartListening(PinDevice pinDevice, MatchChannel channel) { var createdDevice = CreatePinDevice(pinDevice); var monitor = SubscribeMatches(channel, createdDevice); return(MTuple.New(createdDevice, monitor)); }
/// <summary> /// Creates the pin device. /// </summary> /// <returns>The pin device.</returns> /// <param name="pinDevice">Pin device.</param> public PinDevice CreatePinDevice(PinDevice pinDevice, bool ignorePersistence = false) { pinDevice.DeviceType = Alps.Model.DeviceType.Pin; if (pinDevice.Location == null) { throw new ArgumentException("Location required for Pin Device"); } var createdDevice = _deviceApi.CreateDevice(pinDevice); //The generated swagger api returns a generic device partially losing the information about the pin. //We rewrite the data to fit the pin device contract. var createdPin = new PinDevice { Id = createdDevice.Id, CreatedAt = createdDevice.CreatedAt, DeviceType = createdDevice.DeviceType, Location = pinDevice.Location, Group = createdDevice.Group, Name = createdDevice.Name, UpdatedAt = createdDevice.UpdatedAt }; if (!ignorePersistence) { _state.AddPinDevice(createdPin); } return(createdPin); }
public void Persists_pins() { var pin = new PinDevice { Id = "nonsense_id", Name = "example pin", Location = new Location { Latitude = 10, Longitude = 13 } }; state.AddPinDevice(pin); state = null; var newState = new StateManager(localhost, stateManagerFile); var persistedPin = newState.Pins.Find(p => p.Id == "nonsense_id"); Assert.AreEqual(pin.Id, persistedPin.Id); Assert.AreEqual(pin.Name, persistedPin.Name); Assert.AreEqual(pin.Location.Latitude, persistedPin.Location.Latitude); Assert.AreEqual(pin.Location.Longitude, persistedPin.Location.Longitude); Assert.AreEqual(pin.Location.Altitude, persistedPin.Location.Altitude); }
public void AddPinDevice(PinDevice pinDevice) { _state.Pins.Add(pinDevice); Save(); }