private void LoadPacks() { _allPathableResourceManagers = new List <PathableResourceManager>(); var iconProgressIndicator = new Progress <string>((report) => { GameService.Pathing.Icon.LoadingMessage = report; }); var dirDataReader = new DirectoryReader(_markerDirectory); var dirResourceManager = new PathableResourceManager(dirDataReader); _allPathableResourceManagers.Add(dirResourceManager); dirDataReader.LoadOnFileType((Stream fileStream, IDataReader dataReader) => { PackFormat.TacO.Readers.MarkerPackReader.ReadFromXmlPack(fileStream, dirResourceManager); }, ".xml", iconProgressIndicator); // TODO: Cleanup string[] packFiles = Directory.GetFiles(_markerDirectory, "*.zip", SearchOption.AllDirectories); foreach (string packFile in packFiles) { // Potentially contains many packs within var zipDataReader = new ZipArchiveReader(packFile); var zipResourceManager = new PathableResourceManager(zipDataReader); _allPathableResourceManagers.Add(zipResourceManager); zipDataReader.LoadOnFileType((Stream fileStream, IDataReader dataReader) => { PackFormat.TacO.Readers.MarkerPackReader.ReadFromXmlPack(fileStream, zipResourceManager); }, ".xml", iconProgressIndicator); } }
public void TestImportBeatmapThenCleanup() { RunTestWithRealmAsync(async(realmFactory, storage) => { using (var importer = new BeatmapImporter(realmFactory, storage)) using (new RealmRulesetStore(realmFactory, storage)) { ILive <RealmBeatmapSet>?imported; using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream())) imported = await importer.Import(reader); Assert.AreEqual(1, realmFactory.Context.All <RealmBeatmapSet>().Count()); Assert.NotNull(imported); Debug.Assert(imported != null); imported.PerformWrite(s => s.DeletePending = true); Assert.AreEqual(1, realmFactory.Context.All <RealmBeatmapSet>().Count(s => s.DeletePending)); } }); Logger.Log("Running with no work to purge pending deletions"); RunTestWithRealm((realmFactory, _) => { Assert.AreEqual(0, realmFactory.Context.All <RealmBeatmapSet>().Count()); }); }
public override void SetUp() { using (var resources = new DllResourceStore(typeof(TestResources).Assembly)) using (var archive = resources.GetStream("Resources/Archives/241526 Soleily - Renatus.osz")) using (var reader = new ZipArchiveReader(archive)) reader.GetStream("Soleily - Renatus (Gamu) [Insane].osu").CopyTo(beatmapStream); }
public WaveformTestBeatmap(AudioManager audioManager) : base(new BeatmapInfo(), audioManager) { stream = TestResources.GetTestBeatmapStream(); reader = new ZipArchiveReader(stream); trackStore = audioManager.GetTrackStore(reader); }
public void AddFromExtension() { // Arrange var zipArchive = ZipFile.Open(@"Samples\IFRST_2017-03-09.zip", ZipArchiveMode.Read); var fileReader = new ZipArchiveReader(zipArchive); var taxonomySource = new TaxonomyFileSet(fileReader); var dts = new DiscoverableTaxonomySet(); var baseTaxonomy = dts.AddTaxonomy(new Uri("http://xbrl.ifrs.org/taxonomy/2017-03-09/full_ifrs_entry_point_2017-03-09.xsd"), taxonomySource); XNamespace bSharpNamespace = "http://banan-it.com/taxonomy/2018-07-05/bsharp"; XNamespace ifrsNamespace = "http://xbrl.ifrs.org/taxonomy/2017-03-09/ifrs-full"; var extension = new TaxonomyExtension("banan", bSharpNamespace); var concept1 = new ExtensionConcept("ComputerEquipment", DataTypeRegistry.Monetary, BalanceTypes.Debit, PeriodTypes.Instant); concept1.AddLabel("Computer equipment", "en"); concept1.AddLocation(new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-800100"), ifrsNamespace + "PropertyPlantAndEquipmentAbstract", ifrsNamespace + "OfficeEquipment"); extension.ExtensionItems.Add(concept1); var member1 = new ExtensionMember("BestPaintMember"); member1.AddLabel("Best Paint", "en"); member1.AddLocation( ifrsNamespace + "DisclosureOfOperatingSegmentsTable", ifrsNamespace + "SegmentsAxis", ifrsNamespace + "ReportableSegmentsMember", null); extension.ExtensionItems.Add(member1); // Act var extensionTaxonomy = dts.AddTaxonomy(new Uri("banan-20180710.xsd", UriKind.Relative), extension); }
public void WriteAsInlineXbrlFiling() { // Arrange var zipArchive = ZipFile.Open(@"Samples\IFRST_2017-03-09.zip", ZipArchiveMode.Read); var fileReader = new ZipArchiveReader(zipArchive); var taxonomySource = new TaxonomyFileSet(fileReader); var instance = LoadInstanceFromExcelDocument(@"Samples\BSharpIfrsFactsValuesSampleV1.xlsx"); instance.Dts.AddTaxonomy(new Uri("http://xbrl.ifrs.org/taxonomy/2017-03-09/full_ifrs_entry_point_2017-03-09.xsd"), taxonomySource); AddExtensionTaxonomy(instance.Dts); var writerSettings = new InlineXbrlFilingWriterSettings { Title = "iXBRL Export", Culture = new CultureInfo("en-GB"), Scale = 3, Scope = new ScopeSettings { PresentationNetworks = GetSupportedPresentationNetworks() }, InlineXbrlFileName = "banan-20180710.xhtml" }; // Act var xTemplate = XDocument.Load(@"Samples\iXBRL.xhtml"); var writer = new InlineXbrlFilingWriter(xTemplate, writerSettings); instance.Save(writer); // Assert File.WriteAllBytes(@"C:\temp\banan-20180710.zip", writer.ZipArchiveBytes); }
public void WriteAsWord() { // Arrange var zipArchive = ZipFile.Open(@"Samples\IFRST_2017-03-09.zip", ZipArchiveMode.Read); var fileReader = new ZipArchiveReader(zipArchive); var taxonomySource = new TaxonomyFileSet(fileReader); var instance = LoadInstanceFromExcelDocument(@"Samples\BSharpIfrsFactsValuesSampleV1.xlsx"); instance.Dts.AddTaxonomy(new Uri("http://xbrl.ifrs.org/taxonomy/2017-03-09/full_ifrs_entry_point_2017-03-09.xsd"), taxonomySource); AddExtensionTaxonomy(instance.Dts); var writerSettings = new WordWriterSettings { Culture = new CultureInfo("en-GB"), Scale = 3, Scope = new ScopeSettings { PresentationNetworks = GetSupportedPresentationNetworks() }, }; // Act var templateBytes = File.ReadAllBytes(@"Samples\Word.docx"); var writer = new WordWriter(templateBytes, writerSettings); instance.Save(writer); // Assert File.WriteAllBytes(@"C:\temp\banan-20180710.docx", writer.DocumentBytes); }
public void TestReadBeatmaps() { using (var osz = TestResources.GetTestBeatmapStream()) { var reader = new ZipArchiveReader(osz); string[] expected = { "Soleily - Renatus (Deif) [Platter].osu", "Soleily - Renatus (Deif) [Rain].osu", "Soleily - Renatus (Deif) [Salad].osu", "Soleily - Renatus (ExPew) [Another].osu", "Soleily - Renatus (ExPew) [Hyper].osu", "Soleily - Renatus (ExPew) [Normal].osu", "Soleily - Renatus (Gamu) [Hard].osu", "Soleily - Renatus (Gamu) [Insane].osu", "Soleily - Renatus (Gamu) [Normal].osu", "Soleily - Renatus (MMzz) [Futsuu].osu", "Soleily - Renatus (MMzz) [Muzukashii].osu", "Soleily - Renatus (MMzz) [Oni].osu" }; string[] maps = reader.Filenames.ToArray(); foreach (string map in expected) { Assert.Contains(map, maps); } } }
public void TestReadMetadata() { using (var osz = TestResources.GetTestBeatmapStream()) { var reader = new ZipArchiveReader(osz); Beatmap beatmap; using (var stream = new LineBufferedReader(reader.GetStream("Soleily - Renatus (Deif) [Platter].osu"))) beatmap = Decoder.GetDecoder <Beatmap>(stream).Decode(stream); var meta = beatmap.Metadata; Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet.OnlineBeatmapSetID); Assert.AreEqual("Soleily", meta.Artist); Assert.AreEqual("Soleily", meta.ArtistUnicode); Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile); Assert.AreEqual("Deif", meta.Author.Username); Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile); Assert.AreEqual(164471, meta.PreviewTime); Assert.AreEqual(string.Empty, meta.Source); Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", meta.Tags); Assert.AreEqual("Renatus", meta.Title); Assert.AreEqual("Renatus", meta.TitleUnicode); } }
public void TestAddFileToAsyncImportedBeatmap() { RunTestWithRealm((realm, storage) => { BeatmapSetInfo?detachedSet = null; using (var importer = new BeatmapModelManager(realm, storage)) using (new RealmRulesetStore(realm, storage)) { Task.Run(async() => { Live <BeatmapSetInfo>?beatmapSet; using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream())) // ReSharper disable once AccessToDisposedClosure beatmapSet = await importer.Import(reader); Assert.NotNull(beatmapSet); Debug.Assert(beatmapSet != null); // Intentionally detach on async thread as to not trigger a refresh on the main thread. beatmapSet.PerformRead(s => detachedSet = s.Detach()); }).WaitSafely(); Debug.Assert(detachedSet != null); importer.AddFile(detachedSet, new MemoryStream(), "test"); } }); }
private void LoadPacks() { _currentReader = new MarkerPackReader(); _allPathableResourceManagers = new List <PathableResourceManager>(); var iconProgressIndicator = new Progress <string>((report) => { _mapIcon.LoadingMessage = report; }); var dirDataReader = new DirectoryReader(_markerDirectory); var dirResourceManager = new PathableResourceManager(dirDataReader); _allPathableResourceManagers.Add(dirResourceManager); dirDataReader.LoadOnFileType((Stream fileStream, IDataReader dataReader) => { _currentReader.ReadFromXmlPack(fileStream, dirResourceManager); }, ".xml", iconProgressIndicator); // Load archive marker packs List <string> zipPackFiles = new List <string>(); zipPackFiles.AddRange(Directory.GetFiles(_markerDirectory, "*.zip", SearchOption.AllDirectories)); zipPackFiles.AddRange(Directory.GetFiles(_markerDirectory, "*.taco", SearchOption.AllDirectories)); foreach (string packFile in zipPackFiles) { // Potentially contains many packs within var zipDataReader = new ZipArchiveReader(packFile); var zipResourceManager = new PathableResourceManager(zipDataReader); _allPathableResourceManagers.Add(zipResourceManager); zipDataReader.LoadOnFileType((Stream fileStream, IDataReader dataReader) => { _currentReader.ReadFromXmlPack(fileStream, zipResourceManager); }, ".xml", iconProgressIndicator); } _packsLoaded = true; }
public void TestUpdateDetachedBeatmapSet() { RunTestWithRealmAsync(async(realm, storage) => { using (var importer = new BeatmapModelManager(realm, storage)) using (new RealmRulesetStore(realm, storage)) { Live <BeatmapSetInfo>?beatmapSet; using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream())) beatmapSet = await importer.Import(reader); Assert.NotNull(beatmapSet); Debug.Assert(beatmapSet != null); // Detach at the BeatmapInfo point, similar to what GetWorkingBeatmap does. BeatmapInfo?detachedBeatmap = null; beatmapSet.PerformRead(s => detachedBeatmap = s.Beatmaps.First().Detach()); BeatmapSetInfo?detachedBeatmapSet = detachedBeatmap?.BeatmapSet; Debug.Assert(detachedBeatmapSet != null); var newUser = new RealmUser { Username = "******", OnlineID = 2 }; detachedBeatmapSet.Beatmaps.First().Metadata.Artist = "New Artist"; detachedBeatmapSet.Beatmaps.First().Metadata.Author = newUser; Assert.AreNotEqual(detachedBeatmapSet.Status, BeatmapOnlineStatus.Ranked); detachedBeatmapSet.Status = BeatmapOnlineStatus.Ranked; beatmapSet.PerformWrite(s => { detachedBeatmapSet.CopyChangesToRealm(s); }); beatmapSet.PerformRead(s => { // Check above changes explicitly. Assert.AreEqual(BeatmapOnlineStatus.Ranked, s.Status); Assert.AreEqual("New Artist", s.Beatmaps.First().Metadata.Artist); Assert.AreEqual(newUser, s.Beatmaps.First().Metadata.Author); Assert.NotZero(s.Files.Count); // Check nothing was lost in the copy operation. Assert.AreEqual(s.Files.Count, detachedBeatmapSet.Files.Count); Assert.AreEqual(s.Files.Select(f => f.File).Count(), detachedBeatmapSet.Files.Select(f => f.File).Count()); Assert.AreEqual(s.Beatmaps.Count, detachedBeatmapSet.Beatmaps.Count); Assert.AreEqual(s.Beatmaps.Select(f => f.Difficulty).Count(), detachedBeatmapSet.Beatmaps.Select(f => f.Difficulty).Count()); Assert.AreEqual(s.Metadata, detachedBeatmapSet.Metadata); }); } }); }
public void AddFromFileSet() { // Arrange var zipArchive = ZipFile.Open(@"Samples\IFRST_2017-03-09.zip", ZipArchiveMode.Read); var fileReader = new ZipArchiveReader(zipArchive); var taxonomySource = new TaxonomyFileSet(fileReader); // Act var dts = new DiscoverableTaxonomySet(); var taxonomy = dts.AddTaxonomy(new Uri("http://xbrl.ifrs.org/taxonomy/2017-03-09/full_ifrs_entry_point_2017-03-09.xsd"), taxonomySource); }
public void TestReadFile() { using (var osz = TestResources.GetTestBeatmapStream()) { var reader = new ZipArchiveReader(osz); using (var stream = new StreamReader(reader.GetStream("Soleily - Renatus (Deif) [Platter].osu"))) { Assert.AreEqual("osu file format v13", stream.ReadLine()?.Trim()); } } }
public void WriteBaseTaxonomy() { // Arrange var zipArchive = ZipFile.Open(@"Samples\IFRST_2017-03-09.zip", ZipArchiveMode.Read); var fileReader = new ZipArchiveReader(zipArchive); var taxonomySource = new TaxonomyFileSet(fileReader); var dts = new DiscoverableTaxonomySet(); var baseTaxonomy = dts.AddTaxonomy(new Uri("http://xbrl.ifrs.org/taxonomy/2017-03-09/full_ifrs_entry_point_2017-03-09.xsd"), taxonomySource); // Act var writer = new ZipArchiveWriter(); baseTaxonomy.Save(writer); // Assert File.WriteAllBytes(@"C:\temp\IFRST_2017-03-09-exported.zip", writer.ZipArchiveBytes); }
public override void Invoke() { base.Invoke(); if (!NamedParameters.ContainsKey("entry")) { Context.Logger.WriteLine("Parameter 'entry' is missing."); return; } var entry = NamedParameters["entry"]; IFileReader fileReader; if (NamedParameters.ContainsKey("manifest")) { var manifest = NamedParameters["manifest"]; var manifestReader = new ManifestResourcesReader(GetType()); var stream = manifestReader.GetStream(manifest); var zipArchive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: false); fileReader = new ZipArchiveReader(zipArchive); } else if (NamedParameters.ContainsKey("archive")) { var archive = NamedParameters["archive"]; var zipArchive = ZipFile.Open(archive, ZipArchiveMode.Read); fileReader = new ZipArchiveReader(zipArchive); } else if (NamedParameters.ContainsKey("dir")) { var dir = NamedParameters["dir"]; fileReader = new FileSystemReader(dir); } else { Context.Logger.WriteLine("You must specify either dir, manifest or archive to define the source location of the entry point."); return; } var taxonomySource = new TaxonomyFileSet(fileReader); Instance.Dts.AddTaxonomy(new Uri(entry), taxonomySource); }
public void TestDetachBeatmapSet() { RunTestWithRealmAsync(async(realm, storage) => { using (var importer = new BeatmapModelManager(realm, storage)) using (new RealmRulesetStore(realm, storage)) { Live <BeatmapSetInfo>?beatmapSet; using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream())) beatmapSet = await importer.Import(reader); Assert.NotNull(beatmapSet); Debug.Assert(beatmapSet != null); BeatmapSetInfo?detachedBeatmapSet = null; beatmapSet.PerformRead(live => { detachedBeatmapSet = live.Detach(); // files are omitted Assert.AreEqual(0, detachedBeatmapSet.Files.Count); Assert.AreEqual(live.Beatmaps.Count, detachedBeatmapSet.Beatmaps.Count); Assert.AreEqual(live.Beatmaps.Select(f => f.Difficulty).Count(), detachedBeatmapSet.Beatmaps.Select(f => f.Difficulty).Count()); Assert.AreEqual(live.Metadata, detachedBeatmapSet.Metadata); }); Debug.Assert(detachedBeatmapSet != null); // Check detached instances can all be accessed without throwing. Assert.AreEqual(0, detachedBeatmapSet.Files.Count); Assert.NotNull(detachedBeatmapSet.Beatmaps.Count); Assert.NotZero(detachedBeatmapSet.Beatmaps.Select(f => f.Difficulty).Count()); Assert.NotNull(detachedBeatmapSet.Metadata); // Check cyclic reference to beatmap set Assert.AreEqual(detachedBeatmapSet, detachedBeatmapSet.Beatmaps.First().BeatmapSet); } }); }
public void WriteAsXbrl() { // Arrange var zipArchive = ZipFile.Open(@"Samples\IFRST_2017-03-09.zip", ZipArchiveMode.Read); var fileReader = new ZipArchiveReader(zipArchive); var taxonomySource = new TaxonomyFileSet(fileReader); var instance = LoadInstanceFromExcelDocument(@"Samples\BSharpIfrsFactsValuesSampleV1.xlsx"); instance.Dts.AddTaxonomy(new Uri("http://xbrl.ifrs.org/taxonomy/2017-03-09/full_ifrs_entry_point_2017-03-09.xsd"), taxonomySource); AddExtensionTaxonomy(instance.Dts); // Act var writer = new XbrlWriter(); instance.Save(writer); // Assert File.WriteAllText(@"C:\temp\banan-20180710.xml", writer.Document.ToString()); }
private static BeatmapInfo getTestBeatmapInfo(string archiveFile) { BeatmapInfo info; using (var archive = new ZipArchiveReader(File.OpenRead(archiveFile))) using (var stream = archive.GetStream("Soleily - Renatus (Gamu) [Insane].osu")) using (var reader = new LineBufferedReader(stream)) { var decoder = Decoder.GetDecoder <Beatmap>(reader); var beatmap = decoder.Decode(reader); info = beatmap.BeatmapInfo; info.BeatmapSet.Beatmaps = new List <BeatmapInfo> { info }; info.BeatmapSet.Metadata = info.Metadata; info.MD5Hash = stream.ComputeMD5Hash(); info.Hash = stream.ComputeSHA2Hash(); } return(info); }
public void TestReadMetadata() { using (var osz = Resource.OpenResource("Beatmaps.241526 Soleily - Renatus.osz")) { var reader = new ZipArchiveReader(osz); BeatmapMetadata meta; using (var stream = new StreamReader(reader.GetStream("Soleily - Renatus (Deif) [Platter].osu"))) meta = Decoder.GetDecoder <Beatmap>(stream).Decode(stream).Metadata; Assert.AreEqual(241526, meta.OnlineBeatmapSetID); Assert.AreEqual("Soleily", meta.Artist); Assert.AreEqual("Soleily", meta.ArtistUnicode); Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile); Assert.AreEqual("Deif", meta.AuthorString); Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile); Assert.AreEqual(164471 + LegacyBeatmapDecoder.UniversalOffset, meta.PreviewTime); Assert.AreEqual(string.Empty, meta.Source); Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", meta.Tags); Assert.AreEqual("Renatus", meta.Title); Assert.AreEqual("Renatus", meta.TitleUnicode); } }
public WaveformTestBeatmap() : base(new BeatmapInfo()) { stream = File.OpenRead(ImportBeatmapTest.TEST_OSZ_PATH); reader = new ZipArchiveReader(stream); }
/// <summary> /// Downloads a beatmap. /// This will post notifications tracking progress. /// </summary> /// <param name="beatmapSetInfo">The <see cref="BeatmapSetInfo"/> to be downloaded.</param> /// <param name="noVideo">Whether the beatmap should be downloaded without video. Defaults to false.</param> public void Download(BeatmapSetInfo beatmapSetInfo, bool noVideo = false) { var existing = GetExistingDownload(beatmapSetInfo); if (existing != null || api == null) { return; } if (!api.LocalUser.Value.IsSupporter) { PostNotification?.Invoke(new SimpleNotification { Icon = FontAwesome.fa_superpowers, Text = "You gotta be an osu!supporter to download for now 'yo" }); return; } var downloadNotification = new ProgressNotification { CompletionText = $"Imported {beatmapSetInfo.Metadata.Artist} - {beatmapSetInfo.Metadata.Title}!", Text = $"Downloading {beatmapSetInfo.Metadata.Artist} - {beatmapSetInfo.Metadata.Title}", }; var request = new DownloadBeatmapSetRequest(beatmapSetInfo, noVideo); request.DownloadProgressed += progress => { downloadNotification.State = ProgressNotificationState.Active; downloadNotification.Progress = progress; }; request.Success += data => { downloadNotification.Text = $"Importing {beatmapSetInfo.Metadata.Artist} - {beatmapSetInfo.Metadata.Title}"; Task.Factory.StartNew(() => { // This gets scheduled back to the update thread, but we want the import to run in the background. using (var stream = new MemoryStream(data)) using (var archive = new ZipArchiveReader(stream, beatmapSetInfo.ToString())) Import(archive); downloadNotification.State = ProgressNotificationState.Completed; currentDownloads.Remove(request); }, TaskCreationOptions.LongRunning); }; request.Failure += error => { if (error is OperationCanceledException) { return; } downloadNotification.State = ProgressNotificationState.Cancelled; Logger.Error(error, "Beatmap download failed!"); currentDownloads.Remove(request); }; downloadNotification.CancelRequested += () => { request.Cancel(); currentDownloads.Remove(request); downloadNotification.State = ProgressNotificationState.Cancelled; return(true); }; currentDownloads.Add(request); PostNotification?.Invoke(downloadNotification); // don't run in the main api queue as this is a long-running task. Task.Factory.StartNew(() => request.Perform(api), TaskCreationOptions.LongRunning); BeatmapDownloadBegan?.Invoke(request); }
private void UnpackInternalModules() { var internalModulesReader = new ZipArchiveReader("ref.dat"); internalModulesReader.LoadOnFileType(ExtractPackagedModule, MODULE_EXTENSION); }
public WaveformTestBeatmap() : base(new BeatmapInfo()) { stream = TestResources.GetTestBeatmapStream(); reader = new ZipArchiveReader(stream); }