public override void ExecuteCmdlet() { MediaServicesClient = MediaServicesClient ?? new MediaServicesClient(CurrentSubscription, WriteDebug); StorageAccountGetKeysResponse storageKeysResponse = null; Uri storageEndPoint = null; string storageAccountKey = null; CatchAggregatedExceptionFlattenAndRethrow(() => { storageKeysResponse = MediaServicesClient.GetStorageServiceKeysAsync(StorageAccountName).Result; }); storageAccountKey = storageKeysResponse.PrimaryKey; StorageServiceGetResponse storageGetResponse = null; CatchAggregatedExceptionFlattenAndRethrow(() => { storageGetResponse = MediaServicesClient.GetStorageServicePropertiesAsync(StorageAccountName).Result; }); if (storageGetResponse.Properties != null && storageGetResponse.Properties.Endpoints.Count > 0) { storageEndPoint = storageGetResponse.Properties.Endpoints[0]; } else { throw new Exception(string.Format(Resources.EndPointNotFoundForBlobStorage, Name)); } AccountCreationResult result = null; var request = new MediaServicesAccountCreateParameters() { AccountName = Name, BlobStorageEndpointUri = storageEndPoint, Region = Location, StorageAccountKey = storageAccountKey, StorageAccountName = StorageAccountName }; CatchAggregatedExceptionFlattenAndRethrow(() => { result = new AccountCreationResult(MediaServicesClient.CreateNewAzureMediaServiceAsync(request).Result); }); WriteObject(result, false); }
public async void HandleMessage(Client.Client sender, PacketReader stream) { if (sender == null) { throw new ArgumentNullException(nameof(sender)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } try { string userName = stream.ReadString(); string password = stream.ReadString(); AccountCreationResult result = await _AuthenticationService.CreateAccountAsync(userName, password); if (result is AccountCreationSuccessful successfulResult) { using (var writer = _PacketWriterPool.GetScriptMessageStream(ScriptMessages.AccountCreationResult)) { writer.Write(true); sender.SendScriptMessage(writer, NetPriority.Medium, NetReliability.ReliableOrdered); } } else if (result is AccountCreationFailed failedResult) { using (var writer = _PacketWriterPool.GetScriptMessageStream(ScriptMessages.AccountCreationResult)) { writer.Write(false); writer.Write(failedResult.ReasonText); sender.SendScriptMessage(writer, NetPriority.Medium, NetReliability.ReliableOrdered); } } } catch (Exception e) { _Log.Error($"Something went wrong while trying to handle a '{SupportedMessage}' script message. Exception: {e}"); } }
public override void ExecuteCmdlet() { MediaServicesClient = MediaServicesClient ?? new MediaServicesClient(Profile, Profile.Context.Subscription, WriteDebug); StorageAccountGetKeysResponse storageKeysResponse = null; Uri storageEndPoint = null; string storageAccountKey = null; CatchAggregatedExceptionFlattenAndRethrow(() => { storageKeysResponse = MediaServicesClient.GetStorageServiceKeysAsync(StorageAccountName).Result; }); storageAccountKey = storageKeysResponse.PrimaryKey; StorageAccountGetResponse storageGetResponse = null; CatchAggregatedExceptionFlattenAndRethrow(() => { storageGetResponse = MediaServicesClient.GetStorageServicePropertiesAsync(StorageAccountName).Result; }); if (storageGetResponse.StorageAccount.Properties != null && storageGetResponse.StorageAccount.Properties.Endpoints.Count > 0) { storageEndPoint = storageGetResponse.StorageAccount.Properties.Endpoints[0]; } else { throw new Exception(string.Format(Resources.EndPointNotFoundForBlobStorage, Name)); } AccountCreationResult result = null; var request = new MediaServicesAccountCreateParameters() { AccountName = Name, BlobStorageEndpointUri = storageEndPoint, Region = Location, StorageAccountKey = storageAccountKey, StorageAccountName = StorageAccountName }; CatchAggregatedExceptionFlattenAndRethrow(() => { result = new AccountCreationResult(MediaServicesClient.CreateNewAzureMediaServiceAsync(request).Result); }); WriteObject(result, false); }
public override void ExecuteCmdlet() { MediaServicesClient = MediaServicesClient ?? new MediaServicesClient(CurrentSubscription, WriteDebug); StorageService storage = null; Uri storageEndPoint = null; string storageAccountKey = null; CatchAggregatedExceptionFlattenAndRethrow(() => { storage = MediaServicesClient.GetStorageServiceKeys(StorageAccountName).Result; }); storageAccountKey = storage.StorageServiceKeys.Primary; CatchAggregatedExceptionFlattenAndRethrow(() => { storage = MediaServicesClient.GetStorageServiceProperties(StorageAccountName).Result; }); if (storage.StorageServiceProperties != null && storage.StorageServiceProperties.Endpoints.Count > 0) { storageEndPoint = new Uri(storage.StorageServiceProperties.Endpoints[0]); } else { throw new Exception(string.Format(Utilities.Properties.Resources.EndPointNotFoundForBlobStorage, Name)); } AccountCreationResult result = null; var request = new AccountCreationRequest { AccountName = Name, BlobStorageEndpointUri = storageEndPoint.ToString(), Region = Location, StorageAccountKey = storageAccountKey, StorageAccountName = StorageAccountName }; CatchAggregatedExceptionFlattenAndRethrow(() => { result = MediaServicesClient.CreateNewAzureMediaServiceAsync(request).Result; }); WriteObject(result, false); }
public void NewMediaServiceAccountShouldPassWithValidParameters() { // Setup Mock <IMediaServicesClient> clientMock = new Mock <IMediaServicesClient>(); const string storageAccountName = "teststorage"; const string storageAccountKey = "key"; const string accountName = "testaccount"; const string region = "West US"; const string blobStorageEndpointUri = "http://awesome.blob.core.windows.net/"; MediaServicesAccountCreateParameters request = new MediaServicesAccountCreateParameters { AccountName = accountName, BlobStorageEndpointUri = new Uri(blobStorageEndpointUri), Region = region, StorageAccountKey = storageAccountKey, StorageAccountName = storageAccountName }; clientMock.Setup(f => f.CreateNewAzureMediaServiceAsync(It.Is <MediaServicesAccountCreateParameters>(creationRequest => request.AccountName == accountName))).Returns( Task.Factory.StartNew(() => new MediaServicesAccountCreateResponse { Account = new MediaServicesCreatedAccount { AccountId = Guid.NewGuid().ToString(), AccountName = request.AccountName, SubscriptionId = Guid.NewGuid().ToString() } })); clientMock.Setup(f => f.GetStorageServiceKeysAsync(storageAccountName)).Returns( Task.Factory.StartNew(() => new StorageAccountGetKeysResponse { PrimaryKey = storageAccountKey, SecondaryKey = storageAccountKey })); clientMock.Setup(f => f.GetStorageServicePropertiesAsync(storageAccountName)).Returns(Task.Factory.StartNew(() => { StorageAccountGetResponse response = new StorageAccountGetResponse { StorageAccount = new StorageAccount { Properties = new StorageAccountProperties() } }; response.StorageAccount.Properties.Endpoints.Add(new Uri(blobStorageEndpointUri)); return(response); })); // Test NewAzureMediaServiceCommand command = new NewAzureMediaServiceCommand { CommandRuntime = new MockCommandRuntime(), Name = accountName, Location = region, StorageAccountName = storageAccountName, MediaServicesClient = clientMock.Object, }; command.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count); AccountCreationResult accountCreationResult = (AccountCreationResult)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(accountCreationResult); Assert.AreEqual(accountName, accountCreationResult.Name); }
public string Format(AccountCreationResult account) { return($"ptc,{account.Username},{account.Password}"); }
void SendCallback(AccountCreationResult result) { m_CreationCallback(result, userTB.Text, nickTB.Text); Close(); }