コード例 #1
0
ファイル: Program.cs プロジェクト: gh0stwizard/yawhois-dotnet
        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);
            }
        }
コード例 #2
0
ファイル: Threads.cs プロジェクト: gh0stwizard/yawhois-dotnet
 public void Setup()
 {
     _whois = new YaWhoisClient();
 }
コード例 #3
0
ファイル: WhoisHub.cs プロジェクト: gh0stwizard/VwM
        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();
            });
        }
コード例 #4
0
 public void Setup()
 {
     _whois = new TestClient();
 }