Skip to content

Commit 6725587

Browse files
David Klinehpsin
authored andcommitted
0.9.4 Release
Fixes #226, #227, #228 , boosts version number and Copyright dates
1 parent 5a7a85d commit 6725587

File tree

7 files changed

+230
-9
lines changed

7 files changed

+230
-9
lines changed

WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/OsInformation.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,22 @@ public DevicePortalPlatforms Platform
245245
}
246246
catch
247247
{
248+
switch (this.OsEdition)
249+
{
250+
case "Enterprise":
251+
case "Home":
252+
case "Professional":
253+
platform = DevicePortalPlatforms.Windows;
254+
break;
255+
256+
case "Mobile":
257+
platform = DevicePortalPlatforms.Mobile;
258+
break;
259+
260+
default:
261+
platform = DevicePortalPlatforms.Unknown;
262+
break;
263+
}
248264
}
249265

250266
return platform;

WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/Power.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,13 @@ public class BatteryState
152152
/// </summary>
153153
public float Level
154154
{
155-
get { return 100.0f * ((float)this.RemainingCapacity / this.MaximumCapacity); }
155+
get
156+
{
157+
// Desktop PCs typically do not have a battery, return 100%
158+
if (this.MaximumCapacity == 0) { return 100f; }
159+
160+
return 100.0f * ((float)this.RemainingCapacity / this.MaximumCapacity);
161+
}
156162
}
157163
}
158164

WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/Core/AppDeployment.cs

Lines changed: 148 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
using System.Runtime.Serialization.Json;
1212
using System.Text;
1313
using System.Threading.Tasks;
14-
using Windows.Foundation;
1514
using Windows.Security.Credentials;
15+
using Windows.Storage;
1616
using Windows.Storage.Streams;
1717
using Windows.Web.Http;
1818
using Windows.Web.Http.Filters;
19-
using Windows.Web.Http.Headers;
2019
using static Microsoft.Tools.WindowsDevicePortal.DevicePortalException;
2120

2221
namespace Microsoft.Tools.WindowsDevicePortal
@@ -112,5 +111,152 @@ public async Task<ApplicationInstallStatus> GetInstallStatusAsync()
112111
return status;
113112
}
114113
#pragma warning restore 1998
114+
115+
public async Task InstallApplicationAsync(
116+
string appName,
117+
StorageFile packageFile,
118+
List<StorageFile> dependencyFiles,
119+
StorageFile certificateFile= null,
120+
short stateCheckIntervalMs = 500,
121+
short timeoutInMinutes = 15,
122+
bool uninstallPreviousVersion = true)
123+
{
124+
string installPhaseDescription = string.Empty;
125+
126+
try
127+
{
128+
// If appName was not provided, use the package file name
129+
if (string.IsNullOrWhiteSpace(appName))
130+
{
131+
appName = packageFile.DisplayName;
132+
}
133+
134+
// Uninstall the application's previous version, if one exists.
135+
if (uninstallPreviousVersion)
136+
{
137+
installPhaseDescription = string.Format("Uninstalling any previous version of {0}", appName);
138+
this.SendAppInstallStatus(
139+
ApplicationInstallStatus.InProgress,
140+
ApplicationInstallPhase.UninstallingPreviousVersion,
141+
installPhaseDescription);
142+
AppPackages installedApps = await this.GetInstalledAppPackagesAsync();
143+
foreach (PackageInfo package in installedApps.Packages)
144+
{
145+
if (package.Name == appName)
146+
{
147+
await this.UninstallApplicationAsync(package.FullName);
148+
break;
149+
}
150+
}
151+
}
152+
153+
// Create the API endpoint and generate a unique boundary string.
154+
Uri uri;
155+
string boundaryString;
156+
this.CreateAppInstallEndpointAndBoundaryString(
157+
packageFile.Name,
158+
out uri,
159+
out boundaryString);
160+
161+
using (MemoryStream dataStream = new MemoryStream())
162+
{
163+
byte[] data;
164+
165+
// Copy the application package.
166+
installPhaseDescription = string.Format("Copying: {0}", packageFile.Name);
167+
this.SendAppInstallStatus(
168+
ApplicationInstallStatus.InProgress,
169+
ApplicationInstallPhase.CopyingFile,
170+
installPhaseDescription);
171+
data = Encoding.ASCII.GetBytes(string.Format("--{0}\r\n", boundaryString));
172+
dataStream.Write(data, 0, data.Length);
173+
await CopyFileToRequestStream(
174+
packageFile,
175+
dataStream);
176+
177+
// Copy dependency files, if any.
178+
foreach (StorageFile depFile in dependencyFiles)
179+
{
180+
installPhaseDescription = string.Format("Copying: {0}", depFile.Name);
181+
this.SendAppInstallStatus(
182+
ApplicationInstallStatus.InProgress,
183+
ApplicationInstallPhase.CopyingFile,
184+
installPhaseDescription);
185+
data = Encoding.ASCII.GetBytes(string.Format("\r\n--{0}\r\n", boundaryString));
186+
dataStream.Write(data, 0, data.Length);
187+
await CopyFileToRequestStream(
188+
depFile,
189+
dataStream);
190+
}
191+
192+
// Copy the certificate file, if provided.
193+
if (certificateFile != null)
194+
{
195+
installPhaseDescription = string.Format("Copying: {0}", certificateFile.Name);
196+
this.SendAppInstallStatus(
197+
ApplicationInstallStatus.InProgress,
198+
ApplicationInstallPhase.CopyingFile,
199+
installPhaseDescription);
200+
data = Encoding.ASCII.GetBytes(string.Format("\r\n--{0}\r\n", boundaryString));
201+
dataStream.Write(data, 0, data.Length);
202+
await CopyFileToRequestStream(
203+
certificateFile,
204+
dataStream);
205+
}
206+
207+
// Close the installation request data.
208+
data = Encoding.ASCII.GetBytes(string.Format("\r\n--{0}--\r\n", boundaryString));
209+
dataStream.Write(data, 0, data.Length);
210+
211+
dataStream.Position = 0;
212+
213+
string contentType = string.Format("multipart/form-data; boundary={0}", boundaryString);
214+
215+
// Make the HTTP request.
216+
await this.PostAsync(uri, dataStream, contentType);
217+
}
218+
219+
// Poll the status until complete.
220+
ApplicationInstallStatus status = ApplicationInstallStatus.InProgress;
221+
do
222+
{
223+
installPhaseDescription = string.Format("Installing {0}", appName);
224+
this.SendAppInstallStatus(
225+
ApplicationInstallStatus.InProgress,
226+
ApplicationInstallPhase.Installing,
227+
installPhaseDescription);
228+
229+
await Task.Delay(TimeSpan.FromMilliseconds(stateCheckIntervalMs));
230+
231+
status = await this.GetInstallStatusAsync().ConfigureAwait(false);
232+
}
233+
while (status == ApplicationInstallStatus.InProgress);
234+
235+
installPhaseDescription = string.Format("{0} installed successfully", appName);
236+
this.SendAppInstallStatus(
237+
ApplicationInstallStatus.Completed,
238+
ApplicationInstallPhase.Idle,
239+
installPhaseDescription);
240+
}
241+
catch (Exception e)
242+
{
243+
DevicePortalException dpe = e as DevicePortalException;
244+
245+
if (dpe != null)
246+
{
247+
this.SendAppInstallStatus(
248+
ApplicationInstallStatus.Failed,
249+
ApplicationInstallPhase.Idle,
250+
string.Format("Failed to install {0}: {1}", appName, dpe.Reason));
251+
}
252+
else
253+
{
254+
this.SendAppInstallStatus(
255+
ApplicationInstallStatus.Failed,
256+
ApplicationInstallPhase.Idle,
257+
string.Format("Failed to install {0}: {1}", appName, installPhaseDescription));
258+
}
259+
}
260+
}
115261
}
116262
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//----------------------------------------------------------------------------------------------
2+
// <copyright file="RequestHelpers.cs" company="Microsoft Corporation">
3+
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
4+
// </copyright>
5+
//----------------------------------------------------------------------------------------------
6+
7+
using System;
8+
using System.IO;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using Windows.Storage;
12+
using Windows.Storage.Streams;
13+
14+
namespace Microsoft.Tools.WindowsDevicePortal
15+
{
16+
/// <content>
17+
/// Methods for working with Http requests.
18+
/// </content>
19+
public partial class DevicePortal
20+
{
21+
/// <summary>
22+
/// Copies a file to the specified stream and prepends the necessary content information
23+
/// required to be part of a multipart form data request.
24+
/// </summary>
25+
/// <param name="file">The file to be copied.</param>
26+
/// <param name="stream">The stream to which the file will be copied.</param>
27+
private static async Task CopyFileToRequestStream(
28+
StorageFile file,
29+
Stream stream)
30+
{
31+
byte[] data;
32+
string fn = file.Name;
33+
string contentDisposition = string.Format(
34+
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n",
35+
fn,
36+
fn);
37+
string contentType = "Content-Type: application/octet-stream\r\n\r\n";
38+
39+
data = Encoding.ASCII.GetBytes(contentDisposition);
40+
stream.Write(data, 0, data.Length);
41+
42+
data = Encoding.ASCII.GetBytes(contentType);
43+
stream.Write(data, 0, data.Length);
44+
45+
using (IRandomAccessStreamWithContentType ras = await file.OpenReadAsync())
46+
{
47+
Stream fs = ras.AsStreamForRead();
48+
fs.CopyTo(stream);
49+
}
50+
}
51+
}
52+
}

WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[assembly: AssemblyConfiguration("")]
1616
[assembly: AssemblyCompany("")]
1717
[assembly: AssemblyProduct("WindowsDevicePortalWrapper.UniversalWindows")]
18-
[assembly: AssemblyCopyright("Copyright © 2016")]
18+
[assembly: AssemblyCopyright("Copyright © 2016-2017")]
1919
[assembly: AssemblyTrademark("")]
2020
[assembly: AssemblyCulture("")]
2121

@@ -29,6 +29,6 @@
2929
// You can specify all the values or you can default the Build and Revision Numbers
3030
// by using the '*' as shown below:
3131
// [assembly: AssemblyVersion("1.0.*")]
32-
[assembly: AssemblyVersion("0.9.3.0")]
33-
[assembly: AssemblyFileVersion("0.9.3.0")]
32+
[assembly: AssemblyVersion("0.9.4.0")]
33+
[assembly: AssemblyFileVersion("0.9.4.0")]
3434
[assembly: ComVisible(false)]

WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/WindowsDevicePortalWrapper.UniversalWindows.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<Compile Include="CertificateHandling.cs" />
113113
<Compile Include="Core\AppDeployment.cs" />
114114
<Compile Include="DefaultDevicePortalConnection.cs" />
115+
<Compile Include="HttpRest\RequestHelpers.cs" />
115116
<Compile Include="HttpRest\RestPost.cs" />
116117
<Compile Include="HttpRest\RestPut.cs" />
117118
<Compile Include="HttpRest\RestDelete.cs" />

WindowsDevicePortalWrapper/WindowsDevicePortalWrapper/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[assembly: AssemblyConfiguration("")]
1616
[assembly: AssemblyCompany("")]
1717
[assembly: AssemblyProduct("WindowsDevicePortalWrapper")]
18-
[assembly: AssemblyCopyright("Copyright © 2016")]
18+
[assembly: AssemblyCopyright("Copyright © 2016-2017")]
1919
[assembly: AssemblyTrademark("")]
2020
[assembly: AssemblyCulture("")]
2121

@@ -37,5 +37,5 @@
3737
// You can specify all the values or you can default the Build and Revision Numbers
3838
// by using the '*' as shown below:
3939
// [assembly: AssemblyVersion("1.0.*")]
40-
[assembly: AssemblyVersion("0.9.3.0")]
41-
[assembly: AssemblyFileVersion("0.9.3.0")]
40+
[assembly: AssemblyVersion("0.9.4.0")]
41+
[assembly: AssemblyFileVersion("0.9.4.0")]

0 commit comments

Comments
 (0)