public void ClientMkdirRequest(string content) { if (this.DirWatcher.AllowedPath()) { try { ServerCommand.Mkdir(this.DirWatcher.Path, content); } catch (Exception e) { this.SendServerError(e); } } }
public void ClientRenameRequest(Dictionary <string, string> contents) { if (this.DirWatcher.AllowedPath() && contents.TryGetValue("Old", out string oldName) && contents.TryGetValue("New", out string newName)) { try { ServerCommand.Rename(this.DirWatcher.Path, oldName, newName); } catch (Exception e) { this.SendServerError(e); } } }
public void SendDir() { try { this.SendAes(Json.Encode(new ServerMessage() { Command = "dir", Contents = ServerCommand.Dir(this.DirWatcher.Path) })); } catch (Exception e) { this.SendServerError(e); } }
public void GetFile(Dictionary <string, string> contents) { if (contents.TryGetValue("Name", out string name) && contents.TryGetValue("FileRequestID", out string fileRequestId)) { string path = this.DirWatcher.Path + @"\" + name; if (this.DirWatcher.AllowedPath(path)) { try { using (FileStream fs = ServerCommand.GetFile(path)) { FileInfo fi = new FileInfo(path); FileRequest fr = new FileRequest(fileRequestId); int offset = 0; int bufferSize = WebSocketManager.BUFFER_SIZE; this.SendAes(Json.Encode(new ServerMessage() { Command = "filerequestinit", Contents = new Dictionary <string, string>(2) { { "FileRequestID", fileRequestId }, { "s", (fi.Length / (long)bufferSize).ToString() } } })); int bytesRead = bufferSize; while (bytesRead == bufferSize) { byte[] buffer = new byte[bufferSize]; bytesRead = fs.Read(buffer, offset, bufferSize); if (bytesRead < bufferSize) { byte[] smallBuff = new byte[bytesRead]; for (int i = 0; i < bytesRead; i++) { smallBuff[i] = buffer[i]; } buffer = smallBuff; } fr.Data = System.Convert.ToBase64String(buffer); fr.Complete = bytesRead != bufferSize; this.SendAes(Json.Encode(new ServerMessage() { Command = "filerequest", Contents = fr })); fr.segmentNum++; } fs.Close(); } } catch (Exception e) { this.SendServerError(e); } } } }