mirror of https://github.com/ogoun/Zero.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.6 KiB
40 lines
1.6 KiB
using System;
|
|
using ZeroLevel.Models;
|
|
|
|
namespace ZeroLevel.Network.FileTransfer
|
|
{
|
|
public sealed class FileReceiver
|
|
{
|
|
private readonly string _baseFolder;
|
|
private readonly ClientFolderNameMapper _nameMapper;
|
|
private readonly FileWriter _receiver;
|
|
|
|
public FileReceiver(IRouter router, string baseFolder, ClientFolderNameMapper nameMapper)
|
|
{
|
|
_baseFolder = baseFolder ?? throw new Exception(nameof(baseFolder));
|
|
_nameMapper = nameMapper ?? throw new Exception(nameof(nameMapper));
|
|
_receiver = new FileWriter(baseFolder);
|
|
|
|
if (false == router.ContainsRequestorInbox("__file_transfer_start_transfer__"))
|
|
{
|
|
router.RegisterInbox<FileStartFrame, InvokeResult>("__file_transfer_start_transfer__",
|
|
(c, f) => _receiver.Incoming(f, nameMapper(c)));
|
|
}
|
|
if (false == router.ContainsRequestorInbox("__file_transfer_frame__"))
|
|
{
|
|
router.RegisterInbox<FileFrame, InvokeResult>("__file_transfer_frame__",
|
|
(_, f) => _receiver.Incoming(f));
|
|
}
|
|
if (false == router.ContainsRequestorInbox("__file_transfer_complete_transfer__"))
|
|
{
|
|
router.RegisterInbox<FileEndFrame, InvokeResult>("__file_transfer_complete_transfer__",
|
|
(_, f) => _receiver.Incoming(f));
|
|
}
|
|
if (false == router.ContainsRequestorInbox("__file_transfer_ping__"))
|
|
{
|
|
router.RegisterInbox<bool>("__file_transfer_ping__", (_) => true);
|
|
}
|
|
}
|
|
}
|
|
}
|