/// <summary> /// Makes this Builder an ExtractCommand-Builder. /// </summary> /// <returns><see cref="ExtractCommandBuilder"/>.</returns> public ExtractCommandBuilder InExtractMode() { var command = new ExtractCommand(); Command = command; return(new ExtractCommandBuilder(ref command)); }
/// <summary> /// Created a new instance of <see cref="MainWindowViewModel" /> /// </summary> internal MainWindowViewModel() { AddFilesCommand = new AddFilesCommand(this); ExtractCommand = new ExtractCommand(this); ExportCommand = new ExportCommand(this); FilterCommand = new FilterCommand(this); PopulateCategoryFiltersCommand = new PopulateCategoryFiltersCommand(this); Files = new List <string>(); ExtractedData = new ObservableCollection <INode>(); ExtractedDataShadow = new List <INode>(); NodeTypeFilters = new ObservableCollection <INodeTypeFilterViewModel>(); CategoryFilters = new ObservableCollection <ICategoryFilterViewModel>(); ExtractSuits = true; _includeIgnores = true; foreach ( var filter in Enum.GetValues(typeof(NodeTypes)) .Cast <NodeTypes>() .Select(nodeType => new NodeTypeFilterViewModel(nodeType))) { NodeTypeFilters.Add(filter); filter.PropertyChanged += delegate { FilterCommand.Execute(null); PopulateCategoryFiltersCommand.Execute(null); }; } }
public void WithoutFullPathExtraction_sets_UseFullPaths_to_false_on_the_command() { var command = new ExtractCommand(); var sut = new ExtractCommandBuilder(ref command); sut.WithoutFullPathExtraction(); command.UseFullPaths.ShouldBeFalse(); }
public void WithoutFullPathExtraction_returns_the_builder() { var command = new ExtractCommand(); var sut = new ExtractCommandBuilder(ref command); var actual = sut.WithoutFullPathExtraction(); actual.ShouldBe(sut); }
public void ExecuteWithAllParameters() { var parameters = new ExtractParameters(null, "1", "text.doc"); var conn = new MSolrConnection(); conn.postStream += new Moroco.MFunc <string, string, System.IO.Stream, System.Collections.Generic.IEnumerable <System.Collections.Generic.KeyValuePair <string, string> >, string>((url, type, stream, kvs) => { Assert.Equal("/update/extract", url); Assert.Equal("application/word-document", type); var p = new[] { KV.Create("literal.id", parameters.Id), KV.Create("resource.name", parameters.ResourceName), KV.Create("literal.field1", "value1"), KV.Create("literal.field2", "value2"), KV.Create("stream.type", "application/word-document"), KV.Create("commit", "true"), KV.Create("uprefix", "pref"), KV.Create("defaultField", "field1"), KV.Create("extractOnly", "true"), KV.Create("extractFormat", "text"), KV.Create("capture", "html"), KV.Create("captureAttr", "true"), KV.Create("xpath", "body"), KV.Create("lowernames", "true") }; Assert.Equal(p, kvs); //ignore order should be added return(""); }); var cmd = new ExtractCommand(new ExtractParameters(null, "1", "text.doc") { AutoCommit = true, Capture = "html", CaptureAttributes = true, DefaultField = "field1", ExtractOnly = true, ExtractFormat = ExtractFormat.Text, Fields = new[] { new ExtractField("field1", "value1"), new ExtractField("field2", "value2") }, LowerNames = true, XPath = "body", Prefix = "pref", StreamType = "application/word-document" }); cmd.Execute(conn); Assert.Equal(1, conn.postStream.Calls); }
public void ExecuteWithDuplicateIdField() { const string DuplicateId = "duplicateId"; var cmd = new ExtractCommand(new ExtractParameters(null, DuplicateId, "text.doc") { Fields = new[] { new ExtractField("id", DuplicateId), new ExtractField("field2", "value2"), } }); Assert.Throws <ArgumentException>(() => cmd.Execute(null)); }
public void ExecuteWithDuplicateIdField() { const string DuplicateId = "duplicateId"; var cmd = new ExtractCommand(new ExtractParameters(null, DuplicateId, "text.doc") { Fields = new[] { new ExtractField("id", DuplicateId), new ExtractField("field2", "value2"), } }); cmd.Execute(null); }
public void ExecuteWithDuplicateIdField() { var mocks = new MockRepository(); var conn = mocks.StrictMock <ISolrConnection>(); const string DuplicateId = "duplicateId"; var cmd = new ExtractCommand(new ExtractParameters(null, DuplicateId, "text.doc") { Fields = new[] { new ExtractField("id", DuplicateId), new ExtractField("field2", "value2") } }); cmd.Execute(conn); }
public void CollectGamesTest() { //arrange var cmd = new ExtractCommand(); var lines = File.ReadAllLines(@"testData\badges.txt"); //act var data = cmd.CollectGames(lines); //assert Assert.AreEqual(4, data.Count()); Assert.IsFalse(data.Any(p => p.Name == "Zombie Zoeds")); Assert.IsTrue(data.Any(p => p.Name == "Big Pharma")); Assert.AreEqual(6, data.Single(p => p.Name == "Big Pharma").CardsRemaining); Assert.AreEqual(1, data.Single(p => p.Name == "Slime Rancher").CardsRemaining); }
public void ExecuteWithAllParameters() { var mocks = new MockRepository(); var conn = mocks.StrictMock <ISolrConnection>(); var parameters = new ExtractParameters(null, "1", "text.doc"); With.Mocks(mocks).Expecting(() => { Expect.Call(conn.PostStream("/update/extract", "application/word-document", null, new List <KeyValuePair <string, string> > { KV.Create("literal.id", parameters.Id), KV.Create("resource.name", parameters.ResourceName), KV.Create("literal.field1", "value1"), KV.Create("literal.field2", "value2"), KV.Create("stream.type", "application/word-document"), KV.Create("commit", "true"), KV.Create("uprefix", "pref"), KV.Create("defaultField", "field1"), KV.Create("extractOnly", "true"), KV.Create("extractFormat", "text"), KV.Create("capture", "html"), KV.Create("captureAttr", "true"), KV.Create("xpath", "body"), KV.Create("lowernames", "true") })) .Repeat.Once() .Return(""); }) .Verify(() => { var cmd = new ExtractCommand(new ExtractParameters(null, "1", "text.doc") { AutoCommit = true, Capture = "html", CaptureAttributes = true, DefaultField = "field1", ExtractOnly = true, ExtractFormat = ExtractFormat.Text, Fields = new[] { new ExtractField("field1", "value1"), new ExtractField("field2", "value2") }, LowerNames = true, XPath = "body", Prefix = "pref", StreamType = "application/word-document" }); cmd.Execute(conn); }); }
/// <summary> /// Creates selected command instance /// </summary> /// <param name="operation">Operation type</param> /// <param name="mathUnit">Math unit</param> /// <returns>Command instance</returns> public static Command Create(string operation, MathUnit mathUnit) { Command command = null; switch (operation) { case "+": command = new AdditionCommand(mathUnit); break; case "-": command = new SubtractCommand(mathUnit); break; case "*": command = new MultiplicationCommand(mathUnit); break; case "/": command = new DivisionCommand(mathUnit); break; case "pow": command = new PowCommand(mathUnit); break; case "extract": command = new ExtractCommand(mathUnit); break; case "round": command = new RoundCommand(mathUnit); break; case "exp": command = new ExpCommand(mathUnit); break; case "log": command = new LogCommand(mathUnit); break; } return(command); }
public void Execute() { var mocks = new MockRepository(); var conn = mocks.StrictMock <ISolrConnection>(); var parameters = new ExtractParameters(null, "1", "text.doc"); With.Mocks(mocks).Expecting(() => { Expect.Call(conn.PostStream("/update/extract", null, null, new List <KeyValuePair <string, string> > { KV("literal.id", parameters.Id), KV("resource.name", parameters.ResourceName), })) .Repeat.Once() .Return(""); }) .Verify(() => { var cmd = new ExtractCommand(new ExtractParameters(null, "1", "text.doc")); cmd.Execute(conn); }); }
public void Execute() { var parameters = new ExtractParameters(null, "1", "text.doc"); var conn = new MSolrConnection(); conn.postStream += new Moroco.MFunc <string, string, System.IO.Stream, System.Collections.Generic.IEnumerable <System.Collections.Generic.KeyValuePair <string, string> >, string>((url, b, stream, kvs) => { Assert.Equal("/update/extract", url); var p = new[] { KV.Create("literal.id", parameters.Id), KV.Create("resource.name", parameters.ResourceName), }; Assert.Equal(p, kvs); //ignore order should be added return(""); }); var cmd = new ExtractCommand(parameters); cmd.Execute(conn); Assert.Equal(1, conn.postStream.Calls); }
public void Execute() { var parameters = new ExtractParameters(null, "1", "text.doc"); var conn = new MSolrConnection(); conn.postStream += (url, b, stream, kvs) => { Assert.AreEqual("/update/extract", url); var p = new[] { KV.Create("literal.id", parameters.Id), KV.Create("resource.name", parameters.ResourceName), }; CollectionAssert.AreEquivalent(p, kvs); return(""); }; var cmd = new ExtractCommand(parameters); cmd.Execute(conn); Assert.AreEqual(1, conn.postStream.Calls); }
private static void StartOperation() { string path = ReadTargetFilePath(); List <string> commands = ReadCommands(); ExtractCommand extractCommand = new ExtractCommand(path); extractCommand.Execute(); for (int i = 0; i < commands.Count; i++) { GetCommandToExecute(commands[i], out ICommand commandToExecute, extractCommand); if (commandToExecute == null) { Console.WriteLine($"Ann error has occured! {commands[i]} couldn't be created"); continue; } Console.WriteLine(commandToExecute.Execute()); } }
private void WriteMetadata(IDataLoadEventListener listener) { ExtractCommand.ElevateState(ExtractCommandState.WritingMetadata); WordDataWriter wordDataWriter; try { wordDataWriter = new WordDataWriter(this); wordDataWriter.GenerateWordFile();//run the report } catch (Exception e) { //something about the pipeline resulted i a known unsupported state (e.g. extracting to a database) so we can't use WordDataWritter with this // tell user that we could not run the report and set the status to warning ExtractCommand.ElevateState(ExtractCommandState.Warning); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, "Word metadata document NOT CREATED", e)); return; } //if there were any exceptions if (wordDataWriter.ExceptionsGeneratingWordFile.Any()) { ExtractCommand.ElevateState(ExtractCommandState.Warning); foreach (Exception e in wordDataWriter.ExceptionsGeneratingWordFile) { listener.OnNotify(wordDataWriter, new NotifyEventArgs(ProgressEventType.Warning, "Word metadata document creation caused exception", e)); } } else { ExtractCommand.ElevateState(ExtractCommandState.Completed); } }
public void Smoke() { using (var context = new TemporalMongoUnitTestContext(this)) { // Root of the C# source code of the DataCentric module string srcRootFolder = Path.Combine(context.TestFolderPath, "..\\..\\.."); string libFolder = Path.Combine(srcRootFolder, "DataCentric.Test\\bin\\Debug\\netcoreapp2.1"); // TODO - support Linux and release modes var options = new ExtractCommand { Assemblies = Directory.GetFiles(libFolder, "*.dll"), OutputFolder = context.TestFolderPath, Types = new List <string>(), ProjectPath = srcRootFolder }; AssemblyCache assemblies = new AssemblyCache(); // Create list of assemblies (enrolling masks when needed) foreach (string assemblyPath in options.Assemblies) { string assemblyName = Path.GetFileName(assemblyPath); if (!string.IsNullOrEmpty(assemblyName)) { string assemblyDirectory = string.IsNullOrEmpty(assemblyDirectory = Path.GetDirectoryName(assemblyPath)) ? Environment.CurrentDirectory : Path.GetFullPath(assemblyDirectory); assemblies.AddFiles(Directory.EnumerateFiles(assemblyDirectory, assemblyName)); } } List <IDecl> declarations = new List <IDecl>(); foreach (Assembly assembly in assemblies) { CommentNavigator.TryCreate(assembly, out CommentNavigator docNavigator); ProjectNavigator.TryCreate(options.ProjectPath, assembly, out ProjectNavigator projNavigator); List <Type> types = TypesExtractor.GetTypes(assembly, options.Types); List <Type> enums = TypesExtractor.GetEnums(assembly, options.Types); declarations.AddRange(types.Concat(enums) .Select(type => DeclarationConvertor.ToDecl(type, docNavigator, projNavigator))); } var converted = DeclarationToPythonConverter.ConvertSet(declarations); var result = new Dictionary <string, string>(); foreach (var file in converted) { if (file.FolderName == null) { result[$"{file.FileName}"] = file.Content; } else { result[$"{file.FolderName}/{file.FileName}"] = file.Content; } } // Record the contents of a selected list of generated files // for the purposes of approval testing var approvalTestFiles = new List <string> { "job_status", "job", "job_key", "zone", "zone_key" }; // Record approval test output foreach (var file in result.OrderBy(f => f.Key)) { string[] tokens = file.Key.Split('/'); string fileName = tokens[tokens.Length - 1].Split('.')[0]; if (approvalTestFiles.Contains(fileName)) { context.Log.Verify(file.Key, file.Value); } } // Enable to generate files on disk if (false) { foreach (var file in result) { var fullPath = Path.Combine(options.OutputFolder, file.Key); var directory = Path.GetDirectoryName(fullPath); Directory.CreateDirectory(directory); File.WriteAllText(fullPath, file.Value); } } } }
/// <summary> /// Runs the extraction once and returns true if it was success otherwise false /// </summary> /// <param name="listener"></param> /// <returns></returns> private bool ExecuteOnce(IDataLoadEventListener listener) { try { ExtractCommand.ElevateState(ExtractCommandState.WaitingToExecute); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, $"Running Extraction {ExtractCommand} with Pipeline {_pipeline.Name} (ID={_pipeline.ID})")); var engine = GetEngine(_pipeline, listener); try { engine.ExecutePipeline(Token ?? new GracefulCancellationToken()); listener.OnNotify(Destination, new NotifyEventArgs(ProgressEventType.Information, "Extraction completed successfully into : " + Destination.GetDestinationDescription())); } catch (Exception e) { ExtractCommand.ElevateState(ExtractCommandState.Crashed); _dataLoadInfo.LogFatalError("Execute extraction pipeline", ExceptionHelper.ExceptionToListOfInnerMessages(e, true)); if (ExtractCommand is ExtractDatasetCommand) { //audit to extraction results var result = (ExtractCommand as ExtractDatasetCommand).CumulativeExtractionResults; result.Exception = ExceptionHelper.ExceptionToListOfInnerMessages(e, true); result.SaveToDatabase(); } else { //audit to extraction results var result = (ExtractCommand as ExtractGlobalsCommand).ExtractionResults; foreach (var extractionResults in result) { extractionResults.Exception = ExceptionHelper.ExceptionToListOfInnerMessages(e, true); extractionResults.SaveToDatabase(); } } //throw so it can be audited to UI (triple audit yay!) throw new Exception("An error occurred while executing pipeline", e); } if (Source == null) { throw new Exception("Execute Pipeline completed without Exception but Source was null somehow?!"); } if (Source.WasCancelled) { Destination.TableLoadInfo.DataLoadInfoParent.LogFatalError(this.GetType().Name, "User Cancelled Extraction"); ExtractCommand.ElevateState(ExtractCommandState.UserAborted); if (ExtractCommand is ExtractDatasetCommand) { //audit to extraction results var result = (ExtractCommand as ExtractDatasetCommand).CumulativeExtractionResults; result.Exception = "User Cancelled Extraction"; result.SaveToDatabase(); } else { //audit to extraction results var result = (ExtractCommand as ExtractGlobalsCommand).ExtractionResults; foreach (var extractionResults in result) { extractionResults.Exception = "User Cancelled Extraction"; extractionResults.SaveToDatabase(); } } } } catch (Exception ex) { listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, "Execute pipeline failed with Exception", ex)); ExtractCommand.ElevateState(ExtractCommandState.Crashed); } //if it didn't crash / get aborted etc if (ExtractCommand.State < ExtractCommandState.WritingMetadata) { if (ExtractCommand is ExtractDatasetCommand) { WriteMetadata(listener); } else { ExtractCommand.ElevateState(ExtractCommandState.Completed); } } else { return(false); // it crashed or was aborted etc } return(true); }
public ExtractResponse Extract(ExtractParameters parameters) { var cmd = new ExtractCommand(parameters); return(SendAndParseExtract(cmd)); }
private static int Main(string[] arguments) { // Configure logging. var loggingLevelSwitch = new LoggingLevelSwitch { MinimumLevel = LogEventLevel.Information }; Log.Logger = new LoggerConfiguration() .MinimumLevel.ControlledBy(loggingLevelSwitch) .WriteTo.Console() .CreateLogger(); var showHelp = false; var argumentParser = new ArgumentParser(); argumentParser.Add("help|version|?", "Show this message.", (value) => { showHelp = true; }); argumentParser.Add("verbose|v", "Increase amount of log messages.", (value) => loggingLevelSwitch.MinimumLevel = LogEventLevel.Debug); // Handle all exceptions by showing them in the console try { var commandArgument = arguments.Length > 0 ? arguments[0] : "help"; BaseCommand?command = null; switch (commandArgument) { case "extract": command = new ExtractCommand(argumentParser); break; case "info": command = new InfoCommand(argumentParser); break; case "audio": command = new AudioCommand(argumentParser); break; case "items": command = new ItemsCommand(argumentParser); break; case "help": case "--help": case "--version": commandArgument = "help"; break; } if (command == null) { Program.ShowHelp(argumentParser, commandArgument); return(commandArgument == "help" ? Program.ExitCodeOk : Program.ExitCodeInvalidArgument); } command.Configure(arguments.Skip(1)); // Show help, now with configured argument parser for command-specific help. if (showHelp) { Program.ShowHelp(argumentParser, commandArgument); return(Program.ExitCodeOk); } if (argumentParser.UnparsedArguments.Any()) { // Do not accept invalid arguments because they usually indicate faulty usage foreach (var unparsedArgument in argumentParser.UnparsedArguments) { Console.WriteLine($"Unknown argument \"{unparsedArgument}\"."); } Console.WriteLine(); Program.ShowHelp(argumentParser, commandArgument); return(Program.ExitCodeInvalidArgument); } var exitCode = command.Run(); if (exitCode == Program.ExitCodeInvalidArgument) { Console.WriteLine(); Program.ShowHelp(argumentParser, commandArgument); } return(exitCode); } catch (System.Exception exception) { // Use first exception in aggregates for easier debugging. while (exception is AggregateException && exception.InnerException != null) { exception = exception.InnerException; } // Rethrow for debugger to process. if (Debugger.IsAttached) { throw; } Log.Fatal(exception.Message + "\n" + exception.StackTrace); return(Program.ExitCodeError); } }
/// <summary> /// Initializes a new instance of the <see cref="ExtractCommandBuilder"/> class. /// </summary> /// <param name="command">The command.</param> internal ExtractCommandBuilder(ref ExtractCommand command) { this.command = command; }
/// <inheritdoc /> public Task <ExtractResponse> ExtractAsync(ExtractParameters parameters) { var cmd = new ExtractCommand(parameters); return(SendAndParseExtractAsync(cmd)); }
public ElevateStateListener(ExtractCommand extractCommand) { this.extractCommand = extractCommand; }
public static void Main(string[] args) { App app = new App(); Program program = new Program(); app.SetCurrentCulture(); program.SetExtractValues(); CommandLineApplication commandLineApplication = new CommandLineApplication(true) { Description = "Extract Heroes of the Storm game data into XML and JSON format", }; commandLineApplication.HelpOption("-?|-h|--help"); commandLineApplication.VersionOption("-v|--version", $"Heroes Data Parser ({App.Version})"); ListCommand.Add(commandLineApplication).SetCommand(); ReadCommand.Add(commandLineApplication).SetCommand(); ExtractCommand.Add(commandLineApplication).SetCommand(); ImageCommand.Add(commandLineApplication).SetCommand(); QuickCompareCommand.Add(commandLineApplication).SetCommand(); V4ConvertCommand.Add(commandLineApplication).SetCommand(); CommandArgument storagePathArgument = commandLineApplication.Argument("storage-path", "The 'Heroes of the Storm' directory or an already extracted 'mods' directory."); CommandOption setOutputDirectoryOption = commandLineApplication.Option("-o|--output-directory <FILEPATH>", "Sets the output directory.", CommandOptionType.SingleValue); CommandOption setDescriptionOption = commandLineApplication.Option("-d|--description <VALUE>", "Sets the description output type (0 - 6) - Default: 0.", CommandOptionType.SingleValue); CommandOption extractDataFilesOption = commandLineApplication.Option("-e|--extract-data <VALUE>", $"Extracts data files - Default: herodata.", CommandOptionType.MultipleValue); CommandOption extractImageFilesOption = commandLineApplication.Option("-i|--extract-images <VALUE>", $"Extracts image files, only available using the Heroes of the Storm game directory.", CommandOptionType.MultipleValue); CommandOption setGameStringLocalizations = commandLineApplication.Option("-l|--localization <LOCALE>", "Sets the gamestring localization(s) - Default: enUS.", CommandOptionType.MultipleValue); CommandOption setBuildOption = commandLineApplication.Option("-b|--build <NUMBER>", "Sets the override build file(s).", CommandOptionType.SingleValue); CommandOption setMaxDegreeParallismOption = commandLineApplication.Option("-t|--threads <NUMBER>", "Limits the maximum amount of threads to use.", CommandOptionType.SingleValue); CommandOption xmlOutputOption = commandLineApplication.Option("--xml", "Creates xml output.", CommandOptionType.NoValue); CommandOption jsonOutputOption = commandLineApplication.Option("--json", "Creates json output.", CommandOptionType.NoValue); CommandOption setFileSplitOption = commandLineApplication.Option("--file-split", "Splits the XML and JSON file(s) into multiple files.", CommandOptionType.NoValue); CommandOption localizedTextOption = commandLineApplication.Option("--localized-text", "Extracts localized gamestrings from the XML and JSON file(s) into a text file.", CommandOptionType.NoValue); CommandOption minifyOption = commandLineApplication.Option("--minify", "Creates .min file(s) along with current output file(s).", CommandOptionType.NoValue); CommandOption validationWarningsOption = commandLineApplication.Option("--warnings", "Displays all validation warnings.", CommandOptionType.NoValue); commandLineApplication.OnExecute(() => { App.Defaults = false; if (extractImageFilesOption.HasValue() && !extractDataFilesOption.HasValue()) { return(InvalidCommand("You need to set the -e|--extract-data option")); } if (!string.IsNullOrWhiteSpace(storagePathArgument.Value)) { App.StoragePath = storagePathArgument.Value; } if (setMaxDegreeParallismOption.HasValue() && int.TryParse(setMaxDegreeParallismOption.Value(), out int result)) { App.MaxParallelism = result; } if (setDescriptionOption.HasValue() && Enum.TryParse(setDescriptionOption.Value(), out DescriptionType resultType)) { App.DescriptionType = resultType; } if (setBuildOption.HasValue() && int.TryParse(setBuildOption.Value(), out result)) { App.OverrideBuild = result; } if (setOutputDirectoryOption.HasValue()) { App.OutputDirectory = setOutputDirectoryOption.Value(); } else { App.OutputDirectory = Path.Combine(program.AssemblyPath, "output"); } // data file extraction if (extractDataFilesOption.HasValue()) { if (extractDataFilesOption.Values.Exists(x => x.Equals("ALL", StringComparison.OrdinalIgnoreCase))) { App.ExtractDataOption = ExtractDataOption.All; } else { foreach (ExtractDataOption extractDataOption in Enum.GetValues(typeof(ExtractDataOption))) { if (extractDataOption == ExtractDataOption.None || extractDataOption == ExtractDataOption.All) { continue; } if (program.ExtractDataValues.TryGetValue(extractDataOption, out List <string> values)) { if (extractDataFilesOption.Values.Intersect(values, StringComparer.OrdinalIgnoreCase).Any()) { App.ExtractDataOption |= extractDataOption; } } } } // none is default as defined in App if (App.ExtractDataOption != ExtractDataOption.None) { App.ExtractDataOption &= ~ExtractDataOption.None; } } else { App.ExtractDataOption = ExtractDataOption.HeroData; } // image file extraction if (extractImageFilesOption.HasValue() && !string.IsNullOrEmpty(storagePathArgument.Value)) { if (extractImageFilesOption.Values.Exists(x => x.Equals("ALL", StringComparison.OrdinalIgnoreCase))) { App.ExtractFileOption = ExtractImageOption.All; } else if (extractImageFilesOption.Values.Exists(x => x.Equals("ALL-SPLIT", StringComparison.OrdinalIgnoreCase) || x.Equals("ALLSPLIT", StringComparison.OrdinalIgnoreCase))) { App.ExtractFileOption = ExtractImageOption.AllSplit; } else { foreach (ExtractImageOption extractFileOption in Enum.GetValues(typeof(ExtractImageOption))) { if (extractFileOption == ExtractImageOption.None || extractFileOption == ExtractImageOption.All) { continue; } if (program.ExtractImageValues.TryGetValue(extractFileOption, out List <string> values)) { if (extractImageFilesOption.Values.Intersect(values, StringComparer.OrdinalIgnoreCase).Any()) { App.ExtractFileOption |= extractFileOption; } } } } // none is default as defined in App if (App.ExtractFileOption != ExtractImageOption.None) { App.ExtractFileOption &= ~ExtractImageOption.None; } } if (setGameStringLocalizations.HasValue()) { IEnumerable <string> localizations = new List <string>(); if (setGameStringLocalizations.Values.Exists(x => x.Equals("ALL", StringComparison.OrdinalIgnoreCase))) { localizations = Enum.GetNames(typeof(Localization)); } else { localizations = setGameStringLocalizations.Values; } foreach (string locale in localizations) { if (Enum.TryParse(locale, true, out Localization localization)) { app.Localizations.Add(localization); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Unknown localization - {locale}"); } } Console.ResetColor(); Console.WriteLine(); } else { app.Localizations.Add(Localization.ENUS); } App.CreateXml = xmlOutputOption.HasValue(); App.CreateJson = jsonOutputOption.HasValue(); // if both not set, default to both true if (!xmlOutputOption.HasValue() && !jsonOutputOption.HasValue()) { App.CreateXml = true; App.CreateJson = true; } App.ShowValidationWarnings = validationWarningsOption.HasValue(); App.IsFileSplit = setFileSplitOption.HasValue(); App.IsLocalizedText = localizedTextOption.HasValue(); App.CreateMinFiles = minifyOption.HasValue(); app.Run(); Console.ResetColor(); return(0); }); if (args != null && args.Length > 0) { try { commandLineApplication.Execute(args); } catch (CommandParsingException) { return; } } else // defaults { App.Defaults = true; app.Run(); } Console.ResetColor(); }
private static void ExtractSingle(BA2Archive archive, ExtractCommand cmd) { archive.Extract(cmd.Source, cmd.Destination, true); }
private static void GetCommandToExecute(string command, out ICommand commandToExecute, ExtractCommand extractCommand) { switch (command) { case "d": Console.Write("Enter delay between download calls: "); string timeOutInput = Console.ReadLine(); if (!int.TryParse(timeOutInput, out int timeOut)) { timeOut = 2000; } commandToExecute = new DownloadCommand(timeOut, extractCommand.links); return; case "p": commandToExecute = new PrintCommand(extractCommand.links); return; case "s": commandToExecute = new SaveCommand(extractCommand.links, ReadSaveFilePath()); return; } commandToExecute = null; }