/// <summary>
        /// Use this method to fetch the Registration Key which can used for device registration.
        /// </summary>
        /// <param name="operations">
        /// The operations group for this extension method.
        /// </param>
        /// <param name="resourceGroupName">
        /// The resource group name.
        /// </param>
        /// <param name="managerName">
        /// The manager name.
        /// </param>
        /// <returns>
        /// The device registration key.
        /// </returns>
        public static string GetDeviceRegistrationKey(this IManagersOperations operations, string resourceGroupName, string managerName)
        {
            Key activationKey = null;

            try
            {
                activationKey = operations.GetActivationKey(resourceGroupName, managerName);
            }
            catch (Exception exception)
            {
                throw new Exception(
                          "The call to get the activation key failed. Check inner exception for more details.",
                          exception);
            }

            ManagerExtendedInfo managerExtendedInfo = null;

            try
            {
                managerExtendedInfo = operations.GetExtendedInfo(resourceGroupName, managerName);
            }
            catch (Microsoft.Rest.Azure.CloudException cloudException)
            {
                if (cloudException != null && cloudException.Response != null &&
                    !string.IsNullOrEmpty(cloudException.Response.Content))
                {
                    #if FullNetFx
                    if (cloudException.Response.Content.IndexOf("ResourceExtendedInfoNotFound", StringComparison.InvariantCultureIgnoreCase) >= 0)
                    #else
                    if (cloudException.Response.Content.IndexOf("ResourceExtendedInfoNotFound", StringComparison.OrdinalIgnoreCase) >= 0)
                    #endif
                    {
                        // Manager extended info not found for manager, creating new extended info"
                        var extendedInfo = new ManagerExtendedInfo()
                        {
                            IntegrityKey = GenerateRandomKey(128),
                            Algorithm    = "None",
                        };

                        managerExtendedInfo = operations.CreateExtendedInfo(extendedInfo, resourceGroupName, managerName);
                    }
                    else
                    {
                        // cases like user session token expired, etc.
                        throw cloudException;
                    }
                }
            }

            var registrationKeyWithoutHash = string.Format(
                "{0}:{1}",
                activationKey.ActivationKey,
                managerExtendedInfo.IntegrityKey);

            var sha512Hash = GenerateSha512Hash(registrationKeyWithoutHash);

            var truncatedHash = sha512Hash.Substring(0, 16);

            return(string.Format("{0}#{1}", registrationKeyWithoutHash, truncatedHash));
        }
 /// <summary>
 /// Updates the extended info of the manager.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='parameters'>
 /// The manager extended information.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The resource group name
 /// </param>
 /// <param name='managerName'>
 /// The manager name
 /// </param>
 /// <param name='ifMatch'>
 /// Pass the ETag of ExtendedInfo fetched from GET call
 /// </param>
 public static ManagerExtendedInfo UpdateExtendedInfo(this IManagersOperations operations, ManagerExtendedInfo parameters, string resourceGroupName, string managerName, string ifMatch)
 {
     return(operations.UpdateExtendedInfoAsync(parameters, resourceGroupName, managerName, ifMatch).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Updates the extended info of the manager.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='parameters'>
 /// The manager extended information.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The resource group name
 /// </param>
 /// <param name='managerName'>
 /// The manager name
 /// </param>
 /// <param name='ifMatch'>
 /// Pass the ETag of ExtendedInfo fetched from GET call
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ManagerExtendedInfo> UpdateExtendedInfoAsync(this IManagersOperations operations, ManagerExtendedInfo parameters, string resourceGroupName, string managerName, string ifMatch, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateExtendedInfoWithHttpMessagesAsync(parameters, resourceGroupName, managerName, ifMatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates the extended info of the manager.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='managerExtendedInfo'>
 /// The manager extended information.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The resource group name
 /// </param>
 /// <param name='managerName'>
 /// The manager name
 /// </param>
 public static ManagerExtendedInfo CreateExtendedInfo(this IManagersOperations operations, ManagerExtendedInfo managerExtendedInfo, string resourceGroupName, string managerName)
 {
     return(operations.CreateExtendedInfoAsync(managerExtendedInfo, resourceGroupName, managerName).GetAwaiter().GetResult());
 }