public void MatchTeamByRegex_InvalidRegex() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Team t1 = CreateTeam("Inkology"); t1.AddClanTag("¡g", Builtins.ManualSource, TagOption.Front); Team t2 = CreateTeam("Inkfected"); t2.AddClanTag("τイ", Builtins.ManualSource, TagOption.Front); database.expectedTeams = new List <Team> { t1, t2 }; controller.LoadDatabase(); Team[] matched = controller.MatchTeam("[", new MatchOptions { IgnoreCase = true, QueryIsRegex = true }); Assert.IsNotNull(matched); Assert.AreEqual(0, matched.Length); }
public void MatchTeamAmbiguous() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); Team t1 = CreateTeam("Team 17"); t1.AddClanTag("x", Builtins.ManualSource, TagOption.Front); Team t2 = CreateTeam("Example 18"); t2.AddClanTag("e", Builtins.ManualSource, TagOption.Front); database.expectedTeams = new List <Team> { t1, t2 }; controller.Initialise(); // Match 'e' which will match the 'e' for a tag and 'e' in team Team[] matched = controller.MatchTeam("e"); Assert.IsNotNull(matched); Assert.IsTrue(matched.Length == 2); // Assert that the returned order is t2 then t1. Assert.IsTrue(matched[0] == t2); Assert.IsTrue(matched[1] == t1); }
/// <summary> /// Patch the current Database. Optionally save. /// </summary> /// <param name="saveFolder">The working directory of the Controller. Set to null for default handling.</param> /// <returns>The Generic Importer and the Controller.</returns> /// <exception cref="Exception">This method may throw based on the Initialisation method.</exception> public static void GenerateDatabasePatch( string patchFile, string?saveFolder = null) { Console.WriteLine($"GenerateDatabasePatch called with patchFile={patchFile}, saveFolder={saveFolder}..."); if (saveFolder == null) { saveFolder = Directory.GetParent(patchFile).FullName; } try { WinApi.TryTimeBeginPeriod(1); Directory.CreateDirectory(saveFolder); // Load. SplatTagJsonSnapshotDatabase splatTagJsonSnapshotDatabase = new SplatTagJsonSnapshotDatabase(saveFolder); GenericFilesToIImporters iImporters = new GenericFilesToIImporters(saveFolder, patchFile); MultiDatabase database = new MultiDatabase() .With(splatTagJsonSnapshotDatabase) .With(iImporters); SplatTagController splatTagController = new SplatTagController(database); splatTagController.Initialise(); // Now that we've initialised, take a snapshot of everything. SaveDatabase(splatTagController, splatTagJsonSnapshotDatabase); } finally { WinApi.TryTimeEndPeriod(1); } }
public void BuildControllerTest() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Assert.IsTrue(database.loadCalled); }
public void LoadDatabaseTest() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Assert.IsTrue(database.loadCalled); database.loadCalled = false; Team exampleTeam = new Team("Example Team", Builtins.ManualSource); exampleTeam.AddClanTag("e.g", Builtins.ManualSource, TagOption.Front); exampleTeam.AddDivision(new Division(1, DivType.DSB), Builtins.ManualSource); var TEAM_ID = exampleTeam.Id; database.expectedTeams = new List <Team> { exampleTeam }; var PLAYER_NAME = "Example Name"; database.expectedPlayers = new List <Player> { new Player(PLAYER_NAME, new Guid[] { TEAM_ID }, Builtins.ManualSource) }; var PLAYER_ID = database.expectedPlayers[0].Id; controller.LoadDatabase(); Assert.IsTrue(database.loadCalled); // Also check the player and team is now in the controller var players = controller.MatchPlayer(PLAYER_ID.ToString(), new MatchOptions { FilterOptions = FilterOptions.SlappId }); Assert.IsNotNull(players.FirstOrDefault()); var player = players[0]; Assert.IsTrue(player.Name.Value == PLAYER_NAME); var teams = controller.MatchTeam(TEAM_ID.ToString(), new MatchOptions { FilterOptions = FilterOptions.SlappId }); Assert.IsNotNull(teams.FirstOrDefault()); var team = teams[0]; Assert.IsTrue(team.CurrentDiv.Value == 1); Assert.IsTrue(team.CurrentDiv.DivType == DivType.DSB); // Verify getting the players for that team returns our player var playersForExampleTeam = controller.GetPlayersForTeam(exampleTeam); Assert.IsNotNull(playersForExampleTeam); Assert.IsTrue(playersForExampleTeam.Count == 1); Assert.IsTrue(playersForExampleTeam[0].player.Equals(player)); }
public void MatchPlayerNoMatchTest() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Player[] matched = controller.MatchPlayer("example"); Assert.IsNotNull(matched); Assert.IsTrue(matched.Length == 0); }
public void MatchTeamNoMatchTest() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Team[] matched = controller.MatchTeam("WO"); Assert.IsNotNull(matched); Assert.IsTrue(matched.Length == 0); }
public void MatchPlayerByNameTest() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Player p1 = CreatePlayer("Player 17"); // Purposefully mixed case database.expectedPlayers = new List <Player> { p1 }; controller.LoadDatabase(); Player[] matched = controller.MatchPlayer("player"); // Purposefully mixed case Assert.IsNotNull(matched); Assert.IsTrue(matched.Length == 1); }
public void MatchPlayerByTagTest_NearMatched() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Player p1 = CreatePlayer("BΛÐ SΛVΛGΞ"); database.expectedPlayers = new List <Player> { p1 }; controller.LoadDatabase(); Player[] matched = controller.MatchPlayer("bad savage"); Assert.IsNotNull(matched); Assert.IsTrue(matched.Length == 1); }
public void MatchTeamByNameTest() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Team t = CreateTeam("Team 17"); // Purposefully mixed case t.AddClanTag("WO", Builtins.ManualSource, TagOption.Front); // Purposefully upper-case database.expectedTeams = new List <Team> { t }; controller.LoadDatabase(); Team[] matched = controller.MatchTeam("team"); // Purposefully mixed case Assert.IsNotNull(matched); Assert.IsTrue(matched.Length == 1); }
public void MatchPlayersAmbiguous() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Player p1 = CreatePlayer("Player 17"); Player p2 = CreatePlayer("Player 18"); database.expectedPlayers = new List <Player> { p1, p2 }; controller.LoadDatabase(); Player[] matched = controller.MatchPlayer("lay"); Assert.IsNotNull(matched); Assert.IsTrue(matched.Length == 2); }
public void MatchTeamByTagTest_NearMatched() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Team t = CreateTeam("Inkology"); t.AddClanTag("¡g", Builtins.ManualSource, TagOption.Front); database.expectedTeams = new List <Team> { t }; controller.LoadDatabase(); Team[] matched = controller.MatchTeam("ig"); // Note i != ¡ Assert.IsNotNull(matched); Assert.IsTrue(matched.Length == 1); }
public void MatchPlayerByTagTest_ExactMatched() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Player p1 = CreatePlayer("BΛÐ SΛVΛGΞ"); database.expectedPlayers = new List <Player> { p1 }; controller.LoadDatabase(); Player[] matched = controller.MatchPlayer("BΛÐ SΛVΛGΞ", new MatchOptions { IgnoreCase = false, NearCharacterRecognition = false }); Assert.IsNotNull(matched); Assert.IsTrue(matched.Length == 1); }
public void MatchPlayerByRegex_InvalidRegex() { UnitTestDatabase database = new UnitTestDatabase(); SplatTagController controller = new SplatTagController(database); controller.Initialise(); Player p1 = CreatePlayer("¡g Slate"); Player p2 = CreatePlayer("Slate*NBF"); database.expectedPlayers = new List <Player> { p1, p2 }; controller.LoadDatabase(); Player[] matched = controller.MatchPlayer("[", new MatchOptions { IgnoreCase = true, QueryIsRegex = true }); Assert.IsNotNull(matched); Assert.AreEqual(0, matched.Length); }
/// <summary> /// Generate a new Database. Optionally save. /// </summary> /// <param name="saveFolder">The working directory of the Controller. Set to null for default handling.</param> /// <returns>The Generic Importer and the Controller.</returns> /// <exception cref="Exception">This method may throw based on the Initialisation method.</exception> public static (GenericFilesToIImporters, SplatTagController) GenerateNewDatabase( string?saveFolder = null, string?sourcesFile = null) { Console.WriteLine($"GenerateNewDatabase called with saveFolder={saveFolder}, sourcesFile={sourcesFile}..."); if (sourcesFile == null) { sourcesFile = GenericFilesToIImporters.DefaultSourcesFileName; if (saveFolder == null) { saveFolder = GetDefaultPath(); } } else if (saveFolder == null) { saveFolder = Directory.GetParent(sourcesFile).FullName; } try { WinApi.TryTimeBeginPeriod(1); // Directories created in GenericFilesToIImporters GenericFilesToIImporters sourcesImporter = new GenericFilesToIImporters(saveFolder, sourcesFile); MultiDatabase splatTagDatabase = new MultiDatabase().With(sourcesImporter); SplatTagController splatTagController = new SplatTagController(splatTagDatabase); Console.WriteLine($"Full load of {sourcesImporter.Sources.Count} files from dir {Path.GetFullPath(saveFolder)}..."); splatTagController.Initialise(); // Now that we've initialised, take a snapshot of everything. SaveDatabase(splatTagController, saveFolder); return(sourcesImporter, splatTagController); } finally { WinApi.TryTimeEndPeriod(1); } }
/// <summary> /// Create the <see cref="SplatTagController"/> and an optional <see cref="GenericFilesToIImporters"/>. /// </summary> /// <param name="suppressLoad">Suppress the initialisation of the database. Can be used for a rebuild.</param> /// <param name="saveFolder">Optional save folder. If null, defaults to %appdata%/SplatTag.</param> /// <param name="sourcesFile">Optional sources file. If null, defaults to default sources.yaml</param> /// <returns>SplatTagController and GenericFilesImporter if one was created.</returns> public static (SplatTagController, GenericFilesToIImporters?) CreateController(bool suppressLoad = false, string?saveFolder = null, string?sourcesFile = null) { if (saveFolder == null) { saveFolder = GetDefaultPath(); } Directory.CreateDirectory(saveFolder); GenericFilesToIImporters? sourcesImporter = null; SplatTagJsonSnapshotDatabase snapshotDatabase = new SplatTagJsonSnapshotDatabase(saveFolder); SplatTagController splatTagController = new SplatTagController(snapshotDatabase); if (suppressLoad) { return(splatTagController, sourcesImporter); } // Try a load here. // If we were able to load from a snapshot then we don't need the other importers. // Otherwise, do the processing and record the snapshot. try { splatTagController.Initialise(); if (splatTagController.MatchPlayer(null).Length == 0) { (sourcesImporter, splatTagController) = GenerateNewDatabase( saveFolder: saveFolder, sourcesFile: sourcesFile); } } catch (Exception ex) { string error = $"Unable to initialise the {nameof(SplatTagController)} because of an exception:\n {ex} \n"; Console.Error.WriteLine(error); Console.WriteLine(error); } return(splatTagController, sourcesImporter); }
static SlappCommand() { // Initialise Slapp try { // Construct the database jsonDatabase = new SplatTagJsonDatabase(saveFolder); multiSourceImporter = new GenericFilesImporter(saveFolder); splatTagDatabase = new MultiDatabase(saveFolder, jsonDatabase, multiSourceImporter); // Construct the controller. splatTagController = new SplatTagController(splatTagDatabase); initialiseTask = Task.Run(() => { // Load the database splatTagController.Initialise(); }); } catch (Exception ex) { throw new InvalidOperationException("Exception: " + ex.ToString()); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); // Get our UI controls from the loaded layout EditText enteredQuery = FindViewById <EditText>(Resource.Id.enteredQuery); playersResults = FindViewById <TextView>(Resource.Id.playersResults); teamsResults = FindViewById <TextView>(Resource.Id.teamsResults); Button goButton = FindViewById <Button>(Resource.Id.goButton); // Get the asset files List <string> sources = new List <string>(); try { Directory.CreateDirectory(splatTagFolder); // Unpack the assets AssetManager assetManager = this.ApplicationContext.Assets; foreach (var file in from string file in assetManager.List("") where Path.GetExtension(file) == ".json" && !File.Exists(Path.Combine(splatTagFolder, file)) select file) { // Read the contents of our asset string content; using (StreamReader sr = new StreamReader(assetManager.Open(file))) { content = sr.ReadToEnd(); } string fileSource = Path.Combine(splatTagFolder, file); sources.Add(fileSource); File.WriteAllText(fileSource, content); } } catch (Exception ex) { teamsResults.Text = ex.ToString(); Toast.MakeText(this, "Exception: " + ex.ToString(), ToastLength.Long).Show(); } try { // Construct the database snapshotDatabase = new SplatTagJsonSnapshotDatabase(splatTagFolder); splatTagController = new SplatTagController(snapshotDatabase); // Load the database splatTagController.Initialise(); // Hook up events enteredQuery.AfterTextChanged += (sender, e) => Search(enteredQuery.Text); goButton.Click += (sender, e) => Search(enteredQuery.Text); } catch (Exception ex) { playersResults.Text = ex.ToString(); Toast.MakeText(this, "Exception: " + ex.ToString(), ToastLength.Long).Show(); } }