public static Tuple <ILocalCommand, Commands.Attributes.Command> GetLocalCommand(string commandName) { Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName == module); if (assembly == null) { try { assembly = Assembly.Load(module); } catch { } } var exportedTypes = assembly.ExportedTypes .Where(t => t.IsClass && typeof(ILocalCommand).IsAssignableFrom(t) && t.GetCustomAttributes(typeof(Commands.Attributes.Command)).Count() > 0).ToList(); ILocalCommand command = null; Commands.Attributes.Command attribute = null; foreach (var type in exportedTypes) { var commandAttribute = type.GetCustomAttributes(typeof(Commands.Attributes.Command), true) .Cast <Commands.Attributes.Command>().FirstOrDefault(); if (commandAttribute.Name == commandName) { command = (ILocalCommand)Activator.CreateInstance(type); attribute = commandAttribute; break; } } return(new Tuple <ILocalCommand, Commands.Attributes.Command>(command, attribute)); }
public void MakeRequest(string commandName, string[] args, IGlobalCommand command, Commands.Attributes.Command attribute) { var template = attribute.Template; var body = command.Send(args); var targets = command.GetTargets(args); string hostName = Dns.GetHostName(); // Retrive the Name of HOST var ips = Dns.GetHostByName(hostName).AddressList; string ip = ips[ips.Length - 1].ToString(); foreach (var target in targets) { var socket = client.StartSocket(target.Item1, target.Item2); if (!AsyncClient.CanConnect) { Console.WriteLine($"Cannot connect to {target.Item1}:{target.Item2}"); continue; } var data = new SocketDataBody() { CommandName = commandName, Body = body, Type = SocketDataType.Send, NodesPair = new Tuple <string, string>($"{ip}:{AsyncListener.Port}", $"{target.Item1.ToString()}:{target.Item2}") }; client.Send(socket, data); AsyncClient.sendDone.WaitOne(); client.Receive(socket); AsyncClient.receiveDone.WaitOne(); //client.StopSocket(socket); } }