public async Task TestListSpecificLimit() { IDnsService provider = CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(10)))) { IEnumerable <LimitType> limitTypes = await provider.ListLimitTypesAsync(cancellationTokenSource.Token); Assert.IsNotNull(limitTypes); if (!limitTypes.Any()) { Assert.Inconclusive("No limit types were returned by the server"); } foreach (var limitType in limitTypes) { Console.WriteLine(); Console.WriteLine("Limit Type: {0}", limitType); Console.WriteLine(); DnsServiceLimits limits = await provider.ListLimitsAsync(limitType, cancellationTokenSource.Token); Console.WriteLine(await JsonConvert.SerializeObjectAsync(limits, Formatting.Indented)); } } }
public async Task TestListLimitTypes() { IDnsService provider = CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(10)))) { IEnumerable <LimitType> limitTypes = await provider.ListLimitTypesAsync(cancellationTokenSource.Token); Assert.IsNotNull(limitTypes); if (!limitTypes.Any()) { Assert.Inconclusive("No limit types were returned by the server"); } foreach (var limitType in limitTypes) { Console.WriteLine(limitType.Name); } Assert.IsTrue(limitTypes.Contains(LimitType.Rate)); Assert.IsTrue(limitTypes.Contains(LimitType.Domain)); Assert.IsTrue(limitTypes.Contains(LimitType.DomainRecord)); } }
private void Bind() { IDnsService dnsService = IoC.Resolve <IDnsService>(); var result = dnsService.GetAll().ToList(); this.repList.DataSource = result; this.repList.DataBind(); }
public async Task TestCreateDomain() { string domainName = CreateRandomDomainName(); IDnsService provider = CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(60)))) { DnsConfiguration configuration = new DnsConfiguration( new DnsDomainConfiguration( name: domainName, timeToLive: default(TimeSpan?), emailAddress: "admin@" + domainName, comment: "Integration test domain", records: new DnsDomainRecordConfiguration[] { }, subdomains: new DnsSubdomainConfiguration[] { })); DnsJob <DnsDomains> createResponse = await provider.CreateDomainsAsync(configuration, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); IEnumerable <DnsDomain> createdDomains = Enumerable.Empty <DnsDomain>(); if (createResponse.Status == DnsJobStatus.Error) { Console.WriteLine(createResponse.Error.ToString(Formatting.Indented)); Assert.Fail(); } else { Console.WriteLine(JsonConvert.SerializeObject(createResponse.Response, Formatting.Indented)); createdDomains = createResponse.Response.Domains; } ReadOnlyCollection <DnsDomain> domains = await ListAllDomainsAsync(provider, domainName, null, cancellationTokenSource.Token); Assert.IsNotNull(domains); if (!domains.Any()) { Assert.Inconclusive("No domains were returned by the server"); } foreach (var domain in domains) { Console.WriteLine(); Console.WriteLine("Domain: {0} ({1})", domain.Name, domain.Id); Console.WriteLine(); Console.WriteLine(await JsonConvert.SerializeObjectAsync(domain, Formatting.Indented)); } DnsJob deleteResponse = await provider.RemoveDomainsAsync(createdDomains.Select(i => i.Id), false, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (deleteResponse.Status == DnsJobStatus.Error) { Console.WriteLine(deleteResponse.Error.ToString(Formatting.Indented)); Assert.Fail("Failed to delete temporary domain created during the integration test."); } } }
public Handler( IDnsService dns, ICacheService cache, IOptions <CacheExpirerOptions> options ) { this.dns = dns; this.cache = cache; this.options = options.Value; }
public async Task TestCloneDomain() { string domainName = CreateRandomDomainName(); string clonedName = CreateRandomDomainName(); IDnsService provider = CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(60)))) { List <DomainId> domainsToRemove = new List <DomainId>(); DnsConfiguration configuration = new DnsConfiguration( new DnsDomainConfiguration( name: domainName, timeToLive: default(TimeSpan?), emailAddress: "admin@" + domainName, comment: "Integration test domain", records: new DnsDomainRecordConfiguration[] { }, subdomains: new DnsSubdomainConfiguration[] { })); DnsJob <DnsDomains> createResponse = await provider.CreateDomainsAsync(configuration, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (createResponse.Status == DnsJobStatus.Error) { Console.WriteLine(createResponse.Error.ToString(Formatting.Indented)); Assert.Fail(); } else { Console.WriteLine(JsonConvert.SerializeObject(createResponse.Response, Formatting.Indented)); domainsToRemove.AddRange(createResponse.Response.Domains.Select(i => i.Id)); } DnsJob <DnsDomains> cloneResponse = await provider.CloneDomainAsync(createResponse.Response.Domains[0].Id, clonedName, true, true, true, true, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (cloneResponse.Status == DnsJobStatus.Error) { Console.WriteLine(cloneResponse.Error.ToString(Formatting.Indented)); Assert.Fail(); } else { Console.WriteLine(JsonConvert.SerializeObject(cloneResponse.Response, Formatting.Indented)); domainsToRemove.AddRange(cloneResponse.Response.Domains.Select(i => i.Id)); } DnsJob deleteResponse = await provider.RemoveDomainsAsync(domainsToRemove, false, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (deleteResponse.Status == DnsJobStatus.Error) { Console.WriteLine(deleteResponse.Error.ToString(Formatting.Indented)); Assert.Fail("Failed to delete temporary domain created during the integration test."); } } }
public WatchedRecordsService(ILogger <WatchedRecordsService> logger, IDnsWatcherDbContext context, IMapper mapper, IWatchedDomainsService domainsService, IDnsService dnsService) { _logger = logger; _context = context; _mapper = mapper; _domainsService = domainsService; _dnsService = dnsService; }
protected void lbBtn_Command(object sender, CommandEventArgs e) { var cmdResult = e.CommandArgument; if (null == cmdResult) { return; } IDnsService dnsService = IoC.Resolve <IDnsService>(); dnsService.Delete(Convert.ToInt32(cmdResult.ToString())); dnsService.Save(); this.Bind(); }
public async Task TestListLimits() { IDnsService provider = CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(10)))) { DnsServiceLimits limits = await provider.ListLimitsAsync(cancellationTokenSource.Token); Assert.IsNotNull(limits); Assert.IsNotNull(limits.RateLimits); Assert.IsNotNull(limits.AbsoluteLimits); Console.WriteLine(await JsonConvert.SerializeObjectAsync(limits, Formatting.Indented)); } }
/// <summary> /// 验证域名 /// </summary> private void Verification() { string dns = Request.Params["account"]; string code = Request.Params["code"]; if (string.IsNullOrEmpty(dns) || string.IsNullOrEmpty(code)) { AppGlobal.RenderResult(ApiCode.ParamEmpty); return; } if (System.Web.HttpContext.Current.Session["verification_dns"] == null || code != System.Web.HttpContext.Current.Session["verification_dns"].ToString()) { AppGlobal.RenderResult(ApiCode.Security); return; } //验证 IDnsService dnsService = IoC.Resolve <IDnsService>(); var fs = dnsService.GetAll().ToList(); if (fs == null) { AppGlobal.RenderResult(ApiCode.NotSell); return; } else { dns = dns.ToLower(); bool fis = false; foreach (var item in fs) { if (dns.IndexOf(item.SiteDnsUrl.ToLower()) != -1) { fis = true; break; } } if (fis) { AppGlobal.RenderResult(ApiCode.Success); } else { AppGlobal.RenderResult(ApiCode.NotSell); } } }
protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.Params["action"])) { var dns = Request.Params["dns"]; var auto = Request.Params["auto"]; if (string.IsNullOrEmpty(dns)) { Response.Write("-1"); } else { IDnsService dnsService = IoC.Resolve <IDnsService>(); switch (Request.Params["action"]) { case "add": dnsService.Create(new Ytg.BasicModel.SiteDns() { SiteDnsUrl = dns, OccDate = DateTime.Now, IsShowAutoRegist = auto == "0"?true:false }); break; case "update": int id = Convert.ToInt32(Request.Params["id"]); var item = dnsService.Get(id); if (item != null) { item.SiteDnsUrl = dns; item.IsShowAutoRegist = auto == "0" ? true : false; } dnsService.Save(); break; } dnsService.Save(); Response.Write("0"); } Response.End(); } if (!IsPostBack) { this.Bind(); } }
public MailSender(IDnsService dnsService, IParameters parameters) { if (dnsService == null) throw new ArgumentNullException("dnsService"); _dnsService = dnsService; if (!string.IsNullOrEmpty(parameters.SmtpServer)) { if (parameters.EnableSsl) { _client.EnableSsl = true; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; ServicePointManager.CheckCertificateRevocationList = false; } _client.Host = parameters.SmtpServer; _client.Credentials = new NetworkCredential(parameters.SmtpLogin, parameters.SmtpPassword); } }
private void BindData() { IDnsService dnsServices = IoC.Resolve <IDnsService>(); var result = dnsServices.GetAll().Where(c => c.IsShowAutoRegist).ToList(); foreach (var item in result) { item.SiteDnsUrl += "/AutoRegist.html?regsionUnqiue=" + CookUserInfo.Id; } result.Add(new BasicModel.SiteDns() { SiteDnsUrl = "http://" + Request.Url.Authority + "/AutoRegist.html?regsionUnqiue=" + CookUserInfo.Id }); this.fe_text12.DataTextField = "SiteDnsUrl"; this.fe_text12.DataValueField = "SiteDnsUrl"; this.fe_text12.DataSource = result; this.fe_text12.DataBind(); this.minPlayType = CookUserInfo.PlayType == BasicModel.UserPlayType.P1800 ? 1800 : 1700; }
public async Task CleanupTestDomains() { const int BatchSize = 10; IDnsService provider = CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(60)))) { Func <DnsDomain, bool> domainFilter = domain => { if (domain.Name.StartsWith(TestDomainPrefix, StringComparison.OrdinalIgnoreCase)) { return(true); } else if (domain.Name.IndexOf('.' + TestDomainPrefix, StringComparison.OrdinalIgnoreCase) >= 0) { return(true); } return(false); }; DnsDomain[] allDomains = (await ListAllDomainsAsync(provider, null, null, cancellationTokenSource.Token)).Where(domainFilter).ToArray(); List <Task> deleteTasks = new List <Task>(); for (int i = 0; i < allDomains.Length; i += BatchSize) { for (int j = i; j < i + BatchSize && j < allDomains.Length; j++) { Console.WriteLine("Deleting domain: {0}", allDomains[j].Name); } deleteTasks.Add(provider.RemoveDomainsAsync(allDomains.Skip(i).Take(BatchSize).Select(domain => domain.Id), true, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null)); } Task.WaitAll(deleteTasks.ToArray()); } }
private void GetDns() { string str = Request.Params["form"]; if (string.IsNullOrEmpty(str)) { Response.Write(""); Response.End(); return; } //获取有效域名 IDnsService dnsService = IoC.Resolve <IDnsService>(); var fs = dnsService.GetAll().Where(x => x.IsShowAutoRegist).ToList(); string dnsStr = ""; foreach (var item in fs) { dnsStr += item.SiteDnsUrl + ","; } Response.Write(dnsStr); Response.End(); }
private void BindData() { IDnsService dnsServices = IoC.Resolve <IDnsService>(); var result = dnsServices.GetAll().Where(c => c.IsShowAutoRegist).ToList(); if (CookUserInfo.Head == 0) { foreach (var item in result) { item.SiteDnsUrl += "/adduser.aspx?usercode=" + CookUserInfo.Id; } result.Add(new BasicModel.SiteDns() { SiteDnsUrl = "http://" + Request.Url.Authority + "/adduser.aspx?usercode=" + CookUserInfo.Id + "&from=augist" }); } else { foreach (var item in result) { item.SiteDnsUrl += "/adduser.aspx?usercode=" + CookUserInfo.Id + "&from=augist"; } result.Add(new BasicModel.SiteDns() { SiteDnsUrl = "http://" + Request.Url.Authority + "/adduser.aspx?usercode=" + CookUserInfo.Id + "&from=augist" }); } this.fe_text12.DataTextField = "SiteDnsUrl"; this.fe_text12.DataValueField = "SiteDnsUrl"; this.fe_text12.DataSource = result; this.fe_text12.DataBind(); this.minPlayType = CookUserInfo.PlayType == BasicModel.UserPlayType.P1800 ? 1800 : 1700; }
public async Task ShouldClearCommandCache( string command, IPAddress ip1, IPAddress ip2, SnsMessage <CacheExpirationRequest> request, [Frozen] IDnsService dns, [Frozen] ICacheService cache, [Frozen] CacheExpirerOptions options, [Target] Handler handler, CancellationToken cancellationToken ) { request.Message.Type = CacheExpirationType.Command; request.Message.Id = command; dns.GetIPAddresses(Any <string>(), Any <CancellationToken>()).Returns(new[] { ip1, ip2 }); await handler.Handle(request, cancellationToken); await dns.Received().GetIPAddresses(Is(options.AdapterUrl), Is(cancellationToken)); await cache.Received().ExpireCommandCache(Is(ip1), Is(command), Is(cancellationToken)); await cache.Received().ExpireCommandCache(Is(ip2), Is(command), Is(cancellationToken)); }
public async Task TestListDomains() { IDnsService provider = CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(30)))) { ReadOnlyCollection <DnsDomain> domains = await ListAllDomainsAsync(provider, null, null, cancellationTokenSource.Token); Assert.IsNotNull(domains); if (!domains.Any()) { Assert.Inconclusive("No domains were returned by the server"); } foreach (var domain in domains) { Console.WriteLine(); Console.WriteLine("Domain: {0} ({1})", domain.Name, domain.Id); Console.WriteLine(); Console.WriteLine(await JsonConvert.SerializeObjectAsync(domain, Formatting.Indented)); } } }
public async Task TestCreatePtrRecords() { string domainName = CreateRandomDomainName(); string loadBalancerName = UserLoadBalancerTests.CreateRandomLoadBalancerName(); IDnsService provider = CreateProvider(); ILoadBalancerService loadBalancerProvider = UserLoadBalancerTests.CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(60)))) { IEnumerable <LoadBalancingProtocol> protocols = await loadBalancerProvider.ListProtocolsAsync(cancellationTokenSource.Token); LoadBalancingProtocol httpProtocol = protocols.First(i => i.Name.Equals("HTTP", StringComparison.OrdinalIgnoreCase)); LoadBalancerConfiguration loadBalancerConfiguration = new LoadBalancerConfiguration( name: loadBalancerName, nodes: null, protocol: httpProtocol, virtualAddresses: new[] { new LoadBalancerVirtualAddress(LoadBalancerVirtualAddressType.Public) }, algorithm: LoadBalancingAlgorithm.RoundRobin); LoadBalancer loadBalancer = await loadBalancerProvider.CreateLoadBalancerAsync(loadBalancerConfiguration, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); Assert.IsNotNull(loadBalancer.VirtualAddresses); Assert.IsTrue(loadBalancer.VirtualAddresses.Count > 0); string originalData = loadBalancer.VirtualAddresses[0].Address.ToString(); string originalName = string.Format("www.{0}", domainName); string updatedName = string.Format("www2.{0}", domainName); string originalCommentValue = "Integration test record"; string updatedCommentValue = "Integration test record 2"; TimeSpan?originalTimeToLive; TimeSpan?updatedTimeToLive = TimeSpan.FromMinutes(12); DnsDomainRecordConfiguration[] recordConfigurations = { new DnsDomainRecordConfiguration( type: DnsRecordType.Ptr, name: string.Format("www.{0}",domainName), data: originalData, timeToLive: null, comment: originalCommentValue, priority: null) }; string serviceName = "cloudLoadBalancers"; Uri deviceResourceUri = await((UserLoadBalancerTests.TestCloudLoadBalancerProvider)loadBalancerProvider).GetDeviceResourceUri(loadBalancer, cancellationTokenSource.Token); DnsJob <DnsRecordsList> recordsResponse = await provider.AddPtrRecordsAsync(serviceName, deviceResourceUri, recordConfigurations, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); Assert.IsNotNull(recordsResponse.Response); Assert.IsNotNull(recordsResponse.Response.Records); DnsRecord[] records = recordsResponse.Response.Records.ToArray(); Assert.AreEqual(recordConfigurations.Length, records.Length); originalTimeToLive = records[0].TimeToLive; Assert.AreNotEqual(originalTimeToLive, updatedTimeToLive); Assert.AreEqual(originalData, records[0].Data); Assert.AreEqual(originalTimeToLive, records[0].TimeToLive); Assert.AreEqual(originalCommentValue, records[0].Comment); foreach (var record in records) { Console.WriteLine(); Console.WriteLine("Record: {0} ({1})", record.Name, record.Id); Console.WriteLine(); Console.WriteLine(await JsonConvert.SerializeObjectAsync(record, Formatting.Indented)); } // update the comment and verify nothing else changed DnsDomainRecordUpdateConfiguration recordUpdateConfiguration = new DnsDomainRecordUpdateConfiguration(records[0], originalName, originalData, comment: updatedCommentValue); await provider.UpdatePtrRecordsAsync(serviceName, deviceResourceUri, new[] { recordUpdateConfiguration }, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); DnsRecord updatedRecord = await provider.ListPtrRecordDetailsAsync(serviceName, deviceResourceUri, records[0].Id, cancellationTokenSource.Token); Assert.IsNotNull(updatedRecord); Assert.AreEqual(originalData, updatedRecord.Data); Assert.AreEqual(originalName, updatedRecord.Name); Assert.AreEqual(originalTimeToLive, updatedRecord.TimeToLive); Assert.AreEqual(updatedCommentValue, updatedRecord.Comment); // update the TTL and verify nothing else changed recordUpdateConfiguration = new DnsDomainRecordUpdateConfiguration(records[0], originalName, originalData, timeToLive: updatedTimeToLive); await provider.UpdatePtrRecordsAsync(serviceName, deviceResourceUri, new[] { recordUpdateConfiguration }, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); updatedRecord = await provider.ListPtrRecordDetailsAsync(serviceName, deviceResourceUri, records[0].Id, cancellationTokenSource.Token); Assert.IsNotNull(updatedRecord); Assert.AreEqual(originalData, updatedRecord.Data); Assert.AreEqual(originalName, updatedRecord.Name); Assert.AreEqual(updatedTimeToLive, updatedRecord.TimeToLive); Assert.AreEqual(updatedCommentValue, updatedRecord.Comment); // update the name and verify nothing else changed recordUpdateConfiguration = new DnsDomainRecordUpdateConfiguration(records[0], updatedName, originalData); await provider.UpdatePtrRecordsAsync(serviceName, deviceResourceUri, new[] { recordUpdateConfiguration }, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); updatedRecord = await provider.ListPtrRecordDetailsAsync(serviceName, deviceResourceUri, records[0].Id, cancellationTokenSource.Token); Assert.IsNotNull(updatedRecord); Assert.AreEqual(originalData, updatedRecord.Data); Assert.AreEqual(updatedName, updatedRecord.Name); Assert.AreEqual(updatedTimeToLive, updatedRecord.TimeToLive); Assert.AreEqual(updatedCommentValue, updatedRecord.Comment); // remove the PTR record // TODO: verify result? await provider.RemovePtrRecordsAsync(serviceName, deviceResourceUri, loadBalancer.VirtualAddresses[0].Address, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); /* Cleanup */ await loadBalancerProvider.RemoveLoadBalancerAsync(loadBalancer.Id, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); } }
/// <summary> /// Gets all existing subdomains for a particular domain through a series of /// asynchronous operations, each of which requests a subset of the available /// subdomains. /// </summary> /// <remarks> /// Each of the returned tasks is executed asynchronously but sequentially. This /// method will not send concurrent requests to the DNS service. /// <para> /// Due to the way the list end is detected, the final task may return an empty /// collection of <see cref="DnsSubdomain"/> instances. /// </para> /// </remarks> /// <param name="provider">The DNS service.</param> /// <param name="limit">The maximum number of <see cref="DnsSubdomain"/> objects to return from a single task. If this value is <c>null</c>, a provider-specific default is used.</param> /// <param name="detailed"><c>true</c> to return detailed information for each subdomain; otherwise, <c>false</c>.</param> /// <returns> /// A collections of <see cref="Task{TResult}"/> objects, each of which /// represents an asynchronous operation to gather a subset of the available /// subdomains. /// </returns> private static IEnumerable<DnsSubdomain> ListAllSubdomains(IDnsService provider, DomainId domainId, int? limit, CancellationToken cancellationToken) { if (limit <= 0) throw new ArgumentOutOfRangeException("limit"); int index = 0; int previousIndex; int? totalEntries = null; do { previousIndex = index; Task<Tuple<IEnumerable<DnsSubdomain>, int?>> subdomains = provider.ListSubdomainsAsync(domainId, index, limit, cancellationToken); totalEntries = subdomains.Result.Item2; foreach (DnsSubdomain subdomain in subdomains.Result.Item1) { index++; yield return subdomain; } if (limit == null) { // this service will return a 400 error if offset is not a multiple of limit, // or if the limit is not specified limit = index; } } while (index > previousIndex && (totalEntries == null || index < totalEntries)); }
public async Task TestDomainExportImport() { string domainName = CreateRandomDomainName(); IDnsService provider = CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(60)))) { List <DomainId> domainsToRemove = new List <DomainId>(); DnsConfiguration configuration = new DnsConfiguration( new DnsDomainConfiguration( name: domainName, timeToLive: default(TimeSpan?), emailAddress: "admin@" + domainName, comment: "Integration test domain", records: new DnsDomainRecordConfiguration[] { }, subdomains: new DnsSubdomainConfiguration[] { })); DnsJob <DnsDomains> createResponse = await provider.CreateDomainsAsync(configuration, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (createResponse.Status == DnsJobStatus.Error) { Console.WriteLine(createResponse.Error.ToString(Formatting.Indented)); Assert.Fail("Failed to create a test domain."); } else { Console.WriteLine(JsonConvert.SerializeObject(createResponse.Response, Formatting.Indented)); domainsToRemove.AddRange(createResponse.Response.Domains.Select(i => i.Id)); } DnsJob <ExportedDomain> exportedDomain = await provider.ExportDomainAsync(createResponse.Response.Domains[0].Id, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (exportedDomain.Status == DnsJobStatus.Error) { Console.WriteLine(exportedDomain.Error.ToString(Formatting.Indented)); Assert.Fail("Failed to export test domain."); } Assert.AreEqual(DnsJobStatus.Completed, exportedDomain.Status); Assert.IsNotNull(exportedDomain.Response); Console.WriteLine("Exported domain:"); Console.WriteLine(JsonConvert.SerializeObject(exportedDomain.Response, Formatting.Indented)); Console.WriteLine(); Console.WriteLine("Formatted exported output:"); Console.WriteLine(exportedDomain.Response.Contents); Assert.IsNotNull(exportedDomain.Response.Id); Assert.IsNotNull(exportedDomain.Response.AccountId); Assert.IsFalse(string.IsNullOrEmpty(exportedDomain.Response.Contents)); Assert.IsNotNull(exportedDomain.Response.ContentType); DnsJob deleteResponse = await provider.RemoveDomainsAsync(domainsToRemove, false, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (deleteResponse.Status == DnsJobStatus.Error) { Console.WriteLine(deleteResponse.Error.ToString(Formatting.Indented)); Assert.Fail("Failed to delete temporary domain created during the integration test."); } domainsToRemove.Clear(); SerializedDomain serializedDomain = new SerializedDomain( RemoveDefaultNameserverEntries(exportedDomain.Response.Contents), exportedDomain.Response.ContentType); DnsJob <DnsDomains> importedDomain = await provider.ImportDomainAsync(new[] { serializedDomain }, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (importedDomain.Status == DnsJobStatus.Error) { Console.WriteLine(importedDomain.Error.ToString(Formatting.Indented)); Assert.Fail("Failed to import the test domain."); } else { Console.WriteLine(JsonConvert.SerializeObject(importedDomain.Response, Formatting.Indented)); domainsToRemove.AddRange(importedDomain.Response.Domains.Select(i => i.Id)); } deleteResponse = await provider.RemoveDomainsAsync(domainsToRemove, false, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (deleteResponse.Status == DnsJobStatus.Error) { Console.WriteLine(deleteResponse.Error.ToString(Formatting.Indented)); Assert.Fail("Failed to delete temporary domain created during the integration test."); } } }
public async Task TestCreateRecords() { string domainName = CreateRandomDomainName(); IDnsService provider = CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(60)))) { DnsConfiguration configuration = new DnsConfiguration( new DnsDomainConfiguration( name: domainName, timeToLive: default(TimeSpan?), emailAddress: "admin@" + domainName, comment: "Integration test domain", records: new DnsDomainRecordConfiguration[] { }, subdomains: new DnsSubdomainConfiguration[] { })); DnsJob <DnsDomains> createResponse = await provider.CreateDomainsAsync(configuration, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); IEnumerable <DnsDomain> createdDomains = Enumerable.Empty <DnsDomain>(); if (createResponse.Status == DnsJobStatus.Error) { Console.WriteLine(createResponse.Error.ToString(Formatting.Indented)); Assert.Fail(); } else { Console.WriteLine(JsonConvert.SerializeObject(createResponse.Response, Formatting.Indented)); createdDomains = createResponse.Response.Domains; } ReadOnlyCollection <DnsDomain> domains = await ListAllDomainsAsync(provider, domainName, null, cancellationTokenSource.Token); Assert.IsNotNull(domains); Assert.AreEqual(1, domains.Count); foreach (var domain in domains) { Console.WriteLine(); Console.WriteLine("Domain: {0} ({1})", domain.Name, domain.Id); Console.WriteLine(); Console.WriteLine(await JsonConvert.SerializeObjectAsync(domain, Formatting.Indented)); } string originalData = "127.0.0.1"; string updatedData = "192.168.0.1"; string originalCommentValue = "Integration test record"; string updatedCommentValue = "Integration test record 2"; TimeSpan?originalTimeToLive; TimeSpan?updatedTimeToLive = TimeSpan.FromMinutes(12); DomainId domainId = createResponse.Response.Domains[0].Id; DnsDomainRecordConfiguration[] recordConfigurations = { new DnsDomainRecordConfiguration( type: DnsRecordType.A, name: string.Format("www.{0}",domainName), data: originalData, timeToLive: null, comment: originalCommentValue, priority: null) }; DnsJob <DnsRecordsList> recordsResponse = await provider.AddRecordsAsync(domainId, recordConfigurations, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); Assert.IsNotNull(recordsResponse.Response); Assert.IsNotNull(recordsResponse.Response.Records); DnsRecord[] records = recordsResponse.Response.Records.ToArray(); Assert.AreEqual(recordConfigurations.Length, records.Length); originalTimeToLive = records[0].TimeToLive; Assert.AreNotEqual(originalTimeToLive, updatedTimeToLive); Assert.AreEqual(originalData, records[0].Data); Assert.AreEqual(originalTimeToLive, records[0].TimeToLive); Assert.AreEqual(originalCommentValue, records[0].Comment); foreach (var record in records) { Console.WriteLine(); Console.WriteLine("Record: {0} ({1})", record.Name, record.Id); Console.WriteLine(); Console.WriteLine(await JsonConvert.SerializeObjectAsync(record, Formatting.Indented)); } DnsDomainRecordUpdateConfiguration recordUpdateConfiguration = new DnsDomainRecordUpdateConfiguration(records[0], records[0].Name, comment: updatedCommentValue); await provider.UpdateRecordsAsync(domainId, new[] { recordUpdateConfiguration }, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); DnsRecord updatedRecord = await provider.ListRecordDetailsAsync(domainId, records[0].Id, cancellationTokenSource.Token); Assert.IsNotNull(updatedRecord); Assert.AreEqual(originalData, updatedRecord.Data); Assert.AreEqual(originalTimeToLive, updatedRecord.TimeToLive); Assert.AreEqual(updatedCommentValue, updatedRecord.Comment); recordUpdateConfiguration = new DnsDomainRecordUpdateConfiguration(records[0], records[0].Name, timeToLive: updatedTimeToLive); await provider.UpdateRecordsAsync(domainId, new[] { recordUpdateConfiguration }, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); updatedRecord = await provider.ListRecordDetailsAsync(domainId, records[0].Id, cancellationTokenSource.Token); Assert.IsNotNull(updatedRecord); Assert.AreEqual(originalData, updatedRecord.Data); Assert.AreEqual(updatedTimeToLive, updatedRecord.TimeToLive); Assert.AreEqual(updatedCommentValue, updatedRecord.Comment); recordUpdateConfiguration = new DnsDomainRecordUpdateConfiguration(records[0], records[0].Name, data: updatedData); await provider.UpdateRecordsAsync(domainId, new[] { recordUpdateConfiguration }, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); updatedRecord = await provider.ListRecordDetailsAsync(domainId, records[0].Id, cancellationTokenSource.Token); Assert.IsNotNull(updatedRecord); Assert.AreEqual(updatedData, updatedRecord.Data); Assert.AreEqual(updatedTimeToLive, updatedRecord.TimeToLive); Assert.AreEqual(updatedCommentValue, updatedRecord.Comment); await provider.RemoveRecordsAsync(domainId, new[] { records[0].Id }, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); DnsJob deleteResponse = await provider.RemoveDomainsAsync(createdDomains.Select(i => i.Id), false, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null); if (deleteResponse.Status == DnsJobStatus.Error) { Console.WriteLine(deleteResponse.Error.ToString(Formatting.Indented)); Assert.Fail("Failed to delete temporary domain created during the integration test."); } } }
/// <summary> /// Gets all subdomains associated with a domain through a series of asynchronous operations, /// each of which requests a subset of the available subdomains. /// </summary> /// <param name="provider">The DNS service.</param> /// <param name="domainId">The top-level domain ID. This is obtained from <see cref="DnsDomain.Id">DnsDomain.Id</see>.</param> /// <param name="limit">The maximum number of domains to return in a single page.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that the task will observe.</param> /// <param name="progress">An optional callback object to receive progress notifications. If this is <see langword="null"/>, no progress notifications are sent.</param> /// <returns> /// A <see cref="Task"/> object representing the asynchronous operation. When the task completes successfully, /// the <see cref="Task{TResult}.Result"/> property will return a collection of <see cref="DnsDomain"/> objects /// representing the requested domains. /// </returns> /// <exception cref="ArgumentNullException">If <paramref name="provider"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception> private static async Task <ReadOnlyCollection <DnsSubdomain> > ListAllSubdomainsAsync(IDnsService provider, DomainId domainId, int?limit, CancellationToken cancellationToken, net.openstack.Core.IProgress <ReadOnlyCollectionPage <DnsSubdomain> > progress = null) { if (provider == null) { throw new ArgumentNullException("provider"); } if (limit <= 0) { throw new ArgumentOutOfRangeException("limit"); } return(await(await provider.ListSubdomainsAsync(domainId, null, limit, cancellationToken)).Item1.GetAllPagesAsync(cancellationToken, progress)); }
public DomainController(IWhoisService WhoisService, IDnsService DnsService) { _WhoisService = WhoisService; _DnsService = DnsService; }