使用 C# 查询 Azure 时序见解第 2 代环境中的数据Query data from the Azure Time Series Insights Gen2 environment using C Sharp

本 C# 示例演示了如何在 Azure 时序见解 Gen2 环境中通过 Gen2 数据访问 API 查询数据。This C# example demonstrates how to query data from the Gen2 Data Access APIs in Azure Time Series Insights Gen2 environments.

提示

可以访问 https://github.com/Azure-Samples/Azure-Time-Series-Insights 查看 Gen2 C# 代码示例。View Gen2 C# code samples at https://github.com/Azure-Samples/Azure-Time-Series-Insights.

总结Summary

下面的示例代码演示了以下功能:The sample code below demonstrates the following features:

先决条件和设置Prerequisites and setup

在编译和运行示例代码之前,请完成以下步骤:Complete the following steps before you compile and run the sample code:

  1. 预配 Azure 时序见解 Gen2 环境。Provision a Gen2 Azure Time Series Insights environment.
  2. 为 Azure Active Directory 配置 Azure 时序见解环境,如身份验证和授权中所述。Configure your Azure Time Series Insights environment for Azure Active Directory as described in Authentication and authorization.
  3. 按照 Readme.md 中指定的方式运行 GenerateCode.bat,以生成 Azure 时序见解 Gen2 客户端依赖项。Run the GenerateCode.bat as specified in the Readme.md to generate the Azure Time Series Insights Gen2 client dependencies.
  4. 打开 TSIPreviewDataPlaneclient.sln 解决方案,并将 DataPlaneClientSampleApp 设置为 Visual Studio 中的默认项目。Open the TSIPreviewDataPlaneclient.sln solution and set DataPlaneClientSampleApp as the default project in Visual Studio.
  5. 使用下面所述的步骤安装所需的项目依赖项,并将示例编译为可执行 .exe 文件。Install the required project dependencies using the steps described below and compile the example to an executable .exe file.
  6. 通过双击 .exe 文件来运行它。Run the .exe file by double-clicking on it.

项目依赖项Project dependencies

建议使用最新版本的 Visual Studio:It's recommended that you use the newest version of Visual Studio:

示例代码具有多个必需的依赖项,可以在 packages.config 文件中进行查看。The sample code has several required dependencies which can be viewed in the packages.config file.

在 Visual Studio 2019 中,通过选择“生成” > “生成解决方案”选项下载包。Download the packages in Visual Studio 2019 by selecting the Build > Build Solution option.

或者,使用 NuGet 2.12 添加每个包。Alternatively, add each package using NuGet 2.12+. 例如:For example:

  • dotnet add package Microsoft.IdentityModel.Clients.ActiveDirectory --version 4.5.1

C# 示例代码C# sample code

请参阅 Azure 时序见解存储库以访问 C# 示例代码。Please refer to the Azure Time Series Insights repo to access the C# sample code.

备注

  • 可以在不更改默认环境变量的情况下执行代码示例。The code sample can be executed without altering the default environment variables.
  • 代码示例将编译为 .NET 可执行控制台应用。The code sample will compile to a .NET executable console app.

后续步骤Next steps