Add files via upload

This commit is contained in:
Christian Wade 2017-04-06 12:14:22 -07:00 committed by GitHub
parent f1fba14b20
commit b5c341131e
26 changed files with 33385 additions and 0 deletions

View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TracingSample", "TracingSample\TracingSample.csproj", "{4BA683EB-9E69-4ADD-BA80-CCEB6D6458C1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4BA683EB-9E69-4ADD-BA80-CCEB6D6458C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4BA683EB-9E69-4ADD-BA80-CCEB6D6458C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BA683EB-9E69-4ADD-BA80-CCEB6D6458C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BA683EB-9E69-4ADD-BA80-CCEB6D6458C1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@ -0,0 +1,218 @@
/*============================================================================
Summary: Contains class implementiong xEvent data logging for Azure Analysis Services
Copyright (C) Microsoft Corporation.
This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
============================================================================*/
using System;
using System.Xml;
using System.Threading;
using System.IO;
using System.Text;
using Microsoft.AnalysisServices;
using Microsoft.AnalysisServices.AdomdClient;
using Microsoft.SqlServer.XEvent.Linq; // Referenced from the GAC version of Microsoft.SqlServer.XEvent.Linq
namespace TracingSample
{
public class Worker
{
private string UserName;
private string AsServer;
private string AsDatabase;
private string eventTmsl;
private string logFile;
public Worker(string user, string server, string db, string events, string log)
{
UserName = user;
AsServer = server;
AsDatabase = db;
eventTmsl = events;
logFile = log;
}
// This method will be called when the thread is started. 
public void DoWork()
{
try
{
using (Server server = new Server())
{
//Connect and get main objects
string serverConnectionString;
// Assume integratedAuth
// otherwise serverConnectionString = $"Provider=MSOLAP;Data Source={AsServer};User ID={UserName};Password={Password};Impersonation Level=Impersonate;";
serverConnectionString = $"Provider=MSOLAP;Data Source={AsServer};Integrated Security=SSPI";
server.Connect(serverConnectionString);
Database database = server.Databases.FindByName(AsDatabase);
if (database == null)
{
throw new Microsoft.AnalysisServices.ConnectionException($"Could not connect to database {AsDatabase}.");
}
//Register the events you want to trace
string queryString = System.IO.File.ReadAllText(eventTmsl);
server.Execute(queryString);
// Now you need to subscribe to the xEvent stream and execute a data reader
// You need to have the same name as in the TMSL file!
// NOTE calls to the reader will block until new values show up!
string sessionId = "SampleXEvents";
AdomdConnection conn = new AdomdConnection(serverConnectionString);
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText =
"<Subscribe xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">" +
"<Object xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">" +
"<TraceID>" + sessionId + "</TraceID>" +
"</Object>" +
"</Subscribe>";
XmlReader inputReader = XmlReader.Create(cmd.ExecuteXmlReader(), new XmlReaderSettings() { Async = true });
//Connect to this with QueryableXEventData
using (QueryableXEventData data =
new QueryableXEventData(inputReader, EventStreamSourceOptions.EventStream, EventStreamCacheOptions.CacheToDisk))
{
using (FileStream fs = new FileStream(logFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
//Write out the data in a long format for illustration
// this could would be adpated for your specific needs
foreach (PublishedEvent evt in data)
{
StringBuilder s = new StringBuilder();
s.Append($"Event: {evt.Name}\t");
s.Append(Environment.NewLine);
s.Append($"Timestamp: {evt.Timestamp}\t");
s.Append(Environment.NewLine);
foreach (PublishedEventField fld in evt.Fields)
{
s.Append($"Field: {fld.Name} = {fld.Value}\t");
s.Append(Environment.NewLine);
}
foreach (PublishedAction act in evt.Actions)
{
s.Append($"Action: {act.Name} = {act.Value}\t");
s.Append(Environment.NewLine);
}
s.Append(Environment.NewLine);
//Write the data to a log file
// the format and sink should be changed for your proposes
byte[] bytes = Encoding.ASCII.GetBytes(s.ToString().ToCharArray());
fs.Write(bytes, 0, s.Length);
if (_shouldStop == true)
{
break;
}
// Writing a . to show progress
Console.Write(".");
//Uncomment this to output to the Console
//Console.WriteLine(s);
}
//TODO stop the trace !
fs.Close();
}
conn.Close();
//clean up the trace on exit -- or you can keep it running
//var stopCommand = conn.CreateCommand();
//stopCommand.CommandType = System.Data.CommandType.Text;
var stopCommand =
"<Execute xmlns = \"urn:schemas-microsoft-com:xml-analysis\">" +
"<Command>" +
"<Batch …>" +
"<Delete …>" +
// You need to have the same name as in the TMSL file!
"<Object><TraceID>"+sessionId+"</TraceID></Object>" +
"</Delete>" +
"<Batch …>" +
"<Command>" +
"<Properties></Properties>" +
"</Execute>";
server.Execute(queryString);
server.Disconnect();
}
}
}
catch (Exception e)
{
//TODO: handle exceptions :-)
Console.WriteLine(e.ToString());
Console.WriteLine("There was an error. Verify the command-line parmaters. Press any key to exit.");
}
//Worker thread: terminating gracefully.
}
public void RequestStop()
{
_shouldStop = true;
}
// Volatile is used as hint to the compiler that this data 
// member will be accessed by multiple threads. 
private volatile bool _shouldStop;
}
class Program
{
static void Main(string[] args)
{
string UserName = "user@contoso.com";
string AsServer = "asazure://region.asazure.windows.net/myinstance";
string AsDatabase = "SalesBI";
string eventTmsl = @"C:\AsXEventSample\eventTmsl.xmla"; // location of the xEvents TMSL file you want to collect, you can create this with SSMS script out
string logFile = @"C:\AsXEventSample\aslog.txt"; //location of the outputfile
// Using a thread here as data comes in asychronously
// Create the thread object. This does not start the thread.
Worker workerObject = new Worker(UserName, AsServer, AsDatabase, eventTmsl, logFile);
Thread workerThread = new Thread(workerObject.DoWork);
// Start the worker thread.
workerThread.Start();
// For monitoring, this would be upgraded to a windows service
Console.WriteLine("Listening for trace events which are sent when there is trace activity.");
Console.WriteLine("Type the letter q and enter to quit. The process will exit after the next trace event is received.");
bool cont = true;
while (cont)
{
Thread.Sleep(1);
if (ConsoleKey.Q == Console.ReadKey().Key)
{
workerObject.RequestStop();
Console.WriteLine("\nStopping reader on next trace event received...");
cont = false;
}
}
//wait for the worker to exit
workerThread.Join();
Console.WriteLine($"File is stored at: {logFile}");
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TracingSample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TracingSample")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4ba683eb-9e69-4add-ba80-cceb6d6458c1")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4BA683EB-9E69-4ADD-BA80-CCEB6D6458C1}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TracingSample</RootNamespace>
<AssemblyName>TracingSample</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.AnalysisServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\Microsoft.AnalysisServices.DLL</HintPath>
</Reference>
<Reference Include="Microsoft.AnalysisServices.AdomdClient, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\140\Microsoft.AnalysisServices.AdomdClient.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AnalysisServices.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\Microsoft.AnalysisServices.Core.DLL</HintPath>
</Reference>
<Reference Include="Microsoft.SqlServer.XEvent.Linq, Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Windows\Microsoft.NET\assembly\GAC_64\Microsoft.SqlServer.XEvent.Linq\v4.0_13.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.XEvent.Linq.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>
</StartArguments>
</PropertyGroup>
</Project>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.AnalysisServices.SPClient.Interfaces" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1 @@
ae9773ae50bed2e355c73f0d6462e1f6c7b92a68

View File

@ -0,0 +1,30 @@
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\TracingSample.exe.config
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\TracingSample.exe
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\TracingSample.pdb
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.AdomdClient.dll
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Core.dll
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.dll
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Tabular.dll
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Tabular.Json.dll
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.xml
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Core.xml
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Tabular.xml
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\obj\Debug\TracingSample.csprojResolveAssemblyReference.cache
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\obj\Debug\TracingSample.exe
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\obj\Debug\TracingSample.pdb
C:\Users\ChWade\Desktop\temp\xEventSample\xEventSample\xEventSample\TracingSample\bin\Debug\Microsoft.SqlServer.XEvent.Linq.dll
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\TracingSample.exe.config
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\TracingSample.exe
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\TracingSample.pdb
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.AdomdClient.dll
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Core.DLL
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.DLL
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\Microsoft.SqlServer.XEvent.Linq.dll
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Tabular.dll
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Tabular.Json.dll
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.xml
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Core.xml
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\bin\Debug\Microsoft.AnalysisServices.Tabular.xml
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\obj\Debug\TracingSample.csprojResolveAssemblyReference.cache
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\obj\Debug\TracingSample.exe
C:\Users\ChWade\Source\Repos\Analysis-Services\AsXEventSample\TracingSample\obj\Debug\TracingSample.pdb

View File

@ -0,0 +1,20 @@
<Create xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<ObjectDefinition>
<Trace>
<ID>SampleXEvents</ID>
<Name>SampleXEvents</Name>
<XEvent xmlns="http://schemas.microsoft.com/analysisservices/2011/engine/300/300">
<event_session name="SampleXEvents" dispatchLatency="0" maxEventSize="0" maxMemory="4" memoryPartition="none" eventRetentionMode="AllowSingleEventLoss" trackCausality="true" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<event package="AS" name="CommandBegin">
<action package="AS" name="attach_current_activity_id" />
<action package="AS" name="attach_current_activity_type" />
</event>
<event package="AS" name="CommandEnd" />
<event package="AS" name="CommandEndWithError" />
<event package="AS" name="ExecutionStatistics" />
<target package="package0" name="event_stream" />
</event_session>
</XEvent>
</Trace>
</ObjectDefinition>
</Create>

View File

@ -0,0 +1,7 @@
This sample shows how to collect streaming xEvents and profiler traces with C#.
Update the server information in Program.cs to connect to your
Azure Analysis Services instance.
The current version of this sample can be found at:
https://github.com/Microsoft/Analysis-Services