private void OnRequestLogLevelFilteredData(object sender, ListArguments e) { string data = LogHandler.ReadLog(); string[] lines = data.Split( new[] { Environment.NewLine }, StringSplitOptions.None ); List <object> list = new List <object>(lines); List <object> filteredList = new List <object>(); int iter = 0; foreach (string item in list) { if (iter <= 1) { filteredList.Add(item); iter++; continue; } foreach (LogLevel logLevel in e.Value) { if (item.Contains(logLevel.ToString())) { filteredList.Add(item); } } } _controller.LogData(new ListArguments(filteredList)); }
private void OnOpenConfig(object sender, ListArguments list) { List <object> data = list.Value; _controller.TextConfigNameLoaded((string)data[1]); string path = (string)data[0]; path = path.Replace((string)data[1], ""); _controller.TextConfigLoaded(_logic.FileHandler.ReadAllText((string)data[1], path)); }
private void OnSaveData(object sender, object list) { ListArguments listArgument = (ListArguments)list; List <object> data = (List <object>)listArgument.Value; _logic.FileHandler.CreateFileIfNotExist((string)data[0]); string row = (string)data[1]; string[] logList = row.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); _logic.FileHandler.AppendAll((string)data[0], logList); }
private void OnActivateConfig(object sender, ListArguments list) { List <object> data = list.Value; _controller.TextActiveConfigFile((string)data[0]); _logic.Config = _logic.XmlHandler.GetDeserializedConfigObject((string)data[1]); // Creates a local copy in the config file path if it doesn't exist. short result = _logic.FileHandler.CreateFileIfNotExist((string)data[0], LogicConstants.CONFIG_FILE_PATH); if (result != 1 && result != -1) { _logic.FileHandler.AppendText((string)data[0], (string)data[1], LogicConstants.CONFIG_FILE_PATH); } // Overwrite the config.ini with the current value. _logic.FileHandler.OverwriteFile(LogicConstants.CONFIG_FILE_NAME, (string)data[0], LogicConstants.CONFIG_FILE_PATH); }
/// <inheritdoc/> public override async Task<FtpResponse> Process(FtpCommand command, CancellationToken cancellationToken) { await Connection.WriteAsync(new FtpResponse(150, "Opening data connection."), cancellationToken); ITcpSocketClient responseSocket; try { responseSocket = await Connection.CreateResponseSocket(); } catch (Exception) { return new FtpResponse(425, "Can't open data connection."); } try { // Parse arguments in a way that's compatible with broken FTP clients var argument = new ListArguments(command.Argument); var showHidden = argument.All; // Instantiate the formatter IListFormatter formatter; if (string.Equals(command.Name, "NLST", StringComparison.OrdinalIgnoreCase)) { formatter = new ShortListFormatter(); } else if (string.Equals(command.Name, "LS", StringComparison.OrdinalIgnoreCase)) { formatter = new LongListFormatter(); } else { formatter = new LongListFormatter(); } // Parse the given path to determine the mask (e.g. when information about a file was requested) var directoriesToProcess = new Queue<DirectoryQueueItem>(); // Use braces to avoid the definition of mask and path in the following parts // of this function. { var mask = "*"; var path = Data.Path.Clone(); if (!string.IsNullOrEmpty(argument.Path)) { var foundEntry = await Data.FileSystem.SearchEntryAsync(path, argument.Path, cancellationToken); if (foundEntry?.Directory == null) return new FtpResponse(550, "File system entry not found."); var dirEntry = foundEntry.Entry as IUnixDirectoryEntry; if (dirEntry == null) { mask = foundEntry.FileName; } else if (!dirEntry.IsRoot) { path.Push(dirEntry); } } directoriesToProcess.Enqueue(new DirectoryQueueItem(path, mask)); } var encoding = Data.NlstEncoding ?? Connection.Encoding; using (var stream = await Connection.CreateEncryptedStream(responseSocket.WriteStream)) { using (var writer = new StreamWriter(stream, encoding, 4096, true) { NewLine = "\r\n", }) { while (directoriesToProcess.Count != 0) { var queueItem = directoriesToProcess.Dequeue(); var currentPath = queueItem.Path; var mask = queueItem.Mask; var currentDirEntry = currentPath.Count != 0 ? currentPath.Peek() : Data.FileSystem.Root; if (argument.Recursive) { var line = currentPath.ToDisplayString() + ":"; Connection.Log?.Debug(line); await writer.WriteLineAsync(line); } var mmOptions = new Options() { IgnoreCase = Data.FileSystem.FileSystemEntryComparer.Equals("a", "A"), NoGlobStar = true, Dot = true, }; var mm = new Minimatcher(mask, mmOptions); var entries = await Data.FileSystem.GetEntriesAsync(currentDirEntry, cancellationToken); var enumerator = new DirectoryListingEnumerator(entries, Data.FileSystem, currentPath, true); while (enumerator.MoveNext()) { var name = enumerator.Name; if (!enumerator.IsDotEntry) { if (!mm.IsMatch(name)) continue; if (name.StartsWith(".") && !showHidden) continue; } var entry = enumerator.Entry; if (argument.Recursive && !enumerator.IsDotEntry) { var dirEntry = entry as IUnixDirectoryEntry; if (dirEntry != null) { var subDirPath = currentPath.Clone(); subDirPath.Push(dirEntry); directoriesToProcess.Enqueue(new DirectoryQueueItem(subDirPath, "*")); } } var line = formatter.Format(entry, name); Connection.Log?.Debug(line); await writer.WriteLineAsync(line); } } } } } finally { responseSocket.Dispose(); } // Use 250 when the connection stays open. return new FtpResponse(250, "Closing data connection."); }
private void OnSaveNewPassword(object sender, ListArguments list) { List <object> data = list.Value; _logic.SaveNewPassword((string)data[0]); }