public T SetTransientRetryDelay(RetryDelay retryDelay) { TransientRetryDelay = retryDelay; // Are there alternatives to this double cast? return((T)(object)this); }
public override void UpdateSoaRecord(string zoneName, string host, string primaryNsServer, string primaryPerson) { if (ZoneExists(zoneName)) { // if (String.IsNullOrEmpty(primaryPerson)) { primaryPerson = "hostmaster"; } // Connection cn = SetupProviderConnection(); DNSZone dnsZone = cn.GetZone(zoneName); dnsZone.Comments = "Updated by WebsitePanel DNS API at " + DateTime.Now.ToString(); DNSRecord soaRecord = (dnsZone.Records.Count == 0) ? dnsZone.Records.Add("@", "SOA") : dnsZone.Records[0]; // Fill record fields with the data soaRecord.DataFields[SOA_PRIMARY_NAME_SERVER] = CorrectSOARecord(zoneName, primaryNsServer); soaRecord.DataFields[SOA_RESPONSIBLE_PERSON] = primaryPerson; soaRecord.DataFields[SOA_SERIAL_NUMBER] = UpdateSerialNumber(soaRecord.DataFields[SOA_SERIAL_NUMBER]); soaRecord.DataFields[SOA_REFRESH_INTERVAL] = RefreshInterval.ToString(); soaRecord.DataFields[SOA_RETRY_DELAY] = RetryDelay.ToString(); soaRecord.DataFields[SOA_EXPIRE_LIMIT] = ExpireLimit.ToString(); soaRecord.DataFields[SOA_MINIMUM_TTL] = MinimumTTL.ToString(); // remove "dumb" internal Name Server string internalNameServer = System.Net.Dns.GetHostEntry("LocalHost").HostName; dnsZone.Records.Remove(zoneName, "NS", internalNameServer); // save zone cn.UpdateZone(dnsZone, false); } }
[Repeat(42)] // 42 is indeed that number of times to run a test to ensure its always true public void PickDelay_IsWithinBounds() { // Arrange const double max = 1000; const double min = 500; var sut = RetryDelay.Between( TimeSpan.FromMilliseconds(min), TimeSpan.FromMilliseconds(max)); // Act var delay = sut.PickDelay(); // Assert delay.TotalMilliseconds.Should().BeGreaterOrEqualTo(min); delay.TotalMilliseconds.Should().BeLessOrEqualTo(max); }
/// <summary> /// Retries the function for specfied times with specified delays between /// each retry. /// </summary> /// <typeparam name="T">The type of parameter.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="func">The function.</param> /// <param name="param1">The param1.</param> /// <param name="predicate">Determines whether this is the situtation that we /// should retry.</param> /// <returns></returns> public TResult RetryFunc <T, TResult, TException>(Func <T, TResult> func, T param1, Predicate <TException> predicate) where TException : Exception { if (func == null) { throw new ArgumentNullException("func"); } TResult result; int numRetriesLeft = NumRetries; do { RetryExecuted = NumRetries - numRetriesLeft; try { result = func(param1); } catch (TException ex) { Logger.WriteLineIf(LogLevel.Error, _log_props, string.Format( "Exception caught when retrying. Retries left: {0}", numRetriesLeft)); if (!predicate(ex)) { throw; } if (numRetriesLeft <= 0) { // Retries exhausted. throw; } else { result = default(TResult); } if (!RetryDelay.Equals(default(TimeSpan))) { Thread.Sleep(RetryDelay); } } } while (numRetriesLeft-- > 0); return(result); }
public override void AddPrimaryZone(string zoneName, string[] secondaryServers) { Connection cn = SetupProviderConnection(); // CREATE PRIMARY DNS ZONE string primaryNameServer = System.Net.Dns.GetHostEntry("LocalHost").HostName; DNSZone zoneObj = cn.CreateZone(zoneName, primaryNameServer, "hostmaster"); zoneObj.Comments = String.Concat("Created with SolidCP DNS API at ", DateTime.Now); // Setup zone data transfer if (secondaryServers != null && secondaryServers.Length != 0) { if (secondaryServers.Length == 1 && secondaryServers[0] == "*") { zoneObj.AllowZoneTransfer = "*"; } else { zoneObj.AllowZoneTransfer = String.Join(" ", secondaryServers); } } // Update SOA record DNSRecord soaRecord = zoneObj.Records[0]; soaRecord.DataFields[SOA_PRIMARY_NAME_SERVER] = CorrectSOARecord(zoneName, primaryNameServer); soaRecord.DataFields[SOA_RESPONSIBLE_PERSON] = CorrectSOARecord(zoneName, "hostmaster"); // Issue new serial number for the zone soaRecord.DataFields[SOA_SERIAL_NUMBER] = UpdateSerialNumber(null); soaRecord.DataFields[SOA_REFRESH_INTERVAL] = RefreshInterval.ToString(); soaRecord.DataFields[SOA_RETRY_DELAY] = RetryDelay.ToString(); soaRecord.DataFields[SOA_EXPIRE_LIMIT] = ExpireLimit.ToString(); soaRecord.DataFields[SOA_MINIMUM_TTL] = MinimumTTL.ToString(); // Publish updates are made cn.UpdateZone(zoneObj, false); }
public IMsSqlConfiguration SetServerBusyRetryDelay(RetryDelay retryDelay) { ServerBusyRetryDelay = retryDelay; return(this); }