Exemplo n.º 1
0
 public static void ThrowInvalidArgumentError(this ServiceManagementBaseCmdlet cmdlet, string format, params object[] args)
 {
     cmdlet.ThrowTerminatingError(
         new ErrorRecord(
             new ArgumentException(string.Format(CultureInfo.CurrentUICulture, format, args)),
             string.Empty,
             ErrorCategory.InvalidArgument,
             null));
 }
Exemplo n.º 2
0
        public ExtensionManager(ServiceManagementBaseCmdlet cmdlet, string serviceName)
        {
            if (cmdlet == null || cmdlet.Profile.Context.Subscription == null)
            {
                throw new ArgumentNullException("cmdlet");
            }

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            Cmdlet         = cmdlet;
            SubscriptionId = cmdlet.Profile.Context.Subscription.Id.ToString();
            ServiceName    = serviceName;
        }
Exemplo n.º 3
0
        public ExtensionManager(ServiceManagementBaseCmdlet cmdlet, string serviceName)
        {
            if (cmdlet == null || cmdlet.Profile.Context.Subscription == null)
            {
                throw new ArgumentNullException("cmdlet");
            }

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            Cmdlet = cmdlet;
            SubscriptionId = cmdlet.Profile.Context.Subscription.Id.ToString();
            ServiceName = serviceName;
        }
        public static VhdDownloadContext Download(DownloaderParameters downloadParameters, ServiceManagementBaseCmdlet cmdlet)
        {
            Program.SyncOutput = new PSSyncOutputEvents(cmdlet);

            downloadParameters.ProgressDownloadComplete = Program.SyncOutput.ProgressDownloadComplete;
            downloadParameters.ProgressDownloadStatus = Program.SyncOutput.ProgressDownloadStatus;

            var downloader = new Downloader(downloadParameters);
            downloader.Download();

            return new VhdDownloadContext
            {
                LocalFilePath =  new FileInfo(downloadParameters.LocalFilePath),
                Source = downloadParameters.BlobUri.Uri
            };
        }
Exemplo n.º 5
0
        public ExtensionManager(ServiceManagementBaseCmdlet cmdlet, string serviceName)
        {
            if (cmdlet == null || cmdlet.Channel == null || cmdlet.CurrentSubscription == null)
            {
                throw new ArgumentNullException("cmdlet");
            }

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            Cmdlet = cmdlet;
            Channel = cmdlet.Channel;
            SubscriptionId = cmdlet.CurrentSubscription.SubscriptionId;
            ServiceName = serviceName;
        }
Exemplo n.º 6
0
        public ExtensionManager(ServiceManagementBaseCmdlet cmdlet, string serviceName)
        {
            if (cmdlet == null || cmdlet.Channel == null || cmdlet.CurrentSubscription == null)
            {
                throw new ArgumentNullException("cmdlet");
            }

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            Cmdlet         = cmdlet;
            Channel        = cmdlet.Channel;
            SubscriptionId = cmdlet.CurrentSubscription.SubscriptionId;
            ServiceName    = serviceName;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Attempts to get the user's credentials from the given Storage Context or the current subscription, if the former is null.
        /// Throws a terminating error if the credentials cannot be determined.
        /// </summary>
        public static StorageCredentials GetStorageCredentials(this ServiceManagementBaseCmdlet cmdlet, AzureStorageContext storageContext)
        {
            StorageCredentials credentials = null;

            if (storageContext != null)
            {
                credentials = storageContext.StorageAccount.Credentials;
            }
            else
            {
                var storageAccountName = cmdlet.CurrentContext.Subscription.GetProperty(AzureSubscription.Property.StorageAccount);

                if (!string.IsNullOrEmpty(storageAccountName))
                {
                    var keys = cmdlet.StorageClient.StorageAccounts.GetKeys(storageAccountName);

                    if (keys != null)
                    {
                        var storageAccountKey = string.IsNullOrEmpty(keys.PrimaryKey) ? keys.SecondaryKey : keys.PrimaryKey;

                        credentials = new StorageCredentials(storageAccountName, storageAccountKey);
                    }
                }
            }

            if (credentials == null)
            {
                cmdlet.ThrowTerminatingError(
                    new ErrorRecord(
                        new UnauthorizedAccessException(Resources.AzureVMDscDefaultStorageCredentialsNotFound),
                        string.Empty,
                        ErrorCategory.PermissionDenied,
                        null));
            }

            if (string.IsNullOrEmpty(credentials.AccountName))
            {
                cmdlet.ThrowInvalidArgumentError(Resources.AzureVMDscStorageContextMustIncludeAccountName);
            }

            return(credentials);
        }
Exemplo n.º 8
0
 public ClientProvider(ServiceManagementBaseCmdlet baseCmdlet)
 {
     this.svcMgmtBaseCmdlet = baseCmdlet;
 }
        public static VhdDownloadContext Download(DownloaderParameters downloadParameters, ServiceManagementBaseCmdlet cmdlet)
        {
            Program.SyncOutput = new PSSyncOutputEvents(cmdlet);

            downloadParameters.ProgressDownloadComplete = Program.SyncOutput.ProgressDownloadComplete;
            downloadParameters.ProgressDownloadStatus   = Program.SyncOutput.ProgressDownloadStatus;

            var downloader = new Downloader(downloadParameters);

            downloader.Download();

            return(new VhdDownloadContext
            {
                LocalFilePath = new FileInfo(downloadParameters.LocalFilePath),
                Source = downloadParameters.BlobUri.Uri
            });
        }