コード例 #1
0
        /// <summary>
        /// Fetches policies by name
        /// </summary>
        /// <param name="policyName">Name of the policy to be fetched</param>
        /// <param name="serviceClientAdapter">Service client adapter with which to make calls</param>
        /// <param name="vaultName"></param>
        /// <param name="resourceGroupName"></param>
        /// <returns></returns>
        public static ProtectionPolicyResource GetProtectionPolicyByName(
            string policyName,
            ServiceClientAdapter serviceClientAdapter,
            string vaultName         = null,
            string resourceGroupName = null)
        {
            ProtectionPolicyResource response = null;

            try
            {
                response = serviceClientAdapter.GetProtectionPolicy(
                    policyName,
                    vaultName: vaultName,
                    resourceGroupName: resourceGroupName);
                Logger.Instance.WriteDebug("Successfully fetched policy from service: " + policyName);
            }
            catch (AggregateException exception)
            {
                // if http response is NotFound - then ignore and return NULL response
                if (exception.InnerException != null && exception.InnerException is CloudException)
                {
                    var cloudEx = exception.InnerException as CloudException;
                    if (cloudEx.Response != null)
                    {
                        if (cloudEx.Response.StatusCode != SystemNet.HttpStatusCode.NotFound)
                        {
                            Logger.Instance.WriteDebug("CloudException Response statusCode: " +
                                                       cloudEx.Response.StatusCode);
                            throw;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                else
                {
                    throw;
                }
            }

            return(response);
        }