Skip to content

Commit

Permalink
Merge pull request #16348 from venkatgct/master
Browse files Browse the repository at this point in the history
Reference Data API documentation
  • Loading branch information
Ja-Dunn authored Jun 30, 2017
2 parents 81479e9 + eb28923 commit 9f5b2c3
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 81 deletions.
2 changes: 2 additions & 0 deletions articles/time-series-insights/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## [Create an environment](time-series-insights-get-started.md)
## [Grant data access](time-series-insights-data-access.md)
## [Create an event source](time-series-insights-add-event-source.md)
## [Create a reference data set](time-series-insights-add-reference-data-set.md)
## [Send events](time-series-insights-send-events.md)

# How to
Expand All @@ -15,6 +16,7 @@
## Develop
### [Authentication and authorization](time-series-insights-authentication-and-authorization.md)
### [Query data using C#](time-series-insights-query-data-csharp.md)
### [Manage reference data using C#](time-series-insights-manage-reference-data-csharp.md)

# Reference
## [Query API](/rest/api/time-series-insights/time-series-insights-reference-queryapi)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ ms.date: 04/21/2017
ms.author: omravi
---

# Create an event source for your Time Series Insights environment using the Azure portal
# Create an event source for your Time Series Insights environment using the Ibiza portal

Time Series Insights Event Source is derived from an event broker, like Azure Event Hubs. Time Series Insights connects directly to Event Sources, ingesting the data stream without requiring users to write a single line of code. Currently, Time Series Insights supports Azure Event Hubs and Azure IoT Hubs, and in the future, more Event Sources will be added.
Time Series Insights Event Source is derived from an event broker, like Azure Event Hubs. Time Series Insights connects directly to Event Sources, ingesting the data stream without requiring users to write a single line of code. Currently, Time Series Insights supports Azure Event Hubs and Azure IoT Hubs. In the future, more Event Sources will be added.

## Steps to add an event source to your environment

1. Sign in to the [Azure portal](https://portal.azure.com).
2. Click “All resources” in the menu on the left side of the Azure portal.
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 event source](media/add-event-source/getstarted-create-eventsource1.png)
![Create the Time Series Insights event source](media/add-event-source/getstarted-create-event-source-1.png)

4. Select “Event Sources”, click “+ Add.”

![Create the Time Series Insights event source - details](media/add-event-source/getstarted-create-eventsource2.png)
![Create the Time Series Insights event source - details](media/add-event-source/getstarted-create-event-source-2.png)

5. Specify the name of the event source. This name is associated with all events coming from this event source and is available at query time.
6. Select an event hub from the list of Event Hub resources in the current subscription or choose Import option "Provide Event Hub settings manually” to specify an event hub located in another subscription. Events must be published in JSON format.
6. Select an event hub from the list of Event Hub resources in the current subscription. Otherwise choose import option "Provide Event Hub settings manually” to specify an event hub in another subscription. Events must be published in JSON format.
7. Select policy that has read permission in the event hub.
8. Specify event hub consumer group.

Expand Down
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.
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();
}
}
}
```
Loading

0 comments on commit 9f5b2c3

Please sign in to comment.