public void ClientSendMessageGetAllDevicesTest() { DatabaseConnection.Initialize(@"SERVER\SQLEXPRESS", "Domotica", "kaku", "kaku"); TcpServerHelperClass.Start(IPAddress.Loopback, 8222); TcpClientHelperClass.Connect(IPAddress.Loopback, 8222); DeviceHelper.InitializeAsClient(Statics.DeviceViewCollection); Statics.DeviceViewCollection = new DeviceViewCollection(); Statics.DeviceViewCollection.GetAll(); DeviceView device = Statics.DeviceViewCollection.GetDevice(Letter.E, 1); TcpMessage message = new TcpMessage("kaku", "kaku"); message.AddTcpAction(TcpMessage.Type.GetAllDevices, null); TcpClientHelperClass.SendMessage(message); }
/// <summary> /// Power device On/Off /// </summary> /// <param name="device"></param> /// <param name="power"></param> /// <param name="logDetails"></param> private static void powerOnOrOff(DeviceView device, Power power, string logDetails) { if (!isInitialized) throw new Exception("DeviceHelper is not initialized!"); LogAction logAction = (power == Power.On ? LogAction.DeviceOn : LogAction.DeviceOff); switch (device.Type) { case BrandType.Radiographically: if (power == Power.On) { if (_isServerContext) RF.PowerDeviceOn(device.Group.ToString(), device.Number); else { TcpMessage message = new TcpMessage("kaku", "kaku"); message.AddTcpAction(TcpMessage.Type.PowerDeviceOn, device); TcpClientHelperClass.SendMessage(message); } } if (power == Power.Off) { if (_isServerContext) RF.PowerDeviceOff(device.Group.ToString(), device.Number); else { TcpMessage message = new TcpMessage("kaku", "kaku"); message.AddTcpAction(TcpMessage.Type.PowerDeviceOff, device); TcpClientHelperClass.SendMessage(message); } } break; case BrandType.X10: if (power == Power.On) { if (_isServerContext) { _cm11.TurnOnDevice(device.Address); //_cm11.BrightenLamp(device.Address, 50); updateDatabase(device, power, logAction, logDetails); if (OnDevicePowerOn != null) OnDevicePowerOn(device); } else { TcpMessage message = new TcpMessage("kaku", "kaku"); message.AddTcpAction(TcpMessage.Type.PowerDeviceOn, device); TcpClientHelperClass.SendMessage(message); } } if (power == Power.Off) { if (_isServerContext) { _cm11.TurnOffDevice(device.Address); //_cm11.BrightenLamp(device.Address, 50); updateDatabase(device, power, logAction, logDetails); if (OnDevicePowerOff != null) OnDevicePowerOff(device); } else { TcpMessage message = new TcpMessage("kaku", "kaku"); message.AddTcpAction(TcpMessage.Type.PowerDeviceOff, device); TcpClientHelperClass.SendMessage(message); } } break; } }