Skip to content

Commit

Permalink
Update stream-analytics-dotnet-management-sdk.md
Browse files Browse the repository at this point in the history
  • Loading branch information
abatishchev authored Mar 25, 2017
1 parent af4bcfa commit fd95028
Showing 1 changed file with 19 additions and 41 deletions.
60 changes: 19 additions & 41 deletions articles/stream-analytics/stream-analytics-dotnet-management-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,48 +76,30 @@ To create an analytics job use the Stream Analytics API for .NET, first set up y

using System;
using System.Configuration;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure;
using Microsoft.Azure.Management.StreamAnalytics;
using Microsoft.Azure.Management.StreamAnalytics.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2. Add an authentication helper method:

```
public static string GetAuthorizationHeader()
private static async Task<string> GetAuthorizationHeader()
{
AuthenticationResult result = null;
var thread = new Thread(() =>
{
try
{
var context = new AuthenticationContext(
ConfigurationManager.AppSettings["ActiveDirectoryEndpoint"] +
ConfigurationManager.AppSettings["ActiveDirectoryTenantId"]);
result = context.AcquireToken(
resource: ConfigurationManager.AppSettings["WindowsManagementUri"],
clientId: ConfigurationManager.AppSettings["AsaClientId"],
redirectUri: new Uri(ConfigurationManager.AppSettings["RedirectUri"]),
promptBehavior: PromptBehavior.Always);
}
catch (Exception threadEx)
{
Console.WriteLine(threadEx.Message);
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Name = "AcquireTokenThread";
thread.Start();
thread.Join();
if (result != null)
{
return result.AccessToken;
}
var context = new AuthenticationContext(
ConfigurationManager.AppSettings["ActiveDirectoryEndpoint"] +
ConfigurationManager.AppSettings["ActiveDirectoryTenantId"]);
AuthenticationResult result = await context.AcquireTokenASync(
resource: ConfigurationManager.AppSettings["WindowsManagementUri"],
clientId: ConfigurationManager.AppSettings["AsaClientId"],
redirectUri: new Uri(ConfigurationManager.AppSettings["RedirectUri"]),
promptBehavior: PromptBehavior.Always);
if (result != null)
return result.AccessToken;
throw new InvalidOperationException("Failed to acquire token");
}
```
Expand All @@ -134,10 +116,9 @@ Add the following code to the beginning of the **Main** method:
string streamAnalyticsTransformationName = "<YOUR JOB TRANSFORMATION NAME>";

// Get authentication token
TokenCloudCredentials aadTokenCredentials =
new TokenCloudCredentials(
ConfigurationManager.AppSettings["SubscriptionId"],
GetAuthorizationHeader());
TokenCloudCredentials aadTokenCredentials = new TokenCloudCredentials(
ConfigurationManager.AppSettings["SubscriptionId"],
GetAuthorizationHeader().Result);

// Create Stream Analytics management client
StreamAnalyticsManagementClient client = new StreamAnalyticsManagementClient(aadTokenCredentials);
Expand Down Expand Up @@ -297,8 +278,6 @@ The following sample code starts a Stream Analytics job with a custom output sta

LongRunningOperationResponse jobStartResponse = client.StreamingJobs.Start(resourceGroupName, streamAnalyticsJobName, jobStartParameters);



## Stop a Stream Analytics job
You can stop a running Stream Analytics job by calling the **Stop** method.

Expand All @@ -311,7 +290,6 @@ The **Delete** method will delete the job as well as the underlying sub-resource
// Delete a Stream Analytics job
LongRunningOperationResponse jobDeleteResponse = client.StreamingJobs.Delete(resourceGroupName, streamAnalyticsJobName);


## Get support
For further assistance, try our [Azure Stream Analytics forum](https://social.msdn.microsoft.com/Forums/en-US/home?forum=AzureStreamAnalytics).

Expand Down

0 comments on commit fd95028

Please sign in to comment.