forked from TansuoTro/MineRealmsUupdateSystem-Server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomizeHandler.cs
67 lines (57 loc) · 2.56 KB
/
CustomizeHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Text;
using ESPlus.Application.CustomizeInfo.Server;
using ESPlus.Application.FileTransfering.Server;
using MRUS.Core;
using ESPlus.Serialization;
using ESPlus.FileTransceiver;
using ESPlus.Application.FileTransfering;
using ESPlus.Application;
using ESPlus.Application.CustomizeInfo;
namespace MRUS.Server
{
class CustomizeHandler : ICustomizeHandler
{
private IFileController fileController;
private UpdateConfiguration fileConfig;
public void Initialize(IFileController _fileController, UpdateConfiguration _fileConfig)
{
this.fileController = _fileController;
this.fileConfig = _fileConfig;
this.fileController.FileRequestReceived += new CbFileRequestReceived(fileController_FileRequestReceived);
}
void fileController_FileRequestReceived(string projectID, string senderID, string fileName, ulong totalSize, ResumedProjectItem resumedFileItem, string savePath)
{
this.fileController.BeginReceiveFile(projectID, savePath);
}
public void HandleInformation(string sourceUserID, int informationType, byte[] info)
{
if (informationType == InformationTypes.DownloadFiles)
{
DownloadFileContract contract = CompactPropertySerializer.Default.Deserialize<DownloadFileContract>(info, 0);
string fileID;
string filePath = string.Format("{0}FileFolder\\{1}", AppDomain.CurrentDomain.BaseDirectory, contract.FileName);
this.fileController.BeginSendFile(sourceUserID, filePath, contract.FileName, out fileID);
}
}
public byte[] HandleQuery(string sourceUserID, int informationType, byte[] info)
{
if (informationType == InformationTypes.GetAllFilesInfo)
{
FilesInfoContract contract = new FilesInfoContract();
contract.AllFileInfoList = this.fileConfig.FileList;
return CompactPropertySerializer.Default.Serialize<FilesInfoContract>(contract);
}
if (informationType == InformationTypes.GetLastUpdateTime)
{
LastUpdateTimeContract contract = new LastUpdateTimeContract(this.fileConfig.ClientVersion);
return CompactPropertySerializer.Default.Serialize<LastUpdateTimeContract>(contract);
}
return null;
}
public void OnTransmitFailed(Information information)
{
}
}
}