Skip to content

Commit 61b4d32

Browse files
committed
Windows 11 future version - September 2024 Samples Update
* PowerGrid: Fix divide by zero error * WebSocket: Use a script to generate the certificates and private keys * LampArray: New LampArray.IsAvailable property
2 parents bad4b17 + 0db108e commit 61b4d32

21 files changed

Lines changed: 243 additions & 23 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,6 @@ FakesAssemblies/
203203

204204
# Custom ignores
205205
gallery.xml
206-
project.lock.json
206+
project.lock.json
207+
Samples/WebSocket/server/WebSocketSampleScriptSettings
208+
Samples/StreamSocket/**/StreamSocketSampleScriptSettings.xml

Samples/LampArray/cppwinrt/SampleConfiguration.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using namespace winrt::SDKTemplate;
1818
using namespace winrt::Windows::Devices::Lights;
1919
using namespace winrt::Windows::Foundation::Collections;
2020

21-
hstring winrt::to_hstring(LampArrayKind lampArrayKind)
21+
std::wstring std::to_wstring(LampArrayKind lampArrayKind)
2222
{
2323
switch (lampArrayKind)
2424
{
@@ -44,7 +44,8 @@ hstring winrt::to_hstring(LampArrayKind lampArrayKind)
4444
return L"Art";
4545
case LampArrayKind::Undefined:
4646
default:
47-
return L"Unknown LampArrayKind";
47+
// Additional lamp array kinds can be looked up in the USB HID specification.
48+
return std::to_wstring(static_cast<uint32_t>(lampArrayKind));
4849
}
4950
}
5051

Samples/LampArray/cppwinrt/SampleConfiguration.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#pragma once
1313
#include "pch.h"
1414

15-
namespace winrt
15+
namespace std
1616
{
17-
hstring to_hstring(winrt::Windows::Devices::Lights::LampArrayKind lampArrayKind);
17+
std::wstring to_wstring(winrt::Windows::Devices::Lights::LampArrayKind lampArrayKind);
1818
}
1919

2020
namespace winrt::SDKTemplate
@@ -29,5 +29,7 @@ namespace winrt::SDKTemplate
2929
winrt::hstring const id;
3030
winrt::hstring const displayName;
3131
winrt::Windows::Devices::Lights::LampArray const lampArray;
32+
33+
winrt::Windows::Devices::Lights::LampArray::AvailabilityChanged_revoker availabilityChangedRevoker;
3234
};
3335
}

Samples/LampArray/cppwinrt/Scenario1_Basics.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ namespace winrt::SDKTemplate::implementation
7070
co_return;
7171
}
7272

73+
// Set up the AvailabilityChanged event callback for being notified whether this process can control
74+
// RGB lighting for the newly attached LampArray.
75+
info->availabilityChangedRevoker = info->lampArray.AvailabilityChanged(winrt::auto_revoke, { this, &Scenario1_Basics::LampArray_AvailabilityChanged });
76+
7377
// Remember this new LampArray and add it to the list.
7478
m_attachedLampArrays.push_back(std::move(info));
7579
UpdateLampArrayList();
@@ -91,14 +95,24 @@ namespace winrt::SDKTemplate::implementation
9195
UpdateLampArrayList();
9296
}
9397

98+
// The AvailabilityChanged event will fire when this calling process gains or loses control of RGB lighting
99+
// for the specified LampArray.
100+
winrt::fire_and_forget Scenario1_Basics::LampArray_AvailabilityChanged(const LampArray& sender, const IInspectable&)
101+
{
102+
co_await winrt::resume_foreground(Dispatcher());
103+
104+
UpdateLampArrayList();
105+
}
106+
94107
void Scenario1_Basics::UpdateLampArrayList()
95108
{
96109
std::wstring message = std::wstring(L"Attached LampArrays: ") + std::to_wstring(m_attachedLampArrays.size()) + L"\n";
97110

98111
for (auto&& info : m_attachedLampArrays)
99112
{
100113
message += std::wstring(L"\t") + std::wstring(info->displayName) + L" ("
101-
+ winrt::to_hstring(info->lampArray.LampArrayKind()) + L", " + std::to_wstring(info->lampArray.LampCount()) + L" lamps)\n";
114+
+ std::to_wstring(info->lampArray.LampArrayKind()) + L", " + std::to_wstring(info->lampArray.LampCount()) + L" lamps, "
115+
+ std::wstring(info->lampArray.IsAvailable() ? L"Available" : L"Unavailable") + L")\n";
102116
}
103117

104118
LampArraysSummary().Text(message);

Samples/LampArray/cppwinrt/Scenario1_Basics.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ namespace winrt::SDKTemplate::implementation
4545
winrt::Windows::Devices::Enumeration::DeviceWatcher const&,
4646
winrt::Windows::Devices::Enumeration::DeviceInformationUpdate deviceInformationUpdate);
4747

48+
winrt::fire_and_forget LampArray_AvailabilityChanged(
49+
winrt::Windows::Devices::Lights::LampArray const& sender,
50+
winrt::Windows::Foundation::IInspectable const&);
51+
4852
void UpdateLampArrayList();
4953

5054
void ApplySettingsToLampArray(winrt::Windows::Devices::Lights::LampArray const& lampArray);

Samples/LampArray/cppwinrt/Scenario2_Effects.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ namespace winrt::SDKTemplate::implementation
9191
// Initial condition for the new LampArray is all lights off.
9292
info->lampArray.SetColor(Colors::Black());
9393

94+
// Set up the AvailabilityChanged event callback for being notified whether this process can control
95+
// RGB lighting for the newly attached LampArray.
96+
info->availabilityChangedRevoker = info->lampArray.AvailabilityChanged(winrt::auto_revoke, { this, &Scenario2_Effects::LampArray_AvailabilityChanged });
97+
9498
m_attachedLampArrays.push_back(std::move(info));
9599

96100
UpdateLampArrayList();
@@ -112,14 +116,24 @@ namespace winrt::SDKTemplate::implementation
112116
UpdateLampArrayList();
113117
}
114118

119+
// The AvailabilityChanged event will fire when this calling process gains or loses control of RGB lighting
120+
// for the specified LampArray.
121+
winrt::fire_and_forget Scenario2_Effects::LampArray_AvailabilityChanged(const LampArray& sender, const IInspectable&)
122+
{
123+
co_await winrt::resume_foreground(Dispatcher());
124+
125+
UpdateLampArrayList();
126+
}
127+
115128
void Scenario2_Effects::UpdateLampArrayList()
116129
{
117130
std::wstring message = std::wstring(L"Attached LampArrays: ") + std::to_wstring(m_attachedLampArrays.size()) + L"\n";
118131

119132
for (auto&& info : m_attachedLampArrays)
120133
{
121134
message += L"\t" + info->displayName + L" ("
122-
+ winrt::to_hstring(info->lampArray.LampArrayKind()) + L", " + std::to_wstring(info->lampArray.LampCount()) + L" lamps)\n";
135+
+ std::to_wstring(info->lampArray.LampArrayKind()) + L", " + std::to_wstring(info->lampArray.LampCount()) + L" lamps, "
136+
+ std::wstring(info->lampArray.IsAvailable() ? L"Available" : L"Unavailable") + L")\n";
123137
}
124138

125139
LampArraysSummary().Text(message);

Samples/LampArray/cppwinrt/Scenario2_Effects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ namespace winrt::SDKTemplate::implementation
125125
winrt::Windows::Devices::Enumeration::DeviceWatcher const&,
126126
winrt::Windows::Devices::Enumeration::DeviceInformationUpdate deviceInformationUpdate);
127127

128+
winrt::fire_and_forget LampArray_AvailabilityChanged(
129+
winrt::Windows::Devices::Lights::LampArray const& sender,
130+
winrt::Windows::Foundation::IInspectable const&);
131+
128132
void UpdateLampArrayList();
129133
void CleanupPreviousEffect();
130134

Samples/LampArray/cs/Scenario1_Basics.xaml.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
7272
return;
7373
}
7474

75+
// Set up the AvailabilityChanged event callback for being notified whether this process can control
76+
// RGB lighting for the newly attached LampArray.
77+
info.lampArray.AvailabilityChanged += LampArray_AvailabilityChanged;
78+
7579
// Remember this new LampArray and add it to the list.
7680
m_attachedLampArrays.Add(info);
7781
UpdateLampArrayList();
@@ -90,12 +94,23 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
9094
});
9195
}
9296

97+
// The AvailabilityChanged event will fire when this calling process gains or loses control of RGB lighting
98+
// for the specified LampArray.
99+
private async void LampArray_AvailabilityChanged(LampArray sender, object args)
100+
{
101+
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
102+
{
103+
UpdateLampArrayList();
104+
});
105+
}
106+
93107
private void UpdateLampArrayList()
94108
{
95109
string message = $"Attached LampArrays: {m_attachedLampArrays.Count}\n";
96110
foreach (LampArrayInfo info in m_attachedLampArrays)
97111
{
98-
message += $"\t{info.displayName} ({info.lampArray.LampArrayKind}, {info.lampArray.LampCount} lamps)\n";
112+
message += $"\t{info.displayName} ({info.lampArray.LampArrayKind.ToString()}, {info.lampArray.LampCount} lamps, " +
113+
$"{(info.lampArray.IsAvailable ? "Available" : "Unavailable")})\n";
99114
}
100115
LampArraysSummary.Text = message;
101116
}

Samples/LampArray/cs/Scenario2_Effects.xaml.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
125125
// Initial condition for the new LampArray is all lights off.
126126
info.lampArray.SetColor(Colors.Black);
127127

128+
// Set up the AvailabilityChanged event callback for being notified whether this process can control
129+
// RGB lighting for the newly attached LampArray.
130+
info.lampArray.AvailabilityChanged += LampArray_AvailabilityChanged;
131+
128132
m_attachedLampArrays.Add(info);
129133

130134
UpdateLampArrayList();
@@ -143,12 +147,23 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
143147
});
144148
}
145149

150+
// The AvailabilityChanged event will fire when this calling process gains or loses control of RGB lighting
151+
// for the specified LampArray.
152+
private async void LampArray_AvailabilityChanged(LampArray sender, object args)
153+
{
154+
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
155+
{
156+
UpdateLampArrayList();
157+
});
158+
}
159+
146160
private void UpdateLampArrayList()
147161
{
148162
string message = $"Attached LampArrays: {m_attachedLampArrays.Count}\n";
149163
foreach (LampArrayInfo info in m_attachedLampArrays)
150164
{
151-
message += $"\t{info.displayName} ({info.lampArray.LampArrayKind.ToString()}, {info.lampArray.LampCount} lamps)\n";
165+
message += $"\t{info.displayName} ({info.lampArray.LampArrayKind.ToString()}, {info.lampArray.LampCount} lamps, " +
166+
$"{(info.lampArray.IsAvailable ? "Available" : "Unavailable")})\n";
152167
}
153168
LampArraysSummary.Text = message;
154169
}

Samples/PowerGrid/README.md

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,76 @@
1-
# PowerGrid API usage sample
2-
------------------------------
1+
---
2+
page_type: sample
3+
languages:
4+
- csharp
5+
- cpp
6+
- cppwinrt
7+
products:
8+
- windows
9+
- windows-uwp
10+
urlFragment: PowerGrid
11+
extendedZipContent:
12+
- path: SharedContent
13+
target: SharedContent
14+
- path: LICENSE
15+
target: LICENSE
16+
description: "Shows how to use power grid forecasts."
17+
---
18+
19+
# Power grid forecast sample
20+
21+
> **Note:** This sample is part of a large collection of UWP feature samples.
22+
> You can download this sample as a standalone ZIP file
23+
> [from docs.microsoft.com](https://docs.microsoft.com/samples/microsoft/windows-universal-samples/resizeappview/),
24+
> or you can download the entire collection as a single
25+
> [ZIP file](https://github.com/Microsoft/Windows-universal-samples/archive/master.zip), but be
26+
> sure to unzip everything to access shared dependencies. For more info on working with the ZIP file,
27+
> the samples collection, and GitHub, see [Get the UWP samples from GitHub](https://aka.ms/ovu2uq).
28+
> For more samples, see the [Samples portal](https://aka.ms/winsamples) on the Windows Dev Center.
29+
330
Shows how to use the PowerGrid Forecast API.
431

532
This sample covers the following:
6-
- Obtaining the PowerGrid Forecast
33+
- Obtaining the power grid forecast
734
- Registering for ForecastUpdated notifications
835
- Looking for the lowest severity in a specified timeframe
936

10-
## Requirements
11-
- Visual Studio 2022
12-
- Windows 11 SDK
13-
- Windows 11
37+
**Note** The Windows universal samples require Visual Studio to build and Windows 11 to execute.
38+
39+
To obtain information about Windows development, go to the [Windows Dev Center](http://go.microsoft.com/fwlink/?LinkID=532421)
40+
41+
To obtain information about Microsoft Visual Studio and the tools for developing Windows apps, go to [Visual Studio](http://go.microsoft.com/fwlink/?LinkID=532422)
42+
43+
## Related topics
44+
45+
### Reference
46+
47+
[PowerGridForecast class](https://learn.microsoft.com/uwp/api/windows.devices.power.powergridforecast)
48+
49+
### Related samples
50+
51+
[Power grid forecast from a Win32 app](https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/PowerGrid)
52+
53+
## System requirements
54+
55+
- Windows 11 SDK (build 26100 or higher)
56+
- Windows 11 (build 26100 or higher)
1457

1558
## Build the sample
16-
Open the solution in Visual Studio 2022 and build.
59+
60+
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.
61+
2. Start Microsoft Visual Studio and select **File** \> **Open** \> **Project/Solution**.
62+
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.
63+
4. Press Ctrl+Shift+B, or select **Build** \> **Build Solution**.
1764

1865
## Run the sample
19-
Run from within Visual Studio or open Windows Terminal and navigate to the directory with the built executable. From the terminal run `PowerGrid.exe`.
66+
67+
The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.
68+
69+
### Deploying the sample
70+
71+
- Select Build > Deploy Solution.
72+
73+
### Deploying and running the sample
74+
75+
- 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.
76+

0 commit comments

Comments
 (0)