public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session) { // Connect NetworkChannel channel = new NetworkChannel(Connection); // Request JsonBrowseRequestMessage jsonRequestMessage = JsonBrowseRequestMessage.Parse(jsonRequest.Message); JsonClient jsonClient = jsonRequestMessage.Client; if (jsonClient == null) { channel.SendNotFound(); return; } Entity entity = ClientMap.Get(jsonClient.Id); if (entity == null) { channel.SendNotFound(); return; } // Command TunnelComponent tunnel = entity.Get <TunnelComponent>(); BrowseRequestCommand command = new BrowseRequestCommand(entity, tunnel.Connection); string jsonData = command.Execute(jsonRequest.Data); if (string.IsNullOrEmpty(jsonData)) { channel.SendNotFound(); return; } // Response JsonBrowseResponseMessage jsonResponseMessage = new JsonBrowseResponseMessage(); JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage, jsonData); HttpResponse httpResponse = new HttpResponse() { Data = session.Encrypt(jsonResponse) }; channel.Send(httpResponse); #if DEBUG Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse); #endif }
public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest) { Clear(); // Connect NetworkChannel channel = new NetworkChannel(Connection); // Request JsonBrowseRequestMessage jsonRequestMessage = JsonBrowseRequestMessage.Parse(jsonRequest.Message); JsonBrowseRequestData jsonRequestData = JsonBrowseRequestData.Parse(Group.Decrypt(jsonRequest.Data)); JsonFile jsonFolder = (jsonRequestData != null) ? jsonRequestData.Folder : null; // Data List <JsonFile> folders = new List <JsonFile>(); List <JsonFile> files = new List <JsonFile>(); if (jsonFolder != null) { FileComponent file = FolderMap.Get(jsonFolder.Id); if (file == null) { channel.SendNotFound(); return; } // Folders foreach (FileComponent f in file.Folders) { JsonFile json = (JsonFile)f; folders.Add(json); } // Files foreach (FileComponent f in file.Files) { JsonFile json = (JsonFile)f; files.Add(json); } } else { // Folders FolderListComponent shared = Entity.Get <FolderListComponent>(); foreach (FileComponent f in shared) { JsonFile json = (JsonFile)f; folders.Add(json); } } // Response JsonBrowseResponseMessage jsonResponseMessage = new JsonBrowseResponseMessage(); JsonBrowseResponseData jsonResponseData = new JsonBrowseResponseData() { Files = files, Folders = folders }; JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage, Group.Encrypt(jsonResponseData)); HttpResponse httpResponse = new HttpResponse() { Data = Session.Encrypt(jsonResponse) }; channel.Send(httpResponse); #if DEBUG Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse); #endif }