/* * Copyright (c) 2025 Proton AG * * This file is part of ProtonVPN. * * ProtonVPN is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProtonVPN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProtonVPN. If not, see . */ using System.Collections.Generic; using System.Threading.Tasks; using ProtonVPN.Api.Contracts; using ProtonVPN.Api.Contracts.Common; using ProtonVPN.Client.Common.Messages; using ProtonVPN.Client.EventMessaging.Contracts; using ProtonVPN.Client.Settings.Contracts; using ProtonVPN.Common.Core.StatisticalEvents; using ProtonVPN.Configurations.Contracts; using ProtonVPN.Logging.Contracts; using ProtonVPN.StatisticalEvents.Contracts.Models; using ProtonVPN.StatisticalEvents.Events.Senders.Contracts; using ProtonVPN.StatisticalEvents.Files; namespace ProtonVPN.StatisticalEvents.Events.Senders; public class UnauthenticatedStatisticalEventSender : StatisticEventSenderBase, IUnauthenticatedStatisticalEventSender, IEventMessageReceiver, IEventMessageReceiver { protected override bool IsShareStatisticsEnabled => true; protected override bool CanSendTelemetryEvents => true; public UnauthenticatedStatisticalEventSender( IApiClient api, ILogger logger, ISettings settings, IConfiguration config, IStatisticalEventsFileReaderWriter statisticalEventsFileReaderWriter) : base(api, logger, settings, config, statisticalEventsFileReaderWriter) { } protected async override Task> SendApiRequestAsync( StatisticalEventsBatch statisticalEventsBatch) { return await Api.PostUnauthenticatedStatisticalEventsAsync(statisticalEventsBatch); } protected override List GetStatisticalEventsFromFile() { return StatisticalEventsFileReaderWriter.ReadUnauthenticatedEvents().StatisticalEvents ?? []; } protected override void SaveToFile(List events) { StatisticalEventsFileReaderWriter.SaveUnauthenticatedEvents(new StatisticalEventsFile() { StatisticalEvents = events }); } public async void Receive(ApplicationStartedMessage message) { await StartAsync(); } public async void Receive(ApplicationStoppedMessage message) { await StopAsync(); } }