forked from MicrosoftDocs/azure-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16348 from venkatgct/master
Reference Data API documentation
- Loading branch information
Showing
11 changed files
with
354 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
Binary file added
BIN
+32 KB
...nsights/media/add-reference-data-set/getstarted-create-reference-data-set-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.39 KB
...nsights/media/add-reference-data-set/getstarted-create-reference-data-set-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.9 KB
...nsights/media/add-reference-data-set/getstarted-create-reference-data-set-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
articles/time-series-insights/time-series-insights-add-reference-data-set.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: Add reference data set to your Azure Time Series Insights environment | Microsoft Docs | ||
description: In this tutorial, you add reference data set to your Time Series Insights environment | ||
keywords: | ||
services: time-series-insights | ||
documentationcenter: | ||
author: venkatgct | ||
manager: almineev | ||
editor: cgronlun | ||
|
||
ms.assetid: | ||
ms.service: time-series-insights | ||
ms.devlang: na | ||
ms.topic: get-started-article | ||
ms.tgt_pltfrm: na | ||
ms.workload: big-data | ||
ms.date: 06/29/2017 | ||
ms.author: venkatja | ||
--- | ||
|
||
# Create reference data set for your Time Series Insights environment using the Ibiza portal | ||
|
||
A Reference Data Set is a collection of items that are augmented with the events from your event source. Time Series Insights ingress engine joins an event from your event source with an item in your reference data set. This augmented event is then available for query. This join is based on the keys defined in your reference data set. | ||
|
||
## Steps to add a reference data set to your environment | ||
|
||
1. Sign in to the [Ibiza portal](https://portal.azure.com). | ||
2. Click “All resources” in the menu on the left side of the Ibiza portal. | ||
3. Select your Time Series Insights environment. | ||
|
||
![Create the Time Series Insights reference data set](media/add-reference-data-set/getstarted-create-reference-data-set-1.png) | ||
|
||
4. Select “Reference Data Sets”, click “+ Add.” | ||
|
||
![Create the Time Series Insights reference data set - details](media/add-reference-data-set/getstarted-create-reference-data-set-2.png) | ||
|
||
5. Specify the name of the reference data set. | ||
6. Specify the key name and its type. This name and type is used to pick the correct property from the event in your event source. For instance, if you provide key name as “DeviceId” and type as “String”, then the ingress engine looks for a property with the name “DeviceId” of type “String” in the incoming event. You can provide more than one key to join with the event. The property name match is case-sensitive. | ||
|
||
![Create the Time Series Insights reference data set - details](media/add-reference-data-set/getstarted-create-reference-data-set-3.png) | ||
|
||
9. Click “Create.” | ||
|
||
## Next steps | ||
|
||
* [Manage reference data](time-series-insights-manage-reference-data-csharp.md) programmatically. |
220 changes: 220 additions & 0 deletions
220
articles/time-series-insights/time-series-insights-manage-reference-data-csharp.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
--- | ||
title: Manage reference data for an Azure Time Series Insights environment by using C# | Microsoft Docs | ||
description: This tutorial covers how to manage reference data for an Azure Time Series Insights environment by using C# | ||
keywords: | ||
services: time-series-insights | ||
documentationcenter: | ||
author: venkatgct | ||
manager: almineev | ||
editor: cgronlun | ||
|
||
ms.assetid: | ||
ms.service: time-series-insights | ||
ms.devlang: na | ||
ms.topic: how-to-article | ||
ms.tgt_pltfrm: na | ||
ms.workload: big-data | ||
ms.date: 06/29/2017 | ||
ms.author: venkatja | ||
--- | ||
# Manage reference data for an Azure Time Series Insights environment by using C# | ||
|
||
## Introduction | ||
|
||
This C# sample demonstrates how to manage reference data for an Azure Time Series Insights environment. | ||
Before running the sample, ensure the following steps are completed. | ||
1. A reference data set has been created using [this article](time-series-insights-add-reference-data-set.md). | ||
2. The access token used when running the application is acquired through the Azure Active Directory API. This token should be passed in the `Authorization` header of every Query API request. For setting up non-interactive applications, see the [Authentication and authorization](time-series-insights-authentication-and-authorization.md) article. | ||
3. All the constants defined at the beginning of the sample are correctly set. | ||
|
||
## C# sample | ||
|
||
```csharp | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.IdentityModel.Clients.ActiveDirectory; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace TimeSeriesInsightsReferenceDataSampleApp | ||
{ | ||
public static class Program | ||
{ | ||
// SET the environment fqdn. | ||
private const string EnvironmentFqdn = "dummyid.env.timeseries.azure.com"; | ||
|
||
// SET the environment reference data set name used when creating it. | ||
private const string EnvironmentReferenceDataSetName = "contosords"; | ||
|
||
// For automated execution under application identity, | ||
// use application created in Active Directory. | ||
// To create the application in AAD, follow the steps provided here: | ||
// https://docs.microsoft.com/en-us/azure/time-series-insights/time-series-insights-authentication-and-authorization | ||
// SET the application ID of application registered in your Azure Active Directory | ||
private const string ApplicationClientId = "fe1bc0a0-3097-4b7c-9efc-ee919be80c9e"; | ||
|
||
// SET the application key of the application registered in your Azure Active Directory | ||
private const string ApplicationClientSecret = "#DUMMYSECRET#"; | ||
|
||
private static async Task DemoReferenceDataAsync() | ||
{ | ||
// 1. Acquire an access token. | ||
string accessToken = await AcquireAccessTokenAsync(); | ||
|
||
// 2. Put a new reference data item. | ||
{ | ||
HttpWebRequest request = CreateWebRequest(accessToken); | ||
string input = @" | ||
{ | ||
""put"": [{ | ||
""DeviceId"": ""Fan1"", | ||
""Type"": ""Fan"", | ||
""BladeCount"": ""3"" | ||
}] | ||
}"; | ||
await SendRequestAsync(request, input); | ||
string output = await GetResponseAsync(request); | ||
PrintInputOutput(action: "Put", input: input, output: output); | ||
} | ||
|
||
// 3. Get reference data item. | ||
{ | ||
HttpWebRequest request = CreateWebRequest(accessToken); | ||
string input = @" | ||
{ | ||
""get"": [{ | ||
""DeviceId"": ""Fan1"" | ||
}] | ||
}"; | ||
await SendRequestAsync(request, input); | ||
string output = await GetResponseAsync(request); | ||
PrintInputOutput(action: "Get", input: input, output: output); | ||
} | ||
|
||
// 4. Patch an existing reference data item. | ||
// Update BladeCount and add Colour. | ||
{ | ||
HttpWebRequest request = CreateWebRequest(accessToken); | ||
string input = @" | ||
{ | ||
""patch"": [{ | ||
""DeviceId"": ""Fan1"", | ||
""BladeCount"": ""4"", | ||
""Colour"": ""Brown"" | ||
}] | ||
}"; | ||
await SendRequestAsync(request, input); | ||
string output = await GetResponseAsync(request); | ||
PrintInputOutput(action: "Patch", input: input, output: output); | ||
} | ||
|
||
// 5. Delete a property from an existing reference data item. | ||
{ | ||
HttpWebRequest request = CreateWebRequest(accessToken); | ||
string input = @" | ||
{ | ||
""deleteproperties"": [{ | ||
""key"": { | ||
""DeviceId"": ""Fan1"" | ||
}, | ||
""properties"": [""BladeCount""] | ||
}] | ||
}"; | ||
await SendRequestAsync(request, input); | ||
string output = await GetResponseAsync(request); | ||
PrintInputOutput(action: "DeleteProperties", input: input, output: output); | ||
} | ||
|
||
// 6. Delete an existing reference data item. | ||
{ | ||
HttpWebRequest request = CreateWebRequest(accessToken); | ||
string input = @" | ||
{ | ||
""delete"": [{ | ||
""DeviceId"": ""Fan1"" | ||
}] | ||
}"; | ||
await SendRequestAsync(request, input); | ||
string output = await GetResponseAsync(request); | ||
PrintInputOutput(action: "Delete", input: input, output: output); | ||
} | ||
} | ||
|
||
private static async Task<string> AcquireAccessTokenAsync() | ||
{ | ||
var authenticationContext = new AuthenticationContext( | ||
"https://login.windows.net/common", | ||
TokenCache.DefaultShared); | ||
|
||
AuthenticationResult token = await authenticationContext.AcquireTokenAsync( | ||
resource: "https://api.timeseries.azure.com/", | ||
clientCredential: new ClientCredential( | ||
clientId: ApplicationClientId, | ||
clientSecret: ApplicationClientSecret)); | ||
|
||
// Show interactive logon dialog to acquire token on behalf of the user. | ||
// Suitable for native apps, and not on server-side of a web application. | ||
//AuthenticationResult token = await authenticationContext.AcquireTokenAsync( | ||
// resource: "https://api.timeseries.azure.com/", | ||
// clientId: "1950a258-227b-4e31-a9cf-717495945fc2", | ||
// redirectUri: new Uri("urn:ietf:wg:oauth:2.0:oob"), | ||
// parameters: new PlatformParameters(PromptBehavior.Auto)); | ||
return token.AccessToken; | ||
} | ||
|
||
private static HttpWebRequest CreateWebRequest(string accessToken) | ||
{ | ||
Uri uri = new UriBuilder("https", EnvironmentFqdn) | ||
{ | ||
Path = $"referencedatasets/{EnvironmentReferenceDataSetName}/$batch", | ||
Query = "api-version=2016-12-12" | ||
}.Uri; | ||
HttpWebRequest request = WebRequest.CreateHttp(uri); | ||
request.Method = "POST"; | ||
request.Headers.Add("x-ms-client-application-name", "TimeSeriesInsightsReferenceDataSample"); | ||
request.Headers.Add("Authorization", "Bearer " + accessToken); | ||
return request; | ||
} | ||
|
||
private static async Task SendRequestAsync(HttpWebRequest request, string json) | ||
{ | ||
using (var stream = await request.GetRequestStreamAsync()) | ||
using (var streamWriter = new StreamWriter(stream)) | ||
{ | ||
await streamWriter.WriteAsync(json); | ||
await streamWriter.FlushAsync(); | ||
streamWriter.Close(); | ||
} | ||
} | ||
|
||
private static async Task<string> GetResponseAsync(HttpWebRequest request) | ||
{ | ||
using (WebResponse webResponse = await request.GetResponseAsync()) | ||
using (var sr = new StreamReader(webResponse.GetResponseStream())) | ||
{ | ||
string result = await sr.ReadToEndAsync(); | ||
return result; | ||
} | ||
} | ||
|
||
private static void PrintInputOutput(string action, string input, string output) | ||
{ | ||
Console.WriteLine("=== {0} request ===", action); | ||
Console.WriteLine("Input: {0}", JsonConvert.SerializeObject(JsonConvert.DeserializeObject<JObject>(input), Formatting.Indented)); | ||
Console.WriteLine("Output: {0}", JsonConvert.SerializeObject(JsonConvert.DeserializeObject<JObject>(output), Formatting.Indented)); | ||
Console.WriteLine(); | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
Task.Run(async () => await DemoReferenceDataAsync()).Wait(); | ||
} | ||
} | ||
} | ||
``` |
Oops, something went wrong.