initial library and core test app
This commit is contained in:
Родитель
9024de595a
Коммит
4bca4b4d12
|
@ -0,0 +1,63 @@
|
|||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
|
@ -0,0 +1,245 @@
|
|||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
[Xx]64/
|
||||
[Xx]86/
|
||||
[Bb]uild/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
|
||||
# TODO: Un-comment the next line if you do not want to checkin
|
||||
# your web deploy settings because they may include unencrypted
|
||||
# passwords
|
||||
#*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Microsoft Azure ApplicationInsights config file
|
||||
ApplicationInsights.config
|
||||
|
||||
# Windows Store app package directory
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# LightSwitch generated files
|
||||
GeneratedArtifacts/
|
||||
ModelManifest.xml
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
|
@ -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>
|
|
@ -0,0 +1,122 @@
|
|||
using Microsoft.Tools.WindowsDevicePortal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TestApp
|
||||
{
|
||||
public class DevicePortalConnection : IDevicePortalConnection
|
||||
{
|
||||
private X509Certificate2 _deviceCertificate = null;
|
||||
|
||||
public Uri Connection
|
||||
{ get; private set; }
|
||||
|
||||
public NetworkCredential Credentials
|
||||
{ get; private set; }
|
||||
|
||||
public String Name
|
||||
{ get; set; }
|
||||
|
||||
public OperatingSystemInformation OsInfo
|
||||
{ get; set; }
|
||||
|
||||
public String QualifiedName
|
||||
{ get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public DevicePortalConnection(String address,
|
||||
String userName,
|
||||
String password)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(address))
|
||||
{
|
||||
address = "localhost:10080";
|
||||
}
|
||||
|
||||
Connection = new Uri(String.Format("{0}://{1}", GetUriScheme(address), address));
|
||||
Credentials = new NetworkCredential(userName, password);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Byte[] GetDeviceCertificateData()
|
||||
{
|
||||
return _deviceCertificate.GetRawCertData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="certificateData"></param>
|
||||
public void SetDeviceCertificate(Byte[] certificateData)
|
||||
{
|
||||
X509Certificate2 cert = new X509Certificate2(certificateData);
|
||||
if (!cert.IssuerName.Name.Contains(DevicePortal.DevicePortalCertificateIssuer))
|
||||
{
|
||||
throw new DevicePortalException((HttpStatusCode)0,
|
||||
"Invalid certificate issuer",
|
||||
null,
|
||||
"Failed to download device certificate");
|
||||
}
|
||||
_deviceCertificate = cert;
|
||||
}
|
||||
|
||||
public void UpdateConnection(Boolean requiresHttps)
|
||||
{
|
||||
Connection = new Uri(String.Format("{0}://{1}", GetUriScheme(Connection.Authority, requiresHttps), Connection.Authority));
|
||||
}
|
||||
|
||||
public void UpdateConnection(IpConfiguration ipConfig,
|
||||
Boolean requiresHttps = false)
|
||||
{
|
||||
Uri newConnection = null;
|
||||
|
||||
foreach (NetworkAdapterInfo adapter in ipConfig.Adapters)
|
||||
{
|
||||
foreach (IpAddressInfo addressInfo in adapter.IpAddresses)
|
||||
{
|
||||
// We take the first, non-169.x.x.x address we find that is not 0.0.0.0.
|
||||
if ((addressInfo.Address != "0.0.0.0") && !addressInfo.Address.StartsWith("169."))
|
||||
{
|
||||
newConnection = new Uri(String.Format("{0}://{1}", GetUriScheme(addressInfo.Address, requiresHttps), addressInfo.Address));
|
||||
// BUGBUG qualified name
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (newConnection != null)
|
||||
{
|
||||
Connection = newConnection;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="requiresHttps"></param>
|
||||
/// <returns></returns>
|
||||
private String GetUriScheme(String address,
|
||||
Boolean requiresHttps = true)
|
||||
{
|
||||
return (address.Contains("127.0.0.1") ||
|
||||
address.Contains("localhost") ||
|
||||
!requiresHttps) ? "http" : "https";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
using Microsoft.Tools.WindowsDevicePortal;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TestApp
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private String _ipAddress = null;
|
||||
private String _userName = null;
|
||||
private String _password = null;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Program app = new Program();
|
||||
|
||||
try
|
||||
{
|
||||
app.ParseCommandLine(args);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
// TODO: Make a usage display
|
||||
Console.WriteLine(e.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
DevicePortal portal = new DevicePortal(new DevicePortalConnection(app._ipAddress, app._userName, app._password));
|
||||
Console.WriteLine("Connecting...");
|
||||
Task connectTask = portal.Connect();
|
||||
connectTask.Wait();
|
||||
Console.WriteLine("Connected to: " + portal.Address);
|
||||
Console.WriteLine("OS version: " + portal.OperatingSystemVersion);
|
||||
Console.WriteLine("Platform: " + portal.Platform.ToString());
|
||||
|
||||
Task <String> getNameTask = portal.GetDeviceName();
|
||||
getNameTask.Wait();
|
||||
Console.WriteLine("Device name: " + getNameTask.Result);
|
||||
|
||||
while(true)
|
||||
{
|
||||
System.Threading.Thread.Sleep(0);
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseCommandLine(String[] args)
|
||||
{
|
||||
for (Int32 i = 0; i < args.Length; i++)
|
||||
{
|
||||
String arg = args[i].ToLower();
|
||||
if (!arg.StartsWith("/'") && !arg.StartsWith("-"))
|
||||
{
|
||||
throw new Exception(String.Format("Unrecognized argument: {0}", args[i]));
|
||||
}
|
||||
|
||||
arg = arg.Substring(1);
|
||||
|
||||
if (arg.StartsWith("ip:"))
|
||||
{
|
||||
_ipAddress = GetArgData(arg);
|
||||
}
|
||||
else if (arg.StartsWith("user:"))
|
||||
{
|
||||
_userName = GetArgData(arg);
|
||||
}
|
||||
else if (arg.StartsWith("pwd:"))
|
||||
{
|
||||
_password = GetArgData(arg);
|
||||
}
|
||||
// TODO: ssid, networkKey
|
||||
else
|
||||
{
|
||||
throw new Exception(String.Format("Unrecognized argument: {0}", args[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// We require at least a user name and password to proceed.
|
||||
if (String.IsNullOrWhiteSpace(_userName) || String.IsNullOrWhiteSpace(_password))
|
||||
{
|
||||
throw new Exception("You must specify a user name and a password");
|
||||
}
|
||||
}
|
||||
|
||||
private String GetArgData(String arg)
|
||||
{
|
||||
Int32 idx = arg.IndexOf(':');
|
||||
return arg.Substring(idx+1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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("TestApp")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("TestApp")]
|
||||
[assembly: AssemblyCopyright("Copyright © 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("46c9836d-211a-43b8-b032-076c53a3d57c")]
|
||||
|
||||
// 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,65 @@
|
|||
<?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>{46C9836D-211A-43B8-B032-076C53A3D57C}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TestApp</RootNamespace>
|
||||
<AssemblyName>TestApp</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="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DevicePortalConnection.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WindowsDevicePortalWrapper\WindowsDevicePortalWrapper.csproj">
|
||||
<Project>{6a9e862e-5cda-4a8a-bbc0-56e9ea921e39}</Project>
|
||||
<Name>WindowsDevicePortalWrapper</Name>
|
||||
</ProjectReference>
|
||||
</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,28 @@
|
|||
|
||||
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}") = "WindowsDevicePortalWrapper", "WindowsDevicePortalWrapper\WindowsDevicePortalWrapper.csproj", "{6A9E862E-5CDA-4A8A-BBC0-56E9EA921E39}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{46C9836D-211A-43B8-B032-076C53A3D57C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6A9E862E-5CDA-4A8A-BBC0-56E9EA921E39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6A9E862E-5CDA-4A8A-BBC0-56E9EA921E39}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6A9E862E-5CDA-4A8A-BBC0-56E9EA921E39}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6A9E862E-5CDA-4A8A-BBC0-56E9EA921E39}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{46C9836D-211A-43B8-B032-076C53A3D57C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{46C9836D-211A-43B8-B032-076C53A3D57C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{46C9836D-211A-43B8-B032-076C53A3D57C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{46C9836D-211A-43B8-B032-076C53A3D57C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,118 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _installedPackagesApi = "api/app/packagemanager/packages";
|
||||
private static readonly String _installStateApi = "api/app/packagemanager/state";
|
||||
private static readonly String _packageManagerApi = "api/app/packagemanager/package";
|
||||
|
||||
public ApplicationInstallStatusEventHandler AppInstallStatus;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of applications installed on the device.
|
||||
/// </summary>
|
||||
/// <returns>AppPackages object containing the list of installed application packages.</returns>
|
||||
public async Task<AppPackages> GetInstalledAppPackages()
|
||||
{
|
||||
return await Get<AppPackages>(_installedPackagesApi);
|
||||
}
|
||||
|
||||
public async Task InstallApplication(/* BUGBUG */)
|
||||
{
|
||||
// BUGBUG
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uninstalls the specified application.
|
||||
/// </summary>
|
||||
/// <param name="packageName">The name of the application package to uninstall.</param>
|
||||
public async Task UninstallApplication(String packageName)
|
||||
{
|
||||
|
||||
await Delete(_packageManagerApi,
|
||||
// NOTE: When uninstalling an app package, the package name is not Hex64 encoded.
|
||||
String.Format("package={0}", packageName));
|
||||
}
|
||||
|
||||
private void SendAppInstallStatus(AppInstallStatus status,
|
||||
AppInstallPhase phase,
|
||||
String message = "")
|
||||
{
|
||||
AppInstallStatus?.Invoke(this,
|
||||
new ApplicationInstallStatusEventArgs(status, phase, message));
|
||||
}
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
[DataContract]
|
||||
public class AppPackages
|
||||
{
|
||||
[DataMember(Name="InstalledPackages")]
|
||||
public List<PackageInfo> Packages { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class PackageInfo
|
||||
{
|
||||
[DataMember(Name="Name")]
|
||||
public String Name { get; set; }
|
||||
|
||||
[DataMember(Name="PackageFamilyName")]
|
||||
public String FamilyName { get; set; }
|
||||
|
||||
[DataMember(Name="PackageFullName")]
|
||||
public String FullName { get; set; }
|
||||
|
||||
[DataMember(Name="PackageRelativeId")]
|
||||
public String AppId { get; set; }
|
||||
|
||||
[DataMember(Name="Publisher")]
|
||||
public String Publisher { get; set; }
|
||||
|
||||
[DataMember(Name="Version")]
|
||||
public PackageVersion Version { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} ({1})", Name, Version);
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class PackageVersion
|
||||
{
|
||||
[DataMember(Name="Build")]
|
||||
public Int32 Build { get; set; }
|
||||
|
||||
[DataMember(Name="Major")]
|
||||
public Int32 Major { get; set; }
|
||||
|
||||
[DataMember(Name="Minor")]
|
||||
public Int32 Minor { get; set; }
|
||||
|
||||
[DataMember(Name="Revision")]
|
||||
public Int32 Revision { get; set; }
|
||||
|
||||
public Version Version
|
||||
{
|
||||
get { return new Version(Major, Minor, Build, Revision); }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Version.ToString();
|
||||
}
|
||||
}
|
||||
#endregion // Data contract
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _ipConfigApi = "api/networking/ipconfig";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the IP configuration data of the device.
|
||||
/// </summary>
|
||||
/// <returns>IpConfiguration object containing details of the device's network configuration.</returns>
|
||||
public async Task<IpConfiguration> GetIpConfig()
|
||||
{
|
||||
return await Get<IpConfiguration>(_ipConfigApi);
|
||||
}
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
[DataContract]
|
||||
public class Dhcp
|
||||
{
|
||||
[DataMember(Name="LeaseExpires")]
|
||||
public Int64 LeaseExpiresRaw { get; set; }
|
||||
|
||||
[DataMember(Name="LeaseObtained")]
|
||||
public Int64 LeaseObtainedRaw { get; set; }
|
||||
|
||||
[DataMember(Name="Address")]
|
||||
public IpAddressInfo Address { get; set; }
|
||||
|
||||
public DateTimeOffset LeaseExpires
|
||||
{
|
||||
get { return new DateTimeOffset(new DateTime(LeaseExpiresRaw)); }
|
||||
}
|
||||
|
||||
public DateTimeOffset LeaseObtained
|
||||
{
|
||||
get { return new DateTimeOffset(new DateTime(LeaseObtainedRaw)); }
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class IpAddressInfo
|
||||
{
|
||||
[DataMember(Name="IpAddress")]
|
||||
public String Address { get; set; }
|
||||
|
||||
[DataMember(Name="Mask")]
|
||||
public String SubnetMask { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class IpConfiguration
|
||||
{
|
||||
[DataMember(Name="Adapters")]
|
||||
public List<NetworkAdapterInfo> Adapters { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class NetworkAdapterInfo
|
||||
{
|
||||
[DataMember(Name="Description")]
|
||||
public String Description { get; set; }
|
||||
|
||||
[DataMember(Name="HardwareAddress")]
|
||||
public String MacAddress { get; set; }
|
||||
|
||||
[DataMember(Name="Index")]
|
||||
public Int32 Index { get; set; }
|
||||
|
||||
[DataMember(Name="Name")]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[DataMember(Name="Type")]
|
||||
public String AdapterType { get; set; }
|
||||
|
||||
[DataMember(Name="DHCP")]
|
||||
public Dhcp Dhcp { get; set; }
|
||||
|
||||
// BUGBUG - WINS
|
||||
|
||||
[DataMember(Name="Gateways")]
|
||||
public List<IpAddressInfo> Gateways { get; set; }
|
||||
|
||||
[DataMember(Name="IpAddresses")]
|
||||
public List<IpAddressInfo> IpAddresses { get; set; }
|
||||
}
|
||||
#endregion // Data contract
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _machineNameApi = "api/os/machinename";
|
||||
private static readonly String _osInfoApi = "api/os/info";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the device.
|
||||
/// </summary>
|
||||
/// <returns>String containing the device's name.</returns>
|
||||
public async Task<String> GetDeviceName()
|
||||
{
|
||||
DeviceName deviceName = await Get<DeviceName>(_machineNameApi);
|
||||
return deviceName.Name;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets information about the device's operating system.
|
||||
/// </summary>
|
||||
/// <returns>OperatingSystemInformation object containing details of the installed operating system.</returns>
|
||||
public async Task<OperatingSystemInformation> GetOperatingSystemInformation()
|
||||
{
|
||||
return await Get<OperatingSystemInformation>(_osInfoApi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the device's name
|
||||
/// </summary>
|
||||
/// <param name="name">The name to assign to the device.</param>
|
||||
/// <param name="reboot">True to reboot the device after setting the name, false otherwise.</param>
|
||||
/// <remarks>The new name does not take effect until the device has been restarted.</remarks>
|
||||
public async Task SetDeviceName(String name,
|
||||
Boolean reboot = true)
|
||||
{
|
||||
await Post(_machineNameApi,
|
||||
String.Format("name={0}", Utilities.Hex64Encode(name)));
|
||||
|
||||
// Names do not take effect until after a reboot.
|
||||
if (reboot)
|
||||
{
|
||||
await Reboot();
|
||||
}
|
||||
|
||||
// BUGBUG - wait until device has rebooted, then update the device name (osinfo and qualified name too?)
|
||||
}
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
|
||||
[DataContract]
|
||||
public class DeviceName
|
||||
{
|
||||
[DataMember(Name="ComputerName")]
|
||||
public String Name { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class OperatingSystemInformation
|
||||
{
|
||||
[DataMember(Name="ComputerName")]
|
||||
public String Name { get; set; }
|
||||
|
||||
[DataMember(Name="Language")]
|
||||
public String Languasge { get; set; }
|
||||
|
||||
[DataMember(Name="OsEdition")]
|
||||
public String OsEdition { get; set; }
|
||||
|
||||
[DataMember(Name="OsEditionId")]
|
||||
public UInt32 OsEditionId { get; set; }
|
||||
|
||||
[DataMember(Name="OsVersion")]
|
||||
public String OsVersionString { get; set; }
|
||||
|
||||
[DataMember(Name="Platform")]
|
||||
public String PlatformRaw { get; set; }
|
||||
|
||||
public DevicePortalPlatforms Platform
|
||||
{
|
||||
get
|
||||
{
|
||||
DevicePortalPlatforms platform = DevicePortalPlatforms.Unknown;
|
||||
|
||||
try
|
||||
{
|
||||
switch(PlatformRaw)
|
||||
{
|
||||
case "Xbox One":
|
||||
platform = DevicePortalPlatforms.XboxOne;
|
||||
break;
|
||||
|
||||
default:
|
||||
platform = (DevicePortalPlatforms)Enum.Parse(typeof(DevicePortalPlatforms), PlatformRaw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{}
|
||||
|
||||
return platform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum DevicePortalPlatforms
|
||||
{
|
||||
Unknown = -1,
|
||||
|
||||
// BUGBUG are these the correct names?
|
||||
Windows = 0,
|
||||
Mobile,
|
||||
IoT,
|
||||
HoloLens,
|
||||
XboxOne
|
||||
}
|
||||
#endregion // Data contract
|
||||
}
|
|
@ -0,0 +1,205 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
public static readonly String _runningProcessApi = "api/resourcemanager/processes";
|
||||
public static readonly String _systemPerfApi = "api/resourcemanager/systemperf";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of processes running on the device.
|
||||
/// </summary>
|
||||
/// <returns>RunningProcesses object containing the list of running processes.</returns>
|
||||
public async Task<RunningProcesses> GetRunningProcesses()
|
||||
{
|
||||
return await Get<RunningProcesses>(_runningProcessApi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets system performance information for the device.
|
||||
/// </summary>
|
||||
/// <returns>SystemPerformanceInformation object containing information such as memory usage.</returns>
|
||||
public async Task<SystemPerformanceInformation> GetSystemPerf()
|
||||
{
|
||||
return await Get<SystemPerformanceInformation>(_systemPerfApi);
|
||||
}
|
||||
}
|
||||
|
||||
#region Device contract
|
||||
|
||||
[DataContract]
|
||||
public class DeviceProcessInfo
|
||||
{
|
||||
[DataMember(Name="AppName")]
|
||||
public String AppName { get; set; }
|
||||
|
||||
[DataMember(Name="CPUUsage")]
|
||||
public Single CpuUsage { get; set; }
|
||||
|
||||
[DataMember(Name="ImageName")]
|
||||
public String Name { get; set; }
|
||||
|
||||
[DataMember(Name="ProcessId")]
|
||||
public Int32 ProcessId { get; set; }
|
||||
|
||||
[DataMember(Name="UserName")]
|
||||
public String UserName { get; set; }
|
||||
|
||||
[DataMember(Name="PackageFullName")]
|
||||
public String PackageFullName { get; set; }
|
||||
|
||||
[DataMember(Name="PageFileUsage")]
|
||||
public UInt32 PageFile { get; set; }
|
||||
|
||||
[DataMember(Name="WorkingSetSize")]
|
||||
public UInt32 WorkingSet { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} ({1})", AppName, Name);
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class GpuAdapters
|
||||
{
|
||||
[DataMember(Name="DedicatedMemory")]
|
||||
public UInt32 DedicatedMemory { get; set; }
|
||||
|
||||
[DataMember(Name="DedicatedMemoryUsed")]
|
||||
public UInt32 DedicatedMemoryUsed { get; set; }
|
||||
|
||||
[DataMember(Name="Description")]
|
||||
public String Description { get; set; }
|
||||
|
||||
[DataMember(Name="SystemMemory")]
|
||||
public UInt32 SystemMemory { get; set; }
|
||||
|
||||
[DataMember(Name="SystemMemoryUsed")]
|
||||
public UInt32 SystemMemoryUsed { get; set; }
|
||||
|
||||
[DataMember(Name="EnginesUtilization")]
|
||||
public List<Single> EnginesUtilization { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class GpuPerformanceData
|
||||
{
|
||||
[DataMember(Name="AvailableAdapters")]
|
||||
public List<GpuAdapters> Adapters { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class NetworkPerformanceData
|
||||
{
|
||||
[DataMember(Name="NetworkInBytes")]
|
||||
public Int32 BytesIn { get; set; }
|
||||
|
||||
[DataMember(Name="NetworkOutBytes")]
|
||||
public Int32 BytesOut { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class RunningProcesses
|
||||
{
|
||||
[DataMember(Name="Processes")]
|
||||
public DeviceProcessInfo[] Processes { get; set; }
|
||||
|
||||
public Boolean Contains(Int32 processId)
|
||||
{
|
||||
Boolean found = false;
|
||||
|
||||
if (Processes != null)
|
||||
{
|
||||
foreach (DeviceProcessInfo pi in Processes)
|
||||
{
|
||||
if (pi.ProcessId == processId)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
public Boolean Contains(String packageName, Boolean caseSensitive=true)
|
||||
{
|
||||
Boolean found = false;
|
||||
|
||||
if (Processes != null)
|
||||
{
|
||||
foreach (DeviceProcessInfo pi in Processes)
|
||||
{
|
||||
if (0 == String.Compare(pi.PackageFullName,
|
||||
packageName,
|
||||
caseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class SystemPerformanceInformation
|
||||
{
|
||||
[DataMember(Name="AvailablePages")]
|
||||
public Int32 AvailablePages { get; set; }
|
||||
|
||||
[DataMember(Name="CommitLimit")]
|
||||
public Int32 CommitLimit { get; set; }
|
||||
|
||||
[DataMember(Name="CommittedPages")]
|
||||
public Int32 CommittedPages { get; set; }
|
||||
|
||||
[DataMember(Name="CpuLoad")]
|
||||
public Int32 CpuLoad { get; set; }
|
||||
|
||||
[DataMember(Name="IOOtherSpeed")]
|
||||
public Int32 IoOtherSpeed { get; set; }
|
||||
|
||||
[DataMember(Name="IOReadSpeed")]
|
||||
public Int32 IoReadSpeed { get; set; }
|
||||
|
||||
[DataMember(Name="IOWriteSpeed")]
|
||||
public Int32 IoWriteSpeed { get; set; }
|
||||
|
||||
[DataMember(Name="NonPagedPoolPages")]
|
||||
public Int32 NonPagedPoolPages { get; set; }
|
||||
|
||||
[DataMember(Name="PageSize")]
|
||||
public Int32 PageSize { get; set; }
|
||||
|
||||
[DataMember(Name="PagedPoolPages")]
|
||||
public Int32 PagedPoolPages { get; set; }
|
||||
|
||||
[DataMember(Name="TotalInstalledInKb")]
|
||||
public Int32 TotalInstalledKb { get; set; }
|
||||
|
||||
[DataMember(Name="TotalPages")]
|
||||
public Int32 TotalPages { get; set; }
|
||||
|
||||
[DataMember(Name="GPUData")]
|
||||
public GpuPerformanceData GpuData { get; set; }
|
||||
|
||||
[DataMember(Name="NetworkingData")]
|
||||
public NetworkPerformanceData NetworkData { get; set; }
|
||||
}
|
||||
|
||||
#endregion // Device contract
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _batteryStateApi = "api/power/battery";
|
||||
private static readonly String _powerStateApi = "api/power/state";
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current state of the device's battery.
|
||||
/// </summary>
|
||||
/// <returns>BatteryState object containing details such as the current battery level.</returns>
|
||||
public async Task<BatteryState> GetBatteryState()
|
||||
{
|
||||
return await Get<BatteryState>(_batteryStateApi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the device's current power state.
|
||||
/// </summary>
|
||||
/// <returns>PowerState object containing details such as whether or not the device is in low power mode.</returns>
|
||||
public async Task<PowerState> GetPowerState()
|
||||
{
|
||||
return await Get<PowerState>(_powerStateApi);
|
||||
}
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
|
||||
[DataContract]
|
||||
public class BatteryState
|
||||
{
|
||||
[DataMember(Name="AcOnline")]
|
||||
public Boolean IsOnAcPower { get; set; }
|
||||
|
||||
[DataMember(Name="BatteryPresent")]
|
||||
public Boolean IsBatteryPresent { get; set; }
|
||||
|
||||
[DataMember(Name="Charging")]
|
||||
public Boolean IsCharging { get; set; }
|
||||
|
||||
[DataMember(Name="DefaultAlert1")]
|
||||
public Int32 DefaultAlert1 { get; set; }
|
||||
|
||||
[DataMember(Name="DefaultAlert2")]
|
||||
public Int32 DefaultAlert2 { get; set; }
|
||||
|
||||
[DataMember(Name="EstimatedTime")]
|
||||
public UInt32 EstimatedTimeRaw { get; set; }
|
||||
|
||||
[DataMember(Name="MaximumCapacity")]
|
||||
public UInt32 MaximumCapacity { get; set; }
|
||||
|
||||
[DataMember(Name="RemainingCapacity")]
|
||||
public Int32 RemainingCapacity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the battery level as a percentage of the maximum capacity.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Current battery level.
|
||||
/// </returns>
|
||||
public Single Level
|
||||
{
|
||||
get { return 100.0f * ((Single)RemainingCapacity/(Single)MaximumCapacity); }
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class PowerState
|
||||
{
|
||||
[DataMember(Name="LowPowerState")]
|
||||
public Boolean InLowPowerState { get; set; }
|
||||
|
||||
[DataMember(Name="LowPowerStateAvailable")]
|
||||
public Boolean IsLowPowerStateAvailable { get; set; }
|
||||
}
|
||||
|
||||
#endregion // Data contract
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _rebootApi = "api/control/restart";
|
||||
private static readonly String _shutdownApi = "api/control/shutdown";
|
||||
|
||||
/// <summary>
|
||||
/// Reboots the device.
|
||||
/// </summary>
|
||||
public async Task Reboot()
|
||||
{
|
||||
await Post(_rebootApi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down the device.
|
||||
/// </summary>
|
||||
public async Task Shutdown()
|
||||
{
|
||||
await Post(_shutdownApi);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _taskManagerApi = "api/taskmanager/app";
|
||||
|
||||
/// <summary>
|
||||
/// Starts running the specified application.
|
||||
/// </summary>
|
||||
/// <param name="appid">Application ID</param>
|
||||
/// <param name="packageName">The name of the application package.</param>
|
||||
/// <returns>Process identifier for the application instance.</returns>
|
||||
public async Task<Int32> LaunchApplication(String appid,
|
||||
String packageName)
|
||||
{
|
||||
String payload = String.Format("appid={0}&package={1}",
|
||||
Utilities.Hex64Encode(appid),
|
||||
Utilities.Hex64Encode(packageName));
|
||||
|
||||
await Post(_taskManagerApi,
|
||||
payload);
|
||||
|
||||
RunningProcesses runningApps = await GetRunningProcesses();
|
||||
|
||||
Int32 processId = 0;
|
||||
foreach (DeviceProcessInfo process in runningApps.Processes)
|
||||
{
|
||||
if (0 == String.Compare(process.PackageFullName, packageName))
|
||||
{
|
||||
processId = process.ProcessId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return processId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the specified application from running.
|
||||
/// </summary>
|
||||
/// <param name="packageName">The name of the application package.</param>
|
||||
public async Task TerminateApplication(String packageName)
|
||||
{
|
||||
await Delete(_taskManagerApi,
|
||||
String.Format("package={0}", Utilities.Hex64Encode(packageName)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _wifiInterfacesApi = "api/wifi/interfaces";
|
||||
private static readonly String _wifiNetworkApi = "api/wifi/network";
|
||||
private static readonly String _wifiNetworksApi = "api/wifi/networks";
|
||||
|
||||
public async Task ConnectToWifiNetwork(Guid networkAdapter,
|
||||
String ssid,
|
||||
String networkKey)
|
||||
{
|
||||
String payload = String.Format("interface={0}&ssid={1}&op=connect&createprofile=yes&key={2}",
|
||||
networkAdapter.ToString(),
|
||||
Utilities.Hex64Encode(ssid),
|
||||
Utilities.Hex64Encode(networkKey));
|
||||
|
||||
await Post(_wifiNetworkApi,
|
||||
payload);
|
||||
}
|
||||
|
||||
public async Task<WifiInterfaces> GetWifiInterfaces()
|
||||
{
|
||||
return await Get<WifiInterfaces>(_wifiInterfacesApi);
|
||||
}
|
||||
|
||||
public async Task<WifiNetworks> GetWifiNetworks(Guid interfaceGuid)
|
||||
{
|
||||
return await Get<WifiNetworks>(_wifiNetworksApi,
|
||||
String.Format("interface={0}", interfaceGuid.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
|
||||
[DataContract]
|
||||
public class WifiInterface
|
||||
{
|
||||
[DataMember(Name="Description")]
|
||||
public String Description { get; set; }
|
||||
|
||||
[DataMember(Name="GUID")]
|
||||
public Guid Guid { get; set; }
|
||||
|
||||
[DataMember(Name="Index")]
|
||||
public Int32 Index { get; set; }
|
||||
|
||||
[DataMember(Name = "ProfilesList")]
|
||||
public List<WifiNetworkProfile> Profiles { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class WifiInterfaces
|
||||
{
|
||||
[DataMember(Name="Interfaces")]
|
||||
public List<WifiInterface> Interfaces { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class WifiNetworks
|
||||
{
|
||||
[DataMember(Name="AvailableNetworks")]
|
||||
public List<WifiNetworkInfo> AvailableNetworks { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class WifiNetworkInfo
|
||||
{
|
||||
[DataMember(Name="AlreadyConnected")]
|
||||
public Boolean IsConnected { get; set; }
|
||||
|
||||
[DataMember(Name="AuthenticationAlgorithm")]
|
||||
public String AuthenticationAlgorithm { get; set; }
|
||||
|
||||
[DataMember(Name="Channel")]
|
||||
public Int32 Channel { get; set; }
|
||||
|
||||
[DataMember(Name="CipherAlgorithm")]
|
||||
public String CipherAlgorithm { get; set; }
|
||||
|
||||
[DataMember(Name="Connectable")]
|
||||
public Boolean IsConnectable { get; set; }
|
||||
|
||||
[DataMember(Name="InfrastructureType")]
|
||||
public String InfrastructureType { get; set; }
|
||||
|
||||
[DataMember(Name="ProfileAvailable")]
|
||||
public Boolean IsProfileAvailable { get; set; }
|
||||
|
||||
[DataMember(Name="ProfileName")]
|
||||
public String ProfileName { get; set; }
|
||||
|
||||
[DataMember(Name="SSID")]
|
||||
public String Ssid { get; set; }
|
||||
|
||||
[DataMember(Name="SecurityEnabled")]
|
||||
public Boolean IsSecurityEnabled { get; set; }
|
||||
|
||||
[DataMember(Name="SignalQuality")]
|
||||
public Int32 SignalQuality { get; set; }
|
||||
|
||||
[DataMember(Name = "BSSID")]
|
||||
public List<Int32> Bssid { get; set; }
|
||||
|
||||
[DataMember(Name = "PhysicalTypes")]
|
||||
public List<String> NetworkTypes { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class WifiNetworkProfile
|
||||
{
|
||||
[DataMember(Name="GroupPolicyProfile")]
|
||||
public Boolean IsGroupPolicyProfile { get; set; }
|
||||
|
||||
[DataMember(Name="Name")]
|
||||
public String Name { get; set; }
|
||||
|
||||
[DataMember(Name="PerUserProfile")]
|
||||
public Boolean IsPerUserProfile { get; set; }
|
||||
}
|
||||
#endregion // Data contract
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,205 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
public static readonly String DevicePortalCertificateIssuer = "Microsoft Windows Web Management";
|
||||
|
||||
private static readonly String _rootCertificateEndpoint = "config/rootcertificate";
|
||||
private IDevicePortalConnection _deviceConnection;
|
||||
|
||||
public DeviceConnectionStatusEventHandler ConnectionStatus;
|
||||
|
||||
public String Address
|
||||
{
|
||||
get { return _deviceConnection.Connection.Authority; }
|
||||
}
|
||||
|
||||
public String OperatingSystemVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return (_deviceConnection.OsInfo != null) ? _deviceConnection.OsInfo.OsVersionString : "";
|
||||
}
|
||||
}
|
||||
|
||||
public DevicePortalPlatforms Platform
|
||||
{
|
||||
get
|
||||
{
|
||||
return (_deviceConnection.OsInfo != null) ? _deviceConnection.OsInfo.Platform : DevicePortalPlatforms.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public DevicePortal(IDevicePortalConnection connection)
|
||||
{
|
||||
_deviceConnection = connection;
|
||||
}
|
||||
|
||||
public async Task Connect(String ssid = null,
|
||||
String ssidKey = null,
|
||||
Boolean updateConnection = true)
|
||||
{
|
||||
String connectionPhase = String.Empty;
|
||||
|
||||
// BUGBUG - add status event. this can take a LONG time
|
||||
try
|
||||
{
|
||||
// Get the device certificate
|
||||
connectionPhase = String.Format("Acquiring device certificate");
|
||||
SendConnectionStatus(DeviceConnectionStatus.Connecting,
|
||||
DeviceConnectionPhase.AcquiringCertificate,
|
||||
connectionPhase);
|
||||
_deviceConnection.SetDeviceCertificate(await GetDeviceCertificate());
|
||||
|
||||
// Get the operating system information.
|
||||
connectionPhase = String.Format("Requesting operating system information");
|
||||
SendConnectionStatus(DeviceConnectionStatus.Connecting,
|
||||
DeviceConnectionPhase.RequestingOperatingSystemInformation,
|
||||
connectionPhase);
|
||||
_deviceConnection.OsInfo = await GetOperatingSystemInformation();
|
||||
|
||||
Boolean requiresHttps = true; // BUGBUG - is this the correct default?
|
||||
if (_deviceConnection.OsInfo.Platform != DevicePortalPlatforms.XboxOne) // TODO: need a better check.
|
||||
{
|
||||
// Check to see if HTTPS is required to communicate with this device.
|
||||
connectionPhase = String.Format("Checking secure connection requirements");
|
||||
|
||||
try
|
||||
{
|
||||
requiresHttps = await GetIsHttpsRequired();
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{ }
|
||||
}
|
||||
|
||||
// Connect the device to the specified network.
|
||||
if (!String.IsNullOrWhiteSpace(ssid))
|
||||
{
|
||||
connectionPhase = String.Format("Connecting to {0} network", ssid);
|
||||
SendConnectionStatus(DeviceConnectionStatus.Connecting,
|
||||
DeviceConnectionPhase.ConnectingToTargetNetwork,
|
||||
connectionPhase);
|
||||
WifiInterfaces wifiInterfaces = await GetWifiInterfaces();
|
||||
// BUGBUG - consider what to do if there is more than one wifi interface on a device
|
||||
await ConnectToWifiNetwork(wifiInterfaces.Interfaces[0].Guid, ssid, ssidKey);
|
||||
|
||||
// BUGBUG - note that in some instances, the hololens was receiving a KeepAlive exception, yet the network connection succeeded.
|
||||
// this COULD have been an RTM bug that is now fixed, or it could have been the fault of the access point
|
||||
// some investigation and defensive measures should be implemented here to avoid excessive noise / false failures
|
||||
}
|
||||
|
||||
// Get the device's IP configuration and update the connection as appropriate.
|
||||
if (updateConnection)
|
||||
{
|
||||
connectionPhase = String.Format("Updating device connection");
|
||||
SendConnectionStatus(DeviceConnectionStatus.Connecting,
|
||||
DeviceConnectionPhase.UpdatingDeviceAddress,
|
||||
connectionPhase);
|
||||
_deviceConnection.UpdateConnection(await GetIpConfig(), requiresHttps);
|
||||
}
|
||||
|
||||
SendConnectionStatus(DeviceConnectionStatus.Connected,
|
||||
DeviceConnectionPhase.Idle,
|
||||
"Device connection established");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
DevicePortalException dpe = e as DevicePortalException;
|
||||
|
||||
HttpStatusCode status = (HttpStatusCode)0;
|
||||
Uri request = null;
|
||||
if (dpe != null)
|
||||
{
|
||||
status = dpe.StatusCode;
|
||||
request = dpe.RequestUri;
|
||||
}
|
||||
|
||||
SendConnectionStatus(DeviceConnectionStatus.Failed,
|
||||
DeviceConnectionPhase.Idle,
|
||||
String.Format("Device connection failed: {0}", connectionPhase));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<Byte[]> GetDeviceCertificate()
|
||||
{
|
||||
Byte[] certificateData = null;
|
||||
bool useHttps = true;
|
||||
|
||||
// try https then http
|
||||
while (true)
|
||||
{
|
||||
Uri uri = null;
|
||||
|
||||
if (useHttps)
|
||||
{
|
||||
uri = Utilities.BuildEndpoint(_deviceConnection.Connection, _rootCertificateEndpoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
Uri baseUri = new Uri(String.Format("http://{0}", _deviceConnection.Connection.Authority));
|
||||
uri = Utilities.BuildEndpoint(baseUri, _rootCertificateEndpoint);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (Stream stream = await Get(uri, false))
|
||||
{
|
||||
using (BinaryReader reader = new BinaryReader(stream))
|
||||
{
|
||||
Byte[] certData = reader.ReadBytes((Int32)stream.Length);
|
||||
|
||||
// Validate the issuer.
|
||||
X509Certificate2 cert = new X509Certificate2(certData);
|
||||
if (!cert.IssuerName.Name.Contains(DevicePortalCertificateIssuer))
|
||||
{
|
||||
throw new DevicePortalException((HttpStatusCode)0,
|
||||
"Invalid certificate issuer",
|
||||
uri,
|
||||
"Failed to get device certificate");
|
||||
}
|
||||
certificateData = certData;
|
||||
}
|
||||
}
|
||||
|
||||
return certificateData;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if(useHttps)
|
||||
{
|
||||
useHttps = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="status"></param>
|
||||
/// <param name="phase"></param>
|
||||
/// <param name="message"></param>
|
||||
private void SendConnectionStatus(DeviceConnectionStatus status,
|
||||
DeviceConnectionPhase phase,
|
||||
String message = "")
|
||||
{
|
||||
ConnectionStatus?.Invoke(this,
|
||||
new DeviceConnectionStatusEventArgs(status, phase, message));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
public delegate void ApplicationInstallStatusEventHandler(Object sender, ApplicationInstallStatusEventArgs args);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ApplicationInstallStatusEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public AppInstallStatus Status
|
||||
{ get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public AppInstallPhase Phase
|
||||
{ get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public String Message
|
||||
{ get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="status"></param>
|
||||
/// <param name="phase"></param>
|
||||
/// <param name="message"></param>
|
||||
internal ApplicationInstallStatusEventArgs(AppInstallStatus status,
|
||||
AppInstallPhase phase,
|
||||
String message = "")
|
||||
{
|
||||
Status = status;
|
||||
Phase = phase;
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
|
||||
public enum AppInstallStatus
|
||||
{
|
||||
None,
|
||||
InProgress,
|
||||
Completed,
|
||||
Failed
|
||||
}
|
||||
|
||||
public enum AppInstallPhase
|
||||
{
|
||||
Idle,
|
||||
UninstallingPreviousVersion,
|
||||
CopyingFile,
|
||||
Installing
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
public delegate void DeviceConnectionStatusEventHandler(Object sender, DeviceConnectionStatusEventArgs args);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class DeviceConnectionStatusEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public DeviceConnectionStatus Status
|
||||
{ get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public DeviceConnectionPhase Phase
|
||||
{ get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public String Message
|
||||
{ get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="status"></param>
|
||||
/// <param name="phase"></param>
|
||||
/// <param name="message"></param>
|
||||
internal DeviceConnectionStatusEventArgs(DeviceConnectionStatus status,
|
||||
DeviceConnectionPhase phase,
|
||||
String message = "")
|
||||
{
|
||||
Status = status;
|
||||
Phase = phase;
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum DeviceConnectionStatus
|
||||
{
|
||||
None,
|
||||
Connecting,
|
||||
Connected,
|
||||
Failed,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum DeviceConnectionPhase
|
||||
{
|
||||
Idle,
|
||||
AcquiringCertificate,
|
||||
DeterminingConnectionRequirements,
|
||||
RequestingOperatingSystemInformation,
|
||||
ConnectingToTargetNetwork,
|
||||
UpdatingDeviceAddress
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public class DevicePortalException : Exception
|
||||
{
|
||||
public HttpStatusCode StatusCode { get; private set; }
|
||||
|
||||
public String Reason { get; private set; }
|
||||
|
||||
public Uri RequestUri { get; private set; }
|
||||
|
||||
public DevicePortalException(HttpResponseMessage responseMessage,
|
||||
String message = "",
|
||||
Exception innerException = null) : this(responseMessage.StatusCode,
|
||||
responseMessage.ReasonPhrase,
|
||||
responseMessage.RequestMessage.RequestUri,
|
||||
message,
|
||||
innerException)
|
||||
{ }
|
||||
|
||||
public DevicePortalException(HttpStatusCode statusCode,
|
||||
String reason,
|
||||
Uri requestUri = null,
|
||||
String message = "",
|
||||
Exception innerException = null) : base(message,
|
||||
innerException)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
Reason = reason;
|
||||
RequestUri = requestUri;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _ipdApi = "api/holographic/os/settings/ipd";
|
||||
private static readonly String _servicesApi = "api/holographic/os/services";
|
||||
private static readonly String _webManagementHttpSettingsApi = "api/holographic/os/webmanagement/settings/https";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the interpupilary distance registered on the device.
|
||||
/// </summary>
|
||||
/// <returns>Interpupilary distance, in millimeters.</returns>
|
||||
/// <remarks>This method is only supported on HoloLens devices.</remarks>
|
||||
public async Task<Single> GetInterPupilaryDistance()
|
||||
{
|
||||
if (Platform != DevicePortalPlatforms.HoloLens)
|
||||
{
|
||||
throw new NotSupportedException("The GetInterPupilaryDistance method is only supported on HoloLens.");
|
||||
}
|
||||
|
||||
InterPupilaryDistance ipd = await Get<InterPupilaryDistance>(_ipdApi);
|
||||
return ipd.Ipd;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WiFi http security requirements for communication with the device.
|
||||
/// </summary>
|
||||
/// <returns>True if WiFi based communication requires a secure connection, false otherwise.</returns>
|
||||
/// <remarks>This method is only supported on HoloLens devices.</remarks>
|
||||
private async Task<Boolean> GetIsHttpsRequired()
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((Platform != DevicePortalPlatforms.Unknown) &&
|
||||
(Platform != DevicePortalPlatforms.HoloLens))
|
||||
{
|
||||
throw new NotSupportedException("The GetIsHttpsRequired method is only supported on HoloLens.");
|
||||
}
|
||||
|
||||
WebManagementHttpSettings httpSettings = await Get<WebManagementHttpSettings>(_webManagementHttpSettingsApi);
|
||||
return httpSettings.IsHttpsRequired;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
DevicePortalException dpe = e as DevicePortalException;
|
||||
|
||||
if ((dpe != null) &&
|
||||
(dpe.StatusCode != System.Net.HttpStatusCode.NotFound))
|
||||
{
|
||||
throw new NotSupportedException("The GetIsHttpsRequired method is only supported on HoloLens.");
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the WiFi http security requirements for communication with the device.
|
||||
/// </summary>
|
||||
/// <returns>True if WiFi based communication requires a secure connection, false otherwise.</returns>
|
||||
/// <remarks>This method is only supported on HoloLens devices.</remarks>
|
||||
public async Task SetIsHttpsRequired(Boolean httpsRequired)
|
||||
{
|
||||
if (Platform != DevicePortalPlatforms.HoloLens)
|
||||
{
|
||||
throw new NotSupportedException("The SetIsHttpsRequired method is only supported on HoloLens.");
|
||||
}
|
||||
|
||||
await Post(_webManagementHttpSettingsApi,
|
||||
String.Format("required={0}", httpsRequired));
|
||||
|
||||
_deviceConnection.UpdateConnection(httpsRequired);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the interpupilary distance registered on the device.
|
||||
/// </summary>
|
||||
/// <param name="ipd">Interpupilary distance, in millimeters.</param>
|
||||
/// <remarks>This method is only supported on HoloLens devices.</remarks>
|
||||
public async Task SetInterPupilaryDistance(Single ipd)
|
||||
{
|
||||
if (Platform != DevicePortalPlatforms.HoloLens)
|
||||
{
|
||||
throw new NotSupportedException("The SetInterPupilaryDistance method is only supported on HoloLens.");
|
||||
}
|
||||
|
||||
String payload = String.Format("ipd={0}", (Int32)(ipd * 1000.0f));
|
||||
await Post(_ipdApi,
|
||||
payload);
|
||||
}
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
[DataContract]
|
||||
public class WebManagementHttpSettings
|
||||
{
|
||||
[DataMember(Name="httpsRequired")]
|
||||
public Boolean IsHttpsRequired { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class InterPupilaryDistance
|
||||
{
|
||||
[DataMember(Name="ipd")]
|
||||
public Int32 IpdRaw{ get; set; }
|
||||
|
||||
public Single Ipd
|
||||
{
|
||||
get { return IpdRaw / 1000.0f; }
|
||||
set { IpdRaw = (Int32)(value * 1000); }
|
||||
}
|
||||
}
|
||||
#endregion // Data contract
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _thermalStageApi = "api/holographic/thermal/stage";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the curent thermal stage reading from the device.
|
||||
/// </summary>
|
||||
/// <returns>ThermalStages enum value.</returns>
|
||||
/// <remarks>This method is only supported on HoloLens devices.</remarks>
|
||||
public async Task<ThermalStages> GetThermalStage()
|
||||
{
|
||||
ThermalStage thermalStage = await Get<ThermalStage>(_thermalStageApi);
|
||||
return thermalStage.Stage;
|
||||
}
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
|
||||
public enum ThermalStages
|
||||
{
|
||||
Normal,
|
||||
Warm,
|
||||
Critical,
|
||||
Unknown = 9999
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class ThermalStage
|
||||
{
|
||||
[DataMember(Name="CurrentStage")]
|
||||
public Int32 StageRaw { get; set; }
|
||||
|
||||
public ThermalStages Stage
|
||||
{
|
||||
get
|
||||
{
|
||||
ThermalStages stage = ThermalStages.Unknown;
|
||||
|
||||
try
|
||||
{
|
||||
stage = (ThermalStages)Enum.ToObject(typeof(ThermalStages), StageRaw);
|
||||
|
||||
if (!Enum.IsDefined(typeof(ThermalStages), stage))
|
||||
{
|
||||
stage = ThermalStages.Unknown;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
stage = ThermalStages.Unknown;
|
||||
}
|
||||
|
||||
return stage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion // Data contract
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _mrcFileApi = "api/holographic/mrc/file";
|
||||
private static readonly String _mrcFileListApi = "api/holographic/mrc/files";
|
||||
private static readonly String _mrcPhotoApi = "api/holographic/mrc/photo";
|
||||
private static readonly String _mrcSettingsApi = "api/holographic/mrc/settings";
|
||||
private static readonly String _mrcStartRecordingApi = "api/holographic/mrc/video/control/start";
|
||||
private static readonly String _mrcStatusApi = "api/holographic/mrc/status";
|
||||
private static readonly String _mrcStopRecordingApi = "api/holographic/mrc/video/control/stop";
|
||||
private static readonly String _mrcThumbnailApi = "api/holographic/mrc/thumbnail";
|
||||
|
||||
/// <summary>
|
||||
/// Removes a Mixed Reality Capture file from the device's local storage.
|
||||
/// </summary>
|
||||
/// <param name="fileName">The name of the file to be deleted.</param>
|
||||
public async Task DeleteMrcFile(String fileName)
|
||||
{
|
||||
await Delete(_mrcFileApi,
|
||||
String.Format("filename={0}", Utilities.Hex64Encode(fileName)));
|
||||
}
|
||||
|
||||
public async Task<Byte[]> GetMrcFileData(String fileName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<MrcFileList> GetMrcFileList()
|
||||
{
|
||||
MrcFileList mrcFileList = await Get<MrcFileList>(_mrcFileListApi);
|
||||
|
||||
foreach (MrcFileInformation mfi in mrcFileList.Files)
|
||||
{
|
||||
try
|
||||
{
|
||||
mfi.Thumbnail = await GetMrcThumbnailData(mfi.FileName);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
return mrcFileList;
|
||||
}
|
||||
|
||||
public async Task<Byte[]> GetMrcThumbnailData(String fileName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// BUGBUG public async Task StartMrcRecording()
|
||||
// BUGBUG public async Task StopMrcRecording()
|
||||
|
||||
public async Task TakeMrcPhoto(Boolean includeHolograms,
|
||||
Boolean includeColorCamera)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
|
||||
[DataContract]
|
||||
public class MrcFileList
|
||||
{
|
||||
[DataMember(Name="MrcRecordings")]
|
||||
public List<MrcFileInformation> Files { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class MrcFileInformation
|
||||
{
|
||||
[DataMember(Name="CreationTime")]
|
||||
public Int64 CreationTimeRaw { get; set; }
|
||||
|
||||
[DataMember(Name="FileName")]
|
||||
public String FileName { get; set; }
|
||||
|
||||
[DataMember(Name="FileSize")]
|
||||
public UInt32 FileSize { get; set; }
|
||||
|
||||
public Byte[] Thumbnail { get; internal set; }
|
||||
|
||||
public DateTime Created
|
||||
{
|
||||
get { return new DateTime(CreationTimeRaw); }
|
||||
}
|
||||
}
|
||||
|
||||
// BUGBUG
|
||||
[DataContract]
|
||||
public class SettingKeyValuePair
|
||||
{
|
||||
[DataMember(Name = "Setting")]
|
||||
public String Key { get; set; }
|
||||
|
||||
[DataMember(Name = "Value")]
|
||||
public Object Value { get; set; }
|
||||
|
||||
public SettingKeyValuePair()
|
||||
{ }
|
||||
|
||||
public SettingKeyValuePair(String key, Object value)
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public class MrcOptions
|
||||
{
|
||||
public Boolean Audio { get; set; }
|
||||
|
||||
public Boolean ColorCamera { get; set; }
|
||||
|
||||
public Boolean Holograms { get; set; }
|
||||
|
||||
public Boolean Microphone { get; set; }
|
||||
|
||||
public MrcOptions()
|
||||
{
|
||||
Audio = true;
|
||||
ColorCamera = true;
|
||||
Holograms = true;
|
||||
Microphone = true;
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class MrcSettings
|
||||
{
|
||||
[DataMember(Name = "MrcSettings")]
|
||||
public List<SettingKeyValuePair> Settings { get; set; }
|
||||
|
||||
public MrcSettings()
|
||||
{
|
||||
Settings = new List<SettingKeyValuePair>();
|
||||
}
|
||||
|
||||
public MrcSettings(MrcOptions options) : this()
|
||||
{
|
||||
Settings.Add(new SettingKeyValuePair("EnableCamera", options.ColorCamera));
|
||||
Settings.Add(new SettingKeyValuePair("EnableHolograms", options.Holograms));
|
||||
Settings.Add(new SettingKeyValuePair("EnableSystemAudio", options.Audio));
|
||||
Settings.Add(new SettingKeyValuePair("EnableMicrophone", options.Microphone));
|
||||
}
|
||||
|
||||
public MrcSettings(MrcOptions options, Int32 stabilizationBuffer) : this(options)
|
||||
{
|
||||
Settings.Add(new SettingKeyValuePair("VideoStabilizationBuffer", stabilizationBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class MrcStatus
|
||||
{
|
||||
[DataMember(Name="CreationTime")]
|
||||
public Int64 CreationTimeRaw { get; set; }
|
||||
|
||||
[DataMember(Name="ProcessStatus")]
|
||||
public ProcessStatus Status { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class ProcessStatus
|
||||
{
|
||||
[DataMember(Name="MrcProcess")]
|
||||
public String MrcProcess { get; set; } // BUGBUG this should be an enum
|
||||
|
||||
}
|
||||
#endregion Data contract
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
/// <summary>
|
||||
/// Submits the http delete request to the specified uri.
|
||||
/// </summary>
|
||||
/// <param name="uri">The uri to which the delete request will be issued.</param>
|
||||
private async Task Delete(Uri uri)
|
||||
{
|
||||
WebRequestHandler handler = new WebRequestHandler();
|
||||
handler.UseDefaultCredentials = false;
|
||||
handler.Credentials = _deviceConnection.Credentials;
|
||||
handler.ServerCertificateValidationCallback = ServerCertificateValidation;
|
||||
|
||||
using (HttpClient client = new HttpClient(handler))
|
||||
{
|
||||
Task<HttpResponseMessage> deleteTask = client.DeleteAsync(uri);
|
||||
await deleteTask.ConfigureAwait(false);
|
||||
deleteTask.Wait();
|
||||
|
||||
using (HttpResponseMessage response = deleteTask.Result)
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new DevicePortalException(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls the specified api with the provided payload.
|
||||
/// </summary>
|
||||
/// <param name="apiPath">The relative portion of the uri path that specifies the API to call.</param>
|
||||
/// <param name="payload">The query string portion of the uri path that provides the parameterized data.</param>
|
||||
private async Task Delete(String apiPath,
|
||||
String payload = null)
|
||||
{
|
||||
Uri uri = Utilities.BuildEndpoint(_deviceConnection.Connection,
|
||||
apiPath, payload);
|
||||
await Delete(uri);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
/// <summary>
|
||||
/// Submits the http get request to the specified uri.
|
||||
/// </summary>
|
||||
/// <param name="uri">The uri to which the get request will be issued.</param>
|
||||
/// /// <param name="validateCertificate">Whether the certificate should be validated.</param>
|
||||
/// <returns>Response data as a stream.</returns>
|
||||
private async Task<Stream> Get(Uri uri, bool validateCertificate = true)
|
||||
{
|
||||
MemoryStream dataStream = null;
|
||||
|
||||
WebRequestHandler handler = new WebRequestHandler();
|
||||
handler.UseDefaultCredentials = false;
|
||||
handler.Credentials = _deviceConnection.Credentials;
|
||||
if (validateCertificate)
|
||||
{
|
||||
handler.ServerCertificateValidationCallback = ServerCertificateValidation;
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.ServerCertificateValidationCallback = ServerCertificateNonValidation;
|
||||
}
|
||||
|
||||
using (HttpClient client = new HttpClient(handler))
|
||||
{
|
||||
Task<HttpResponseMessage> getTask = client.GetAsync(uri);
|
||||
await getTask.ConfigureAwait(false);
|
||||
getTask.Wait();
|
||||
|
||||
using (HttpResponseMessage response = getTask.Result)
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
using (HttpContent content = response.Content)
|
||||
{
|
||||
dataStream = new MemoryStream();
|
||||
|
||||
Task copyTask = content.CopyToAsync(dataStream);
|
||||
await copyTask.ConfigureAwait(false);
|
||||
copyTask.Wait();
|
||||
|
||||
// Ensure we return with the stream pointed at the origin.
|
||||
dataStream.Position = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dataStream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls the specified api with the provided payload.
|
||||
/// </summary>
|
||||
/// <param name="apiPath">The relative portion of the uri path that specifies the API to call.</param>
|
||||
/// <param name="payload">The query string portion of the uri path that provides the parameterized data.</param>
|
||||
/// <returns>An object of the specified type containing the data returned by the request.</returns>
|
||||
private async Task<T> Get<T>(String apiPath,
|
||||
String payload = null) where T : new()
|
||||
{
|
||||
T data = default(T);
|
||||
|
||||
Uri uri = Utilities.BuildEndpoint(_deviceConnection.Connection,
|
||||
apiPath, payload);
|
||||
|
||||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
|
||||
|
||||
using (Stream dataStream = await Get(uri))
|
||||
{
|
||||
if (dataStream != null)
|
||||
{
|
||||
Object response = serializer.ReadObject(dataStream);
|
||||
data = (T)response;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
/// <summary>
|
||||
/// Submits the http post request to the specified uri.
|
||||
/// </summary>
|
||||
/// <param name="uri">The uri to which the post request will be issued.</param>
|
||||
private async Task Post(Uri uri)
|
||||
{
|
||||
WebRequestHandler handler = new WebRequestHandler();
|
||||
handler.UseDefaultCredentials = false;
|
||||
handler.Credentials = _deviceConnection.Credentials;
|
||||
handler.ServerCertificateValidationCallback = ServerCertificateValidation;
|
||||
|
||||
using (HttpClient client = new HttpClient(handler))
|
||||
{
|
||||
Task<HttpResponseMessage> postTask = client.PostAsync(uri, null);
|
||||
await postTask.ConfigureAwait(false);
|
||||
postTask.Wait();
|
||||
|
||||
using (HttpResponseMessage response = postTask.Result)
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new DevicePortalException(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls the specified api with the provided payload.
|
||||
/// </summary>
|
||||
/// <param name="apiPath">The relative portion of the uri path that specifies the API to call.</param>
|
||||
/// <param name="payload">The query string portion of the uri path that provides the parameterized data.</param>
|
||||
private async Task Post(String apiPath,
|
||||
String payload = null)
|
||||
{
|
||||
Uri uri = Utilities.BuildEndpoint(_deviceConnection.Connection,
|
||||
apiPath, payload);
|
||||
await Post(uri);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
/// <summary>
|
||||
/// Submits the http put request to the specified uri.
|
||||
/// </summary>
|
||||
/// <param name="uri">The uri to which the put request will be issued.</param>
|
||||
private async Task Put(Uri uri,
|
||||
HttpContent body = null)
|
||||
{
|
||||
WebRequestHandler handler = new WebRequestHandler();
|
||||
handler.UseDefaultCredentials = false;
|
||||
handler.Credentials = _deviceConnection.Credentials;
|
||||
handler.ServerCertificateValidationCallback = ServerCertificateValidation;
|
||||
|
||||
using (HttpClient client = new HttpClient(handler))
|
||||
{
|
||||
// Send the request
|
||||
Task <HttpResponseMessage> putTask = client.PutAsync(uri, body);
|
||||
await putTask.ConfigureAwait(false);
|
||||
putTask.Wait();
|
||||
|
||||
using (HttpResponseMessage response = putTask.Result)
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new DevicePortalException(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls the specified api with the provided payload.
|
||||
/// </summary>
|
||||
/// <param name="apiPath">The relative portion of the uri path that specifies the API to call.</param>
|
||||
/// <param name="payload">The query string portion of the uri path that provides the parameterized data.</param>
|
||||
private async Task Put(String apiPath,
|
||||
String payload = null
|
||||
)
|
||||
{
|
||||
Uri uri = Utilities.BuildEndpoint(_deviceConnection.Connection,
|
||||
apiPath, payload);
|
||||
await Put(uri);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls the specified api with the provided body.
|
||||
/// </summary>
|
||||
/// <param name="apiPath">The relative portion of the uri path that specifies the API to call.</param>
|
||||
/// <param name="payload">The query string portion of the uri path that provides the parameterized data.</param>
|
||||
private async Task Put<T>(String apiPath,
|
||||
T bodyData,
|
||||
String payload = null
|
||||
)
|
||||
{
|
||||
Uri uri = Utilities.BuildEndpoint(_deviceConnection.Connection,
|
||||
apiPath, payload);
|
||||
|
||||
// Serialize the body to a JSON stream
|
||||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
|
||||
Stream stream = new MemoryStream();
|
||||
serializer.WriteObject(stream, bodyData);
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
StreamContent streamContent = new StreamContent(stream);
|
||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
|
||||
await Put(uri, streamContent);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private Boolean ServerCertificateValidation(Object sender,
|
||||
X509Certificate cert,
|
||||
X509Chain chain,
|
||||
SslPolicyErrors policyErrors)
|
||||
{
|
||||
// BUGBUG - really need a GOOD (read: secure) way to do this for .net. uwp already handles nicely
|
||||
|
||||
Byte[] deviceCertData = _deviceConnection.GetDeviceCertificateData();
|
||||
|
||||
if (deviceCertData == null)
|
||||
{
|
||||
// No certificate, fail validation.
|
||||
return false;
|
||||
}
|
||||
|
||||
X509Certificate deviceCert = new X509Certificate(deviceCertData);
|
||||
|
||||
// Check the certificate
|
||||
// * First, make sure we are in the date range
|
||||
DateTime now = DateTime.Now;
|
||||
if ((now < DateTime.Parse(cert.GetEffectiveDateString())) ||
|
||||
(now > DateTime.Parse(cert.GetExpirationDateString())))
|
||||
{
|
||||
// The current date is out of bounds, fail validation.
|
||||
return false;
|
||||
}
|
||||
// * Next, compare the issuer
|
||||
if (deviceCert.Issuer != cert.Issuer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// BUGBUG - need good validation......
|
||||
// Would be nice to allow Fiddler via an override as well--Issuer will show up as something like the following:
|
||||
// "cert.Issuer = "CN=DO_NOT_TRUST_FiddlerRoot, O=DO_NOT_TRUST, OU=Created by http://www.fiddler2.com"
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Boolean ServerCertificateNonValidation(Object sender,
|
||||
X509Certificate cert,
|
||||
X509Chain chain,
|
||||
SslPolicyErrors policyErrors)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public interface IDevicePortalConnection
|
||||
{
|
||||
/// <summary>
|
||||
/// The base uri (ex: http://localhost) used to communicate with the device.
|
||||
/// </summary>
|
||||
Uri Connection { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The credentials used when communicating with the device.
|
||||
/// </summary>
|
||||
NetworkCredential Credentials { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The friendly name of the device (ex: LivingRoomPC).
|
||||
/// </summary>
|
||||
String Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Information describing the operating system installed on the device.
|
||||
/// </summary>
|
||||
OperatingSystemInformation OsInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the raw data of the device's root certificate.
|
||||
/// </summary>
|
||||
/// <returns>Byte array containing the certificate data.</returns>
|
||||
Byte[] GetDeviceCertificateData();
|
||||
|
||||
/// <summary>
|
||||
/// Provides the raw data of the device's root certificate.
|
||||
/// </summary>
|
||||
/// <param name="certificateData">Byte array containing the certificate data.</param>
|
||||
/// <remarks>How this data is used and/or stored is implementation specific.</remarks>
|
||||
void SetDeviceCertificate(Byte[] certificateData);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the http security requirements for device communication.
|
||||
/// </summary>
|
||||
/// <param name="requiresHttps">True if an https connection is required, false otherwise.</param>
|
||||
void UpdateConnection(Boolean requiresHttps);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the connection details (IP address) and http security requirements used when communicating with the device.
|
||||
/// </summary>
|
||||
/// <param name="ipConfig">IpConfiguration object that describes the current network configuration.</param>
|
||||
/// <param name="requiresHttps">True if an https connection is required, false otherwise.</param>
|
||||
void UpdateConnection(IpConfiguration ipConfig,
|
||||
Boolean requiresHttps);
|
||||
}
|
||||
}
|
|
@ -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("WindowsDevicePortalWrapper")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("WindowsDevicePortalWrapper")]
|
||||
[assembly: AssemblyCopyright("Copyright © 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("6a9e862e-5cda-4a8a-bbc0-56e9ea921e39")]
|
||||
|
||||
// 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,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
internal static class Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a fully formed REST API endpoint uri.
|
||||
/// </summary>
|
||||
/// <param name="baseUri">The base uri (typically, just scheme and authority).</param>
|
||||
/// <param name="path">The path to the REST API method (ex: api/control/restart).</param>
|
||||
/// <param name="payload">Parameterized data required by the REST API.</param>
|
||||
/// <returns>Uri object containing the complete path and query string required to issue the REST API call.</returns>
|
||||
public static Uri BuildEndpoint(Uri baseUri,
|
||||
String path,
|
||||
String payload = null)
|
||||
{
|
||||
String relativePart = !String.IsNullOrWhiteSpace(payload) ?
|
||||
String.Format("{0}?{1}", path, payload) : path;
|
||||
return new Uri(baseUri, relativePart);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes the specified string as a base64 value.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to encode.</param>
|
||||
/// <returns>Base64 encoded version of the string data.</returns>
|
||||
internal static String Hex64Encode(String str)
|
||||
{
|
||||
return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?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>{6A9E862E-5CDA-4A8A-BBC0-56E9EA921E39}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.Tools.WindowsDevicePortal</RootNamespace>
|
||||
<AssemblyName>WindowsDevicePortalWrapper</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<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' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Net.Http.WebRequest" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Core\AppDeployment.cs" />
|
||||
<Compile Include="Core\DumpCollection.cs" />
|
||||
<Compile Include="Core\Etw.cs" />
|
||||
<Compile Include="Core\Networking.cs" />
|
||||
<Compile Include="Core\OsInformation.cs" />
|
||||
<Compile Include="Core\PerformanceData.cs" />
|
||||
<Compile Include="Core\Power.cs" />
|
||||
<Compile Include="Core\RemoteControl.cs" />
|
||||
<Compile Include="Core\TaskManager.cs" />
|
||||
<Compile Include="Core\WiFiManagement.cs" />
|
||||
<Compile Include="Core\WindowsPerformanceRecorder.cs" />
|
||||
<Compile Include="DevicePortal.cs" />
|
||||
<Compile Include="Events\ApplicationInstallStatus.cs" />
|
||||
<Compile Include="Events\ConnectionStatus.cs" />
|
||||
<Compile Include="Exceptions\DevicePortalException.cs" />
|
||||
<Compile Include="HoloLens\HolographicOs.cs" />
|
||||
<Compile Include="HoloLens\HolographicPerception.cs" />
|
||||
<Compile Include="HoloLens\HolographicThermal.cs" />
|
||||
<Compile Include="HoloLens\MixedRealityCapture.cs" />
|
||||
<Compile Include="HoloLens\PerceptionSimulationPlayback.cs" />
|
||||
<Compile Include="HoloLens\PerceptionSimulationRecording.cs" />
|
||||
<Compile Include="HttpRest\RestPut.cs" />
|
||||
<Compile Include="HttpRest\ServerCertificateValidation.cs" />
|
||||
<Compile Include="HttpRest\RestDelete.cs" />
|
||||
<Compile Include="HttpRest\RestGet.cs" />
|
||||
<Compile Include="HttpRest\RestPost.cs" />
|
||||
<Compile Include="Interfaces\IDevicePortalConnection.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
<Compile Include="Xbox\NetworkConnection.cs" />
|
||||
<Compile Include="Xbox\SmbShare.cs" />
|
||||
<Compile Include="Xbox\UserManagement.cs" />
|
||||
<Compile Include="Xbox\XboxAppDeployment.cs" />
|
||||
</ItemGroup>
|
||||
<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,111 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal.Xbox
|
||||
{
|
||||
public class NetworkConnection : IDisposable
|
||||
{
|
||||
string _networkName;
|
||||
|
||||
public NetworkConnection(string networkName,
|
||||
NetworkCredential credentials)
|
||||
{
|
||||
_networkName = networkName;
|
||||
|
||||
var netResource = new NetResource()
|
||||
{
|
||||
Scope = ResourceScope.GlobalNetwork,
|
||||
ResourceType = ResourceType.Disk,
|
||||
DisplayType = ResourceDisplaytype.Share,
|
||||
RemoteName = networkName
|
||||
};
|
||||
|
||||
var userName = string.IsNullOrEmpty(credentials.Domain)
|
||||
? credentials.UserName
|
||||
: string.Format(@"{0}\{1}", credentials.Domain, credentials.UserName);
|
||||
|
||||
var result = WNetAddConnection2(
|
||||
netResource,
|
||||
credentials.Password,
|
||||
userName,
|
||||
0);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
throw new Win32Exception(result, "Error connecting to remote share");
|
||||
}
|
||||
}
|
||||
|
||||
~NetworkConnection()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
WNetCancelConnection2(_networkName, 0, true);
|
||||
}
|
||||
|
||||
[DllImport("mpr.dll")]
|
||||
private static extern int WNetAddConnection2(NetResource netResource,
|
||||
string password, string username, int flags);
|
||||
|
||||
[DllImport("mpr.dll")]
|
||||
private static extern int WNetCancelConnection2(string name, int flags,
|
||||
bool force);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public class NetResource
|
||||
{
|
||||
public ResourceScope Scope;
|
||||
public ResourceType ResourceType;
|
||||
public ResourceDisplaytype DisplayType;
|
||||
public int Usage;
|
||||
public string LocalName;
|
||||
public string RemoteName;
|
||||
public string Comment;
|
||||
public string Provider;
|
||||
}
|
||||
|
||||
public enum ResourceScope : int
|
||||
{
|
||||
Connected = 1,
|
||||
GlobalNetwork,
|
||||
Remembered,
|
||||
Recent,
|
||||
Context
|
||||
};
|
||||
|
||||
public enum ResourceType : int
|
||||
{
|
||||
Any = 0,
|
||||
Disk = 1,
|
||||
Print = 2,
|
||||
Reserved = 8,
|
||||
}
|
||||
|
||||
public enum ResourceDisplaytype : int
|
||||
{
|
||||
Generic = 0x0,
|
||||
Domain = 0x01,
|
||||
Server = 0x02,
|
||||
Share = 0x03,
|
||||
File = 0x04,
|
||||
Group = 0x05,
|
||||
Network = 0x06,
|
||||
Root = 0x07,
|
||||
Shareadmin = 0x08,
|
||||
Directory = 0x09,
|
||||
Tree = 0x0a,
|
||||
Ndscontainer = 0x0b
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _getSmbShareInfo = "/ext/smb/developerfolder";
|
||||
|
||||
public async Task<SmbInfo> GetSmbShareInfo()
|
||||
{
|
||||
return await Get<SmbInfo>(_getSmbShareInfo);
|
||||
}
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
|
||||
[DataContract]
|
||||
public class SmbInfo
|
||||
{
|
||||
[DataMember(Name = "Path")]
|
||||
public string Path { get; set; }
|
||||
|
||||
[DataMember(Name = "Username")]
|
||||
public string Username { get; set; }
|
||||
|
||||
[DataMember(Name = "Password")]
|
||||
public string Password { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Path;
|
||||
}
|
||||
}
|
||||
#endregion // Data contract
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _userApi = "ext/user";
|
||||
|
||||
public async Task<UserList> GetXboxLiveUsers()
|
||||
{
|
||||
return await Get<UserList>(_userApi);
|
||||
}
|
||||
|
||||
public async Task UpdateXboxLiveUsers(UserList users)
|
||||
{
|
||||
await Put(_userApi, users);
|
||||
}
|
||||
}
|
||||
|
||||
#region Data contract
|
||||
|
||||
[DataContract]
|
||||
public class UserList
|
||||
{
|
||||
public UserList()
|
||||
{
|
||||
Users = new List<UserInfo>();
|
||||
}
|
||||
|
||||
[DataMember(Name = "Users")]
|
||||
public List<UserInfo> Users { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string userString = "";
|
||||
foreach (UserInfo user in Users)
|
||||
{
|
||||
userString += "User: " + user + "\n";
|
||||
}
|
||||
return userString;
|
||||
}
|
||||
|
||||
public void Add(UserInfo newUser)
|
||||
{
|
||||
Users.Add(newUser);
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class UserInfo
|
||||
{
|
||||
[DataMember(Name = "UserId", EmitDefaultValue = false)]
|
||||
public UInt32? UserId { get; set; }
|
||||
|
||||
[DataMember(Name = "EmailAddress", EmitDefaultValue = false)]
|
||||
public string EmailAddress { get; set; }
|
||||
|
||||
[DataMember(Name = "AutoSignIn", EmitDefaultValue = false)]
|
||||
public bool? AutoSignIn { get; set; }
|
||||
|
||||
[DataMember(Name = "Gamertag", EmitDefaultValue = false)]
|
||||
public string Gamertag { get; set; }
|
||||
|
||||
[DataMember(Name = "SignedIn", EmitDefaultValue = false)]
|
||||
public bool? SignedIn { get; set; }
|
||||
|
||||
[DataMember(Name = "SponsoredUser", EmitDefaultValue = false)]
|
||||
public bool? SponsoredUser { get; set; }
|
||||
|
||||
[DataMember(Name = "XboxUserId", EmitDefaultValue = false)]
|
||||
public string XboxUserId { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return EmailAddress + " : " + Gamertag;
|
||||
}
|
||||
}
|
||||
#endregion // Data contract
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Tools.WindowsDevicePortal
|
||||
{
|
||||
public partial class DevicePortal
|
||||
{
|
||||
private static readonly String _registerPackageApi = "api/app/packagemanager/register";
|
||||
|
||||
public async Task RegisterApplication(string folderName)
|
||||
{
|
||||
await Post(_registerPackageApi,
|
||||
String.Format("folder={0}", Utilities.Hex64Encode(folderName)));
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче