using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.Emulations.Emulators;
using Tango.Integration.ExternalBridge;
using Tango.Integration.Operation;
using Tango.Transport.Adapters;
using Tango.Transport.Transporters;
namespace Tango.Emulations.ExternalBridge
{
///
/// Represents an in-memory external bridge client emulator.
///
///
///
public class EmulatorExternalBridge : MachineOperator, IExternalBridgeClient
{
///
/// Gets a value indicating whether this client requires authentication.
///
public bool RequiresAuthentication { get; }
///
/// Gets or sets the machine serial number.
///
public string SerialNumber { get; set; }
///
/// Gets the emulator.
///
public MachineEmulator Emulator { get; private set; }
///
/// Initializes a new instance of the class.
///
public EmulatorExternalBridge()
{
ComponentName = $"External Bridge Emulator Client {_component_counter++}";
EnableDiagnostics = true;
EnableEmbeddedDebugging = true;
EnableEventsNotification = true;
EnableAutomaticThreadLoading = true;
String address = new string(Guid.NewGuid().ToString().Replace("-", "").TakeLast(4).ToArray());
Adapter = new MemoryTransportAdapter(address);
Emulator = new MachineEmulator(new BasicTransporter(new MemoryTransportAdapter(address)));
}
///
/// Connects the transport component.
///
///
public override async Task Connect()
{
await Emulator.Start();
await base.Connect();
}
///
/// Disconnects the machine operator and the underlying transporter.
///
///
public override async Task Disconnect()
{
await base.Disconnect();
await Emulator.Stop();
}
///
/// Gets the database machine associated with this client.
///
public Machine Machine { get; private set; }
///
/// Sets the database machine.
///
/// The machine.
public void SetMachine(Machine machine)
{
Machine = machine;
}
public bool CompressionEnabled { get; set; }
}
}