diff --git a/README.md b/README.md
index b0639f4b6b..ac37860da5 100644
--- a/README.md
+++ b/README.md
@@ -509,21 +509,24 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github.
JSON
Mobile broadband
- Radios
+ Network connectivity
+ Radios
Socket activity trigger stream socket
StreamSocket
- Syndication
+ Syndication
USSD protocol
WebSocket
- Wi-Fi Direct
+ Wi-Fi Direct
Wi-Fi Direct services
Wi-Fi hotspot authentication
+
+
Wi-Fi scanning
diff --git a/Samples/BarcodeScanner/README.md b/Samples/BarcodeScanner/README.md
index 40c6079e99..1296011c83 100644
--- a/Samples/BarcodeScanner/README.md
+++ b/Samples/BarcodeScanner/README.md
@@ -3,8 +3,6 @@ page_type: sample
languages:
- csharp
- cpp
-- cppcx
-- vb
- cppwinrt
products:
- windows
@@ -95,7 +93,7 @@ To obtain information about Microsoft Visual Studio and the tools for developing
### Related samples
-* [BarcodeScanner sample](/archived/BarcodeScanner/) for JavaScript (archived)
+* [BarcodeScanner sample](/archived/BarcodeScanner/) for JavaScript, Visual Basic, and C++/CX (archived)
## System requirements
diff --git a/Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.cpp b/Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.cpp
index e4e65b8db4..bab6a91df7 100644
--- a/Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.cpp
+++ b/Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.cpp
@@ -66,6 +66,7 @@ namespace winrt::SDKTemplate::implementation
// reset the button state
ScenarioEndScanButton().IsEnabled(false);
ScenarioStartScanButton().IsEnabled(true);
+ ScenarioSoftwareTriggerPanel().Visibility(Visibility::Collapsed);
}
}
@@ -102,6 +103,14 @@ namespace winrt::SDKTemplate::implementation
m_rootPage.NotifyUser(L"Ready to scan. Device ID: " + m_scanner.DeviceId(), NotifyType::StatusMessage);
ScenarioEndScanButton().IsEnabled(true);
+
+ // If the scanner is a software scanner, show the software trigger buttons.
+ if (!m_scanner.VideoDeviceId().empty())
+ {
+ ScenarioSoftwareTriggerPanel().Visibility(Visibility::Visible);
+ ScenarioStartTriggerButton().IsEnabled(true);
+ ScenarioStopTriggerButton().IsEnabled(false);
+ }
}
else
{
@@ -149,4 +158,18 @@ namespace winrt::SDKTemplate::implementation
{
ResetTheScenarioState();
}
+
+ fire_and_forget Scenario1_BasicFunctionality::ScenarioStartTriggerButton_Click(IInspectable const&, RoutedEventArgs const&)
+ {
+ ScenarioStartTriggerButton().IsEnabled(false);
+ co_await m_claimedScanner.StartSoftwareTriggerAsync();
+ ScenarioStopTriggerButton().IsEnabled(true);
+ }
+
+ fire_and_forget Scenario1_BasicFunctionality::ScenarioStopTriggerButton_Click(IInspectable const&, RoutedEventArgs const&)
+ {
+ ScenarioStopTriggerButton().IsEnabled(false);
+ co_await m_claimedScanner.StopSoftwareTriggerAsync();
+ ScenarioStartTriggerButton().IsEnabled(true);
+ }
}
diff --git a/Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.h b/Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.h
index 560b3560cf..42d44a915c 100644
--- a/Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.h
+++ b/Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.h
@@ -21,6 +21,8 @@ namespace winrt::SDKTemplate::implementation
fire_and_forget ScenarioStartScanButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
void ScenarioEndScanButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
+ fire_and_forget ScenarioStartTriggerButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
+ fire_and_forget ScenarioStopTriggerButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs const& e);
void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs const& e);
diff --git a/Samples/BarcodeScanner/cs/Scenario1_BasicFunctionality.xaml.cs b/Samples/BarcodeScanner/cs/Scenario1_BasicFunctionality.xaml.cs
index 5b74e372f7..302d8510d1 100644
--- a/Samples/BarcodeScanner/cs/Scenario1_BasicFunctionality.xaml.cs
+++ b/Samples/BarcodeScanner/cs/Scenario1_BasicFunctionality.xaml.cs
@@ -95,6 +95,14 @@ private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs
rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage);
ScenarioEndScanButton.IsEnabled = true;
+
+ // If the scanner is a software scanner, show the software trigger buttons.
+ if (!string.IsNullOrEmpty(scanner.VideoDeviceId))
+ {
+ ScenarioSoftwareTriggerPanel.Visibility = Visibility.Visible;
+ ScenarioStartTriggerButton.IsEnabled = true;
+ ScenarioStopTriggerButton.IsEnabled = false;
+ }
}
else
{
@@ -172,6 +180,7 @@ private void ResetTheScenarioState()
// reset the button state
ScenarioEndScanButton.IsEnabled = false;
ScenarioStartScanButton.IsEnabled = true;
+ ScenarioSoftwareTriggerPanel.Visibility = Visibility.Collapsed;
}
}
@@ -187,5 +196,26 @@ private void ScenarioEndScanButton_Click(object sender, RoutedEventArgs e)
this.ResetTheScenarioState();
}
+ ///
+ /// Event handler for Start Software Trigger button click.
+ /// Presses the software trigger button.
+ ///
+ private async void ScenarioStartTriggerButton_Click(object sender, RoutedEventArgs e)
+ {
+ ScenarioStartTriggerButton.IsEnabled = false;
+ await claimedScanner.StartSoftwareTriggerAsync();
+ ScenarioStopTriggerButton.IsEnabled = true;
+ }
+
+ ///
+ /// Event handler for Stop Software Trigger button click.
+ /// Releases the software trigger button.
+ ///
+ private async void ScenarioStopTriggerButton_Click(object sender, RoutedEventArgs e)
+ {
+ ScenarioStopTriggerButton.IsEnabled = false;
+ await claimedScanner.StopSoftwareTriggerAsync();
+ ScenarioStartTriggerButton.IsEnabled = true;
+ }
}
}
diff --git a/Samples/BarcodeScanner/shared/Scenario1_BasicFunctionality.xaml b/Samples/BarcodeScanner/shared/Scenario1_BasicFunctionality.xaml
index 1535a29cbf..9a986519a1 100644
--- a/Samples/BarcodeScanner/shared/Scenario1_BasicFunctionality.xaml
+++ b/Samples/BarcodeScanner/shared/Scenario1_BasicFunctionality.xaml
@@ -22,6 +22,7 @@
+
@@ -40,7 +41,13 @@
-
+
+
+
+
+
+
+
@@ -59,12 +66,6 @@
-
-
-
-
-
diff --git a/Samples/BluetoothLE/cppwinrt/BluetoothLEDeviceDisplay.cpp b/Samples/BluetoothLE/cppwinrt/BluetoothLEDeviceDisplay.cpp
index ef0d078d2e..6c5b672e7e 100644
--- a/Samples/BluetoothLE/cppwinrt/BluetoothLEDeviceDisplay.cpp
+++ b/Samples/BluetoothLE/cppwinrt/BluetoothLEDeviceDisplay.cpp
@@ -1,4 +1,4 @@
-#include "pch.h"
+#include "pch.h"
#include "BluetoothLEDeviceDisplay.h"
#include "BluetoothLEDeviceDisplay.g.cpp"
@@ -55,9 +55,16 @@ namespace winrt::SDKTemplate::implementation
fire_and_forget BluetoothLEDeviceDisplay::UpdateGlyphBitmapImage()
{
auto lifetime = get_strong();
- DeviceThumbnail deviceThumbnail = co_await m_deviceInformation.GetGlyphThumbnailAsync();
BitmapImage glyphBitmapImage;
- co_await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
+ try
+ {
+ DeviceThumbnail deviceThumbnail = co_await m_deviceInformation.GetGlyphThumbnailAsync();
+ co_await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
+ }
+ catch (...)
+ {
+ // Something went wrong getting or decoding the device glyph.
+ }
m_glyphBitmapImage = glyphBitmapImage;
OnPropertyChanged(L"GlyphBitmapImage");
}
diff --git a/Samples/BluetoothLE/cs/DisplayHelpers.cs b/Samples/BluetoothLE/cs/DisplayHelpers.cs
index 991ff59003..ac08ba1568 100644
--- a/Samples/BluetoothLE/cs/DisplayHelpers.cs
+++ b/Samples/BluetoothLE/cs/DisplayHelpers.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
@@ -115,9 +115,16 @@ public void Update(DeviceInformationUpdate deviceInfoUpdate)
private async void UpdateGlyphBitmapImage()
{
- DeviceThumbnail deviceThumbnail = await DeviceInformation.GetGlyphThumbnailAsync();
var glyphBitmapImage = new BitmapImage();
- await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
+ try
+ {
+ DeviceThumbnail deviceThumbnail = await DeviceInformation.GetGlyphThumbnailAsync();
+ await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
+ }
+ catch (Exception)
+ {
+ // Something went wrong getting or decoding the device glyph.
+ }
GlyphBitmapImage = glyphBitmapImage;
OnPropertyChanged("GlyphBitmapImage");
}
@@ -317,4 +324,4 @@ public static byte[] ReadBufferToBytes(IBuffer buffer)
return data;
}
}
-}
\ No newline at end of file
+}
diff --git a/Samples/NetworkConnectivity/README.md b/Samples/NetworkConnectivity/README.md
new file mode 100644
index 0000000000..1de9d8508c
--- /dev/null
+++ b/Samples/NetworkConnectivity/README.md
@@ -0,0 +1,72 @@
+---
+page_type: sample
+languages:
+- csharp
+- cpp
+- cppwinrt
+products:
+- windows
+- windows-uwp
+urlFragment: NetworkingConnectivity
+extendedZipContent:
+- path: SharedContent
+ target: SharedContent
+- path: LICENSE
+ target: LICENSE
+description: "Shows how to query network connectivity and respond to network connectivity changes."
+---
+
+# NetworkingConnectivity sample
+
+Demonstrates how to use the NetworkInformation and related classes
+to determine the network connectivity status,
+and shows how to use this information to determine
+when to attempt to connect to the Internet.
+
+Apps can use the NetworkInformation and related Windows Runtime classes
+to check the network connectivity status before attempting to connect to the Internet.
+These class simplify the complex task of determining connectivity for various network configurations.
+These checks are not strictly required because higher-level APIs (such as HttpClient)
+report insufficient network connectivity through failures/results at the point of connection.
+
+This sample also demonstrates how to register for network connectivity change events.
+Apps can subscribe to the events instead of building their
+own logic to track network connectivity changes.
+
+> **Note:** This sample is part of a large collection of UWP feature samples.
+> You can download this sample as a standalone ZIP file
+> [from docs.microsoft.com](https://docs.microsoft.com/samples/microsoft/windows-universal-samples/networkingconnectivity/),
+> or you can download the entire collection as a single
+> [ZIP file](https://github.com/Microsoft/Windows-universal-samples/archive/main.zip), but be
+> sure to unzip everything to access shared dependencies. For more info on working with the ZIP file,
+> the samples collection, and GitHub, see [Get the UWP samples from GitHub](https://aka.ms/ovu2uq).
+> For more samples, see the [Samples portal](https://aka.ms/winsamples) on the Windows Dev Center.
+
+
+### Declaring the internetClient capability
+
+This sample requires that internetClient capability be set in the *Package.appxmanifest* file to allow the app to access the Internet connection at runtime.
+The capability can be set in the app manifest using Microsoft Visual Studio.
+
+## System requirements
+
+* Windows 10
+
+## Build the sample
+
+1. If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build.
+2. Start Microsoft Visual Studio and select **File** \> **Open** \> **Project/Solution**.
+3. Starting in the folder where you unzipped the samples, go to the Samples subfolder, then the subfolder for this specific sample, then the subfolder for your preferred language (C++, C#, or JavaScript). Double-click the Visual Studio Solution (.sln) file.
+4. Press Ctrl+Shift+B or select **Build** \> **Build Solution**.
+
+## Run the sample
+
+The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.
+
+### Deploying the sample
+
+- Select Build > Deploy Solution.
+
+### Debugging and running the sample
+
+- To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or select Debug > Start Without Debugging.
diff --git a/Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.sln b/Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.sln
new file mode 100644
index 0000000000..30580799e9
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.sln
@@ -0,0 +1,43 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.33516.290
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NetworkConnectivity", "NetworkConnectivity.vcxproj", "{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|ARM64 = Debug|ARM64
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|ARM64 = Release|ARM64
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|ARM64.ActiveCfg = Debug|ARM64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|ARM64.Build.0 = Debug|ARM64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|ARM64.Deploy.0 = Debug|ARM64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x64.ActiveCfg = Debug|x64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x64.Build.0 = Debug|x64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x64.Deploy.0 = Debug|x64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x86.ActiveCfg = Debug|Win32
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x86.Build.0 = Debug|Win32
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x86.Deploy.0 = Debug|Win32
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|ARM64.ActiveCfg = Release|ARM64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|ARM64.Build.0 = Release|ARM64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|ARM64.Deploy.0 = Release|ARM64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x64.ActiveCfg = Release|x64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x64.Build.0 = Release|x64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x64.Deploy.0 = Release|x64
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x86.ActiveCfg = Release|Win32
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x86.Build.0 = Release|Win32
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x86.Deploy.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {77D722D2-6DBF-402D-9B3B-6473BA169D27}
+ EndGlobalSection
+EndGlobal
diff --git a/Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.vcxproj b/Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.vcxproj
new file mode 100644
index 0000000000..11ab763ee3
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.vcxproj
@@ -0,0 +1,202 @@
+
+
+
+
+ $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), LICENSE))\SharedContent
+
+
+ true
+ {21C18BA0-582C-4264-B0DD-7F2867D8E3D6}
+ NetworkConnectivity
+ SDKTemplate
+ en-US
+ 15.0
+ true
+ Windows Store
+ 10.0
+ 10.0.22000.0
+ $(WindowsTargetPlatformVersion)
+
+
+
+
+ Debug
+ ARM64
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ ARM64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ Application
+ Unicode
+
+
+ true
+ true
+
+
+ false
+ true
+ false
+
+
+
+
+
+
+
+ $(VC_IncludePath);$(UniversalCRT_IncludePath);$(WindowsSDK_IncludePath);$(SharedContentDir)\cppwinrt
+ true
+
+
+
+ Use
+ pch.h
+ $(IntDir)pch.pch
+ Level4
+ %(AdditionalOptions) /bigobj
+ 4453;28204
+
+
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+
+
+ C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.33.31629\lib\onecore
+
+
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+
+
+
+
+ $(SharedContentDir)\xaml\App.xaml
+
+
+ $(SharedContentDir)\xaml\MainPage.xaml
+
+
+
+ ..\shared\Scenario1_NetworkConnectivity.xaml
+
+
+ ..\shared\Scenario2_NetworkCost.xaml
+
+
+
+ ..\shared\Scenario3_NetworkConnectivityChanges.xaml
+ Code
+
+
+
+
+ Designer
+
+
+ Designer
+
+
+
+
+ Styles\Styles.xaml
+
+
+ Designer
+
+
+
+
+ $(SharedContentDir)\xaml\App.xaml
+
+
+ $(SharedContentDir)\xaml\MainPage.xaml
+
+
+ SampleConfiguration.h
+
+
+ ..\shared\Scenario1_NetworkConnectivity.xaml
+
+
+ ..\shared\Scenario2_NetworkCost.xaml
+
+
+ Create
+ pch.h
+
+
+ Project.idl
+
+
+ ..\shared\Scenario3_NetworkConnectivityChanges.xaml
+ Code
+
+
+
+
+ $(SharedContentDir)\xaml\MainPage.xaml
+
+
+
+
+
+ Designer
+
+
+
+
+
+ Assets\microsoft-sdk.png
+
+
+ Assets\smallTile-sdk.png
+
+
+ Assets\splash-sdk.png
+
+
+ Assets\squareTile-sdk.png
+
+
+ Assets\storeLogo-sdk.png
+
+
+ Assets\tile-sdk.png
+
+
+ Assets\windows-sdk.png
+
+
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
\ No newline at end of file
diff --git a/Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.vcxproj.filters b/Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.vcxproj.filters
new file mode 100644
index 0000000000..5af211dde1
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.vcxproj.filters
@@ -0,0 +1,60 @@
+
+
+
+
+ 4416d50a-7676-4d0a-9b2c-91ff70c6047f
+ bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Samples/NetworkConnectivity/cppwinrt/Package.appxmanifest b/Samples/NetworkConnectivity/cppwinrt/Package.appxmanifest
new file mode 100644
index 0000000000..c665df80ab
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/Package.appxmanifest
@@ -0,0 +1,29 @@
+
+
+
+
+
+ NetworkConnectivity C++/WinRT Sample
+ Microsoft Corporation
+ Assets\StoreLogo-sdk.png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Samples/NetworkConnectivity/cppwinrt/Project.idl b/Samples/NetworkConnectivity/cppwinrt/Project.idl
new file mode 100644
index 0000000000..e274a10600
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/Project.idl
@@ -0,0 +1,31 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+namespace SDKTemplate
+{
+ [default_interface]
+ runtimeclass Scenario1_NetworkConnectivity : Windows.UI.Xaml.Controls.Page
+ {
+ Scenario1_NetworkConnectivity();
+ }
+
+ [default_interface]
+ runtimeclass Scenario2_NetworkCost : Windows.UI.Xaml.Controls.Page
+ {
+ Scenario2_NetworkCost();
+ }
+
+ [default_interface]
+ runtimeclass Scenario3_NetworkConnectivityChanges : Windows.UI.Xaml.Controls.Page
+ {
+ Scenario3_NetworkConnectivityChanges();
+ }
+}
diff --git a/Samples/NetworkConnectivity/cppwinrt/SampleConfiguration.cpp b/Samples/NetworkConnectivity/cppwinrt/SampleConfiguration.cpp
new file mode 100644
index 0000000000..1861442197
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/SampleConfiguration.cpp
@@ -0,0 +1,169 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#include "pch.h"
+#include
+#include "MainPage.h"
+#include "SampleConfiguration.h"
+
+using namespace winrt;
+using namespace winrt::Windows::Foundation;
+using namespace winrt::Windows::Foundation::Collections;
+using namespace winrt::Windows::Networking::Connectivity;
+using namespace winrt::Windows::UI::Xaml::Controls;
+using namespace winrt::Windows::Web::Http;
+using namespace winrt::SDKTemplate;
+
+hstring implementation::MainPage::FEATURE_NAME()
+{
+ return L"NetworkConnectivity C++/WinRT Sample";
+}
+
+IVector implementation::MainPage::scenariosInner = winrt::single_threaded_observable_vector(
+{
+ Scenario{ L"Query network connectivity", xaml_typename() },
+ Scenario{ L"Get network cost information", xaml_typename() },
+ Scenario{ L"Listen to connectivity changes", xaml_typename() },
+});
+
+hstring winrt::to_hstring(NetworkConnectivityLevel value)
+{
+ switch (value)
+ {
+ case NetworkConnectivityLevel::None: return L"None";
+ case NetworkConnectivityLevel::LocalAccess: return L"LocalAccess";
+ case NetworkConnectivityLevel::ConstrainedInternetAccess: return L"ConstrainedInternetAccess";
+ case NetworkConnectivityLevel::InternetAccess: return L"InternetAccess";
+ }
+ return to_hstring(static_cast(value));
+}
+
+hstring winrt::to_hstring(NetworkCostType type)
+{
+ switch (type)
+ {
+ case NetworkCostType::Unknown: return L"Unknown";
+ case NetworkCostType::Unrestricted: return L"Unrestricted";
+ case NetworkCostType::Fixed: return L"Fixed";
+ case NetworkCostType::Variable: return L"Variable";
+ }
+ return winrt::to_hstring(static_cast(type));
+}
+
+void winrt::SDKTemplate::AppendLine(TextBlock const& textBlock, hstring const& message)
+{
+ textBlock.Text(textBlock.Text() + message + L"\n\n");
+}
+
+bool winrt::SDKTemplate::ShouldAttemptToConnectToInternet(NetworkConnectivityLevel level)
+{
+ bool shouldConnectToInternet = false;
+ if (level == NetworkConnectivityLevel::LocalAccess || level == NetworkConnectivityLevel::InternetAccess)
+ {
+ shouldConnectToInternet = true;
+ }
+
+ return shouldConnectToInternet;
+}
+
+namespace
+{
+ IAsyncOperation SendHttpGetRequestAsync()
+ {
+ HttpClient httpClient;
+ HttpGetStringResult result = co_await httpClient.TryGetStringAsync(Uri(L"http://www.msftconnecttest.com/connecttest.txt"));
+ if (result.Succeeded())
+ {
+ co_return L"Success: \"" + result.Value() + L"\"";
+ }
+ else if (HttpResponseMessage responseMessage = result.ResponseMessage(); responseMessage != nullptr)
+ {
+ co_return L"HTTP error: " + to_hstring(static_cast(responseMessage.StatusCode()));
+ }
+ else
+ {
+ co_return L"Error: " + hresult_error(result.ExtendedError(), take_ownership_from_abi).message();
+ }
+ }
+}
+
+
+CostGuidance winrt::SDKTemplate::GetNetworkCostGuidance(ConnectionCost cost)
+{
+ CostGuidance costGuidance = CostGuidance::Normal;
+ if (cost.Roaming() || cost.OverDataLimit())
+ {
+ costGuidance = CostGuidance::OptIn;
+ }
+ else if (cost.NetworkCostType() == NetworkCostType::Fixed || cost.NetworkCostType() == NetworkCostType::Variable)
+ {
+ costGuidance = CostGuidance::Conservative;
+ }
+ else
+ {
+ costGuidance = CostGuidance::Normal;
+ }
+ return costGuidance;
+}
+
+void winrt::SDKTemplate::EvaluateAndReportConnectionCost(ConnectionCost cost, TextBlock const& textBlock)
+{
+ CostGuidance costGuidance = GetNetworkCostGuidance(cost);
+ switch (costGuidance)
+ {
+ // In opt-in scenarios, apps handle cases where the network access cost is significantly higher than the plan cost.
+ // For example, when a user is roaming, a mobile carrier may charge a higher rate data usage.
+ case CostGuidance::OptIn:
+ AppendLine(textBlock, L"Apps should implement opt-in behavior.");
+ break;
+ // In conservative scenarios, apps implement restrictions for optimizing network usage to handle transfers over metered networks.
+ case CostGuidance::Conservative:
+ AppendLine(textBlock, L"Apps should implement conservative behavior.");
+ break;
+ // In normal scenarios, apps do not implement restrictions. Apps treat the connection as unlimited in cost.
+ case CostGuidance::Normal:
+ default:
+ AppendLine(textBlock, L"Apps should implement normal behavior.");
+ break;
+ }
+}
+
+IAsyncAction winrt::SDKTemplate::EvaluateCostAndConnectAsync(ConnectionCost cost, bool optedInToCharges, TextBlock textBlock)
+{
+ CostGuidance costGuidance = GetNetworkCostGuidance(cost);
+
+ switch (costGuidance)
+ {
+ case CostGuidance::OptIn:
+ {
+ AppendLine(textBlock, L"Connecting to the Internet may incur charges.");
+ if (optedInToCharges)
+ {
+ AppendLine(textBlock, L"User has opted in to additional network usage charges.");
+ AppendLine(textBlock, co_await SendHttpGetRequestAsync());
+ }
+ else
+ {
+ AppendLine(textBlock, L"User has opted out of additional network usage charges. Not connecting to the Internet.");
+ }
+ }
+ break;
+ case CostGuidance::Conservative:
+ AppendLine(textBlock, L"Attempting to connect to the Internet, optimizing traffic for conservative network usage.");
+ AppendLine(textBlock, co_await SendHttpGetRequestAsync());
+ break;
+ case CostGuidance::Normal:
+ default:
+ AppendLine(textBlock, L"Attempting to connect to the Internet.");
+ AppendLine(textBlock, co_await SendHttpGetRequestAsync());
+ break;
+ }
+}
diff --git a/Samples/NetworkConnectivity/cppwinrt/SampleConfiguration.h b/Samples/NetworkConnectivity/cppwinrt/SampleConfiguration.h
new file mode 100644
index 0000000000..c6b0e38042
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/SampleConfiguration.h
@@ -0,0 +1,37 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#pragma once
+#include "pch.h"
+
+namespace winrt
+{
+ hstring to_hstring(Windows::Networking::Connectivity::NetworkConnectivityLevel value);
+ hstring to_hstring(Windows::Networking::Connectivity::NetworkCostType type);
+}
+
+namespace winrt::SDKTemplate
+{
+ void AppendLine(Windows::UI::Xaml::Controls::TextBlock const& textBlock, hstring const& message);
+
+ enum class CostGuidance
+ {
+ Normal,
+ OptIn,
+ Conservative
+ };
+
+ bool ShouldAttemptToConnectToInternet(Windows::Networking::Connectivity::NetworkConnectivityLevel level);
+ CostGuidance GetNetworkCostGuidance(Windows::Networking::Connectivity::ConnectionCost cost);
+ void EvaluateAndReportConnectionCost(Windows::Networking::Connectivity::ConnectionCost cost, Windows::UI::Xaml::Controls::TextBlock const& textBlock);
+ winrt::Windows::Foundation::IAsyncAction EvaluateCostAndConnectAsync(Windows::Networking::Connectivity::ConnectionCost cost, bool optedInToCharges, Windows::UI::Xaml::Controls::TextBlock textBlock);
+}
+
diff --git a/Samples/NetworkConnectivity/cppwinrt/Scenario1_NetworkConnectivity.cpp b/Samples/NetworkConnectivity/cppwinrt/Scenario1_NetworkConnectivity.cpp
new file mode 100644
index 0000000000..1e9dfeea60
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/Scenario1_NetworkConnectivity.cpp
@@ -0,0 +1,59 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#include "pch.h"
+#include "Scenario1_NetworkConnectivity.h"
+#include "Scenario1_NetworkConnectivity.g.cpp"
+#include "SampleConfiguration.h"
+
+using namespace winrt;
+using namespace winrt::Windows::Foundation;
+using namespace winrt::Windows::Foundation::Collections;
+using namespace winrt::Windows::Networking::Connectivity;
+using namespace winrt::Windows::UI::Xaml;
+using namespace winrt::Windows::UI::Xaml::Controls;
+using namespace winrt::Windows::UI::Xaml::Navigation;
+
+namespace winrt::SDKTemplate::implementation
+{
+ Scenario1_NetworkConnectivity::Scenario1_NetworkConnectivity()
+ {
+ InitializeComponent();
+ }
+
+ fire_and_forget Scenario1_NetworkConnectivity::QueryCurrentNetworkConnectivityButton_Click(IInspectable const&, RoutedEventArgs const&)
+ {
+ auto lifetime = get_strong();
+
+ ResultsText().Text(L"");
+
+ ConnectionProfile profile = NetworkInformation::GetInternetConnectionProfile();
+ NetworkConnectivityLevel connectivityLevel = NetworkConnectivityLevel::None;
+ if (profile != nullptr)
+ {
+ // It can take the system a few moments to detect a change in network connectivity,
+ // so it's possible that the value returned is slightly out of date.
+ // Scenario3_NetworkConnectivityChanges shows how to be notified when the connectivity
+ // changes.
+ connectivityLevel = profile.GetNetworkConnectivityLevel();
+ }
+
+ AppendLine(ResultsText(), L"Current connectivity is " + to_hstring(connectivityLevel) + L".");
+ if (ShouldAttemptToConnectToInternet(connectivityLevel))
+ {
+ co_await EvaluateCostAndConnectAsync(profile.GetConnectionCost(), OptedInToNetworkUsageToggle().IsOn(), ResultsText());
+ }
+ else
+ {
+ AppendLine(ResultsText(), L"Not attempting to connect to the Internet.");
+ }
+ }
+}
diff --git a/Samples/NetworkConnectivity/cppwinrt/Scenario1_NetworkConnectivity.h b/Samples/NetworkConnectivity/cppwinrt/Scenario1_NetworkConnectivity.h
new file mode 100644
index 0000000000..993fbbe22f
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/Scenario1_NetworkConnectivity.h
@@ -0,0 +1,28 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+#pragma once
+#include "Scenario1_NetworkConnectivity.g.h"
+
+namespace winrt::SDKTemplate::implementation
+{
+ struct Scenario1_NetworkConnectivity : Scenario1_NetworkConnectivityT
+ {
+ Scenario1_NetworkConnectivity();
+ fire_and_forget QueryCurrentNetworkConnectivityButton_Click(Windows::Foundation::IInspectable const&, Windows::UI::Xaml::RoutedEventArgs const&);
+ };
+}
+
+namespace winrt::SDKTemplate::factory_implementation
+{
+ struct Scenario1_NetworkConnectivity : Scenario1_NetworkConnectivityT
+ {
+ };
+}
diff --git a/Samples/NetworkConnectivity/cppwinrt/Scenario2_NetworkCost.cpp b/Samples/NetworkConnectivity/cppwinrt/Scenario2_NetworkCost.cpp
new file mode 100644
index 0000000000..dc773a6306
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/Scenario2_NetworkCost.cpp
@@ -0,0 +1,46 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#include "pch.h"
+#include "Scenario2_NetworkCost.h"
+#include "Scenario2_NetworkCost.g.cpp"
+#include "SampleConfiguration.h"
+
+using namespace winrt;
+using namespace winrt::Windows::Foundation;
+using namespace winrt::Windows::Networking::Connectivity;
+using namespace winrt::Windows::UI::Xaml;
+using namespace winrt::Windows::UI::Xaml::Navigation;
+
+namespace winrt::SDKTemplate::implementation
+{
+ Scenario2_NetworkCost::Scenario2_NetworkCost()
+ {
+ InitializeComponent();
+ }
+
+ void Scenario2_NetworkCost::GetNetworkCost_Click(IInspectable const&, RoutedEventArgs const&)
+ {
+ ResultsText().Text(L"");
+
+ ConnectionProfile profile = NetworkInformation::GetInternetConnectionProfile();
+ if (profile != nullptr)
+ {
+ ConnectionCost connectionCost = profile.GetConnectionCost();
+ AppendLine(ResultsText(), L"Network cost is: " + to_hstring(connectionCost.NetworkCostType()) + L".");
+ EvaluateAndReportConnectionCost(connectionCost, ResultsText());
+ }
+ else
+ {
+ AppendLine(ResultsText(), L"No internet connection profile.");
+ }
+ }
+}
diff --git a/Samples/NetworkConnectivity/cppwinrt/Scenario2_NetworkCost.h b/Samples/NetworkConnectivity/cppwinrt/Scenario2_NetworkCost.h
new file mode 100644
index 0000000000..5601609d96
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/Scenario2_NetworkCost.h
@@ -0,0 +1,28 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+#pragma once
+#include "Scenario2_NetworkCost.g.h"
+
+namespace winrt::SDKTemplate::implementation
+{
+ struct Scenario2_NetworkCost : Scenario2_NetworkCostT
+ {
+ Scenario2_NetworkCost();
+ void GetNetworkCost_Click(Windows::Foundation::IInspectable const&, Windows::UI::Xaml::RoutedEventArgs const&);
+ };
+}
+
+namespace winrt::SDKTemplate::factory_implementation
+{
+ struct Scenario2_NetworkCost : Scenario2_NetworkCostT
+ {
+ };
+}
diff --git a/Samples/NetworkConnectivity/cppwinrt/Scenario3_NetworkConnectivityChanges.cpp b/Samples/NetworkConnectivity/cppwinrt/Scenario3_NetworkConnectivityChanges.cpp
new file mode 100644
index 0000000000..6534d11e60
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/Scenario3_NetworkConnectivityChanges.cpp
@@ -0,0 +1,128 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#include "pch.h"
+#include "Scenario3_NetworkConnectivityChanges.h"
+#include "Scenario3_NetworkConnectivityChanges.g.cpp"
+#include "SampleConfiguration.h"
+
+using namespace winrt;
+using namespace winrt::Windows::Foundation;
+using namespace winrt::Windows::Foundation::Collections;
+using namespace winrt::Windows::Networking::Connectivity;
+using namespace winrt::Windows::UI::Xaml;
+using namespace winrt::Windows::UI::Xaml::Controls;
+using namespace winrt::Windows::UI::Xaml::Navigation;
+using namespace winrt::Windows::Web::Http;
+
+namespace winrt::SDKTemplate::implementation
+{
+ Scenario3_NetworkConnectivityChanges::Scenario3_NetworkConnectivityChanges()
+ {
+ InitializeComponent();
+ }
+
+ void Scenario3_NetworkConnectivityChanges::OnNavigatedTo(NavigationEventArgs const&)
+ {
+ UpdateButtonStates();
+ }
+
+ void Scenario3_NetworkConnectivityChanges::OnNavigatedFrom(NavigationEventArgs const&)
+ {
+ if (m_networkStatusChangeEventToken)
+ {
+ UnregisterNetworkStatusChanged();
+ }
+ }
+
+ fire_and_forget Scenario3_NetworkConnectivityChanges::UpdateNetworkStatus()
+ {
+ // This code runs on the UI thread, so there are no race conditions on these
+ // member variables.
+ if (m_isUpdatingNetworkStatus)
+ {
+ // Update is already in progress. Let it finish before we re-evaluate.
+ m_isNetworkStatusUpdatePending = true;
+ co_return;
+ }
+
+ auto lifetime = get_strong();
+
+ m_isUpdatingNetworkStatus = true;
+
+ do
+ {
+ m_isNetworkStatusUpdatePending = false;
+ ResultsText().Text(L"");
+
+ ConnectionProfile internetConnectionProfile = NetworkInformation::GetInternetConnectionProfile();
+ NetworkConnectivityLevel connectivityLevel = NetworkConnectivityLevel::None;
+ if (internetConnectionProfile != nullptr)
+ {
+ connectivityLevel = internetConnectionProfile.GetNetworkConnectivityLevel();
+ }
+
+ AppendLine(ResultsText(), L"Current connectivity is " + to_hstring(connectivityLevel) + L".");
+ if (ShouldAttemptToConnectToInternet(connectivityLevel))
+ {
+ AppendLine(ResultsText(), L"Checking network cost before connecting to the Internet.");
+ co_await EvaluateCostAndConnectAsync(internetConnectionProfile.GetConnectionCost(), OptedInToNetworkUsageToggle().IsOn(), ResultsText());
+ }
+ else
+ {
+ AppendLine(ResultsText(), L"Not attempting to connect to the Internet.");
+ }
+ }
+ while (m_isNetworkStatusUpdatePending);
+ m_isUpdatingNetworkStatus = false;
+ }
+
+ fire_and_forget Scenario3_NetworkConnectivityChanges::OnNetworkStatusChanged(IInspectable const&)
+ {
+ auto lifetime = get_strong();
+
+ co_await resume_foreground(Dispatcher());
+
+ UpdateNetworkStatus();
+ }
+
+ void Scenario3_NetworkConnectivityChanges::RegisterNetworkStatusChanged()
+ {
+ m_networkStatusChangeEventToken = NetworkInformation::NetworkStatusChanged({ get_weak(), &Scenario3_NetworkConnectivityChanges::OnNetworkStatusChanged });
+ UpdateNetworkStatus();
+ }
+
+ void Scenario3_NetworkConnectivityChanges::UnregisterNetworkStatusChanged()
+ {
+ NetworkInformation::NetworkStatusChanged(std::exchange(m_networkStatusChangeEventToken, {}));
+ }
+
+ void Scenario3_NetworkConnectivityChanges::RegisterUnregisterButton_Click(IInspectable const&, RoutedEventArgs const&)
+ {
+ if (m_networkStatusChangeEventToken)
+ {
+ UnregisterNetworkStatusChanged();
+ }
+ else
+ {
+ RegisterNetworkStatusChanged();
+ }
+ UpdateButtonStates();
+ }
+
+ ///
+ /// Update the UI based on whether we are registered for the event.
+ ///
+ void Scenario3_NetworkConnectivityChanges::UpdateButtonStates()
+ {
+ VisualStateManager::GoToState(*this, m_networkStatusChangeEventToken ? L"Registered" : L"Unregistered", false);
+ }
+}
diff --git a/Samples/NetworkConnectivity/cppwinrt/Scenario3_NetworkConnectivityChanges.h b/Samples/NetworkConnectivity/cppwinrt/Scenario3_NetworkConnectivityChanges.h
new file mode 100644
index 0000000000..7fa4210476
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/Scenario3_NetworkConnectivityChanges.h
@@ -0,0 +1,43 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+#pragma once
+#include "Scenario3_NetworkConnectivityChanges.g.h"
+
+namespace winrt::SDKTemplate::implementation
+{
+ struct Scenario3_NetworkConnectivityChanges : Scenario3_NetworkConnectivityChangesT
+ {
+ Scenario3_NetworkConnectivityChanges();
+
+ void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs const& e);
+ void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs const& e);
+ void RegisterUnregisterButton_Click(Windows::Foundation::IInspectable const&, Windows::UI::Xaml::RoutedEventArgs const&);
+ void OptInOutComboBox_SelectionChanged(Windows::Foundation::IInspectable const&, Windows::UI::Xaml::Controls::SelectionChangedEventArgs const&);
+
+ private:
+ void UpdateButtonStates();
+ fire_and_forget UpdateNetworkStatus();
+ fire_and_forget OnNetworkStatusChanged(Windows::Foundation::IInspectable const&);
+ void RegisterNetworkStatusChanged();
+ void UnregisterNetworkStatusChanged();
+
+ winrt::event_token m_networkStatusChangeEventToken{};
+ bool m_isUpdatingNetworkStatus = false;
+ bool m_isNetworkStatusUpdatePending = false;
+ };
+}
+
+namespace winrt::SDKTemplate::factory_implementation
+{
+ struct Scenario3_NetworkConnectivityChanges : Scenario3_NetworkConnectivityChangesT
+ {
+ };
+}
diff --git a/Samples/NetworkConnectivity/cppwinrt/packages.config b/Samples/NetworkConnectivity/cppwinrt/packages.config
new file mode 100644
index 0000000000..a6b596a22c
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/Samples/NetworkConnectivity/cppwinrt/pch.cpp b/Samples/NetworkConnectivity/cppwinrt/pch.cpp
new file mode 100644
index 0000000000..666344a2e8
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/pch.cpp
@@ -0,0 +1,17 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+//
+// pch.cpp
+// Include the standard header and generate the precompiled header.
+//
+
+#include "pch.h"
diff --git a/Samples/NetworkConnectivity/cppwinrt/pch.h b/Samples/NetworkConnectivity/cppwinrt/pch.h
new file mode 100644
index 0000000000..700f5bfb27
--- /dev/null
+++ b/Samples/NetworkConnectivity/cppwinrt/pch.h
@@ -0,0 +1,31 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
diff --git a/Samples/NetworkConnectivity/cs/Helpers.cs b/Samples/NetworkConnectivity/cs/Helpers.cs
new file mode 100644
index 0000000000..0e66c706be
--- /dev/null
+++ b/Samples/NetworkConnectivity/cs/Helpers.cs
@@ -0,0 +1,135 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+using System;
+using System.Threading.Tasks;
+using Windows.Networking.Connectivity;
+using Windows.UI.Xaml.Controls;
+using Windows.Web.Http;
+
+namespace SDKTemplate
+{
+ internal class Helpers
+ {
+ public static void AppendLine(TextBlock textBlock, string message)
+ {
+ textBlock.Text += message + "\n\n";
+ }
+
+ enum CostGuidance
+ {
+ Normal,
+ OptIn,
+ Conservative
+ }
+
+ public static bool ShouldAttemptToConnectToInternet(NetworkConnectivityLevel connectivityLevel)
+ {
+ bool shouldConnectToInternet = false;
+ if (connectivityLevel == NetworkConnectivityLevel.LocalAccess || connectivityLevel == NetworkConnectivityLevel.InternetAccess)
+ {
+ shouldConnectToInternet = true;
+ }
+
+ return shouldConnectToInternet;
+ }
+
+ private static async Task SendHttpGetRequestAsync()
+ {
+ string message;
+ HttpClient httpClient = new HttpClient();
+ HttpGetStringResult result = await httpClient.TryGetStringAsync(new Uri("http://www.msftconnecttest.com/connecttest.txt"));
+ if (result.Succeeded)
+ {
+ message = $"Connection to server confirmed: \"{result.Value}\"";
+ }
+ else if (result.ResponseMessage != null)
+ {
+ message = $"Cannot connect to server: {result.ResponseMessage.StatusCode}";
+ }
+ else
+ {
+ message = $"Cannot connect to server: {result.ExtendedError.Message}";
+ }
+ return message;
+ }
+
+ private static CostGuidance GetNetworkCostGuidance(ConnectionCost connectionCost)
+ {
+ CostGuidance costGuidance = CostGuidance.Normal;
+ if (connectionCost.Roaming || connectionCost.OverDataLimit)
+ {
+ costGuidance = CostGuidance.OptIn;
+ }
+ else if (connectionCost.NetworkCostType == NetworkCostType.Fixed || connectionCost.NetworkCostType == NetworkCostType.Variable)
+ {
+ costGuidance = CostGuidance.Conservative;
+ }
+ else
+ {
+ costGuidance = CostGuidance.Normal;
+ }
+ return costGuidance;
+ }
+
+ public static void EvaluateAndReportConnectionCost(ConnectionCost connectionCost, TextBlock textBlock)
+ {
+ CostGuidance costGuidance = GetNetworkCostGuidance(connectionCost);
+ switch (costGuidance)
+ {
+ // In opt-in scenarios, apps handle cases where the network access cost is significantly higher than the plan cost.
+ // For example, when a user is roaming, a mobile carrier may charge a higher rate data usage.
+ case CostGuidance.OptIn:
+ AppendLine(textBlock, "Apps should implement opt-in behavior.");
+ break;
+ // In conservative scenarios, apps implement restrictions for optimizing network usage to handle transfers over metered networks.
+ case CostGuidance.Conservative:
+ AppendLine(textBlock, "Apps should implement conservative behavior.");
+ break;
+ // In normal scenarios, apps do not implement restrictions. Apps treat the connection as unlimited in cost.
+ case CostGuidance.Normal:
+ default:
+ AppendLine(textBlock, "Apps should implement normal behavior.");
+ break;
+ }
+ }
+
+ public static async Task EvaluateCostAndConnectAsync(ConnectionCost connectionCost, bool optedInToCharges, TextBlock textBlock)
+ {
+ CostGuidance costGuidance = GetNetworkCostGuidance(connectionCost);
+ switch (costGuidance)
+ {
+ case CostGuidance.OptIn:
+ {
+ AppendLine(textBlock, "Connecting to the Internet may incur charges.");
+ if (optedInToCharges)
+ {
+ AppendLine(textBlock, "User has opted in to additional network usage charges.");
+ AppendLine(textBlock, await SendHttpGetRequestAsync());
+ }
+ else
+ {
+ AppendLine(textBlock, "User has opted out of additional network usage charges. Not connecting to the Internet.");
+ }
+ }
+ break;
+ case CostGuidance.Conservative:
+ AppendLine(textBlock, "Attempting to connect to the Internet, optimizing traffic for conservative network usage.");
+ AppendLine(textBlock, await SendHttpGetRequestAsync());
+ break;
+ case CostGuidance.Normal:
+ default:
+ AppendLine(textBlock, "Attempting to connect to the Internet.");
+ AppendLine(textBlock, await SendHttpGetRequestAsync());
+ break;
+ }
+ }
+ }
+}
diff --git a/Samples/NetworkConnectivity/cs/NetworkConnectivity.csproj b/Samples/NetworkConnectivity/cs/NetworkConnectivity.csproj
new file mode 100644
index 0000000000..defdf0ba13
--- /dev/null
+++ b/Samples/NetworkConnectivity/cs/NetworkConnectivity.csproj
@@ -0,0 +1,202 @@
+
+
+
+
+ $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), LICENSE))\SharedContent
+
+
+ Debug
+ x86
+ {56E04579-CF91-49DF-9903-ABD937B364E5}
+ AppContainerExe
+ Properties
+ SDKTemplate
+ NetworkConnectivity
+ en-US
+ UAP
+ 10.0.22000.0
+ 10.0.22000.0
+ 14
+ true
+ 512
+ {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+
+
+ true
+ bin\ARM64\Debug\
+ DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP
+ ;2008
+ true
+ full
+ ARM64
+ false
+ 7.3
+ prompt
+ true
+ win10-arm64
+
+
+ bin\ARM64\Release\
+ TRACE;NETFX_CORE;WINDOWS_UAP;CODE_ANALYSIS
+ true
+ ;2008
+ true
+ pdbonly
+ ARM64
+ false
+ 7.3
+ prompt
+ true
+ win10-arm64
+ true
+
+
+ true
+ bin\x64\Debug\
+ DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP
+ ;2008
+ full
+ x64
+ false
+ prompt
+ true
+
+
+ bin\x64\Release\
+ TRACE;NETFX_CORE;WINDOWS_UAP
+ true
+ ;2008
+ pdbonly
+ x64
+ false
+ prompt
+ true
+ true
+
+
+ true
+ bin\x86\Debug\
+ DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP
+ ;2008
+ full
+ x86
+ false
+ prompt
+ true
+
+
+ bin\x86\Release\
+ TRACE;NETFX_CORE;WINDOWS_UAP
+ true
+ ;2008
+ pdbonly
+ x86
+ false
+ prompt
+ true
+ true
+
+
+
+ App.xaml.cs
+ App.xaml
+
+
+ MainPage.xaml.cs
+ MainPage.xaml
+
+
+ Properties\AssemblyInfo.cs
+
+
+
+
+ Scenario1_NetworkConnectivity.xaml
+
+
+ Scenario2_NetworkCost.xaml
+
+
+ Scenario3_NetworkConnectivityChanges.xaml
+
+
+
+
+ Designer
+
+
+
+
+ App.xaml
+ MSBuild:Compile
+ Designer
+
+
+ MainPage.xaml
+ MSBuild:Compile
+ Designer
+
+
+ Scenario1_NetworkConnectivity.xaml
+ Designer
+ MSBuild:Compile
+
+
+ Scenario2_NetworkCost.xaml
+ Designer
+ MSBuild:Compile
+
+
+ Scenario3_NetworkConnectivityChanges.xaml
+ MSBuild:Compile
+ Designer
+
+
+ Styles\Styles.xaml
+ MSBuild:Compile
+ Designer
+
+
+
+
+ Properties\Default.rd.xml
+
+
+ Assets\microsoft-sdk.png
+
+
+ Assets\smallTile-sdk.png
+
+
+ Assets\splash-sdk.png
+
+
+ Assets\squareTile-sdk.png
+
+
+ Assets\storeLogo-sdk.png
+
+
+ Assets\tile-sdk.png
+
+
+ Assets\windows-sdk.png
+
+
+
+
+ 5.0.0
+
+
+
+ 14.0
+
+
+
+
\ No newline at end of file
diff --git a/Samples/NetworkConnectivity/cs/NetworkConnectivity.sln b/Samples/NetworkConnectivity/cs/NetworkConnectivity.sln
new file mode 100644
index 0000000000..dfcad7a663
--- /dev/null
+++ b/Samples/NetworkConnectivity/cs/NetworkConnectivity.sln
@@ -0,0 +1,43 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.33516.290
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkConnectivity", "NetworkConnectivity.csproj", "{56E04579-CF91-49DF-9903-ABD937B364E5}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|ARM64 = Debug|ARM64
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|ARM64 = Release|ARM64
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Debug|ARM64.ActiveCfg = Debug|ARM64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Debug|ARM64.Build.0 = Debug|ARM64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Debug|ARM64.Deploy.0 = Debug|ARM64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Debug|x64.ActiveCfg = Debug|x64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Debug|x64.Build.0 = Debug|x64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Debug|x64.Deploy.0 = Debug|x64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Debug|x86.ActiveCfg = Debug|x86
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Debug|x86.Build.0 = Debug|x86
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Debug|x86.Deploy.0 = Debug|x86
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Release|ARM64.ActiveCfg = Release|ARM64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Release|ARM64.Build.0 = Release|ARM64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Release|ARM64.Deploy.0 = Release|ARM64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Release|x64.ActiveCfg = Release|x64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Release|x64.Build.0 = Release|x64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Release|x64.Deploy.0 = Release|x64
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Release|x86.ActiveCfg = Release|x86
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Release|x86.Build.0 = Release|x86
+ {56E04579-CF91-49DF-9903-ABD937B364E5}.Release|x86.Deploy.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {6741F5A0-0251-4B86-B183-C3C278933F7C}
+ EndGlobalSection
+EndGlobal
diff --git a/Samples/NetworkConnectivity/cs/Package.appxmanifest b/Samples/NetworkConnectivity/cs/Package.appxmanifest
new file mode 100644
index 0000000000..a358e11444
--- /dev/null
+++ b/Samples/NetworkConnectivity/cs/Package.appxmanifest
@@ -0,0 +1,30 @@
+
+
+
+
+
+ NetworkConnectivity C# Sample
+ Microsoft Corporation
+ Assets\StoreLogo-sdk.png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Samples/NetworkConnectivity/cs/SampleConfiguration.cs b/Samples/NetworkConnectivity/cs/SampleConfiguration.cs
new file mode 100644
index 0000000000..710a001934
--- /dev/null
+++ b/Samples/NetworkConnectivity/cs/SampleConfiguration.cs
@@ -0,0 +1,35 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+using System;
+using System.Collections.Generic;
+using Windows.UI.Xaml.Controls;
+
+namespace SDKTemplate
+{
+ public partial class MainPage : Page
+ {
+ public const string FEATURE_NAME = "NetworkingConnectivity";
+
+ List scenarios = new List
+ {
+ new Scenario() { Title = "Query network connectivity", ClassType = typeof(Scenario1_NetworkConnectivity) },
+ new Scenario() { Title = "Get network cost information", ClassType = typeof(Scenario2_NetworkCost) },
+ new Scenario() { Title = "Listen to connectivity changes", ClassType = typeof(Scenario3_NetworkConnectivityChanges) },
+ };
+ }
+
+ public class Scenario
+ {
+ public string Title { get; set; }
+ public Type ClassType { get; set; }
+ }
+}
diff --git a/Samples/NetworkConnectivity/cs/Scenario1_NetworkConnectivity.xaml.cs b/Samples/NetworkConnectivity/cs/Scenario1_NetworkConnectivity.xaml.cs
new file mode 100644
index 0000000000..b5850cc54b
--- /dev/null
+++ b/Samples/NetworkConnectivity/cs/Scenario1_NetworkConnectivity.xaml.cs
@@ -0,0 +1,54 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+using Windows.Networking.Connectivity;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+
+namespace SDKTemplate
+{
+ public sealed partial class Scenario1_NetworkConnectivity : Page
+ {
+ public Scenario1_NetworkConnectivity()
+ {
+ this.InitializeComponent();
+ }
+
+ private async void QueryCurrentNetworkConnectivityButton_Click(object sender, RoutedEventArgs e)
+ {
+ ResultsText.Text = string.Empty;
+
+ ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
+ NetworkConnectivityLevel connectivityLevel = NetworkConnectivityLevel.None;
+ if (profile != null)
+ {
+ // It can take the system a few moments to detect a change in network connectivity,
+ // so it's possible that the value returned is slightly out of date.
+ // Scenario3_NetworkConnectivityChanges shows how to be notified when the system
+ // detects connectivity changes.
+ connectivityLevel = profile.GetNetworkConnectivityLevel();
+ }
+
+ Helpers.AppendLine(ResultsText, $"Current connectivity is {connectivityLevel}.");
+
+ if (Helpers.ShouldAttemptToConnectToInternet(connectivityLevel))
+ {
+ await Helpers.EvaluateCostAndConnectAsync(profile.GetConnectionCost(), OptedInToNetworkUsageToggle.IsOn, ResultsText);
+ }
+ else
+ {
+ Helpers.AppendLine(ResultsText, "Not attempting to connect to the Internet.");
+ }
+ }
+ }
+}
+
+
diff --git a/Samples/NetworkConnectivity/cs/Scenario2_NetworkCost.xaml.cs b/Samples/NetworkConnectivity/cs/Scenario2_NetworkCost.xaml.cs
new file mode 100644
index 0000000000..06cf9d945e
--- /dev/null
+++ b/Samples/NetworkConnectivity/cs/Scenario2_NetworkCost.xaml.cs
@@ -0,0 +1,43 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+using Windows.Networking.Connectivity;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+
+namespace SDKTemplate
+{
+ public sealed partial class Scenario2_NetworkCost : Page
+ {
+ public Scenario2_NetworkCost()
+ {
+ this.InitializeComponent();
+ }
+
+ private void GetNetworkCost_Click(object sender, RoutedEventArgs e)
+ {
+ ResultsText.Text = string.Empty;
+
+ ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
+ if (profile != null)
+ {
+ ConnectionCost connectionCost = profile.GetConnectionCost();
+ Helpers.AppendLine(ResultsText, $"Network cost is {connectionCost.NetworkCostType}.");
+
+ Helpers.EvaluateAndReportConnectionCost(connectionCost, ResultsText);
+ }
+ else
+ {
+ Helpers.AppendLine(ResultsText, "No internet connection profile.");
+ }
+ }
+ }
+}
diff --git a/Samples/NetworkConnectivity/cs/Scenario3_NetworkConnectivityChanges.xaml.cs b/Samples/NetworkConnectivity/cs/Scenario3_NetworkConnectivityChanges.xaml.cs
new file mode 100644
index 0000000000..8f896732ee
--- /dev/null
+++ b/Samples/NetworkConnectivity/cs/Scenario3_NetworkConnectivityChanges.xaml.cs
@@ -0,0 +1,126 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+using System;
+using Windows.Networking.Connectivity;
+using Windows.UI.Core;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Navigation;
+
+namespace SDKTemplate
+{
+ public sealed partial class Scenario3_NetworkConnectivityChanges : Page
+ {
+ private bool m_isNetworkStatusChangeCallbackRegistered = false;
+ private bool m_isUpdatingNetworkStatus = false;
+ private bool m_isNetworkStatusUpdatePending = false;
+
+ public Scenario3_NetworkConnectivityChanges()
+ {
+ this.InitializeComponent();
+ }
+
+ protected override void OnNavigatedTo(NavigationEventArgs e)
+ {
+ UpdateButtonStates();
+ }
+
+ protected override void OnNavigatedFrom(NavigationEventArgs e)
+ {
+ if (m_isNetworkStatusChangeCallbackRegistered)
+ {
+ UnregisterNetworkStatusChanged();
+ }
+ }
+
+ async void UpdateNetworkStatus()
+ {
+ // This code runs on the UI thread, so there are no race conditions on these
+ // member variables.
+ if (m_isUpdatingNetworkStatus)
+ {
+ // Update is already in progress. Let it finish before we re-evaluate.
+ m_isNetworkStatusUpdatePending = true;
+ return;
+ }
+
+ m_isUpdatingNetworkStatus = true;
+
+ do
+ {
+ m_isNetworkStatusUpdatePending = false;
+ ResultsText.Text = string.Empty;
+ ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
+ NetworkConnectivityLevel connectivityLevel = NetworkConnectivityLevel.None;
+ if (internetConnectionProfile != null)
+ {
+ connectivityLevel = internetConnectionProfile.GetNetworkConnectivityLevel();
+ }
+
+ Helpers.AppendLine(ResultsText, $"Current connectivity is {connectivityLevel}.");
+ if (Helpers.ShouldAttemptToConnectToInternet(connectivityLevel))
+ {
+ Helpers.AppendLine(ResultsText, "Checking network cost before connecting to the Internet.");
+ await Helpers.EvaluateCostAndConnectAsync(internetConnectionProfile.GetConnectionCost(), OptedInToNetworkUsageToggle.IsOn, ResultsText);
+ }
+ else
+ {
+ Helpers.AppendLine(ResultsText, "Not attempting to connect to the Internet.");
+ }
+ }
+ while (m_isNetworkStatusUpdatePending);
+ m_isUpdatingNetworkStatus = false;
+ }
+
+ async private void OnNetworkStatusChanged(object sender)
+ {
+ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
+ {
+ UpdateNetworkStatus();
+ });
+ }
+
+ private void RegisterNetworkStatusChanged()
+ {
+ NetworkInformation.NetworkStatusChanged += OnNetworkStatusChanged;
+ m_isNetworkStatusChangeCallbackRegistered = true;
+ UpdateNetworkStatus();
+ }
+
+ private void UnregisterNetworkStatusChanged()
+ {
+ NetworkInformation.NetworkStatusChanged -= OnNetworkStatusChanged;
+ m_isNetworkStatusChangeCallbackRegistered = false;
+ }
+
+ private void RegisterUnregisterButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (m_isNetworkStatusChangeCallbackRegistered)
+ {
+ UnregisterNetworkStatusChanged();
+ }
+ else
+ {
+ RegisterNetworkStatusChanged();
+ }
+ UpdateButtonStates();
+ }
+
+ ///
+ /// Update the UI based on whether we are registered for the event.
+ ///
+ private void UpdateButtonStates()
+ {
+ VisualStateManager.GoToState(this, m_isNetworkStatusChangeCallbackRegistered ? "Registered" : "Unregistered", false);
+ }
+ }
+}
diff --git a/Samples/NetworkConnectivity/shared/Scenario1_NetworkConnectivity.xaml b/Samples/NetworkConnectivity/shared/Scenario1_NetworkConnectivity.xaml
new file mode 100644
index 0000000000..d9560d5644
--- /dev/null
+++ b/Samples/NetworkConnectivity/shared/Scenario1_NetworkConnectivity.xaml
@@ -0,0 +1,33 @@
+
+
+
+
+
+ This scenario shows how to query network connectivity, with or without opt-in network usage charges.
+
+
+ Use the network even if it may incur charges
+
+
+
+
+
+
+
diff --git a/Samples/NetworkConnectivity/shared/Scenario2_NetworkCost.xaml b/Samples/NetworkConnectivity/shared/Scenario2_NetworkCost.xaml
new file mode 100644
index 0000000000..7a45ec66fb
--- /dev/null
+++ b/Samples/NetworkConnectivity/shared/Scenario2_NetworkCost.xaml
@@ -0,0 +1,29 @@
+
+
+
+
+
+ This scenario shows how to get network cost and how apps should respond to different cost types.
+
+
+
+
+
+
diff --git a/Samples/NetworkConnectivity/shared/Scenario3_NetworkConnectivityChanges.xaml b/Samples/NetworkConnectivity/shared/Scenario3_NetworkConnectivityChanges.xaml
new file mode 100644
index 0000000000..49b0f86b1f
--- /dev/null
+++ b/Samples/NetworkConnectivity/shared/Scenario3_NetworkConnectivityChanges.xaml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+ This scenario registers for the NetworkStatusChanged event
+ to track changes in network status and network cost, with or without opt-in network usage charges.
+
+
+ Use the network even if it may incur charges
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/archived/BarcodeScanner/README.md b/archived/BarcodeScanner/README.md
index 51173139ee..254eea3540 100644
--- a/archived/BarcodeScanner/README.md
+++ b/archived/BarcodeScanner/README.md
@@ -1,7 +1,9 @@
---
topic: sample
languages:
+- cppcx
- js
+- vb
products:
- windows
- windows-uwp
diff --git a/Samples/BarcodeScanner/cpp/BarcodeScanner.sln b/archived/BarcodeScanner/cpp/BarcodeScanner.sln
similarity index 100%
rename from Samples/BarcodeScanner/cpp/BarcodeScanner.sln
rename to archived/BarcodeScanner/cpp/BarcodeScanner.sln
diff --git a/Samples/BarcodeScanner/cpp/BarcodeScanner.vcxproj b/archived/BarcodeScanner/cpp/BarcodeScanner.vcxproj
similarity index 100%
rename from Samples/BarcodeScanner/cpp/BarcodeScanner.vcxproj
rename to archived/BarcodeScanner/cpp/BarcodeScanner.vcxproj
diff --git a/Samples/BarcodeScanner/cpp/BarcodeScanner.vcxproj.filters b/archived/BarcodeScanner/cpp/BarcodeScanner.vcxproj.filters
similarity index 100%
rename from Samples/BarcodeScanner/cpp/BarcodeScanner.vcxproj.filters
rename to archived/BarcodeScanner/cpp/BarcodeScanner.vcxproj.filters
diff --git a/Samples/BarcodeScanner/cpp/DataHelpers.h b/archived/BarcodeScanner/cpp/DataHelpers.h
similarity index 100%
rename from Samples/BarcodeScanner/cpp/DataHelpers.h
rename to archived/BarcodeScanner/cpp/DataHelpers.h
diff --git a/Samples/BarcodeScanner/cpp/Package.appxmanifest b/archived/BarcodeScanner/cpp/Package.appxmanifest
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Package.appxmanifest
rename to archived/BarcodeScanner/cpp/Package.appxmanifest
diff --git a/Samples/BarcodeScanner/cpp/SampleConfiguration.cpp b/archived/BarcodeScanner/cpp/SampleConfiguration.cpp
similarity index 100%
rename from Samples/BarcodeScanner/cpp/SampleConfiguration.cpp
rename to archived/BarcodeScanner/cpp/SampleConfiguration.cpp
diff --git a/Samples/BarcodeScanner/cpp/SampleConfiguration.h b/archived/BarcodeScanner/cpp/SampleConfiguration.h
similarity index 100%
rename from Samples/BarcodeScanner/cpp/SampleConfiguration.h
rename to archived/BarcodeScanner/cpp/SampleConfiguration.h
diff --git a/Samples/BarcodeScanner/cpp/Scenario1_BasicFunctionality.xaml.cpp b/archived/BarcodeScanner/cpp/Scenario1_BasicFunctionality.xaml.cpp
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario1_BasicFunctionality.xaml.cpp
rename to archived/BarcodeScanner/cpp/Scenario1_BasicFunctionality.xaml.cpp
diff --git a/Samples/BarcodeScanner/cpp/Scenario1_BasicFunctionality.xaml.h b/archived/BarcodeScanner/cpp/Scenario1_BasicFunctionality.xaml.h
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario1_BasicFunctionality.xaml.h
rename to archived/BarcodeScanner/cpp/Scenario1_BasicFunctionality.xaml.h
diff --git a/Samples/BarcodeScanner/cpp/Scenario2_MultipleScanners.xaml.cpp b/archived/BarcodeScanner/cpp/Scenario2_MultipleScanners.xaml.cpp
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario2_MultipleScanners.xaml.cpp
rename to archived/BarcodeScanner/cpp/Scenario2_MultipleScanners.xaml.cpp
diff --git a/Samples/BarcodeScanner/cpp/Scenario2_MultipleScanners.xaml.h b/archived/BarcodeScanner/cpp/Scenario2_MultipleScanners.xaml.h
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario2_MultipleScanners.xaml.h
rename to archived/BarcodeScanner/cpp/Scenario2_MultipleScanners.xaml.h
diff --git a/Samples/BarcodeScanner/cpp/Scenario3_ActiveSymbologies.xaml.cpp b/archived/BarcodeScanner/cpp/Scenario3_ActiveSymbologies.xaml.cpp
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario3_ActiveSymbologies.xaml.cpp
rename to archived/BarcodeScanner/cpp/Scenario3_ActiveSymbologies.xaml.cpp
diff --git a/Samples/BarcodeScanner/cpp/Scenario3_ActiveSymbologies.xaml.h b/archived/BarcodeScanner/cpp/Scenario3_ActiveSymbologies.xaml.h
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario3_ActiveSymbologies.xaml.h
rename to archived/BarcodeScanner/cpp/Scenario3_ActiveSymbologies.xaml.h
diff --git a/Samples/BarcodeScanner/cpp/Scenario4_SymbologyAttributes.xaml.cpp b/archived/BarcodeScanner/cpp/Scenario4_SymbologyAttributes.xaml.cpp
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario4_SymbologyAttributes.xaml.cpp
rename to archived/BarcodeScanner/cpp/Scenario4_SymbologyAttributes.xaml.cpp
diff --git a/Samples/BarcodeScanner/cpp/Scenario4_SymbologyAttributes.xaml.h b/archived/BarcodeScanner/cpp/Scenario4_SymbologyAttributes.xaml.h
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario4_SymbologyAttributes.xaml.h
rename to archived/BarcodeScanner/cpp/Scenario4_SymbologyAttributes.xaml.h
diff --git a/Samples/BarcodeScanner/cpp/Scenario5_DisplayingBarcodePreview.xaml.cpp b/archived/BarcodeScanner/cpp/Scenario5_DisplayingBarcodePreview.xaml.cpp
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario5_DisplayingBarcodePreview.xaml.cpp
rename to archived/BarcodeScanner/cpp/Scenario5_DisplayingBarcodePreview.xaml.cpp
diff --git a/Samples/BarcodeScanner/cpp/Scenario5_DisplayingBarcodePreview.xaml.h b/archived/BarcodeScanner/cpp/Scenario5_DisplayingBarcodePreview.xaml.h
similarity index 100%
rename from Samples/BarcodeScanner/cpp/Scenario5_DisplayingBarcodePreview.xaml.h
rename to archived/BarcodeScanner/cpp/Scenario5_DisplayingBarcodePreview.xaml.h
diff --git a/Samples/BarcodeScanner/cpp/pch.cpp b/archived/BarcodeScanner/cpp/pch.cpp
similarity index 100%
rename from Samples/BarcodeScanner/cpp/pch.cpp
rename to archived/BarcodeScanner/cpp/pch.cpp
diff --git a/Samples/BarcodeScanner/cpp/pch.h b/archived/BarcodeScanner/cpp/pch.h
similarity index 100%
rename from Samples/BarcodeScanner/cpp/pch.h
rename to archived/BarcodeScanner/cpp/pch.h
diff --git a/archived/BarcodeScanner/shared/Scenario1_BasicFunctionality.xaml b/archived/BarcodeScanner/shared/Scenario1_BasicFunctionality.xaml
new file mode 100644
index 0000000000..1535a29cbf
--- /dev/null
+++ b/archived/BarcodeScanner/shared/Scenario1_BasicFunctionality.xaml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Registers an event listener for barcode scanner data and displays the data values as they are reported.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/archived/BarcodeScanner/shared/Scenario2_MultipleScanners.xaml b/archived/BarcodeScanner/shared/Scenario2_MultipleScanners.xaml
new file mode 100644
index 0000000000..a29441764e
--- /dev/null
+++ b/archived/BarcodeScanner/shared/Scenario2_MultipleScanners.xaml
@@ -0,0 +1,125 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Creates two instances for the claimed device to illustrate the use of device Retain/Release functionality.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/archived/BarcodeScanner/shared/Scenario3_ActiveSymbologies.xaml b/archived/BarcodeScanner/shared/Scenario3_ActiveSymbologies.xaml
new file mode 100644
index 0000000000..eda606a3ea
--- /dev/null
+++ b/archived/BarcodeScanner/shared/Scenario3_ActiveSymbologies.xaml
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Lists supported symbologies for the device to illustrate the use of setting active symbologiges functionality. Check or uncheck symbologies and tap "Set Active Symbologies" button to set active symbologies.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/archived/BarcodeScanner/shared/Scenario4_SymbologyAttributes.xaml b/archived/BarcodeScanner/shared/Scenario4_SymbologyAttributes.xaml
new file mode 100644
index 0000000000..be10b1469a
--- /dev/null
+++ b/archived/BarcodeScanner/shared/Scenario4_SymbologyAttributes.xaml
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Lists supported symbologies and attributes for the device to illustrate the use of symbology attribute functionality.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enable check digit
+ Transmit check digit
+ Set decode range limits
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/archived/BarcodeScanner/shared/Scenario5_DisplayingBarcodePreview.xaml b/archived/BarcodeScanner/shared/Scenario5_DisplayingBarcodePreview.xaml
new file mode 100644
index 0000000000..39f17ed147
--- /dev/null
+++ b/archived/BarcodeScanner/shared/Scenario5_DisplayingBarcodePreview.xaml
@@ -0,0 +1,92 @@
+
+
+
+
+
+
+
+
+
+
+
+ Demonstrates how to interact with barcode scanners that support video previewing.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Samples/BarcodeScanner/vb/BarcodeScanner.sln b/archived/BarcodeScanner/vb/BarcodeScanner.sln
similarity index 100%
rename from Samples/BarcodeScanner/vb/BarcodeScanner.sln
rename to archived/BarcodeScanner/vb/BarcodeScanner.sln
diff --git a/Samples/BarcodeScanner/vb/BarcodeScanner.vbproj b/archived/BarcodeScanner/vb/BarcodeScanner.vbproj
similarity index 100%
rename from Samples/BarcodeScanner/vb/BarcodeScanner.vbproj
rename to archived/BarcodeScanner/vb/BarcodeScanner.vbproj
diff --git a/Samples/BarcodeScanner/vb/Package.appxmanifest b/archived/BarcodeScanner/vb/Package.appxmanifest
similarity index 100%
rename from Samples/BarcodeScanner/vb/Package.appxmanifest
rename to archived/BarcodeScanner/vb/Package.appxmanifest
diff --git a/Samples/BarcodeScanner/vb/SampleConfiguration.vb b/archived/BarcodeScanner/vb/SampleConfiguration.vb
similarity index 100%
rename from Samples/BarcodeScanner/vb/SampleConfiguration.vb
rename to archived/BarcodeScanner/vb/SampleConfiguration.vb
diff --git a/Samples/BarcodeScanner/vb/Scenario1_BasicFunctionality.xaml.vb b/archived/BarcodeScanner/vb/Scenario1_BasicFunctionality.xaml.vb
similarity index 100%
rename from Samples/BarcodeScanner/vb/Scenario1_BasicFunctionality.xaml.vb
rename to archived/BarcodeScanner/vb/Scenario1_BasicFunctionality.xaml.vb
diff --git a/Samples/BarcodeScanner/vb/Scenario2_MultipleScanners.xaml.vb b/archived/BarcodeScanner/vb/Scenario2_MultipleScanners.xaml.vb
similarity index 100%
rename from Samples/BarcodeScanner/vb/Scenario2_MultipleScanners.xaml.vb
rename to archived/BarcodeScanner/vb/Scenario2_MultipleScanners.xaml.vb