private static int RunWhois(Options o) { var whois = new YaWhoisClient(); whois.WhenResponseParsed += Whois_ResponseParsed; if (o.UseIANA) { o.Server = "whois.iana.org"; } try { whois.Query(o.Object, o.Server, o.Verbose); return(0); } catch (Exception e) { Console.WriteLine(e.Message); return(2); } }
public void Setup() { _whois = new YaWhoisClient(); }
public async Task ClientReady(string id, Guid queueId, string language) { var login = Context.User.GetLogin(); var client = Clients.Client(id); if (queueId == Guid.Empty) { _logger.LogWarning($"Client {login} | {id} has passed empty queueId."); return; } if (!_queue.Queue.TryRemove(queueId, out IEnumerable <WhoisDto> dtos)) { _logger.LogError($"Failed remove Ping Request {queueId} for client {id}."); await client.SendAsync("Exception", "Queue error."); return; } _logger.LogInformation($"User {login} has started Whois Request {queueId} with {dtos.Count()} host(s)."); var culture = await GetCultureAsync(id, language); _tasks.QueueTask(async token => { if (token.IsCancellationRequested) { return; } Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = culture; var taskFactory = new TaskFactory(TaskScheduler.Current); var cde = new AsyncCountdownEvent(dtos.Count()); var tasks = new List <Task>(); var whois = new YaWhoisClient(); whois.ResponseParsed += Whois_ResponseParsed; whois.ExceptionThrown += Whois_ExceptionThrown; foreach (var host in dtos.Select(a => a.Hostname)) { var data = new YaWhoisData() { Client = client, ClientId = id, Object = host }; tasks.Add(taskFactory.StartNew((d) => { whois.QueryAsync(host, token: token, value: d).Wait(); cde.Signal(); }, data, token)); } try { Task.WaitAll(tasks.ToArray()); } catch (Exception e) { var obj = e.Data["object"].ToString(); _logger.LogError(e, $"Whois {obj} failed (clientId: {id})."); } await cde.WaitAsync(); }); }
public void Setup() { _whois = new TestClient(); }