Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
824 changes: 824 additions & 0 deletions Samples/SampleWdpClient.UniversalWindows/Settings.StyleCop

Large diffs are not rendered by default.

824 changes: 824 additions & 0 deletions Samples/SampleWdpClient/Settings.StyleCop

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Samples/XboxWdpDriver/XboxWdpDriver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(StyleCopTargetsDir)StyleCop.targets" Condition="'$(StyleCopTargetsDir)' != ''" />
<!-- 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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(StyleCopTargetsDir)StyleCop.targets" Condition="'$(StyleCopTargetsDir)' != ''"/>
<!-- 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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public async Task<HttpResponseMessage> GetAsync(Uri uri)
/// <returns>Async task returning the response.</returns>
public async Task<HttpResponseMessage> PostAsync(Uri uri, HttpContent content)
{
if(content != null)
{
await content.ReadAsByteArrayAsync();
}
Task<HttpResponseMessage> task = new Task<HttpResponseMessage>(() => this.HttpStoredResponse(uri, HttpMethods.Post));
task.Start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="..\WindowsDevicePortalWrapper\HttpRest\HttpMultipartFileContent.cs">
<Link>WDPMockImplementations\HttpMultipartFileContent.cs</Link>
</Compile>
<Compile Include="BaseTests.cs" />
<Compile Include="Core\AppFileExplorerTests.cs" />
<Compile Include="Core\WindowsErrorReportingTests.cs" />
Expand Down Expand Up @@ -427,7 +430,6 @@
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="..\WindowsDevicePortalWrapper.Shared\WindowsDevicePortalWrapper.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(StyleCopTargetsDir)StyleCop.targets" Condition="'$(StyleCopTargetsDir)' != ''" />
<!-- 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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,33 @@ public partial class DevicePortal
/// <param name="requestStream">Optional stream containing data for the request body.</param>
/// <param name="requestStreamContentType">The type of that request body data.</param>
/// <returns>Task tracking the completion of the POST request</returns>
private async Task<Stream> PostAsync(
private Task<Stream> PostAsync(
Uri uri,
Stream requestStream = null,
string requestStreamContentType = null)
{
StreamContent requestContent = null;
MemoryStream dataStream = null;

if (requestStream != null)
{
requestContent = new StreamContent(requestStream);
requestContent.Headers.Remove(ContentTypeHeaderName);
requestContent.Headers.TryAddWithoutValidation(ContentTypeHeaderName, requestStreamContentType);
}

return this.PostAsync(uri, requestContent);
}

/// <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>
/// <param name="requestContent">Optional content for the request body.</param>
/// <returns>Task tracking the completion of the POST request</returns>
private async Task<Stream> PostAsync(
Uri uri,
HttpContent requestContent)
{
MemoryStream dataStream = null;
WebRequestHandler requestSettings = new WebRequestHandler();
requestSettings.UseDefaultCredentials = false;
requestSettings.Credentials = this.deviceConnection.Credentials;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#if WINDOWS_UWP
using Windows.Foundation;
using Windows.Security.Credentials;
using Windows.Storage.Streams;
using Windows.Web.Http;
using Windows.Web.Http.Filters;
using Windows.Web.Http.Headers;
Expand Down Expand Up @@ -110,7 +111,7 @@ public async Task InstallApplicationAsync(
}
}
}

// Create the API endpoint and generate a unique boundary string.
Uri uri;
string boundaryString;
Expand All @@ -119,59 +120,17 @@ public async Task InstallApplicationAsync(
out uri,
out boundaryString);

using (MemoryStream dataStream = new MemoryStream())
{
byte[] data;

// Copy the application package.
installPhaseDescription = string.Format("Copying: {0}", packageFile.Name);
this.SendAppInstallStatus(
ApplicationInstallStatus.InProgress,
ApplicationInstallPhase.CopyingFile,
installPhaseDescription);
data = Encoding.ASCII.GetBytes(string.Format("--{0}\r\n", boundaryString));
dataStream.Write(data, 0, data.Length);
CopyFileToRequestStream(packageFile, dataStream);

// Copy dependency files, if any.
foreach (string dependencyFile in dependencyFileNames)
{
FileInfo fi = new FileInfo(dependencyFile);
installPhaseDescription = string.Format("Copying: {0}", fi.Name);
this.SendAppInstallStatus(
ApplicationInstallStatus.InProgress,
ApplicationInstallPhase.CopyingFile,
installPhaseDescription);
data = Encoding.ASCII.GetBytes(string.Format("\r\n--{0}\r\n", boundaryString));
dataStream.Write(data, 0, data.Length);
CopyFileToRequestStream(fi, dataStream);
}

// Copy the certificate file, if provided.
if (!string.IsNullOrEmpty(certificateFileName))
{
FileInfo fi = new FileInfo(certificateFileName);
installPhaseDescription = string.Format("Copying: {0}", fi.Name);
this.SendAppInstallStatus(
ApplicationInstallStatus.InProgress,
ApplicationInstallPhase.CopyingFile,
installPhaseDescription);
data = Encoding.ASCII.GetBytes(string.Format("\r\n--{0}\r\n", boundaryString));
dataStream.Write(data, 0, data.Length);
CopyFileToRequestStream(fi, dataStream);
}

// Close the installation request data.
data = Encoding.ASCII.GetBytes(string.Format("\r\n--{0}--\r\n", boundaryString));
dataStream.Write(data, 0, data.Length);

dataStream.Position = 0;

string contentType = string.Format("multipart/form-data; boundary={0}", boundaryString);
installPhaseDescription = string.Format("Copying: {0}", packageFile.Name);
this.SendAppInstallStatus(
ApplicationInstallStatus.InProgress,
ApplicationInstallPhase.CopyingFile,
installPhaseDescription);

// Make the HTTP request.
await this.PostAsync(uri, dataStream, contentType);
}
var content = new HttpMultipartFileContent();
content.Add(packageFile.FullName);
content.AddRange(dependencyFileNames);
content.Add(certificateFileName);
await this.PostAsync(uri, content);

// Poll the status until complete.
ApplicationInstallStatus status = ApplicationInstallStatus.InProgress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public enum DevicePortalPlatforms
/// </summary>
HoloLens,

/// <summary>
/// HoloLens 2 platform
/// </summary>
HoloLens2,

/// <summary>
/// Xbox One platform
/// </summary>
Expand Down Expand Up @@ -206,8 +211,6 @@ public DevicePortalPlatforms Platform
{
get
{
DevicePortalPlatforms platform = DevicePortalPlatforms.Unknown;

try
{
// MinnowBoard Max model no. can change based on firmware
Expand All @@ -216,31 +219,31 @@ public DevicePortalPlatforms Platform
return DevicePortalPlatforms.IoTMinnowboardMax;
}

switch (this.PlatformName)
// Xbox One platform names may refer to devkit
if (this.PlatformName.Contains("Xbox One"))
{
case "Xbox One":
platform = DevicePortalPlatforms.XboxOne;
break;
return DevicePortalPlatforms.XboxOne;
}

switch (this.PlatformName)
{
case "SBC":
platform = DevicePortalPlatforms.IoTDragonboard410c;
break;
return DevicePortalPlatforms.IoTDragonboard410c;

case "Raspberry Pi 2":
platform = DevicePortalPlatforms.IoTRaspberryPi2;
break;
return DevicePortalPlatforms.IoTRaspberryPi2;

case "Raspberry Pi 3":
platform = DevicePortalPlatforms.IoTRaspberryPi3;
break;
return DevicePortalPlatforms.IoTRaspberryPi3;

case "Virtual Machine":
platform = DevicePortalPlatforms.VirtualMachine;
break;
return DevicePortalPlatforms.VirtualMachine;

case "HoloLens 2":
return DevicePortalPlatforms.HoloLens2;

default:
platform = (DevicePortalPlatforms)Enum.Parse(typeof(DevicePortalPlatforms), this.PlatformName);
break;
return (DevicePortalPlatforms)Enum.Parse(typeof(DevicePortalPlatforms), this.PlatformName);
}
}
catch
Expand All @@ -250,20 +253,15 @@ public DevicePortalPlatforms Platform
case "Enterprise":
case "Home":
case "Professional":
platform = DevicePortalPlatforms.Windows;
break;
return DevicePortalPlatforms.Windows;

case "Mobile":
platform = DevicePortalPlatforms.Mobile;
break;
return DevicePortalPlatforms.Mobile;

default:
platform = DevicePortalPlatforms.Unknown;
break;
return DevicePortalPlatforms.Unknown;
}
}

return platform;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public TimeSpan EstimatedTime
{
get
{
return new TimeSpan(0,0,(int)EstimatedTimeRaw);
return new TimeSpan(0, 0, (int)this.EstimatedTimeRaw);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ public async Task<byte[]> GetWindowsErrorReportingFileAsync(string user, string
byte[] werFile = null;
using (Stream stream = await this.GetAsync(uri))
{
werFile = new byte[stream.Length];
stream.Read(werFile, 0, werFile.Length);
using (MemoryStream outStream = new MemoryStream())
{
await outStream.CopyToAsync(outStream);

werFile = new byte[outStream.Length];
await stream.ReadAsync(werFile, 0, werFile.Length);
}
}

return werFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
#endif // !WINDOWS_UWP
#if WINDOWS_UWP
using System.Runtime.InteropServices.WindowsRuntime;
Expand Down Expand Up @@ -61,12 +62,34 @@ public partial class DevicePortal
private IDevicePortalConnection deviceConnection;
#if !WINDOWS_UWP

// Enable/disable useUnsafeHeaderParsing.
// See https://social.msdn.microsoft.com/Forums/en-US/ff098248-551c-4da9-8ba5-358a9f8ccc57/how-do-i-enable-useunsafeheaderparsing-from-code-net-20?forum=netfxnetcom
private static bool ToggleAllowUnsafeHeaderParsing(bool enable)
{
Type settingsSectionType = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection))?.GetType("System.Net.Configuration.SettingsSectionInternal");
if (settingsSectionType == null) { return false; }

object anInstance = settingsSectionType.InvokeMember("Section", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { });
if (anInstance == null) { return false; }

FieldInfo aUseUnsafeHeaderParsing = settingsSectionType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance);
if (aUseUnsafeHeaderParsing == null) { return false; }

aUseUnsafeHeaderParsing.SetValue(anInstance, enable);

return true;
}

/// <summary>
/// Initializes static members of the <see cref="DevicePortal" /> class.
/// </summary>
static DevicePortal()
{
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
if (!ToggleAllowUnsafeHeaderParsing(true))
{
Console.WriteLine("Failed to enable useUnsafeHeaderParsing");
}
}

#endif
Expand Down Expand Up @@ -185,7 +208,6 @@ public string PlatformName
}
}


/// <summary>
/// Connects to the device pointed to by IDevicePortalConnection provided in the constructor.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,21 @@ public static async Task<DevicePortalException> CreateAsync(
{
HttpErrorResponse errorResponse = DevicePortal.ReadJsonStream<HttpErrorResponse>(dataStream);

error.HResult = errorResponse.ErrorCode;
error.Reason = errorResponse.ErrorMessage;

// If we didn't get the Hresult and reason from these properties, try the other ones.
if (error.HResult == 0)
{
error.HResult = errorResponse.Code;
}

if (string.IsNullOrEmpty(error.Reason))
if (errorResponse != null)
{
error.Reason = errorResponse.Reason;
error.HResult = errorResponse.ErrorCode;
error.Reason = errorResponse.ErrorMessage;

// If we didn't get the Hresult and reason from these properties, try the other ones.
if (error.HResult == 0)
{
error.HResult = errorResponse.Code;
}

if (string.IsNullOrEmpty(error.Reason))
{
error.Reason = errorResponse.Reason;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,12 @@ public async Task<byte[]> GetMrcFileDataAsync(

using (Stream dataStream = await this.GetAsync(uri))
{
dataBytes = new byte[dataStream.Length];
dataStream.Read(dataBytes, 0, dataBytes.Length);
using (MemoryStream outStream = new MemoryStream())
{
await dataStream.CopyToAsync(outStream);
dataBytes = new byte[outStream.Length];
await outStream.ReadAsync(dataBytes, 0, dataBytes.Length);
}
}

return dataBytes;
Expand Down
Loading
Loading