/// <summary> /// Gets a device. /// </summary> /// <param name="deviceId">The device identifier.</param> /// <returns> /// The device. /// </returns> public Device GetDevice(int deviceId) { IntPtr nameIntPtr = NativeWrapper.tdGetName(deviceId); string name = Marshal.PtrToStringAnsi(nameIntPtr); NativeWrapper.tdReleaseString(nameIntPtr); DeviceMethods allMethods = GetAllMethods(); DeviceMethods supportedMethods = (DeviceMethods)NativeWrapper.tdMethods(deviceId, (int)allMethods); if (name == NOT_EXISTING_DEVICE_NAME && supportedMethods == 0) { return(null); } IntPtr modelIntPtr = NativeWrapper.tdGetModel(deviceId); string model = Marshal.PtrToStringAnsi(modelIntPtr); NativeWrapper.tdReleaseString(modelIntPtr); IntPtr protocolIntPtr = NativeWrapper.tdGetProtocol(deviceId); string protocol = Marshal.PtrToStringAnsi(protocolIntPtr); NativeWrapper.tdReleaseString(protocolIntPtr); return(new Device { ID = deviceId, Name = name, Model = model, Protocol = protocol, SupportedMethods = supportedMethods }); }
public void CreateSymbolicLinkToFile() { using (var cleaner = new TestFileCleaner()) { string filePath = cleaner.CreateTestFile("CreateSymbolicLinkToFile"); string symbolicLink = cleaner.GetTestPath(); Action action = () => FileMethods.CreateSymbolicLink(symbolicLink, filePath); if (CanCreateSymbolicLinks()) { action(); var attributes = FileMethods.GetFileAttributes(symbolicLink); attributes.Should().HaveFlag(FileAttributes.ReparsePoint); using (var handle = FileMethods.CreateFile(symbolicLink, CreationDisposition.OpenExisting, DesiredAccess.ReadExtendedAttributes, ShareModes.All, fileFlags: FileFlags.OpenReparsePoint)) { handle.IsInvalid.Should().BeFalse(); var(printName, substituteName, tag) = DeviceMethods.GetReparsePointNames(handle); tag.Should().Be(ReparseTag.SymbolicLink); printName.Should().Be(filePath); substituteName.Should().Be(@"\??\" + filePath); } } else { // Can't create links unless you have admin rights SE_CREATE_SYMBOLIC_LINK_NAME SeCreateSymbolicLinkPrivilege action.ShouldThrow <System.IO.IOException>().And.HResult.Should().Be((int)ErrorMacros.HRESULT_FROM_WIN32(WindowsError.ERROR_PRIVILEGE_NOT_HELD)); } } }
public void QueryStableGuid() { // Need to open the handle with no rights (desiredAccess: 0) to avoid needing to run as admin using (var handle = FileMethods.CreateFile(@"\\.\C:", CreationDisposition.OpenExisting, desiredAccess: 0)) { DeviceMethods.QueryStableGuid(handle).Should().NotBe(Guid.Empty); } }
public void QueryDeviceName() { // Need to open the handle with no rights (desiredAccess: 0) to avoid needing to run as admin using (var handle = FileMethods.CreateFile(@"\\.\C:", CreationDisposition.OpenExisting, desiredAccess: 0)) { DeviceMethods.QueryDeviceName(handle).Should().StartWith(@"\Device\HarddiskVolume"); } }
public async Task <ActionResult <ResultCode> > GetLastCommand(int id) { return(await Task.Factory.StartNew(() => { DeviceMethods lastCommand = telldusCoreService.GetLastCommand(id); return Ok(lastCommand); })); }
public void QueryInterfaceName() { // TODO: Need to conditionalize this on RS1 // Need to open the handle with no rights (desiredAccess: 0) to avoid needing to run as admin using (var handle = FileMethods.CreateFile(@"\\.\C:", CreationDisposition.OpenExisting, desiredAccess: 0)) { DeviceMethods.QueryInterfacename(handle).Should().StartWith(@"\\?\STORAGE#Volume#{"); } }
public void QuerySuggestedLinkName() { // Need to open the handle with no rights (desiredAccess: 0) to avoid needing to run as admin using (var handle = FileMethods.CreateFile(@"\\.\C:", CreationDisposition.OpenExisting, desiredAccess: 0)) { Action action = () => DeviceMethods.QuerySuggestedLinkName(handle); action.ShouldThrow <WInteropIOException>("this is an optional query, not aware of which drivers support this"). And.HResult.Should().Be((int)ErrorMacros.HRESULT_FROM_WIN32(WindowsError.ERROR_NOT_FOUND)); } }
public void SendCommand(int deviceId, DeviceMethods command) { using (ITelldusCoreService service = new TelldusCoreService()) { service.Initialize(); ResultCode result = service.SendCommand(deviceId, command); Assert.Equal(ResultCode.Success, result); } }
/// <summary> /// Sends the command to the specified device, with a parameter. /// </summary> /// <param name="deviceId">The device identifier.</param> /// <param name="command">The command.</param> /// <param name="parameter">The parameter.</param> /// <returns> /// Result of the command. /// </returns> public ResultCode SendCommand(int deviceId, DeviceMethods command, string parameter) { switch (command) { case DeviceMethods.TurnOff: return(TurnOff(deviceId)); case DeviceMethods.TurnOn: return(TurnOn(deviceId)); case DeviceMethods.Bell: return(Bell(deviceId)); case DeviceMethods.Dim: return(Dim(deviceId, Convert.ToInt32(parameter))); case DeviceMethods.Learn: return(Learn(deviceId)); default: return(ResultCode.MethodNotSupported); } }
public void QueryDosVolumePathBasic() { string tempPath = FileMethods.GetTempPath(); using (var directory = DirectoryMethods.CreateDirectoryHandle(tempPath)) { // This will give back the NT path (\Device\HarddiskVolumen...) string fullName = HandleMethods.GetObjectName(directory); string fileName = FileMethods.GetFileName(directory); string deviceName = fullName.Substring(0, fullName.Length - fileName.Length); string dosVolumePath = DeviceMethods.QueryDosVolumePath(deviceName); tempPath.Should().StartWith(dosVolumePath); tempPath.Should().Be(dosVolumePath + fileName + @"\"); } }
public async Task SendDeviceEventWebHook(int deviceId, DeviceMethods command, string parameter) { string jsonData = JsonConvert.SerializeObject(new { deviceId, command, parameter }); foreach (string url in configuration.GetSection("Webhooks:DeviceEvents").Get <string[]>()) { try { bool result = await SendData(url, jsonData); if (!result) { throw new Exception("Invalid response from url"); } } catch (Exception ex) { logger.LogError(ex, $"Failed to send device event to webhook: {url}"); } } }
public async Task <ActionResult <ResultCode> > SendCommand(int id, DeviceMethods command, string parameter = null) { ResultCode result = await Task.Factory.StartNew(() => telldusCoreService.SendCommand(id, command, parameter)); return(Ok(result)); }
/// <summary> /// Gets the last command sent to the specified device. /// This method can be used to check if a device is turned on or off. /// </summary> /// <param name="deviceId">The device identifier.</param> /// <returns> /// The last command sent. /// </returns> public DeviceMethods GetLastCommand(int deviceId) { DeviceMethods deviceMethods = GetAllMethods(); return((DeviceMethods)NativeWrapper.tdLastSentCommand(deviceId, (int)deviceMethods)); }
/// <summary> /// Sends the command to the specified device. /// </summary> /// <param name="deviceId">The device identifier.</param> /// <param name="command">The command.</param> /// <returns> /// Result of the command. /// </returns> public ResultCode SendCommand(int deviceId, DeviceMethods command) { return(SendCommand(deviceId, command, null)); }
internal CommandReceivedEventArgs(Device device, DeviceMethods command, string parameter) { this.Device = device; this.Command = command; this.Parameter = parameter; }
static void Main(string[] args) { //otvori servis ServiceHost svc = new ServiceHost(typeof(DeviceMethods)); svc.AddServiceEndpoint(typeof(IDevice), new NetTcpBinding(), new Uri("net.tcp://localhost:4000/DeviceMethods")); ServiceHost svc2 = new ServiceHost(typeof(AgregatorMethods)); svc2.AddServiceEndpoint(typeof(IAgregator), new NetTcpBinding(), new Uri("net.tcp://localhost:5000/AgregatorMethods")); //otvori client //ChannelFactory<IAgregator> factory = new ChannelFactory<IAgregator>( // new NetTcpBinding(), // new EndpointAddress("net.tcp://localhost:5000/AgregatorMethods")); //IAgregator kanal = factory.CreateChannel(); //otvori server svc.Open(); svc2.Open(); AgregatorMethods agm = new AgregatorMethods(); int a = agm.formirajKljuc(); List <DevClass> ldc = new List <DevClass>(); foreach (var v in Baza.devices.Values) { ldc.Add(v); } Agregator ag = new Agregator(a, ldc); agm.dodajAgregator(a, ag); //dodaje u baza klasu DeviceMethods dvcm = new DeviceMethods(); dvcm.deleteXML(); int i = 1; int j = 1; while (true) { Thread.Sleep(2000); /*if (Baza.devices.ContainsKey(1)) * { * Console.WriteLine("dev " + Baza.devices[1].AMIDevCode + " time " + Baza.devices[1].TimeStamp + " p " + Baza.devices[1].Power.ToString()); * Console.WriteLine("tip "+ Baza.devices[1].ListMerenje[1].Tip + " Vrednost "+ Baza.devices[1].ListMerenje[1].Vrednost); * } * else { * break; * }*/ bool chk = Baza.devices.Any(); if (chk) { foreach (KeyValuePair <int, DevClass> kvp in Baza.devices) { i = kvp.Key; break; } } foreach (KeyValuePair <int, DevClass> dc in Baza.devices) { if (!ag.devs.Contains(dc.Value)) { ag.devs.Add(dc.Value); } i = dc.Key; Console.WriteLine("-------------------------------------------------"); Console.WriteLine("dev " + Baza.devices[i].AMIDevCode + " time " + Baza.devices[i].TimeStamp + " p " + Baza.devices[i].Power.ToString()); foreach (var item in Baza.devices[i].ListMerenje) { j = item.Key; Console.WriteLine("Tip: " + Baza.devices[i].ListMerenje[j].Tip + " Vrednost: " + Baza.devices[i].ListMerenje[j].Vrednost); } Console.WriteLine("-------------------------------------------------"); } dvcm.deleteXML(); foreach (DevClass dc in Baza.devices.Values) { dvcm.XMLWrite(dc); } } }