private static void ProcessArchiveCommand(string args) { Regex archiveRegex = new Regex(@"^(?:(?:(?<is>-is)?|(?<all>-all)?|(?<ct>-ct)?) )*(?<filename>(?:\S+|""(?:\S| )+"")) (?<table>(?:(?:\[(?:\S| )+\])|\S|\.)+)(?: (?:-n (?<n>(?: ?(?<oldTable>(?:(?:\[(?:\S| )+\])|\S|\.)+)\=(?<newTable>(?:(?:\[(?:\S| )+\])|\S|\.)+))+)))?(?: (?:-c (?<c>.+)))?$"); Match archiveMatch = archiveRegex.Match(args); DatabaseObject archiveTable; if (!archiveMatch.Success) { Console.WriteLine($"Error: Invalid syntax for command {ARCHIVE_ENTRIES_COMMAND}, syntax information can be showed by typing: help {ARCHIVE_ENTRIES_COMMAND}"); return; } else if (!_tableByName.TryGetValue(archiveMatch.Groups["table"].Value.Replace("[", "").Replace("]", "").ToLower(), out archiveTable)) { Console.WriteLine($"Error: Table {archiveMatch.Groups["table"].Value} not found"); return; } try { using (StreamWriter fileStream = new StreamWriter(archiveMatch.Groups["filename"].Value)) { ISet <DependencyNode> dependentTables = _dependencies.GetAncestors(archiveTable); dependentTables.Add(_dependencies[archiveTable]); bool createTable = false; bool useInsertIntoSelect = false; bool saveAll = false; string conditions = ""; IDictionary <string, string> nameConvertor = new Dictionary <string, string>(dependentTables.Count); foreach (DependencyNode table in dependentTables) { nameConvertor.Add(table.DbObject.NameWithSchema.ToLower(), table.DbObject.NameWithSchemaBrackets); } if (archiveMatch.Groups["n"].Success) { for (int i = 0; i < archiveMatch.Groups["newTable"].Captures.Count; i++) { nameConvertor[archiveMatch.Groups["oldTable"].Captures[i].Value.Replace("[", "").Replace("]", "").ToLower()] = archiveMatch.Groups["newTable"].Captures[i].Value; } } if (archiveMatch.Groups["ct"].Success) { createTable = true; } if (archiveMatch.Groups["c"].Success) { conditions = archiveMatch.Groups["c"].Value; } if (archiveMatch.Groups["is"].Success) { useInsertIntoSelect = true; } if (archiveMatch.Groups["all"].Success) { saveAll = true; } Console.WriteLine("Archiving in progress..."); if (_optimizer.ArchiveTable(archiveTable, nameConvertor, createTable, conditions, useInsertIntoSelect, saveAll, fileStream)) { Console.WriteLine("Archive has been created and saved"); } else { Console.WriteLine("Nothing to archive"); } } } catch (DatabaseException exc) { Debug.WriteLine(exc); Console.WriteLine($"Error: cannot get data - {exc.InnerException.Message}"); return; } catch (IOException exc) { Debug.WriteLine(exc); Console.WriteLine($"Error: problem data file - {exc.Message}"); return; } }