public async Task RemoveDownload(JObject downloadJson)
        {
            DebugHandler.TraceMessage("RemoveDownload called.", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage(downloadJson.ToString(), DebugSource.TASK, DebugType.PARAMETERS);

            try
            {
                string id       = downloadJson.Value <string>("id");
                string filePath = downloadJson.Value <string>("path");
                string result   = "";
                if (id != null)
                {
                    result = DownloadHandler.RemoveDownload(id, null);
                    await WebSocketHandler.SendMessage(result);

                    string toRemove     = FileHistoryHandler.RemoveFileFromFileHistory(id, null);
                    string resultRemove = FileHandler.DeleteFile(toRemove);
                    await WebSocketHandler.SendMessage(resultRemove);
                }
                else if (filePath != null)
                {
                    result = DownloadHandler.RemoveDownload(null, filePath);
                    await WebSocketHandler.SendMessage(result);

                    string toRemove     = FileHistoryHandler.RemoveFileFromFileHistory(null, filePath);
                    string resultRemove = FileHandler.DeleteFile(toRemove);
                    await WebSocketHandler.SendMessage(resultRemove);
                }
                else
                {
                    JsonError error = new JsonError()
                    {
                        type         = "parse_download_to_remove_error",
                        errormessage = "Neither id or file path have been defined!",
                        errortype    = "warning",
                        exception    = "none"
                    };
                    await WebSocketHandler.SendMessage(error.ToJson());
                }
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING);

                JsonError error = new JsonError()
                {
                    type         = "parse_download_to_remove_error",
                    errormessage = "Could not parse json containing download to remove information.",
                    errortype    = "exception",
                    exception    = e.ToString()
                };


                await WebSocketHandler.SendMessage(error.ToJson());
            }
        }
Ejemplo n.º 2
0
        public async Task DeleteFile(JObject fileInfoJson)
        {
            DebugHandler.TraceMessage("DeleteFile called.", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage(fileInfoJson.ToString(), DebugSource.TASK, DebugType.PARAMETERS);

            try
            {
                string filePath = fileInfoJson.Value <string>("path");

                if (filePath.Contains("//"))
                {
                    filePath.Replace("//", "/");
                }

                if (filePath.Contains("\\\\"))
                {
                    filePath.Replace("\\\\", "\\");
                }

                DownloadHandler.RemoveDownload(filePath);
                FileHistoryHandler.RemoveFileFromFileHistory(filePath);
                string result = FileHandler.DeleteFile(filePath);
                await WebSocketHandler.SendMessage(result);
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING);
                JsonError error = new JsonError()
                {
                    type         = "parse_file_to_delete_error",
                    errormessage = "Could not parse json containing file to delete information.",
                    errortype    = "exception",
                    exception    = e.ToString()
                };
                await WebSocketHandler.SendMessage(error.ToJson());
            }
        }