public string DeleteDirectory(string path) { DebugHandler.TraceMessage("DeleteDirectory Called", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage("Directory Path: " + path, DebugSource.TASK, DebugType.PARAMETERS); try { DirectoryInfo info = new DirectoryInfo(path); int amountOfFiles = info.GetFiles().Length; if (amountOfFiles == 0) { if (Directory.Exists(path)) { Directory.Delete(path); JsonSuccess report = new JsonSuccess() { message = "Succesfully deleted folder with path: " + path }; return(report.ToJson()); } else { JsonSuccess report = new JsonSuccess() { message = "Directory with path : " + path + " already removed." }; return(report.ToJson()); } } else { DebugHandler.TraceMessage("Could not delete directory: " + path + " because there are still files and/or other directories inside!", DebugSource.TASK, DebugType.WARNING); JsonError jsonError = new JsonError { type = "delete_directory_warning", errortype = "warning", errormessage = "Could not delete directory: " + path + " because there are still files and/or other directories inside!" }; return(jsonError.ToJson()); } } catch (Exception e) { DebugHandler.TraceMessage("Could not delete directory: " + e.ToString(), DebugSource.TASK, DebugType.WARNING); JsonError jsonError = new JsonError { type = "delete_directory_error", errortype = "exception", errormessage = "Could not get drives, see log." }; return(jsonError.ToJson()); } }
public async Task DisableSendMessage() { DebugHandler.TraceMessage("DisableSendMessage called.", DebugSource.TASK, DebugType.ENTRY_EXIT); SendMessageToWebSocketClient = false; JsonSuccess jsonSuccess = new JsonSuccess() { message = "Succesfully disabled sending IRC messages to client." }; await WebSocketHandler.SendMessage(jsonSuccess.ToJson()); }
public string StopQueue() { DebugHandler.TraceMessage("StopQueue Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); Stop = true; JsonSuccess succes = new JsonSuccess() { message = "Succesfully told queue to stop running." }; return(succes.ToJson()); }
public string OpenDirectory(string directoryPath) { DebugHandler.TraceMessage("OpenDirectory Called", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage("Directory Path: " + directoryPath, DebugSource.TASK, DebugType.PARAMETERS); try { #if __ANDROID__ Android.Net.Uri uri = Android.Net.Uri.Parse(directoryPath); Android.Content.Intent intent = new Android.Content.Intent(Android.Content.Intent.ActionView); intent.SetDataAndType(uri, "*/*"); intent.SetFlags(Android.Content.ActivityFlags.ClearWhenTaskReset | Android.Content.ActivityFlags.NewTask); Android.App.Application.Context.StartActivity(Android.Content.Intent.CreateChooser(intent, "Choose File Explorer")); #else if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.Linux) { Process.Start("xdg-open", directoryPath); } else if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.OsX) { Process.Start("open", directoryPath); } else { Process.Start("explorer.exe", directoryPath); } #endif JsonSuccess report = new JsonSuccess() { message = "Succesfully opened folder with path: " + directoryPath }; return(report.ToJson()); } catch (Exception e) { DebugHandler.TraceMessage("Could not open directory: " + e.ToString(), DebugSource.TASK, DebugType.WARNING); JsonError jsonError = new JsonError { type = "open_directory_failed", errormessage = "Could not open directory.", errortype = "exception" }; return(jsonError.ToJson()); } }
public async Task <string> AbortDownload(string id = null, string filePath = null) { DebugHandler.TraceMessage("AbortDownload Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage("ID: " + id + ", FILEPATH: " + filePath, DebugSource.TASK, DebugType.PARAMETERS); try { if (IrcClientHandler.IsDownloading() && DownloadProcesOnGoing) { if (CurrentlyDownloading.id == id) { DebugHandler.TraceMessage("Stopping the current download!", DebugSource.TASK, DebugType.INFO); IrcClientHandler.StopDownload(); } } while (IrcClientHandler.IsDownloading()) { DebugHandler.TraceMessage("Current download still running!", DebugSource.TASK, DebugType.INFO); await Task.Delay(100); } DebugHandler.TraceMessage("Current download stopped!", DebugSource.TASK, DebugType.INFO); JsonSuccess succes = new JsonSuccess() { message = "Succesfully aborted download from download queue by download json." }; return(succes.ToJson()); } catch (Exception e) { DebugHandler.TraceMessage("Could not remove download from queue by download json and stop the download.", DebugSource.TASK, DebugType.WARNING); DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING); JsonError error = new JsonError() { type = "remove_download_error", errormessage = "Could not remove download from queue by download json.", errortype = "exception" }; return(error.ToJson()); } }
public string AddDownload(JsonDownloadInfo download) { DebugHandler.TraceMessage("AddDownload Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage(download.ToString(), DebugSource.TASK, DebugType.PARAMETERS); try { if (download.filesize.Contains(".")) { download.filesize = ((int)(double.Parse(download.filesize, System.Globalization.CultureInfo.InvariantCulture) * 1024)).ToString(); } if (UtilityMethods.GetFreeSpace(IrcSettings.fullfilepath) > (int.Parse(download.filesize) * 1024 * 1024)) { download.downloadIndex = DownloadQueue.Count - 1; if (!DownloadQueue.Contains(download) || CurrentlyDownloading != download) { DownloadQueue.Add(download); DebugHandler.TraceMessage("Added download to queue: " + download.ToString(), DebugSource.TASK, DebugType.INFO); JsonSuccess succes = new JsonSuccess() { message = "Succesfully added download to download queue." }; return(succes.ToJson()); } else { DebugHandler.TraceMessage("Could not add download: " + download.ToString() + ", already exist in queue or is already being downloaded ", DebugSource.TASK, DebugType.WARNING); JsonError error = new JsonError() { type = "file_already_being_downloaded_error", errormessage = "Could not add download: " + download.ToString() + ", already exist in queue or is already being downloaded ", errortype = "warning", exception = "none" }; return(error.ToJson()); } } else { DebugHandler.TraceMessage("Could not add download with filesize: " + download.filesize + " due to insufficient space required: " + (UtilityMethods.GetFreeSpace(IrcSettings.fullfilepath) / 1024 / 1024).ToString(), DebugSource.TASK, DebugType.WARNING); JsonError error = new JsonError() { type = "unsufficient_space_error", errormessage = "Could not add download with filesize: " + download.filesize + " due to insufficient space required: " + (UtilityMethods.GetFreeSpace(IrcSettings.fullfilepath) / 1024 / 1024).ToString(), errortype = "warning" }; return(error.ToJson()); } } catch (Exception e) { DebugHandler.TraceMessage("Could not add download with filesize: " + e.ToString(), DebugSource.TASK, DebugType.ERROR); JsonError error = new JsonError() { type = "add_download_error", errormessage = "Could not add download to queue.", errortype = "exception", exception = e.ToString() }; return(error.ToJson()); } }
public string AddDownloads(List <JsonDownloadInfo> download) { DebugHandler.TraceMessage("AddDownloads Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); try { long totalSizeNeeded = 0; foreach (JsonDownloadInfo downloadinfo in download) { DebugHandler.TraceMessage(downloadinfo.ToString(), DebugSource.TASK, DebugType.PARAMETERS); if (downloadinfo.filesize.Contains(".")) { downloadinfo.filesize = ((int)(double.Parse(downloadinfo.filesize, System.Globalization.CultureInfo.InvariantCulture) * 1024)).ToString(); totalSizeNeeded += (int)(double.Parse(downloadinfo.filesize, System.Globalization.CultureInfo.InvariantCulture) * 1024); } else { totalSizeNeeded += int.Parse(downloadinfo.filesize); } } if (UtilityMethods.GetFreeSpace(IrcSettings.fullfilepath) > (totalSizeNeeded * 1024 * 1024)) { DownloadQueue.AddRange(download); DebugHandler.TraceMessage("Succesfully added " + download.Count + " downloads to download queue.", DebugSource.TASK, DebugType.INFO); JsonSuccess succes = new JsonSuccess() { message = "Succesfully added " + download.Count + " downloads to download queue." }; return(succes.ToJson()); } else { DebugHandler.TraceMessage("Could not add downloads with filesize: " + totalSizeNeeded + " due to insufficient space required: " + (UtilityMethods.GetFreeSpace(IrcSettings.fullfilepath) / 1024 / 1024).ToString(), DebugSource.TASK, DebugType.WARNING); JsonError error = new JsonError() { type = "unsufficient_space_error", errormessage = "Could not add download with filesize: " + totalSizeNeeded + " due to insufficient space required: " + (UtilityMethods.GetFreeSpace(IrcSettings.fullfilepath) / 1024 / 1024).ToString(), errortype = "warning" }; return(error.ToJson()); } } catch (Exception e) { DebugHandler.TraceMessage("Could not add downloads: " + e.ToString(), DebugSource.TASK, DebugType.WARNING); JsonError error = new JsonError() { type = "add_download_error", errormessage = "Could not add download to queue.", errortype = "exception", exception = e.ToString() }; return(error.ToJson()); } }
public string RemoveDownload(string id = null, string filepath = null) { DebugHandler.TraceMessage("Remove Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage("ID: " + id, DebugSource.TASK, DebugType.PARAMETERS); DebugHandler.TraceMessage("FILEPATH: " + filepath, DebugSource.TASK, DebugType.PARAMETERS); try { int index = 0; foreach (JsonDownloadInfo queuedDownload in DownloadQueue) { if (id != null) { if (queuedDownload.id == id) { DebugHandler.TraceMessage("Removed download at index: " + index.ToString() + " using id: " + id, DebugSource.TASK, DebugType.INFO); DownloadQueue.RemoveAt(index); break; } } else if (filepath != null) { if (Path.Combine(queuedDownload.fullfilepath, queuedDownload.filename) == filepath) { DebugHandler.TraceMessage("Removed download at index: " + index.ToString() + " using filepath: " + filepath, DebugSource.TASK, DebugType.INFO); DownloadQueue.RemoveAt(index); break; } } else { DebugHandler.TraceMessage("Could not remove download from queue, neither id or filepath is defined.", DebugSource.TASK, DebugType.WARNING); JsonError error = new JsonError() { type = "remove_download_error", errormessage = "Could not remove download from queue, neither id or filepath is defined.", errortype = "warning" }; return(error.ToJson()); } index++; } JsonSuccess succes = new JsonSuccess() { message = "Succesfully removed download from download queue by download json." }; return(succes.ToJson()); } catch (Exception e) { DebugHandler.TraceMessage("Could not remove download from queue by download json: " + e.ToString(), DebugSource.TASK, DebugType.ERROR); JsonError error = new JsonError() { type = "remove_download_error", errormessage = "Could not remove download from queue by download json.", errortype = "exception" }; return(error.ToJson()); } }
public string OpenFile(string filePath, string fileName = null) { DebugHandler.TraceMessage("OpenFile called", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage("FilePath: " + filePath, DebugSource.TASK, DebugType.PARAMETERS); string fullFilePath = filePath; if (fileName != null) { DebugHandler.TraceMessage("FileName: " + fileName, DebugSource.TASK, DebugType.PARAMETERS); fullFilePath = Path.Combine(filePath, fileName); DebugHandler.TraceMessage("Full Filepath: " + fullFilePath, DebugSource.TASK, DebugType.INFO); } try { for (int i = 0; i < 20; i++) { if (File.Exists(fullFilePath)) { #if __ANDROID__ Android.Net.Uri uri = Android.Net.Uri.Parse(fullFilePath); Intent intent = new Intent(Intent.ActionView); intent.SetDataAndType(uri, "video/*"); intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask); Android.App.Application.Context.StartActivity(intent); #else if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.OsX) { Process.Start("open", fullFilePath); } else { var p = new Process { StartInfo = new ProcessStartInfo(fullFilePath) { UseShellExecute = true } }; p.Start(); } #endif JsonSuccess report = new JsonSuccess() { message = "Succesfully opened file with path: " + fullFilePath }; return(report.ToJson()); } Thread.Sleep(200); } JsonError jsonError = new JsonError { type = "open_file_failed", errormessage = "Could not open file but didn't throw exception.", errortype = "warning", exception = "none" }; DebugHandler.TraceMessage("Could not open file but didn't throw exception, file: " + fullFilePath, DebugSource.TASK, DebugType.WARNING); return(jsonError.ToJson()); } catch (Exception e) { DebugHandler.TraceMessage("Could not open file. " + fullFilePath, DebugSource.TASK, DebugType.WARNING); DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING); JsonError jsonError = new JsonError { type = "open_file_failed", errormessage = "Could not open file.", errortype = "exception", exception = e.ToString() }; return(jsonError.ToJson()); } }
public string DeleteFile(string filePath, string fileName = null) { DebugHandler.TraceMessage("DeleteFile called", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage("FilePath: " + filePath, DebugSource.TASK, DebugType.PARAMETERS); string fullFilePath = filePath; if (fileName != null) { DebugHandler.TraceMessage("FileName: " + fileName, DebugSource.TASK, DebugType.PARAMETERS); fullFilePath = Path.Combine(filePath, fileName); DebugHandler.TraceMessage("Full File Path: " + fullFilePath, DebugSource.TASK, DebugType.INFO); } try { if (File.Exists(fullFilePath)) { File.Delete(fullFilePath); string[] filePaths = Directory.GetFiles(Path.GetDirectoryName(filePath)); if (filePaths.Length == 0) { Directory.Delete(filePath); DebugHandler.TraceMessage("Succesfully deleted file: " + fullFilePath + " & empty directory: " + filePath, DebugSource.TASK, DebugType.INFO); JsonSuccess report = new JsonSuccess() { message = "Succesfully deleted file with path: " + fullFilePath + " and directory: " + filePath }; return(report.ToJson()); } else { DebugHandler.TraceMessage("Succesfully deleted file: " + fullFilePath, DebugSource.TASK, DebugType.INFO); JsonSuccess report = new JsonSuccess() { message = "Succesfully deleted file with path: " + fullFilePath }; return(report.ToJson()); } } else { DebugHandler.TraceMessage("File: " + fullFilePath + " does not exist, possibly already deleted.", DebugSource.TASK, DebugType.INFO); JsonSuccess report = new JsonSuccess() { message = "File with filepath: " + fullFilePath + " already removed." }; return(report.ToJson()); } } catch (Exception e) { DebugHandler.TraceMessage("Failed to delete file: " + fullFilePath, DebugSource.TASK, DebugType.WARNING); DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING); JsonError jsonError = new JsonError { type = "delete_file_failed", errormessage = "Could not delete file.", errortype = "exception", exception = e.ToString() }; return(jsonError.ToJson()); } }