/// <summary> /// Instantiates a new instance. /// </summary> /// <param name="apiKey">The API key to use to communicate with the Vultr /// API.</param> /// <param name="apiURL">The optional Vultr API URL to use. Set this if you want /// to override the default endpoint (e.g. for testing).</param> /// <exception cref="ArgumentNullException">If <paramref name="apiKey"/> is null /// or empty.</exception> public VultrClient(string apiKey, string apiURL = VultrApiURL) { if (string.IsNullOrEmpty(apiKey)) { throw new ArgumentNullException("apiKey", "apiKey must not be null"); } Account = new AccountClient(apiKey, apiURL); Application = new ApplicationClient(apiKey, apiURL); Auth = new AuthClient(apiKey, apiURL); Backup = new BackupClient(apiKey, apiURL); Block = new BlockClient(apiKey, apiURL); DNS = new DNSClient(apiKey, apiURL); Firewall = new FirewallClient(apiKey, apiURL); ISOImage = new ISOImageClient(apiKey, apiURL); Network = new NetworkClient(apiKey, apiURL); OperatingSystem = new OperatingSystemClient(apiKey, apiURL); Plan = new PlanClient(apiKey, apiURL); Region = new RegionClient(apiKey, apiURL); ReservedIP = new ReservedIPClient(apiKey, apiURL); Server = new ServerClient(apiKey, apiURL); Snapshot = new SnapshotClient(apiKey, apiURL); SSHKey = new SSHKeyClient(apiKey, apiURL); StartupScript = new StartupScriptClient(apiKey, apiURL); User = new UserClient(apiKey, apiURL); }
public static void GetBestBlockRef() { var blockRefByte = BlockClient.GetBlock(Revision.BEST).BlockRef().ToByteArray(); string blockRef = ByteUtils.ToHexString(blockRefByte, null); WriteLine("BlockRef:"); WriteLine("0x" + blockRef); }
public void simple_synchronous_call_getblockhash_returns_result_with_proxy() { BlockClient client = new BlockClient(); BlockHash hash = client.GetBlockHash(Network.Doge, 200000); Assert.IsNotNull(hash); Assert.IsTrue(hash.Status == Consts.Success); Assert.IsTrue(hash.Data.Blockhash == "092fd3e76db5ff35fbfefe48d5c53ca26e799f0654a4036ddd5fd78de77418c2"); }
public void simple_synchronous_call_getblockdisplaydata_height_returns_result_with_proxy() { BlockClient client = new BlockClient(); BlockDisplayData block = client.GetDisplayData(Network.Doge, 200000); Assert.IsNotNull(block); Assert.IsTrue(block.Status == Consts.Success); Assert.IsTrue(block.Data.Blockhash == "092fd3e76db5ff35fbfefe48d5c53ca26e799f0654a4036ddd5fd78de77418c2"); Assert.IsTrue(block.Data.Size == 20686); }
public static void getBestBlock(string[] args) { Block block = null; if (args != null && args.Length > 2) { var revision = Revision.Create(long.Parse(args[2])); block = BlockClient.GetBlock(revision); } else { block = BlockClient.GetBlock(Revision.BEST); } WriteLine("Block:"); WriteLine(JsonConvert.SerializeObject(block)); }
public void should_simple_synchronous_call_getblock_height_with_bad_height_throws_exception() { BlockClient client = new BlockClient(); ExceptionWithMessage <BlockError> typedException = null; try { client.GetBlock(Network.Doge, -1); } catch (Exception e) { typedException = e?.InnerException as ExceptionWithMessage <BlockError>; } Assert.IsNotNull(typedException); Assert.IsNotNull(typedException.ErrorMessage); Assert.IsTrue(typedException.ErrorMessage.Status == Consts.Fail); }
public static void SendMessagesToServer(IEnumerable <string> messages) { Helper.TraceLine("Started SendMessagesToClient Task"); using (var client = new BlockClient(Client.Helper.GetLocalIpv4(), 11000)) { client.Connect(); foreach (var message in messages) { string response; client.Send(message, out response); Thread.Sleep(500); Helper.TraceLine("SendMessagesToClient(...{0}{1} > {2}", Environment.NewLine, message, response); } client.Close(); } Helper.TraceLine("Finished SendMessagesToClient Task"); }
protected Task LongRunningTask(CancellationToken issResetToken) { CancellationToken manualCancelation = LongTaskCancelation.Token; try { Di.Trace.Write("Long running task started"); using (var client = new BlockClient(Client.Helper.GetLocalIpv4(), 11000)) { client.Connect(); for (int i = 0; i < 10000; i++) { if (issResetToken.IsCancellationRequested || manualCancelation.IsCancellationRequested) { break; } string command = string.Format("Sending message {0}", i); string response; if (client.Send(command, out response)) { Di.Trace.WriteLine("Message sent to server"); Di.Trace.WriteLine(string.Format("{0} > {1}", command, response)); } else { Di.Trace.WriteLine("Can't send message to server. Probably error in communication"); Di.Trace.WriteLine("Ending long running task."); break; } } client.Close(); } } catch (Exception e) { Di.Trace.WriteLine("Error in long running task"); Di.Trace.WriteLine(e.Message); Di.Trace.WriteLine(e.StackTrace); } return(Task.FromResult(false)); }
private Client.IClient GetClient(ClientType type) { IPAddress address; if (!IPAddress.TryParse(txtIpaddress.Text, out address)) { address = Client.Helper.GetLocalIpv4(); } IClient client; if (type == ClientType.Client) { client = new BlockClient(address, 11000); } else { client = new AsyncClient(address, 11000); } client.Connect(); return(client); }
private void addBlockSock(SocketConnection sender) { try { if (UseBlockList) { string ip = sender.IP; if (!BlockClient.ContainsKey(ip)) { BlockClient.Add(ip, new ClienteSocketBlock()); } if (!BlockClient[ip].IsBlock) { if (BlockClient[ip].Timer < DateTime.Now.Ticks) { BlockClient[ip].Intentos = 0; } BlockClient[ip].Intentos++; BlockClient[ip].Timer = DateTime.Now.AddMinutes(1).Ticks; if (BlockClient[ip].Intentos > 6) { Log.Log.GetLog().Info(this, "addBlockSock :" + ip); BlockClient[ip].IsBlock = true; BlockClient[ip].Intentos = 0; BlockClient[ip].Timer = DateTime.Now.AddMinutes(5).Ticks; } } } } catch (Exception e) { Log.Log.GetLog().Error(this, "addBlockSock", e); } }
private void AcceptCallback(IAsyncResult value) { try { if (ListenerSocker == null) { return; } System.Net.Sockets.Socket socket = ListenerSocker.EndAccept(value); if (UseBlockList) { string ip = IP(socket); if (BlockClient.ContainsKey(ip)) { if (BlockClient[ip].IsBlock) { if (BlockClient[ip].Timer > DateTime.Now.Ticks) { Log.Log.GetLog().Info(this, "AcceptCallback Disconnect ip : " + ip); socket.Disconnect(true); } else { BlockClient[ip] = new ClienteSocketBlock(); } } } } if (socket.Connected) { getClientType(socket); } } catch (Exception e) { Log.Log.GetLog().Error(this, "AcceptCallback", e); } finally { try { if (ListenerSocker != null) { ListenerSocker.BeginAccept(new AsyncCallback(AcceptCallback), null); } } catch (Exception e) { Log.Log.GetLog().Error(this, "AcceptCallback - ListenerSocker.BeginAccept", e); try { close(); } catch (Exception ex) { Log.Log.GetLog().Error(this, "AcceptCallback - ListenerSocker.BeginAccept - close", ex); } Thread.Sleep(2000); try { startService(); } catch (Exception ex) { Log.Log.GetLog().Error(this, "AcceptCallback - ListenerSocker.BeginAccept - startService", ex); } } } OnDataChange(); }