Skip to content

Commit

Permalink
Windows 10 future version - September 2018 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnewthing committed Sep 13, 2018
2 parents fb44423 + dca302e commit 5379e10
Show file tree
Hide file tree
Showing 141 changed files with 3,853 additions and 1,557 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github.
<td><a href="Samples/WiFiDirectServices">Wi-Fi Direct services</a></td>
</tr>
<tr>
<td><a href="Samples/HotspotAuthentication">Wi-Fi hotspot authentication</a></td>
<td><a href="Samples/WiFiScan">Wi-Fi scanning</a></td>
</tr>
</table>
Expand Down
1 change: 0 additions & 1 deletion Samples/AdaptiveStreaming/cs/AdaptiveStreaming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
<Link>Shared\Logging\Extensions\MediaPlaybackListStringExtensions.cs</Link>
</Compile>
<Compile Include="Helpers\CommonLicenseRequest.cs" />
<Compile Include="Helpers\MediaPlayerExtensions.cs" />
<Compile Include="Helpers\PlayReadyHelper.cs" />
<Compile Include="Controls\ContentSelector.xaml.cs">
<DependentUpon>ContentSelector.xaml</DependentUpon>
Expand Down
73 changes: 0 additions & 73 deletions Samples/AdaptiveStreaming/cs/Helpers/MediaPlayerExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)
var mp = mediaPlayerElement.MediaPlayer;
if (mp != null)
{
// Explicitly disposing sources facilitates faster memory reclamation.
mp.DisposeSource(); // From SDKTemplate.Helpers.MediaPlayerExtensions

// Ensure MediaPlayerElement drops its reference to MediaPlayer.
mediaPlayerElement.SetMediaPlayer(null);

Expand Down
2 changes: 0 additions & 2 deletions Samples/AdaptiveStreaming/cs/Scenario2_EventHandlers.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)

UnregisterHandlers(mediaPlayer);

mediaPlayer.DisposeSource();
mediaPlayerElement.SetMediaPlayer(null);
mediaPlayer.Dispose();
}
Expand Down Expand Up @@ -133,7 +132,6 @@ private void Page_OnLoaded(object sender, RoutedEventArgs e)
private async Task<MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null)
{
UnregisterHandlers(mediaPlayerElement.MediaPlayer);
mediaPlayerElement.MediaPlayer?.DisposeSource();

AdaptiveMediaSourceCreationResult result = null;
if (httpClient != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)

UnregisterHandlers(mediaPlayer);

mediaPlayer.DisposeSource();
mediaPlayerElement.SetMediaPlayer(null);
mediaPlayer.Dispose();
}
Expand Down Expand Up @@ -149,7 +148,6 @@ private void Page_OnLoaded(object sender, RoutedEventArgs e)
private async Task<MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null)
{
UnregisterHandlers(mediaPlayerElement.MediaPlayer);
mediaPlayerElement.MediaPlayer?.DisposeSource();

if (tokenMethod == AzureKeyAcquisitionMethod.AuthorizationHeader)
{
Expand Down
2 changes: 0 additions & 2 deletions Samples/AdaptiveStreaming/cs/Scenario4_Tuning.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)

UnregisterHandlers(mediaPlayer);

mediaPlayer.DisposeSource();
mediaPlayerElement.SetMediaPlayer(null);
mediaPlayer.Dispose();
}
Expand Down Expand Up @@ -134,7 +133,6 @@ private async void PollForInboundBitsPerSecond(CancellationTokenSource cts)
private async Task<MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null)
{
UnregisterHandlers(mediaPlayerElement.MediaPlayer);
mediaPlayerElement.MediaPlayer?.DisposeSource();

AdaptiveMediaSourceCreationResult result = null;
if (httpClient != null)
Expand Down
2 changes: 0 additions & 2 deletions Samples/AdaptiveStreaming/cs/Scenario5_Metadata.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)

UnregisterHandlers(mediaPlayer);

mediaPlayer.DisposeSource();
mediaPlayerElement.SetMediaPlayer(null);
mediaPlayer.Dispose();
}
Expand Down Expand Up @@ -112,7 +111,6 @@ private void Page_OnLoaded(object sender, RoutedEventArgs e)
private async Task<MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null)
{
UnregisterHandlers(mediaPlayerElement.MediaPlayer);
mediaPlayerElement.MediaPlayer?.DisposeSource();

AdaptiveMediaSourceCreationResult result = null;
if (httpClient != null)
Expand Down
2 changes: 0 additions & 2 deletions Samples/AdaptiveStreaming/cs/Scenario6_AdInsertion.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)

UnregisterHandlers(mediaPlayer);

mediaPlayer.DisposeSource();
mediaPlayerElement.SetMediaPlayer(null);
mediaPlayer.Dispose();
}
Expand Down Expand Up @@ -108,7 +107,6 @@ private void Page_OnLoaded(object sender, RoutedEventArgs e)
private async Task<MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null)
{
UnregisterHandlers(mediaPlayerElement.MediaPlayer);
mediaPlayerElement.MediaPlayer?.DisposeSource();

AdaptiveMediaSourceCreationResult result = null;
if (httpClient != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)

UnregisterHandlers(mediaPlayer);

mediaPlayer.DisposeSource();
mediaPlayerElement.SetMediaPlayer(null);
mediaPlayer.Dispose();
}
Expand Down Expand Up @@ -104,7 +103,6 @@ private void Page_OnLoaded(object sender, RoutedEventArgs e)
private async Task<MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null)
{
UnregisterHandlers(mediaPlayerElement.MediaPlayer);
mediaPlayerElement.MediaPlayer?.DisposeSource();

AdaptiveMediaSourceCreationResult result = null;
if (httpClient != null)
Expand Down
95 changes: 51 additions & 44 deletions Samples/BackgroundTransfer/cpp/Tasks/CompletionGroupTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "pch.h"
#include "CompletionGroupTask.h"

using namespace Concurrency;
using namespace Tasks;
using namespace Platform;
using namespace Platform::Collections;
Expand Down Expand Up @@ -39,6 +40,10 @@ CompletionGroupTask::CompletionGroupTask()
// server, or if you would like to try the transfer again with freshly updated credentials.
void CompletionGroupTask::Run(IBackgroundTaskInstance ^ taskInstance)
{
// The background task carries out asynchronous work (in RetryDownloadsAsync). Take a deferral
// to delay the background task from closing prematurely while the asynchronous code is still running.
Platform::Agile<BackgroundTaskDeferral> deferral(taskInstance->GetDeferral());

BackgroundTransferCompletionGroupTriggerDetails^ details =
dynamic_cast<BackgroundTransferCompletionGroupTriggerDetails^>(taskInstance->TriggerDetails);

Expand All @@ -49,33 +54,34 @@ void CompletionGroupTask::Run(IBackgroundTaskInstance ^ taskInstance)
return;
}

Vector<DownloadOperation^>^ badRequestDownloads = ref new Vector<DownloadOperation^>();
Vector<DownloadOperation^>^ failedDownloads = ref new Vector<DownloadOperation^>();
int succeeded = 0;
int failed = 0;
IVectorView<DownloadOperation^>^ downloads = details->Downloads;
for (IIterator<DownloadOperation^>^ iterator = downloads->First(); iterator->HasCurrent; iterator->MoveNext())
for (DownloadOperation^ download : details->Downloads)
{
DownloadOperation^ download = iterator->Current;
if (Succeeded(download))
{
succeeded++;
}
else if (IsBadRequest(download))
if (IsFailed(download))
{
badRequestDownloads->Append(download);
failedDownloads->Append(download);
}
else
{
failed++;
succeeded++;
}
}

if (badRequestDownloads->Size > 0)
InvokeSimpleToast(succeeded, failedDownloads->Size);

if (failedDownloads->Size > 0)
{
RetryDownloads(badRequestDownloads);
RetryDownloadsAsync(failedDownloads).then([deferral]()
{
deferral->Complete();
});
}
else
{
deferral->Complete();
}

InvokeSimpleToast(succeeded, badRequestDownloads->Size, failed);
}


Expand Down Expand Up @@ -108,7 +114,8 @@ BackgroundDownloader^ CompletionGroupTask::CreateBackgroundDownloader()
return downloader;
}

bool CompletionGroupTask::Succeeded(DownloadOperation^ download)

bool CompletionGroupTask::IsFailed(DownloadOperation^ download)
{
BackgroundTransferStatus status = download->Progress.Status;
if (status == BackgroundTransferStatus::Error || status == BackgroundTransferStatus::Canceled)
Expand All @@ -117,55 +124,55 @@ bool CompletionGroupTask::Succeeded(DownloadOperation^ download)
}

ResponseInformation^ response = download->GetResponseInformation();
if (response != nullptr && response->StatusCode == 200)
if (response == nullptr || response->StatusCode != 200)
{
return true;
}

return false;
}

bool CompletionGroupTask::IsBadRequest(DownloadOperation^ download)
task<void> CompletionGroupTask::RetryDownloadsAsync(IVector<DownloadOperation^>^ downloadsToRetry)
{
ResponseInformation^ response = download->GetResponseInformation();
if (response != nullptr && response->StatusCode == 400)
BackgroundDownloader^ downloader = CompletionGroupTask::CreateBackgroundDownloader();
std::vector<task<void>> postRenameTasks;

for (DownloadOperation^ downloadToRetry : downloadsToRetry)
{
return true;
}
// Retry with the same uri, but save to a different file name.
std::wstring originalName(downloadToRetry->ResultFile->Name->Data());
std::wstring newName = originalName.insert(originalName.find_last_of(L'.'), L"_retried");

return false;
}
auto renameTask = create_task(downloadToRetry->ResultFile->RenameAsync(
ref new String(newName.c_str()),
Windows::Storage::NameCollisionOption::ReplaceExisting));

void CompletionGroupTask::RetryDownloads(IIterable<DownloadOperation^>^ downloads)
{
BackgroundDownloader^ downloader = CompletionGroupTask::CreateBackgroundDownloader();
task<void> postRenameTask = renameTask.then([downloadToRetry, downloader]()
{
DownloadOperation^ download = downloader->CreateDownload(downloadToRetry->RequestedUri, downloadToRetry->ResultFile);

for (IIterator<DownloadOperation^>^ iterator = downloads->First(); iterator->HasCurrent; iterator->MoveNext())
{
DownloadOperation^ download = iterator->Current;
DownloadOperation^ download2 = downloader->CreateDownload(download->RequestedUri, download->ResultFile);

// It is not necessary neither recommended to wait for completion of DownloadOperation::StartAsync() within
// a background task. Waiting for the completion would mean to wait until the download is complete,
// but that is not necessary. The download will continue executing after the background task finishes.
//
// If the a download is initiated from a background task, you need to call
// BackgroundDownloader::GetCurrentDownloadsAsync() when the application restarts,
// as demonstrated in Scenario4_CompletionGroups::AttachDownloads.
auto ignore = download2->StartAsync();
// We do not wait on background transfer asynchronous tasks, since wait will only
// finish after the entire transfer is complete, which may take a very long time.
// The completion of these downloads will be handled by a future CompletionGroupTask instance.
auto ignore = download->StartAsync();
});

postRenameTasks.push_back(postRenameTask);
}

downloader->CompletionGroup->Enable();
return when_all(postRenameTasks.begin(), postRenameTasks.end()).then([downloader]()
{
downloader->CompletionGroup->Enable();
});
}

void CompletionGroupTask::InvokeSimpleToast(int succeeded, int badRequests, int failed)
void CompletionGroupTask::InvokeSimpleToast(int succeeded, int failed)
{
XmlDocument^ toastXml = ToastNotificationManager::GetTemplateContent(ToastTemplateType::ToastText04);

XmlNodeList^ stringElements = toastXml->GetElementsByTagName("text");
stringElements->Item(0)->AppendChild(toastXml->CreateTextNode(succeeded.ToString() + " downloads succeeded."));
stringElements->Item(1)->AppendChild(toastXml->CreateTextNode(badRequests.ToString() + " downloads were bad requests, retrying."));
stringElements->Item(2)->AppendChild(toastXml->CreateTextNode(failed.ToString() + " downloads failed."));
stringElements->Item(1)->AppendChild(toastXml->CreateTextNode(failed.ToString() + " downloads failed."));

ToastNotification^ toast = ref new ToastNotification(toastXml);
ToastNotificationManager::CreateToastNotifier()->Show(toast);
Expand Down
8 changes: 4 additions & 4 deletions Samples/BackgroundTransfer/cpp/Tasks/CompletionGroupTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace Tasks
static Windows::Networking::BackgroundTransfer::BackgroundDownloader^ CreateBackgroundDownloader();

private:
bool Succeeded(Windows::Networking::BackgroundTransfer::DownloadOperation^ download);
bool IsBadRequest(Windows::Networking::BackgroundTransfer::DownloadOperation^ download);
void RetryDownloads(Windows::Foundation::Collections::IIterable<Windows::Networking::BackgroundTransfer::DownloadOperation^>^ downloads);
void InvokeSimpleToast(int succeeded, int badRequests, int failed);
bool IsFailed(Windows::Networking::BackgroundTransfer::DownloadOperation^ download);
Concurrency::task<void> RetryDownloadsAsync(
Windows::Foundation::Collections::IVector<Windows::Networking::BackgroundTransfer::DownloadOperation^>^ downloads);
void InvokeSimpleToast(int succeeded, int failed);
};
}
Loading

0 comments on commit 5379e10

Please sign in to comment.