//
// DummyPacketProvider.cs
//
// Copyright (c) František Boháček. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using DynamicData;
using DynamicData.Binding;
using NosSmooth.PacketSerializer.Abstractions.Attributes;
using PacketLogger.Models.Filters;
using ReactiveUI;
using Remora.Results;
namespace PacketLogger.Models.Packets;
///
public class DummyPacketProvider : IPacketProvider, IDisposable
{
private long _index = 0;
///
/// Initializes a new instance of the class.
///
/// The name of the tab.
public DummyPacketProvider(string name)
{
Name = name;
Packets = new SourceList();
}
///
public event PropertyChangedEventHandler? PropertyChanged;
///
public bool LogReceived
{
get => true;
set { }
}
///
public bool LogSent
{
get => true;
set { }
}
///
public string Name { get; }
///
public bool IsOpen => false;
///
public SourceList Packets { get; }
///
public Task Open()
=> Task.FromResult(Result.FromSuccess());
///
public Task Close()
=> Task.FromResult(Result.FromSuccess());
///
public void Clear()
{
Packets.Clear();
}
///
public Task SendPacket(string packetString, CancellationToken ct = default)
{
Packets.Add(new PacketInfo(_index++, DateTime.Now, PacketSource.Client, packetString));
return Task.FromResult(Result.FromSuccess());
}
///
public Task ReceivePacket(string packetString, CancellationToken ct = default)
{
Packets.Add(new PacketInfo(_index++, DateTime.Now, PacketSource.Server, packetString));
return Task.FromResult(Result.FromSuccess());
}
///
public void Dispose()
{
Packets.Dispose();
}
}