Skip to content

Commit

Permalink
Windows 10 Version 1709 - January 2018 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnewthing committed Jan 4, 2018
1 parent ad44f9b commit e924715
Show file tree
Hide file tree
Showing 186 changed files with 8,904 additions and 1,870 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -150,9 +150,10 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github.
<tr>
<td><a href="Samples/Appointments">Appointment calendar</a></td>
<td><a href="Samples/ContactCards">Contact cards</a></td>
<td><a href="Samples/ContactPicker">Contact picker</a></td>
<td><a href="Samples/ContactPanel">Contact panel</a></td>
</tr>
<tr>
<td><a href="Samples/ContactPicker">Contact picker</a></td>
<td><a href="Samples/MyPeopleNotifications">My People notifications</a></td>
<td><a href="Samples/UserDataAccountManager">UserDataAccountManager</a></td>
</tr>
Expand Down Expand Up @@ -444,6 +445,7 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github.
<td><a href="Samples/HolographicVoiceInput">Holographic voice input</a></td>
<td><a href="Samples/SpatialInteractionSource">Spatial interaction source</a></td>
<td><a href="Samples/HolographicTagAlong">Tag-along hologram</a></td>
<td><a href="Samples/MixedRealityModel">Mixed Reality Model</a></td>
</tr>
</table>

Expand Down
1 change: 1 addition & 0 deletions Samples/BackgroundTransfer/README.md
Expand Up @@ -24,6 +24,7 @@ The sample also showcases several advanced usage scenarios:
- Configuring toast and tile notifications to inform the user when all transfers succeed or when at least one transfer fails.
- Executing a background task when a set of uploads or downloads completes.
- Accessing file content and seeking within that content while a download is still ongoing, effectively altering the order in which remote file data is requested from the server.
- Recovering from a failed download without losing already-downloaded data.

**Note** Background transfer is primarily designed for long-term transfer operations for resources like video, music, and large images. For short-term operations involving transfers of smaller resources (i.e. a few KB), the HTTP APIs are recommended. [HttpClient](http://msdn.microsoft.com/library/windows/apps/dn298639) is preferred and can be used in all languages supported by UWP apps. [XHR](http://msdn.microsoft.com/library/windows/apps/br229787) can be used in JavaScript. [IXHR2](http://msdn.microsoft.com/library/windows/apps/hh770550) can be used in C++.

Expand Down
141 changes: 141 additions & 0 deletions Samples/BackgroundTransfer/Server/website/recoverableErrors.aspx
@@ -0,0 +1,141 @@
<%@ Page Language="C#" AutoEventWireup="true" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
private const uint FullContentLengthInBytes = 10000000; // 10 MB
private readonly byte[] buffer = Encoding.ASCII.GetBytes(new String('a', 1000000)); // 1 MB
private static void GetRange(string rangeHeaderValue, out uint offset, out uint lengthInBytes)
{
offset = 0;
lengthInBytes = FullContentLengthInBytes;
if (String.IsNullOrEmpty(rangeHeaderValue))
{
return;
}
Regex rx = new Regex(@"(bytes)\s*=\s*(?<startIndex>\d+)\s*-\s*(?<endIndex>\d+)?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
Match match = rx.Match(rangeHeaderValue);
uint startIndex = 0;
Capture startIndexCapture = match.Groups["startIndex"];
if ((startIndexCapture == null) || (!UInt32.TryParse(startIndexCapture.Value, out startIndex)))
{
return;
}
if (startIndex < 0 || startIndex >= FullContentLengthInBytes)
{
throw new ArgumentException(
"Requested range starting index is negative or goes beyond the file's length");
}
offset = startIndex;
uint endIndex = 0;
Capture endIndexCapture = match.Groups["endIndex"];
if ((endIndexCapture != null) && (UInt32.TryParse(endIndexCapture.Value, out endIndex)))
{
if (endIndex < startIndex)
{
throw new ArgumentException(
"Requested range ending index is less than the starting index");
}
lengthInBytes = Math.Min(endIndex, FullContentLengthInBytes - 1) - offset + 1;
}
else
{
lengthInBytes = FullContentLengthInBytes - offset;
}
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
// Determine whether this response should emulate a URL that expires.
bool shouldExpire = (Request["shouldExpire"] != null);
// Check if we have a request for partial content (resume scenarios).
bool isRangeRequest = (Request.Headers["Range"] != null);
uint offset = 0;
uint contentLengthInBytes = FullContentLengthInBytes;
if (isRangeRequest)
{
GetRange(Request.Headers["Range"], out offset, out contentLengthInBytes);
}
if (shouldExpire && isRangeRequest && offset > 0)
{
// The client side is attempting to resume an expired URL.
// Fail the request with HTTP 403 (Forbidden) status.
Response.StatusCode = 403;
Response.StatusDescription = "URL has expired";
Response.Flush();
return;
}
if (contentLengthInBytes != FullContentLengthInBytes)
{
Response.StatusCode = 206;
Response.Headers["Content-Range"] = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"bytes {0}-{1}/{2}", offset, offset + contentLengthInBytes - 1, FullContentLengthInBytes);
}
else
{
Response.StatusCode = 200;
}
Response.ContentType = "text/plain";
Response.Headers["Content-Length"] = contentLengthInBytes.ToString(System.Globalization.CultureInfo.InvariantCulture);
Response.Headers["Accept-Ranges"] = "bytes";
Response.Headers["Last-Modified"] = "Thu, 21 Aug 2014 21:34:57 GMT";
Response.Buffer = false;
uint transferLengthInBytes = contentLengthInBytes;
while (transferLengthInBytes > 0)
{
if (shouldExpire && transferLengthInBytes < contentLengthInBytes / 2)
{
// More than half of the response has been sent out. Let's terminate the connection abruptly to
// simulate a URL that expires. If the client attempts to resume the same URL in the future, it
// will receive an HTTP 403 response.
Response.Flush();
Response.Close();
return;
}
System.Threading.Thread.Sleep(1000);
int sendLengthInBytes = (int)Math.Min(transferLengthInBytes, this.buffer.Length);
Response.OutputStream.Write(this.buffer, 0, sendLengthInBytes);
transferLengthInBytes -= (uint)sendLengthInBytes;
}
Response.Flush();
}
catch (Exception ex)
{
Trace.Write(ex.Message);
Response.StatusCode = 500;
Response.StatusDescription = ex.Message;
}
Response.End();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Recoverable Errors Download</title>
</head>
<body>
Hello
</body>
</html>
Expand Up @@ -160,6 +160,9 @@
<ClInclude Include="Scenario5_RandomAccess.xaml.h">
<DependentUpon>..\..\shared\Scenario5_RandomAccess.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="Scenario6_RecoverableErrors.xaml.h">
<DependentUpon>..\..\shared\Scenario6_RecoverableErrors.xaml</DependentUpon>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="..\..\..\..\SharedContent\xaml\App.xaml">
Expand All @@ -173,6 +176,7 @@
<Page Include="..\..\shared\Scenario3_Notifications.xaml" />
<Page Include="..\..\shared\Scenario4_CompletionGroups.xaml" />
<Page Include="..\..\shared\Scenario5_RandomAccess.xaml" />
<Page Include="..\..\shared\Scenario6_RecoverableErrors.xaml" />
<Page Include="..\..\..\..\SharedContent\xaml\Styles.xaml">
<Link>Styles\Styles.xaml</Link>
</Page>
Expand Down Expand Up @@ -213,6 +217,9 @@
<ClCompile Include="Scenario5_RandomAccess.xaml.cpp">
<DependentUpon>..\..\shared\Scenario5_RandomAccess.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="Scenario6_RecoverableErrors.xaml.cpp">
<DependentUpon>..\..\shared\Scenario6_RecoverableErrors.xaml</DependentUpon>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="..\..\..\..\SharedContent\media\microsoft-sdk.png">
Expand Down
Expand Up @@ -22,6 +22,7 @@
<ClCompile Include="Scenario3_Notifications.xaml.cpp" />
<ClCompile Include="Scenario4_CompletionGroups.xaml.cpp" />
<ClCompile Include="Scenario5_RandomAccess.xaml.cpp" />
<ClCompile Include="Scenario6_RecoverableErrors.xaml.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
Expand All @@ -33,6 +34,7 @@
<ClInclude Include="Scenario3_Notifications.xaml.h" />
<ClInclude Include="Scenario4_CompletionGroups.xaml.h" />
<ClInclude Include="Scenario5_RandomAccess.xaml.h" />
<ClInclude Include="Scenario6_RecoverableErrors.xaml.h" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest" />
Expand All @@ -47,6 +49,7 @@
<Page Include="..\..\shared\Scenario3_Notifications.xaml" />
<Page Include="..\..\shared\Scenario4_CompletionGroups.xaml" />
<Page Include="..\..\shared\Scenario5_RandomAccess.xaml" />
<Page Include="..\..\shared\Scenario6_RecoverableErrors.xaml" />
</ItemGroup>
<ItemGroup>
<Image Include="..\..\..\..\SharedContent\media\microsoft-sdk.png">
Expand Down
Expand Up @@ -22,5 +22,5 @@ Platform::Array<Scenario>^ MainPage::scenariosInner = ref new Platform::Array<Sc
{ "Completion Notifications", "SDKTemplate.Scenario3_Notifications" },
{ "Completion Groups", "SDKTemplate.Scenario4_CompletionGroups" },
{ "Random Access Downloads", "SDKTemplate.Scenario5_RandomAccess" },

{ "Recoverable Errors", "SDKTemplate.Scenario6_RecoverableErrors" },
};
Expand Up @@ -163,12 +163,12 @@ String^ Scenario5_RandomAccess::FormatDownloadedRanges(IIterable<BackgroundTrans

void Scenario5_RandomAccess::OnDownloadProgress(IAsyncOperationWithProgress<DownloadOperation^, DownloadOperation^>^ sender, DownloadOperation^ progress)
{
Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this, progress]()
{
// We capture a snapshot of DownloadOperation.Progress because
// it is is updated in real-time while the operation is ongoing.
BackgroundDownloadProgress currentProgress = progress->Progress;
// We capture a snapshot of DownloadOperation.Progress because
// it is is updated in real-time while the operation is ongoing.
BackgroundDownloadProgress currentProgress = progress->Progress;

Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this, currentProgress]()
{
// Prepare the progress message to display in the UI.
uint64_t percent = 100;
if (currentProgress.TotalBytesToReceive > 0)
Expand Down

1 comment on commit e924715

@oldnewthing
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somebody posted a comment about rpcdce but I can't find it because it is buried in the commit. I'm guessing it was a comment on the custom capabilities sample. The custom capabilities team is investigating. Installing the WDK may help.

Please sign in to comment.