public void SaveMediaServiceAccountToSingleDeploymentTest() { // var deploymentToTest = App.Config.Content.ContentProviders[0].MediaServicesSets[1].DataStorageConnections[0]; MediaServicesAccount acct = new MediaServicesAccount { AccountName = App.Config.Content.ContentProviders[0].MediaServicesSets[1].DataStorageConnections[0].AcctName, Location = "US West", SubscriptionName = "AMSLiveStream", AccountCreated = DateTime.Now }; _dataAccess = new AzureDataAccess(App.Config.Content.ContentProviders[0].MediaServicesSets[1].DataStorageConnections); try { var acctList = _dataAccess.SaveMediaServiceAccount(acct, deploymentToTest);//, true); Assert.IsTrue((acctList != null), "Data Connection / Configuration Error"); } catch (Exception ex) { Assert.Fail(ex.Message, ex); } }
//If you get HTTP409: media service name has a conflict with an existing one. private static void CreateMediaServiceAccount() { ManagementRESTAPIHelper helper = new ManagementRESTAPIHelper("https://management.core.windows.net", "A3022B01D70924D819CBD0DC118D22ACAC29DE36", "2db39a66-f5c5-4b03-9d1c-71018352379b"); // Initialize the AccountInfo class. MediaServicesAccount accountInfo = new MediaServicesAccount(); accountInfo.AccountName = "testwzms"; accountInfo.Region = "West US"; accountInfo.StorageAccountName = "testwzstor"; accountInfo.StorageAccountKey = "aPlz4nSy3utNCESR9rTjN2E1QUJnpFPXnE2iRhx8D05HXpQ25X5bNcPMUL/8/k+owfOtTpMCC9gjkXYIImmV8A=="; accountInfo.BlobStorageEndpointUri = "https://testwzstor.blob.core.windows.net/"; AttachStorageAccountRequest storageAccountToAttach = new AttachStorageAccountRequest(); storageAccountToAttach.StorageAccountName = "testwzstor"; storageAccountToAttach.StorageAccountKey = "aPlz4nSy3utNCESR9rTjN2E1QUJnpFPXnE2iRhx8D05HXpQ25X5bNcPMUL/8/k+owfOtTpMCC9gjkXYIImmV8A=="; storageAccountToAttach.BlobStorageEndpointUri = "https://testwzstor.blob.core.windows.net/"; // Call CreateMediaServiceAccountUsingXmlContentType to create a new Media Services account. helper.CreateMediaServiceAccountUsingXmlContentType(accountInfo); // Call AttachStorageAccountToMediaServiceAccount to attach an existing storage account to the Media Services account. //helper.AttachStorageAccountToMediaServiceAccount(accountInfo, storageAccountToAttach); // Call the following methods to get details about Media Services account. //helper.GetAccountDetails(accountInfo); //helper.ListAvailableRegions(accountInfo); //helper.ListSubscriptionAccounts(accountInfo); }
public void Post([FromBody] string value) { MediaServicesAccount acct = new MediaServicesAccount(); /* I know tha tthe string coming in is going to be a json string, but from there, I'm lost*/ }
/// <summary> /// The Get Media Services Account operation gets detailed information /// about a media services account in Windows Azure. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166974.aspx /// for more information) /// </summary> /// <param name='accountName'> /// The name of the Media Services account. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The Get Media Services Account operation response. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.MediaServices.Models.MediaServicesAccountGetResponse> GetAsync(string accountName, CancellationToken cancellationToken) { // Validate if (accountName == null) { throw new ArgumentNullException("accountName"); } // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("accountName", accountName); Tracing.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = new Uri(this.Client.BaseUri, "/").ToString() + this.Client.Credentials.SubscriptionId + "/services/mediaservices/Accounts/" + accountName; // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2011-10-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Json); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result MediaServicesAccountGetResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new MediaServicesAccountGetResponse(); JToken responseDoc = JToken.Parse(responseContent); if (responseDoc != null && responseDoc.Type != JTokenType.Null) { MediaServicesAccount accountInstance = new MediaServicesAccount(); result.Account = accountInstance; JToken accountNameValue = responseDoc["AccountName"]; if (accountNameValue != null && accountNameValue.Type != JTokenType.Null) { string accountNameInstance = (string)accountNameValue; accountInstance.AccountName = accountNameInstance; } JToken accountKeyValue = responseDoc["AccountKey"]; if (accountKeyValue != null && accountKeyValue.Type != JTokenType.Null) { string accountKeyInstance = (string)accountKeyValue; accountInstance.AccountKey = accountKeyInstance; } JToken accountKeysValue = responseDoc["AccountKeys"]; if (accountKeysValue != null && accountKeysValue.Type != JTokenType.Null) { MediaServicesAccount.AccountKeys accountKeysInstance = new MediaServicesAccount.AccountKeys(); accountInstance.StorageAccountKeys = accountKeysInstance; JToken primaryValue = accountKeysValue["Primary"]; if (primaryValue != null && primaryValue.Type != JTokenType.Null) { string primaryInstance = (string)primaryValue; accountKeysInstance.Primary = primaryInstance; } JToken secondaryValue = accountKeysValue["Secondary"]; if (secondaryValue != null && secondaryValue.Type != JTokenType.Null) { string secondaryInstance = (string)secondaryValue; accountKeysInstance.Secondary = secondaryInstance; } } JToken accountRegionValue = responseDoc["AccountRegion"]; if (accountRegionValue != null && accountRegionValue.Type != JTokenType.Null) { string accountRegionInstance = (string)accountRegionValue; accountInstance.AccountRegion = accountRegionInstance; } JToken storageAccountNameValue = responseDoc["StorageAccountName"]; if (storageAccountNameValue != null && storageAccountNameValue.Type != JTokenType.Null) { string storageAccountNameInstance = (string)storageAccountNameValue; accountInstance.StorageAccountName = storageAccountNameInstance; } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
/// <summary> /// The Get Media Services Account operation gets detailed information /// about a media services account in Windows Azure. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166974.aspx /// for more information) /// </summary> /// <param name='accountName'> /// Required. The name of the Media Services account. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The Get Media Services Account operation response. /// </returns> public async Task <MediaServicesAccountGetResponse> GetAsync(string accountName, CancellationToken cancellationToken) { // Validate if (accountName == null) { throw new ArgumentNullException("accountName"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("accountName", accountName); TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/services/mediaservices/Accounts/"; url = url + Uri.EscapeDataString(accountName); string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2011-10-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result MediaServicesAccountGetResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new MediaServicesAccountGetResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { MediaServicesAccount accountInstance = new MediaServicesAccount(); result.Account = accountInstance; JToken accountNameValue = responseDoc["AccountName"]; if (accountNameValue != null && accountNameValue.Type != JTokenType.Null) { string accountNameInstance = ((string)accountNameValue); accountInstance.AccountName = accountNameInstance; } JToken accountKeyValue = responseDoc["AccountKey"]; if (accountKeyValue != null && accountKeyValue.Type != JTokenType.Null) { string accountKeyInstance = ((string)accountKeyValue); accountInstance.AccountKey = accountKeyInstance; } JToken accountKeysValue = responseDoc["AccountKeys"]; if (accountKeysValue != null && accountKeysValue.Type != JTokenType.Null) { MediaServicesAccount.AccountKeys accountKeysInstance = new MediaServicesAccount.AccountKeys(); accountInstance.StorageAccountKeys = accountKeysInstance; JToken primaryValue = accountKeysValue["Primary"]; if (primaryValue != null && primaryValue.Type != JTokenType.Null) { string primaryInstance = ((string)primaryValue); accountKeysInstance.Primary = primaryInstance; } JToken secondaryValue = accountKeysValue["Secondary"]; if (secondaryValue != null && secondaryValue.Type != JTokenType.Null) { string secondaryInstance = ((string)secondaryValue); accountKeysInstance.Secondary = secondaryInstance; } } JToken accountRegionValue = responseDoc["AccountRegion"]; if (accountRegionValue != null && accountRegionValue.Type != JTokenType.Null) { string accountRegionInstance = ((string)accountRegionValue); accountInstance.AccountRegion = accountRegionInstance; } JToken storageAccountNameValue = responseDoc["StorageAccountName"]; if (storageAccountNameValue != null && storageAccountNameValue.Type != JTokenType.Null) { string storageAccountNameInstance = ((string)storageAccountNameValue); accountInstance.StorageAccountName = storageAccountNameInstance; } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
public async Task RunAsync() { string logmessage = string.Empty; DateTime loopStart = DateTime.Now; try { int numberOfAccounts = DataAccess.GetAccounts().Count; //dynamic add from the config file int added = DataAccess.SaveMediaServiceAccount(MediaService.Config); if (numberOfAccounts == 0 && added == 1) { Trace.TraceInformation("{0} Account added to AMS Dashboard", MediaService.Config.AccountName); } else if (numberOfAccounts > 0 && added >= 1) { Trace.TraceInformation("{0} Account Already exists in AMS Dashboard", MediaService.Config.AccountName); } else { Trace.TraceInformation("{0} Account NOT added to AMS Dashboard, Please Check GlobalAlerts", MediaService.Config.AccountName); } try { #region More Detailed Information DateTime channelStart = DateTime.UtcNow; var channels = Task.Run(() => ProcessChannels()); await Task.WhenAll(channels); TotalCompletionTime = DateTime.UtcNow.Subtract(channelStart); string completed = string.Format("{0} Channel Processing completed in {1}", MediaService.Name, TotalCompletionTime); Trace.TraceInformation(completed); DateTime progStart = DateTime.UtcNow; var programs = Task.Run(() => ProcessPrograms()); await Task.WhenAll(programs); TotalCompletionTime += DateTime.UtcNow.Subtract(progStart); completed = string.Format("{0} Program Processing completed in {1}", MediaService.Name, DateTime.UtcNow.Subtract(progStart)); Trace.TraceInformation(completed); DateTime orgStart = DateTime.UtcNow; var origins = Task.Run(() => ProcessOrigins()); await Task.WhenAll(origins); TotalCompletionTime += DateTime.UtcNow.Subtract(orgStart); completed = string.Format("{0} Origin Processing completed in {1}", MediaService.Name, DateTime.UtcNow.Subtract(orgStart)); Trace.TraceInformation(completed); Trace.TraceInformation("Total Completion Time for {0}: {1}", MediaService.Name, TotalCompletionTime); #endregion #region Less Detailed information //var channels = Task.Run(() => ProcessChannels()); //var programs = Task.Run(() => ProcessPrograms()); //var origins = Task.Run(() => ProcessOrigins()); //await Task.WhenAll(channels, programs, origins); #endregion } catch (Exception parEx) { Trace.TraceError("Exception while processing metrics for {0}: {1}", MediaService.Name, parEx); } Account.FindChannelOriginMapping(); _cache.SetAs(Account.Id, Account); Trace.TraceInformation("Added account:{0} Key:{1} to cache.", Account.Name, Account.Id); } catch (AggregateException ae) { Trace.TraceError("Exception while processing metrics for {0}: {1}", MediaService.Name, ae.Flatten()); } catch (Exception ex) { Trace.TraceError("Exception while processing metrics for {0}: {1}", MediaService.Name, ex.Message, ex); } finally { var loopEnd = DateTime.Now; var runTime = loopEnd.Subtract(loopStart); string runDetails = string.Format("Account:{0} Loop execution time:{1}", MediaService.Name, runTime); Trace.TraceInformation(runDetails); if (runTime.Duration().Seconds > 30) { MediaServicesAccount acct = DataAccess.GetAccount(MediaService.Name); Alert yellowAlert = new Alert { AlertTypeID = 1, AlertDate = DateTime.UtcNow.Date, AlertTime = DateTime.UtcNow.TimeOfDay, AlertValue = runTime.Seconds, AccountId = acct.AccountId, MetricName = "LoopExecutionTime", MetricType = MetricType.Account.ToString(), Details = runDetails, ErrorLevel = HealthStatus.Warning.ToString() }; DataAccess.SaveAlert(yellowAlert, acct.AccountName); } TotalCompletionTime = new TimeSpan(); } }