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 IActionResult DeleteFile(string fileLocation, int id)
        {
            switch (_fileHandler.DeleteFile(fileLocation))
            {
            case FileResponse.FileNotFound:
                return(StatusCode(400, "Could not find file to delete"));

            case FileResponse.Exception:
                return(StatusCode(500, "Could not delete file, please see logs for details."));
            }
            return(RedirectToAction(nameof(Edit) + "/" + id));
        }
Ejemplo n.º 3
0
        public void DeleteFile(string fileName, string currentDirectory)
        {
            var folderPath    = _fileHandler.GetAbsolutePath(currentDirectory);
            var fileFullPaths = _fileHandler.EnumerateFiles(folderPath, "*", false);

            foreach (var fullPath in fileFullPaths)
            {
                if (_fileHandler.GetFileName(fullPath) == fileName)
                {
                    _fileHandler.DeleteFile(fullPath);
                }
            }
        }
Ejemplo n.º 4
0
        public void DeleteJournal()
        {
            if (_journalEnabled == false)
            {
                return;
            }

            if (_journal != null)
            {
                _log.Write(Logger.JOURNAL, "delete journal file");

                // clear pages in journal file
                _journalPages.Clear();

                // close journal stream and delete file
                _journal.Dispose();
                _journal = null;

                // remove journal file
                this.TryExec(() => _fileHandler.DeleteFile(_journalFilename));
            }
        }
Ejemplo n.º 5
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());
            }
        }
Ejemplo n.º 6
0
        public bool DeleteFile(string filename)
        {
            var fullPath = _fileHandler.GetFileFullPath(filename);

            return(_fileHandler.DeleteFile(fullPath));
        }
 public ExitCode DeleteFile(string path)
 {
     return(fileHandler.DeleteFile(path));
 }