Skip to content

Commit 0165474

Browse files
committed
Complete final transport review fixes
Apply the code, build, test, and reference updates that accompany the .NET sample move. This prevents filter publication races, removes irrelevant Curl linkage on native platforms, and preserves SQLite cleanup without explicit shutdown. Files changed: - Event filter collection - CMake sample dependency fallback - SQLite storage and unit coverage - .NET sample metadata, solution, build script, and Windows guide Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c4cfcad8-1637-4e46-86cf-6bf200244b04
1 parent 63d3618 commit 0165474

10 files changed

Lines changed: 33 additions & 24 deletions

File tree

‎Solutions/MSTelemetrySDK.sln‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SampleCpp", "..\examples\cp
8787
EndProject
8888
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SampleCppUWP", "..\examples\cpp\SampleCppUWP\SampleCppUWP.vcxproj", "{39DBD601-4D79-49F9-AD18-065404DBA273}"
8989
EndProject
90-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCsNet40", "..\examples\cs\SampleCsNet40\SampleCsNet40.csproj", "{65AFA0E2-F9A2-4309-87E7-E419D59583C1}"
90+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCsNet48", "..\examples\cs\SampleCsNet48\SampleCsNet48.csproj", "{65AFA0E2-F9A2-4309-87E7-E419D59583C1}"
9191
EndProject
9292
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCsUWP", "..\examples\cs\SampleCsUWP\SampleCsUWP.csproj", "{F797B22C-A1C4-4136-9DCC-0682A183A4DA}"
9393
EndProject

‎build-all-windows.bat‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exit /b 1
3434
call tools\gen-version.cmd
3535

3636
set NET40_MD_TARGETS=,net40:Rebuild
37-
set NET40_SAMPLE_TARGETS=,Samples\cs\SampleCsNet40:Rebuild
37+
set NET40_SAMPLE_TARGETS=,Samples\cs\SampleCsNet48:Rebuild
3838
if DEFINED SKIP_NET40_BUILD (
3939
echo Skipping legacy .NET Framework 4.0 targets.
4040
set NET40_MD_TARGETS=

‎docs/cpp-start-windows.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If your project requires the Universal Telemetry Client (a.k.a. UTC) to send tel
2929

3030
The version-specific scripts set `VSTOOLS_VERSION` and `PlatformToolset` before calling `build-all-windows.bat`, which builds the Windows Visual Studio solution matrix. `build-all.bat` remains as a compatibility wrapper for existing automation; if you call either script directly, set both values yourself so `tools\vcvars.cmd` selects the same Visual Studio installation as your requested toolset.
3131

32-
Visual Studio 2022 and newer may report the legacy .NET Framework 4.0 projects (`net40` and `SampleCsNet40`) as unsupported. They are only needed for the legacy .NET Framework wrapper; the VS2022 and VS2026 command-line wrappers skip those projects, and you can unload them in the IDE when building the native SDK.
32+
Visual Studio 2022 and newer may report the legacy .NET Framework 4.0 wrapper project (`net40`) as unsupported. It is only needed by .NET Framework consumers such as `SampleCsNet48`; the VS2022 and VS2026 command-line wrappers skip those projects, and you can unload them in the IDE when building the native SDK.
3333

3434
If your build fails, then you most likely missing the following optional Visual Studio components:
3535

‎examples/cmake/MSTelemetrySample.cmake‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ else()
2424
if(NOT MATSDK_LIBRARY)
2525
message(FATAL_ERROR "Could not find libmat under ${MATSDK_LIB_DIR}. Set MATSDK_INSTALL_DIR or MATSDK_LIB_DIR.")
2626
endif()
27-
find_package(CURL REQUIRED)
2827
find_package(ZLIB REQUIRED)
29-
set(MATSDK_SAMPLE_DEPENDENCY_LIBS CURL::libcurl ZLIB::ZLIB)
28+
set(MATSDK_SAMPLE_DEPENDENCY_LIBS ZLIB::ZLIB)
29+
if(NOT WIN32 AND NOT APPLE
30+
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
31+
find_package(CURL REQUIRED)
32+
list(APPEND MATSDK_SAMPLE_DEPENDENCY_LIBS CURL::libcurl)
33+
endif()
3034
endif()
3135

3236
if(NOT EXISTS "${MATSDK_INCLUDE_DIR}")

‎examples/cs/SampleCsNet48/Properties/AssemblyInfo.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// General Information about an assembly is controlled through the following
66
// set of attributes. Change these attribute values to modify the information
77
// associated with an assembly.
8-
[assembly: AssemblyTitle("SampleCsNet40")]
8+
[assembly: AssemblyTitle("SampleCsNet48")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("Microsoft Corporation")]
12-
[assembly: AssemblyProduct("SampleCsNet40 Testapp")]
12+
[assembly: AssemblyProduct("SampleCsNet48 Testapp")]
1313
[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]

‎examples/cs/SampleCsNet48/SampleCsNet48.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<OutputType>Exe</OutputType>
1111
<AppDesignerFolder>Properties</AppDesignerFolder>
1212
<RootNamespace>CLI</RootNamespace>
13-
<AssemblyName>SampleCsNet40</AssemblyName>
13+
<AssemblyName>SampleCsNet48</AssemblyName>
1414
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
1515
<FileAlignment>512</FileAlignment>
1616
<TargetFrameworkProfile />

‎lib/filter/EventFilterCollection.cpp‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace MAT_NS_BEGIN
2828
std::atomic_store(
2929
&m_filters,
3030
std::shared_ptr<const FilterList>(std::move(updated)));
31-
m_size.store(current == nullptr ? 1 : current->size() + 1);
3231
}
3332
}
3433

@@ -60,7 +59,6 @@ namespace MAT_NS_BEGIN
6059
}
6160

6261
removedFilters = std::move(current);
63-
m_size.store(updated->size());
6462
std::atomic_store(
6563
&m_filters,
6664
updated->empty()
@@ -76,17 +74,11 @@ namespace MAT_NS_BEGIN
7674
std::lock_guard<std::mutex> lock(m_filterLock);
7775
removedFilters = std::atomic_exchange(
7876
&m_filters, std::shared_ptr<const FilterList>{});
79-
m_size.store(0);
8077
}
8178
}
8279

8380
bool EventFilterCollection::CanEventPropertiesBeSent(const EventProperties& properties) const noexcept
8481
{
85-
if (Empty())
86-
{
87-
return true;
88-
}
89-
9082
auto filters = std::atomic_load(&m_filters);
9183
return filters == nullptr || std::all_of(filters->cbegin(), filters->cend(),
9284
[&properties](const std::shared_ptr<IEventFilter>& filter)
@@ -97,12 +89,13 @@ namespace MAT_NS_BEGIN
9789

9890
size_t EventFilterCollection::Size() const noexcept
9991
{
100-
return m_size.load();
92+
auto filters = std::atomic_load(&m_filters);
93+
return filters == nullptr ? 0 : filters->size();
10194
}
10295

10396
bool EventFilterCollection::Empty() const noexcept
10497
{
105-
return (Size() == 0);
98+
return std::atomic_load(&m_filters) == nullptr;
10699
}
107100

108101
} MAT_NS_END

‎lib/filter/EventFilterCollection.hpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <memory>
1212
#include <mutex>
1313
#include <vector>
14-
#include <atomic>
1514

1615
namespace MAT_NS_BEGIN
1716
{
@@ -28,7 +27,6 @@ namespace MAT_NS_BEGIN
2827
protected:
2928
using FilterList = std::vector<std::shared_ptr<IEventFilter>>;
3029

31-
std::atomic<size_t> m_size { 0 };
3230
mutable std::mutex m_filterLock;
3331
std::shared_ptr<const FilterList> m_filters;
3432
};

‎lib/offline/OfflineStorage_SQLite.cpp‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ namespace MAT_NS_BEGIN {
142142
}
143143
}
144144

145-
OfflineStorage_SQLite::~OfflineStorage_SQLite()
146-
{
147-
assert(!m_db);
148-
}
145+
OfflineStorage_SQLite::~OfflineStorage_SQLite() = default;
149146

150147
void OfflineStorage_SQLite::Initialize(IOfflineStorageObserver& observer)
151148
{

‎tests/unittests/OfflineStorageTests_SQLite.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,23 @@ TEST_F(OfflineStorageTests_SQLite, SqliteDbInstancesAreCounted)
11521152
EXPECT_EQ(offlineStorage->GetDbInstanceCount(), 0);
11531153
}
11541154

1155+
TEST_F(OfflineStorageTests_SQLite, DestructionWithoutShutdownClosesDatabase)
1156+
{
1157+
initializeStorage();
1158+
EXPECT_EQ(OfflineStorage_SQLiteNoAutoCommit::GetDbInstanceCount(), 1);
1159+
1160+
storageInitialized = false;
1161+
offlineStorage.reset();
1162+
1163+
EXPECT_EQ(OfflineStorage_SQLiteNoAutoCommit::GetDbInstanceCount(), 0);
1164+
EXPECT_THAT(fileExists(storageFilename), true);
1165+
::remove(storageFilename.c_str());
1166+
for (const char* suffix : { "-wal", "-shm", "-journal" })
1167+
{
1168+
::remove((storageFilename + suffix).c_str());
1169+
}
1170+
}
1171+
11551172
#if !defined(_WIN32)
11561173
// SECURITY: the offline cache buffers pending telemetry/audit events, so it must
11571174
// not be world-readable. SQLite creates the file 0644 by default; SQLiteWrapper

0 commit comments

Comments
 (0)