-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCommandExecutor.cs
More file actions
41 lines (30 loc) · 1.13 KB
/
Copy pathCommandExecutor.cs
File metadata and controls
41 lines (30 loc) · 1.13 KB
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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;
using System.Text;
namespace TCPServerApp{
class CommandExecutor{
ServerListener serverListener;
public CommandExecutor(ServerListener serverListener){
this.serverListener = serverListener;
}
public async void Execute(ServerListener.Command command, string entireMessage){
if(command == ServerListener.Command.download){
if(entireMessage.Split(' ').Length != 2){
serverListener.SendMessage("download command expects 1 parameters");
return;
}
string path = entireMessage.Split(' ')[1];
await Task.Run( () => UploadFileToClient(path) );
}
}
public void UploadFileToClient(string path){
if(File.Exists(path)){
byte[] data = File.ReadAllBytes(path);
serverListener.stream.Write(data, 0, data.Length);
}
else serverListener.SendMessage("could not find file");
}
}
}