Initial commit of ElevatorServer solution

This commit is contained in:
Chris Hammer 2016-07-08 13:19:25 -07:00
Родитель 0f9382f71f
Коммит 8aa4d00ab6
11 изменённых файлов: 642 добавлений и 1 удалений

71
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,71 @@
#OS junk files
[Tt]humbs.db
*.DS_Store
#Visual Studio files
*.[Oo]bj
*.user
*.exe
*.aps
*.pch
*.scc
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.unsuccessfulbuild
UpgradeLog.*
ipch/
obj/
[Bb]in/
[Bb]ackup/
_UpgradeReport_Files/
[Dd]ebug*/
[Rr]elease*/
UserData/
[Ff]ile[Ee]xplorer/
Ankh.NoLoad
.vs/
#MonoDevelop
*.pidb
*.userprefs
#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
#Project files
[Bb]uild/
#Subversion files
.svn
# Office Temp Files
~$*
#NuGet
packages/
#ncrunch
*ncrunch*
*crunch*.local.xml
# visual studio database projects
*.dbmdl
#Test files
*.testsettings

Просмотреть файл

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElevatorServer", "ElevatorServer\ElevatorServer.csproj", "{53CE5840-916D-42F1-8C6D-C2FCEEBE3DDC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{53CE5840-916D-42F1-8C6D-C2FCEEBE3DDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53CE5840-916D-42F1-8C6D-C2FCEEBE3DDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53CE5840-916D-42F1-8C6D-C2FCEEBE3DDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{53CE5840-916D-42F1-8C6D-C2FCEEBE3DDC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Просмотреть файл

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

Просмотреть файл

@ -0,0 +1,171 @@
//--------------------------------------------------------------
//
// Microsoft Edge Elevator Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files(the ""Software""),
// to deal in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//--------------------------------------------------------------
using System;
using System.Diagnostics;
namespace ElevatorServer
{
/// <summary>
/// Provides Windows tracing controls using Windows Performance Recorder (WPR).
/// By default AutomateWPR assumes WPR has been installed on the test machine as part of the Windows Performance Toolkit.
/// Other WPR.exe can optionally be specified by passing the path to the WPR.exe location during instantiation.
///
/// NOTE: TestingPower.exe must be run elevated in order to allow control of WPR.exe.
/// </summary>
internal class AutomateWPR
{
private string _wprExePath;
private string _wprpFile;
public string WprRecordingProfile
{
get
{
return _wprpFile;
}
set
{
_wprpFile = value;
}
}
/// <summary>
/// Initializes a new instance of the AutomateWPR class with default settings.
/// </summary>
public AutomateWPR()
{
_wprExePath = @"C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\";
_wprpFile = ""; // need a default wprp file
}
/// <summary>
/// Initializes a new instance of the WprWrapper class with the specified wprp file, WPR.exe path, and ETL file name.
/// </summary>
/// <param name="wprpFile">The wprp file to use for tracing.</param>
/// <param name="wprPath">The WPR exe path and file name to use for controlling the WPR tracing.</param>
public AutomateWPR(string wprpFile, string wprPath = @"C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\")
{
_wprExePath = wprPath;
_wprpFile = wprpFile;
}
/// <summary>
/// Starts a WPR recording session using the specified wprp file.
/// </summary>
/// <returns>True if the trace session was started successfully.</returns>
public bool StartWPR()
{
bool isSuccess = false;
string commandLine = "-start " + _wprpFile + " -filemode";
isSuccess = this.RunWpr(commandLine);
return isSuccess;
}
/// <summary>
/// Stops the currently running WPR recording and saves it to the specified etl file name.
/// </summary>
/// <param name="etlFileName">The ETL file name to save the recording to.</param>
/// <returns>True if WPR trace recording was stopped.</returns>
public bool StopWPR(string etlFileName = "BrowserPower.etl")
{
bool isSuccess = false;
string commandLine = "-stop " + etlFileName;
isSuccess = this.RunWpr(commandLine);
return isSuccess;
}
/// <summary>
/// Cancels the currently running WPR recording session.
/// </summary>
/// <returns>True if WPR trace recording was cancelled.</returns>
public bool CancelWPR()
{
bool isSuccess = false;
string commandLine = "-cancel";
isSuccess = this.RunWpr(commandLine, true);
return isSuccess;
}
// executes the wpr.exe commandline with the passed in command line parameters
private bool RunWpr(string cmdLine, bool ignoreError = false)
{
bool isSuccess = false;
string errorOutput = "";
string wprExe = System.IO.Path.Combine(_wprExePath, "wpr.exe");
try
{
ProcessStartInfo processInfo = new ProcessStartInfo(wprExe);
processInfo.Arguments = cmdLine;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
Process commandProcess = new Process();
commandProcess.StartInfo = processInfo;
commandProcess.Start();
// capture any error output. We'll use this to throw an exception.
errorOutput = commandProcess.StandardError.ReadToEnd();
commandProcess.WaitForExit();
if (!ignoreError)
{
// output the standard error to the console window. The standard output is routed to the console window by default.
Console.WriteLine(errorOutput);
if (!string.IsNullOrEmpty(errorOutput))
{
throw new Exception(errorOutput.ToString());
}
}
isSuccess = true;
}
catch (Exception e)
{
Console.WriteLine("Exception trying to run wpr.exe!");
Console.WriteLine(e.Message);
return false;
}
return isSuccess;
}
}
}

Двоичные данные
ElevatorServer/ElevatorServer/DefaultPowerTraceProfile.wprp Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,66 @@
<?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>{53CE5840-916D-42F1-8C6D-C2FCEEBE3DDC}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ElevatorServer</RootNamespace>
<AssemblyName>ElevatorServer</AssemblyName>
<TargetFrameworkVersion>v4.6.1</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>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<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="AutomateWPR.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest" />
<None Include="DefaultPowerTraceProfile.wprp" />
</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>

Просмотреть файл

@ -0,0 +1,200 @@
//--------------------------------------------------------------
//
// Microsoft Edge Elevator Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files(the ""Software""),
// to deal in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//--------------------------------------------------------------
using System;
using System.IO;
using System.IO.Pipes;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ElevatorServer
{
internal class Program
{
private const string DefaultPowerTraceProfile = "DefaultPowerTraceProfile.wprp";
private static void Main(string[] args)
{
string traceProfile = "";
CancellationTokenSource tokenSource = null;
if (args.Length > 0)
{
traceProfile = args[0];
}
else
{
Console.WriteLine("No tracing profile file was specified so setting {0} as the tracing profile...", DefaultPowerTraceProfile);
traceProfile = DefaultPowerTraceProfile;
}
// If the trace profile doesn't exist exit the program.
if (!File.Exists(traceProfile))
{
Console.WriteLine("Unable to find the trace profile \"{0}\". Make sure the path and name are correct.", traceProfile);
Console.WriteLine("Exiting....");
Environment.Exit(1);
}
tokenSource = new CancellationTokenSource();
// run the control server in an asynchronous task
Task task = new Task(() => RunTracingControlServer(traceProfile, tokenSource.Token), tokenSource.Token);
task.Start();
Console.WriteLine("Press ESC to stop and exit the Tracing Controller.");
// Wait until the user presses the ESC key.
while (Console.ReadKey().Key != ConsoleKey.Escape)
{
}
// cancel the server task and clean up before exiting
try
{
tokenSource.Cancel();
task.Wait();
}
catch (OperationCanceledException)
{
// expected exception since we canceled the cancel token.
}
finally
{
tokenSource.Dispose();
}
}
// This method runs the main loop of the tracing controller.
// It is run as an asynchronous task and takes a CancellationToken as a parameter.
private static async Task RunTracingControlServer(string traceProfile, CancellationToken cancelToken)
{
AutomateWPR wpr = new AutomateWPR(traceProfile);
string etlFileName = "";
string line = "";
// Need to specifically set the security to allow "Everyone" since this app runs as an admin
// while the client runs as the default user
PipeSecurity pSecure = new PipeSecurity();
pSecure.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow));
while (!cancelToken.IsCancellationRequested)
{
Console.WriteLine("{0}: Tracing Controller Server starting....", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
using (var pipeServer = new NamedPipeServerStream("TracingControllerPipe", PipeDirection.InOut, 10, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 255, 255, pSecure))
{
Console.WriteLine("{0}: Waiting for client connection.", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
try
{
await pipeServer.WaitForConnectionAsync(cancelToken);
}
catch (OperationCanceledException)
{
continue;
}
var inputPipeStream = new StreamReader(pipeServer);
var outputPipeStream = new StreamWriter(pipeServer);
// Begin interacting with the client
while (pipeServer.IsConnected && !cancelToken.IsCancellationRequested)
{
// get a command from the client
line = inputPipeStream.ReadLine();
// sometimes we receive a null or empty line from the client and need to skip
if (string.IsNullOrEmpty(line))
{
continue;
}
// A command line from the client is delimited by spaces
var messageTokens = line.Split(' ');
// the first token of the command line is the actual command
string command = messageTokens[0];
switch (command)
{
case "PASS_START":
Console.WriteLine("{0}: Client is starting the test pass.", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
// acknowledge
outputPipeStream.WriteLine("OK");
outputPipeStream.Flush();
break;
case "START_BROWSER":
Console.WriteLine("{0}: -Starting- Iteration: {1} Browser: {2} Scenario: {3}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), messageTokens[3], messageTokens[1], messageTokens[5]);
Console.WriteLine("{0}: Starting tracing session.", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
// first cancel any currently running trace sessions
wpr.CancelWPR();
// start tracing
wpr.StartWPR();
// create the ETL file name which we will use later
etlFileName = messageTokens[1] + "_" + messageTokens[5] + "_" + messageTokens[3] + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".etl";
// acknowledge
outputPipeStream.WriteLine("OK");
outputPipeStream.Flush();
break;
case "END_BROWSER":
Console.WriteLine("{0}: -Finished- Browser: {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), messageTokens[1]);
Console.WriteLine("{0}: Stopping tracing session and saving as ETL: {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), etlFileName);
// end tracing
wpr.StopWPR(etlFileName);
Console.WriteLine("{0}: Done saving ETL file: {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), etlFileName);
// acknowledge
outputPipeStream.WriteLine("OK");
outputPipeStream.Flush();
break;
case "PASS_END":
Console.WriteLine("{0}: Client test pass has ended.", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
// acknowledge
outputPipeStream.WriteLine("OK");
outputPipeStream.Flush();
break;
default:
throw new Exception($"Unknown command encountered: {command}");
} // switch (Command)
} // while (pipeServer.IsConnected && !cancelToken.IsCancellationRequested)
} // using (var pipeServer
} // while (!cancelToken.IsCancellationRequested)
}
}
}

Просмотреть файл

@ -0,0 +1,62 @@
//--------------------------------------------------------------
//
// Microsoft Edge Elevator Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files(the ""Software""),
// to deal in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//--------------------------------------------------------------
using System.Reflection;
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("ElevatorServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ElevatorServer")]
[assembly: AssemblyCopyright("Copyright \u00A9 2016")]
[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("53ce5840-916d-42f1-8c6d-c2fceebe3ddc")]
// 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")]

Просмотреть файл

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

26
LICENSE Normal file
Просмотреть файл

@ -0,0 +1,26 @@
//--------------------------------------------------------------
//
// Microsoft Edge Elevator
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files(the ""Software""),
// to deal in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//--------------------------------------------------------------

Просмотреть файл

@ -1 +1,7 @@
# Elevator
# Elevator
## Coding Style
This project follows the [dotnet/corefx C# Coding Style](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md).
## Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.