/// <inheritdoc/> public Task SetPolicyAsync(ScalingGroupId groupId, PolicyId policyId, PolicyConfiguration configuration, CancellationToken cancellationToken) { if (groupId == null) { throw new ArgumentNullException("groupId"); } if (policyId == null) { throw new ArgumentNullException("policyId"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } UriTemplate template = new UriTemplate("/groups/{groupId}/policies/{policyId}"); var parameters = new Dictionary <string, string> { { "groupId", groupId.Value }, { "policyId", policyId.Value } }; Func <Task <Tuple <IdentityToken, Uri> >, Task <HttpWebRequest> > prepareRequest = PrepareRequestAsyncFunc(HttpMethod.PUT, template, parameters, configuration); Func <Task <HttpWebRequest>, Task <string> > requestResource = GetResponseAsyncFunc(cancellationToken); return(AuthenticateServiceAsync(cancellationToken) .Then(prepareRequest) .Then(requestResource)); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (Id != null) { hashCode = hashCode * 59 + Id.GetHashCode(); } if (ResourceId != null) { hashCode = hashCode * 59 + ResourceId.GetHashCode(); } if (RoleId != null) { hashCode = hashCode * 59 + RoleId.GetHashCode(); } if (PolicyId != null) { hashCode = hashCode * 59 + PolicyId.GetHashCode(); } if (ScopeMap != null) { hashCode = hashCode * 59 + ScopeMap.GetHashCode(); } return(hashCode); } }
/// <inheritdoc/> public Task DeleteWebhookAsync(ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId, CancellationToken cancellationToken) { if (groupId == null) { throw new ArgumentNullException("groupId"); } if (policyId == null) { throw new ArgumentNullException("policyId"); } if (webhookId == null) { throw new ArgumentNullException("webhookId"); } UriTemplate template = new UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks/{webhookId}"); var parameters = new Dictionary <string, string> { { "groupId", groupId.Value }, { "policyId", policyId.Value }, { "webhookId", webhookId.Value } }; Func <Task <Tuple <IdentityToken, Uri> >, HttpWebRequest> prepareRequest = PrepareRequestAsyncFunc(HttpMethod.DELETE, template, parameters); Func <Task <HttpWebRequest>, Task <string> > requestResource = GetResponseAsyncFunc(cancellationToken); return(AuthenticateServiceAsync(cancellationToken) .Select(prepareRequest) .Then(requestResource)); }
public Policy GetById(PolicyId policyId) { var policy = rep.FindByKey(policyId); policyConfigurator.Config(policy); return(policy); }
public Policy GetById(PolicyId policyId) { var policy = Single(p => p.Id == policyId); policyConfigurator.Config(policy); return(policy); }
/// <summary> /// Serves as the default hash function. /// </summary> /// <returns>A hash code for the current object.</returns> public override int GetHashCode() { var hashCode = 543595584; hashCode = (hashCode * -1521134295) + PolicyId.GetHashCode(); hashCode = (hashCode * -1521134295) + Count.GetHashCode(); return(hashCode); }
public RuleWithPolicyData GetRuleById(PolicyId policyId, RuleId ruleId) { var policy = policyRep.GetRuleBasePolicyById(policyId); var rule = ruleService.GetById(ruleId); return(new RuleWithPolicyData { Policy = policy, Rule = rule }); }
public RuleFunctionBase AddFunction(string name, string content, PolicyId policyId) { using (var scope = new TransactionScope()) { var policy = policyRep.GetRuleBasePolicyById(policyId); var ruleFunction = ruleService.AddRuleFunction(name, content); policy.AssignRuleFunction(ruleFunction); scope.Complete(); return(ruleFunction); } }
public void DeleteRule(PolicyId policyId, RuleId ruleId) { using (var scope = new TransactionScope()) { var policy = policyRep.GetRuleBasePolicyById(policyId); var rule = ruleService.GetById(ruleId); policy.RemoveRule(rule); ruleService.DeleteRule(ruleId); scope.Complete(); } }
public RuleWithPolicyData UpdateRule(PolicyId policyId, RuleId ruleId, string name, string ruleText, RuleType ruleType, int order) { using (var scope = new TransactionScope()) { var policy = policyRep.GetRuleBasePolicyById(policyId); var rule = ruleService.UpdateRule(ruleId, name, ruleText, ruleType, order); scope.Complete(); return(new RuleWithPolicyData { Policy = policy, Rule = rule }); } }
/// <inheritdoc/> public Task <Webhook> CreateWebhookAsync(ScalingGroupId groupId, PolicyId policyId, NewWebhookConfiguration configuration, CancellationToken cancellationToken) { if (groupId == null) { throw new ArgumentNullException("groupId"); } if (policyId == null) { throw new ArgumentNullException("policyId"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } UriTemplate template = new UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks"); var parameters = new Dictionary <string, string> { { "groupId", groupId.Value }, { "policyId", policyId.Value } }; Func <Task <Tuple <IdentityToken, Uri> >, Task <HttpWebRequest> > prepareRequest = PrepareRequestAsyncFunc(HttpMethod.POST, template, parameters, new[] { configuration }); Func <Task <HttpWebRequest>, Task <JObject> > requestResource = GetResponseAsyncFunc <JObject>(cancellationToken); Func <Task <JObject>, Webhook> resultSelector = task => { JObject result = task.Result; if (result == null) { return(null); } JToken valueToken = result["webhooks"]; if (valueToken == null) { return(null); } Webhook[] webhooks = valueToken.ToObject <Webhook[]>(); return(webhooks[0]); }; return(AuthenticateServiceAsync(cancellationToken) .Then(prepareRequest) .Then(requestResource) .Select(resultSelector)); }
/// <inheritdoc/> public Task <Webhook> GetWebhookAsync(ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId, CancellationToken cancellationToken) { if (groupId == null) { throw new ArgumentNullException("groupId"); } if (policyId == null) { throw new ArgumentNullException("policyId"); } if (webhookId == null) { throw new ArgumentNullException("webhookId"); } UriTemplate.UriTemplate template = new UriTemplate.UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks/{webhookId}"); var parameters = new Dictionary <string, string> { { "groupId", groupId.Value }, { "policyId", policyId.Value }, { "webhookId", webhookId.Value } }; Func <Task <Tuple <IdentityToken, Uri> >, HttpWebRequest> prepareRequest = PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters); Func <Task <HttpWebRequest>, Task <JObject> > requestResource = GetResponseAsyncFunc <JObject>(cancellationToken); Func <Task <JObject>, Webhook> resultSelector = task => { JObject result = task.Result; if (result == null) { return(null); } JToken valueToken = result["webhook"]; if (valueToken == null) { return(null); } return(valueToken.ToObject <Webhook>()); }; return(AuthenticateServiceAsync(cancellationToken) .Select(prepareRequest) .Then(requestResource) .Select(resultSelector)); }
public void DeletePolicy(PolicyId policyId) { try { using (var scope = new TransactionScope()) { var policy = policyRep.GetById(policyId); policyRep.DeletePolicy(policy); scope.Complete(); } } catch (Exception exp) { var res = policyRep.TryConvertException(exp); if (res == null) { throw; } throw res; } }
public Policy UpdatePolicy(PolicyId policyId, string name, string dictionaryName) { try { using (var scope = new TransactionScope()) { var policy = policyRep.GetById(policyId); policy.Update(name, dictionaryName); scope.Complete(); return(policy); } } catch (Exception exp) { var res = policyRep.TryConvertException(exp); if (res == null) { throw; } throw res; } }
/// <summary> /// Returns true if Authorization instances are equal /// </summary> /// <param name="other">Instance of Authorization to be compared</param> /// <returns>Boolean</returns> public bool Equals(Authorization other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Id == other.Id || Id != null && Id.Equals(other.Id) ) && ( ResourceId == other.ResourceId || ResourceId != null && ResourceId.Equals(other.ResourceId) ) && ( RoleId == other.RoleId || RoleId != null && RoleId.Equals(other.RoleId) ) && ( PolicyId == other.PolicyId || PolicyId != null && PolicyId.Equals(other.PolicyId) ) && ( ScopeMap == other.ScopeMap || ScopeMap != null && ScopeMap.Equals(other.ScopeMap) )); }
public Calculation AddCalculation(PolicyId policyId, PeriodId periodId, string name, string employeeIdDelimitedList) { try { using (var tr = new TransactionScope()) { var calculation = new Calculation(calculationRep.GetNextId(), periodRep.GetById(periodId), PolicyRep.GetById(policyId), name, DateTime.Now, employeeIdDelimitedList); calculationRep.Add(calculation); tr.Complete(); return(calculation); } } catch (Exception exp) { var res = calculationRep.TryConvertException(exp); if (res == null) { throw; } throw res; } }
/// <summary> /// Get detailed information about a scaling policy. /// </summary> /// <param name="service">The Auto Scale service instance.</param> /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param> /// <param name="policyId">The ID of the scaling policy. This is obtained from <see cref="Policy.Id">Policy.Id</see>.</param> /// <returns>A <see cref="Policy"/> object describing the scaling policy.</returns> /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"> /// If <paramref name="groupId"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="policyId"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="WebException">If the REST request does not return successfully.</exception> /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getPolicy_v1.0__tenantId__groups__groupId__policies__policyId__autoscale-policies.html">Show policy details (Rackspace Auto Scale Developer Guide - API v1.0)</seealso> public static Policy GetPolicy(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId) { if (service == null) { throw new ArgumentNullException("service"); } try { return(service.GetPolicyAsync(groupId, policyId, CancellationToken.None).Result); } catch (AggregateException ex) { ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) { throw innerExceptions[0]; } throw; } }
public RuleWithPolicyData AddRule(string name, string ruleText, RuleType ruleType, PolicyId policyId, int order) { using (var scope = new TransactionScope()) { var policy = policyRep.GetRuleBasePolicyById(policyId); var rule = ruleService.AddRule(name, ruleText, ruleType, order); policy.AssignRule(rule); scope.Complete(); return(new RuleWithPolicyData { Policy = policy, Rule = rule });; } }
/// <summary> /// Gets a collection of webhooks which trigger the execution of a particular /// scaling policy. /// </summary> /// <param name="service">The Auto Scale service instance.</param> /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param> /// <param name="policyId">The ID of the scaling policy. This is obtained from <see cref="Policy.Id">Policy.Id</see>.</param> /// <param name="marker">The <see cref="Webhook.Id"/> of the last item in the previous list. Used for <see href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/pagination.html">pagination</see>. If the value is <see langword="null"/>, the list starts at the beginning.</param> /// <param name="limit">Indicates the maximum number of items to return. Used for <see href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/pagination.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param> /// <returns>A collection of <see cref="Webhook"/> objects describing the webhooks for the scaling policy.</returns> /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"> /// If <paramref name="groupId"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="policyId"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception> /// <exception cref="WebException">If the REST request does not return successfully.</exception> /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getWebhooks_v1.0__tenantId__groups__groupId__policies__policyId__webhooks_autoscale-webhooks.html">List webhooks for the policy (Rackspace Auto Scale Developer Guide - API v1.0)</seealso> public static ReadOnlyCollectionPage <Webhook> ListWebhooks(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId marker, int?limit) { if (service == null) { throw new ArgumentNullException("service"); } try { return(service.ListWebhooksAsync(groupId, policyId, marker, limit, CancellationToken.None).Result); } catch (AggregateException ex) { ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) { throw innerExceptions[0]; } throw; } }
/// <summary> /// Create <SignedSignatureProperties> /// </summary> /// <param name="document"></param> /// <returns></returns> internal XmlElement CreateXadesSignatureProperties(XmlDocument document, X509Certificate2 certificate, SignatureType xadesVersion) { XmlElement signatureProperties = document.CreateElement("SignedSignatureProperties", Xades.XadesNamespaceUrl); // signing time; required for 1.1.1 if (SigningTime.HasValue || xadesVersion < SignatureType.Xades132) { signatureProperties.CreateChild("SigningTime", Xades.XadesNamespaceUrl, (SigningTime ?? DateTime.Now).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")); } // signing certificate; can be omitted >= 1.3.2 if (IncludeSigningCertificate || xadesVersion < SignatureType.Xades132) { XmlElement signingCertificate = signatureProperties.CreateChild("SigningCertificate", Xades.XadesNamespaceUrl); XmlElement signingCert = signingCertificate.CreateChild("Cert", Xades.XadesNamespaceUrl); // certificate digest HashAlgorithm hashAlg = CryptoConfig.CreateFromName(CertificateDigest) as HashAlgorithm; if (hashAlg == null) { throw new CryptographicException("Invalid digest method"); } DigestAlgAndValue certDigest = new DigestAlgAndValue() { Algorithm = CertificateDigest, Digest = hashAlg.ComputeHash(certificate.RawData) }; signingCert.AppendChild(certDigest.CreateXml(signingCert, "CertDigest", Xades.XadesNamespaceUrl)); // certificate issuer XmlElement issuerSerial = signingCert.CreateChild("IssuerSerial", Xades.XadesNamespaceUrl); issuerSerial.CreateChild("X509IssuerName", SignedXml.XmlDsigNamespaceUrl, certificate.Issuer); issuerSerial.CreateChild("X509SerialNumber", SignedXml.XmlDsigNamespaceUrl, XadesUtils.ToDecimal(XadesUtils.HexToBytes(certificate.SerialNumber))); } // signature policy; can be omitted >= 1.3.2 XmlElement sigPolicyId = PolicyId?.GetObjectIdentifier(document, "SigPolicyId", Xades.XadesNamespaceUrl); if (PolicyImplied || xadesVersion < SignatureType.Xades132 || sigPolicyId != null) { XmlElement signaturePolicyIdentifier = signatureProperties.CreateChild("SignaturePolicyIdentifier", Xades.XadesNamespaceUrl); // policy implied if specified (or policyid not specified) if (PolicyImplied || sigPolicyId == null) { signaturePolicyIdentifier.CreateChild("SignaturePolicyImplied", Xades.XadesNamespaceUrl); } else if (sigPolicyId != null) { XmlElement signaturePolicyId = signaturePolicyIdentifier.CreateChild("SignaturePolicyId", Xades.XadesNamespaceUrl); signaturePolicyId.AppendChild(sigPolicyId); if (PolicyTransformChain != null && PolicyTransformChain.Count > 0) { MethodInfo getXmlInfo = typeof(TransformChain).GetMethod("GetXml", BindingFlags.NonPublic | BindingFlags.Instance); signaturePolicyId.AppendChild((XmlElement)getXmlInfo.Invoke(PolicyTransformChain, new object[] { document, SignedXml.XmlDsigNamespaceUrl })); } if (PolicyDigest == null) { CalculatePolicyHash(PolicyURIs.FirstOrDefault() ?? PolicyId.Identifier); } DigestAlgAndValue policyHash = new DigestAlgAndValue() { Algorithm = PolicyDigestMethod, Digest = PolicyDigest }; policyHash.CreateXml(signaturePolicyId, "SigPolicyHash", Xades.XadesNamespaceUrl); XmlElement sigPolicyQualifiers = document.CreateElement("SigPolicyQualifiers", Xades.XadesNamespaceUrl); if (PolicyURIs != null && PolicyURIs.Count > 0) { foreach (string uri in PolicyURIs) { sigPolicyQualifiers.CreateChild("SigPolicyQualifier", Xades.XadesNamespaceUrl).CreateChild("SPURI", Xades.XadesNamespaceUrl, uri); } } if (PolicyNotices != null && PolicyNotices.Count > 0) { foreach (PolicyUserNotice notice in PolicyNotices) { notice.CreateXml(sigPolicyQualifiers.CreateChild("SigPolicyQualifier", Xades.XadesNamespaceUrl)); } } if (sigPolicyQualifiers.ChildNodes.Count > 0) { signaturePolicyId.AppendChild(sigPolicyQualifiers); } } } return(signatureProperties); }
/// <summary> /// Create a collection of webhooks capable of anonymously executing a scaling policy. /// </summary> /// <param name="service">The Auto Scale service instance.</param> /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param> /// <param name="policyId">The ID of the scaling policy. This is obtained from <see cref="Policy.Id">Policy.Id</see>.</param> /// <param name="configurations">A collection of <see cref="NewWebhookConfiguration"/> objects describing the webhook configurations.</param> /// <returns>A collection of <see cref="Webhook"/> objects describing the newly created webhooks.</returns> /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"> /// If <paramref name="groupId"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="policyId"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="configurations"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentException">If <paramref name="configurations"/> contains any <see langword="null"/> values.</exception> /// <exception cref="WebException">If the REST request does not return successfully.</exception> /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_createWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks_autoscale-webhooks.html">Create a webhook (Rackspace Auto Scale Developer Guide - API v1.0)</seealso> public static ReadOnlyCollection <Webhook> CreateWebhookRange(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, IEnumerable <NewWebhookConfiguration> configurations) { if (service == null) { throw new ArgumentNullException("service"); } try { return(service.CreateWebhookRangeAsync(groupId, policyId, configurations, CancellationToken.None).Result); } catch (AggregateException ex) { ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) { throw innerExceptions[0]; } throw; } }
/// <inheritdoc/> public Task <ReadOnlyCollection <Webhook> > CreateWebhookRangeAsync(ScalingGroupId groupId, PolicyId policyId, IEnumerable <NewWebhookConfiguration> configurations, CancellationToken cancellationToken) { if (groupId == null) { throw new ArgumentNullException("groupId"); } if (policyId == null) { throw new ArgumentNullException("policyId"); } if (configurations == null) { throw new ArgumentNullException("configurations"); } NewWebhookConfiguration[] configurationsArray = configurations.ToArray(); if (configurationsArray.Contains(null)) { throw new ArgumentException("configurations cannot contain any null values", "configurations"); } UriTemplate template = new UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks"); var parameters = new Dictionary <string, string> { { "groupId", groupId.Value }, { "policyId", policyId.Value } }; Func <Task <Tuple <IdentityToken, Uri> >, Task <HttpWebRequest> > prepareRequest = PrepareRequestAsyncFunc(HttpMethod.POST, template, parameters, configurations); Func <Task <HttpWebRequest>, Task <JObject> > requestResource = GetResponseAsyncFunc <JObject>(cancellationToken); Func <Task <JObject>, ReadOnlyCollection <Webhook> > resultSelector = task => { JObject result = task.Result; if (result == null) { return(null); } JToken valueToken = result["webhooks"]; if (valueToken == null) { return(null); } ReadOnlyCollection <Webhook> webhooks = valueToken.ToObject <ReadOnlyCollection <Webhook> >(); return(webhooks); }; return(AuthenticateServiceAsync(cancellationToken) .Then(prepareRequest) .Then(requestResource) .Select(resultSelector)); }
public RuleEngineBasedPolicy GetRuleBasePolicyById(PolicyId policyId) { return(Session.Query <Policy>().OfType <RuleEngineBasedPolicy>().First(re => re.Id == policyId)); }
/// <inheritdoc/> public Task <ReadOnlyCollectionPage <Webhook> > ListWebhooksAsync(ScalingGroupId groupId, PolicyId policyId, WebhookId marker, int?limit, CancellationToken cancellationToken) { if (groupId == null) { throw new ArgumentNullException("groupId"); } if (policyId == null) { throw new ArgumentNullException("policyId"); } if (limit <= 0) { throw new ArgumentOutOfRangeException("limit"); } UriTemplate template = new UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks/?marker={marker}&limit={limit}"); var parameters = new Dictionary <string, string>() { { "groupId", groupId.Value }, { "policyId", policyId.Value } }; if (marker != null) { parameters.Add("marker", marker.Value); } if (limit != null) { parameters.Add("limit", limit.ToString()); } Func <Task <Tuple <IdentityToken, Uri> >, HttpWebRequest> prepareRequest = PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters); Func <Task <HttpWebRequest>, Task <JObject> > requestResource = GetResponseAsyncFunc <JObject>(cancellationToken); Func <Task <JObject>, ReadOnlyCollectionPage <Webhook> > resultSelector = task => { JObject result = task.Result; if (result == null) { return(null); } JToken valuesToken = result["webhooks"]; if (valuesToken == null) { return(null); } JToken linksToken = result["webhooks_links"]; Link[] links = linksToken != null?linksToken.ToObject <Link[]>() : null; Webhook[] values = valuesToken.ToObject <Webhook[]>(); WebhookId nextMarker = values.Any() && (links == null || links.Any(i => string.Equals(i.Rel, "next", StringComparison.OrdinalIgnoreCase))) ? values.Last().Id : null; Func <CancellationToken, Task <ReadOnlyCollectionPage <Webhook> > > getNextPageAsync = null; if (nextMarker != null) { getNextPageAsync = nextCancellationToken => ListWebhooksAsync(groupId, policyId, nextMarker, limit, cancellationToken); } return(new BasicReadOnlyCollectionPage <Webhook>(values, getNextPageAsync)); }; return(AuthenticateServiceAsync(cancellationToken) .Select(prepareRequest) .Then(requestResource) .Select(resultSelector)); }
public static void DeleteWebhook(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId) { if (service == null) throw new ArgumentNullException("service"); try { service.DeleteWebhookAsync(groupId, policyId, webhookId, CancellationToken.None).Wait(); } catch (AggregateException ex) { ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) throw innerExceptions[0]; throw; } }
public static ReadOnlyCollection<Webhook> CreateWebhookRange(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, IEnumerable<NewWebhookConfiguration> configurations) { if (service == null) throw new ArgumentNullException("service"); try { return service.CreateWebhookRangeAsync(groupId, policyId, configurations, CancellationToken.None).Result; } catch (AggregateException ex) { ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) throw innerExceptions[0]; throw; } }
public static ReadOnlyCollectionPage<Webhook> ListWebhooks(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId marker, int? limit) { if (service == null) throw new ArgumentNullException("service"); try { return service.ListWebhooksAsync(groupId, policyId, marker, limit, CancellationToken.None).Result; } catch (AggregateException ex) { ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) throw innerExceptions[0]; throw; } }
public Policy GetById(PolicyId policyId) { return(rep.FindByKey(policyId)); }
public void CompileRule(PolicyId policyId, string ruleContent) { var policy = policyRep.GetRuleBasePolicyById(policyId); ruleService.CompileRule(policy.RuleFunctions, ruleContent); }
/// <summary> /// Remove and delete a webhook associated with a scaling policy. /// </summary> /// <param name="service">The Auto Scale service instance.</param> /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param> /// <param name="policyId">The ID of the scaling policy. This is obtained from <see cref="Policy.Id">Policy.Id</see>.</param> /// <param name="webhookId">The ID of the webhook. This is obtained from <see cref="Webhook.Id">Webhook.Id</see>.</param> /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"> /// If <paramref name="groupId"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="policyId"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="webhookId"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="WebException">If the REST request does not return successfully.</exception> /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deleteWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__autoscale-webhooks.html">Delete webhook (Rackspace Auto Scale Developer Guide - API v1.0)</seealso> public static void DeleteWebhook(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId) { if (service == null) { throw new ArgumentNullException("service"); } try { service.DeleteWebhookAsync(groupId, policyId, webhookId, CancellationToken.None).Wait(); } catch (AggregateException ex) { ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) { throw innerExceptions[0]; } throw; } }
public static Policy GetPolicy(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId) { if (service == null) throw new ArgumentNullException("service"); try { return service.GetPolicyAsync(groupId, policyId, CancellationToken.None).Result; } catch (AggregateException ex) { ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) throw innerExceptions[0]; throw; } }
/// <summary> /// Writes an authorization policy an XmlWriter. /// </summary> /// <param name="writer">Writer to write the authorization policy.</param> public override void WriteXml(XmlWriter writer) { _ = writer ?? throw new ArgumentNullException(nameof(writer)); writer.WriteStartElement(AuthorizationConstants.Elements.AuthorizationPolicy, AuthorizationConstants.Namespaces.Xmlns); if (PolicyId != null) { writer.WriteAttributeString(AuthorizationConstants.Attributes.PolicyId, PolicyId.ToString()); } writer.WriteAttributeString(AuthorizationConstants.Attributes.Delegation, XmlConvert.ToString(Delegation)); Expression.WriteXml(writer); if (Transforms != null) { Transforms.WriteXml(writer); } writer.WriteEndElement(); }