private HostMessage SendMessage(Process p, HostCommunication comm, HostCommand cmd, string msg) { try { if (!p.HasExited) { HostMessage mess = new HostMessage(); mess.Command = cmd; if (msg != null) { mess.Message = msg; } return(comm.SendReceive(mess)); } } catch { } return(new HostMessage()); }
/// <summary> /// Discover host and console commands. /// </summary> public static void Discover() { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var asm in assemblies) { foreach (var t in asm.GetTypes()) { foreach (var attr in t.GetCustomAttributes(false)) { if (attr.GetType() == typeof(ThalesConsoleCommandAttribute)) { var consoleAttr = (ThalesConsoleCommandAttribute)attr; var consoleCommand = new Command { Code = consoleAttr.CommandCode, DeclaringType = t, Assembly = asm, Description = consoleAttr.Description, Type = CommandType.Console }; var needsAuth = t.GetCustomAttributes(typeof(AuthorizedStateAttribute), false); consoleCommand.RequiresAuthorizedState = (needsAuth.Length != 0); if (!Commands.ContainsKey(CommandType.Console)) { Commands.Add(CommandType.Console, new SortedList <string, Command>()); } try { Commands[CommandType.Console].Add(consoleCommand.Code, consoleCommand); } catch (ArgumentException) { // Nothing, unit tests. } } if (attr.GetType() == typeof(ThalesHostCommandAttribute)) { var hostAttr = (ThalesHostCommandAttribute)attr; var hostCommand = new HostCommand { Assembly = asm, Code = hostAttr.CommandCode, DeclaringType = t, Description = hostAttr.Description, ResponseCode = hostAttr.ResponseCode, ResponseCodeAfterIo = hostAttr.ResponseCodeAfterIo, Type = CommandType.Host }; var needsAuth = t.GetCustomAttributes(typeof(AuthorizedStateAttribute), false); hostCommand.RequiresAuthorizedState = (needsAuth.Length != 0); if (!Commands.ContainsKey(CommandType.Host)) { Commands.Add(CommandType.Host, new SortedList <string, Command>()); } try { Commands[CommandType.Host].Add(hostCommand.Code, hostCommand); } catch (ArgumentException) { // Nothing, unit tests. } } } } } }
public async Task <bool> UpdateAsync(HostCommand item) { // _context.Entry(item).State = EntityState.Modified; _context.HostCommands.Update(item); return(await _context.SaveChangesAsync() > 0); }
public async Task <bool> DeleteAsync(HostCommand item) { _context.HostCommands.Remove(item); return(await _context.SaveChangesAsync() > 0); }
public async Task <bool> CreateAsync(HostCommand item) { _context.HostCommands.Add(item); return(await _context.SaveChangesAsync() > 0); }