Beispiel #1
0
        public void TestScopedReadWithoutContext()
        {
            RunTestWithRealm((realmFactory, _) =>
            {
                ILive <RealmBeatmap>?liveBeatmap = null;
                Task.Factory.StartNew(() =>
                {
                    using (var threadContext = realmFactory.CreateContext())
                    {
                        var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));

                        liveBeatmap = beatmap.ToLive(realmFactory);
                    }
                }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();

                Debug.Assert(liveBeatmap != null);

                Task.Factory.StartNew(() =>
                {
                    liveBeatmap.PerformRead(beatmap =>
                    {
                        Assert.IsTrue(beatmap.IsValid);
                        Assert.IsFalse(beatmap.Hidden);
                    });
                }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
            });
        }
Beispiel #2
0
Datei: Skin.cs Projekt: bdach/osu
        protected Skin(SkinInfo skin, IStorageResourceProvider resources, [CanBeNull] Stream configurationStream = null)
        {
            SkinInfo       = skin.ToLive();
            this.resources = resources;

            configurationStream ??= getConfigurationStream();

            if (configurationStream != null)
            {
                // stream will be closed after use by LineBufferedReader.
                ParseConfigurationStream(configurationStream);
            }
            else
            {
                Configuration = new SkinConfiguration();
            }

            // skininfo files may be null for default skin.
            SkinInfo.PerformRead(s =>
            {
                // we may want to move this to some kind of async operation in the future.
                foreach (SkinnableTarget skinnableTarget in Enum.GetValues(typeof(SkinnableTarget)))
                {
                    string filename = $"{skinnableTarget}.json";

                    // skininfo files may be null for default skin.
                    var fileInfo = s.Files.FirstOrDefault(f => f.Filename == filename);

                    if (fileInfo == null)
                    {
                        continue;
                    }

                    byte[] bytes = resources?.Files.Get(fileInfo.File.GetStoragePath());

                    if (bytes == null)
                    {
                        continue;
                    }

                    try
                    {
                        string jsonContent      = Encoding.UTF8.GetString(bytes);
                        var deserializedContent = JsonConvert.DeserializeObject <IEnumerable <SkinnableInfo> >(jsonContent);

                        if (deserializedContent == null)
                        {
                            continue;
                        }

                        DrawableComponentInfo[skinnableTarget] = deserializedContent.ToArray();
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "Failed to load skin configuration.");
                    }
                }
            });
        }
Beispiel #3
0
 private void assertImportedOnce(ILive <SkinInfo> import1, ILive <SkinInfo> import2)
 {
     import1.PerformRead(i1 => import2.PerformRead(i2 =>
     {
         Assert.That(i2.ID, Is.EqualTo(i1.ID));
         Assert.That(i2.Hash, Is.EqualTo(i1.Hash));
         Assert.That(i2.Files.First(), Is.EqualTo(i1.Files.First()));
     }));
 }
Beispiel #4
0
        public void TestLiveAssumptions()
        {
            RunTestWithRealm((realmFactory, _) =>
            {
                int changesTriggered = 0;

                using (var updateThreadContext = realmFactory.CreateContext())
                {
                    updateThreadContext.All <RealmBeatmap>().QueryAsyncWithNotifications(gotChange);
                    ILive <RealmBeatmap>?liveBeatmap = null;

                    Task.Factory.StartNew(() =>
                    {
                        using (var threadContext = realmFactory.CreateContext())
                        {
                            var ruleset = CreateRuleset();
                            var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));

                            // add a second beatmap to ensure that a full refresh occurs below.
                            // not just a refresh from the resolved Live.
                            threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));

                            liveBeatmap = beatmap.ToLive(realmFactory);
                        }
                    }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();

                    Debug.Assert(liveBeatmap != null);

                    // not yet seen by main context
                    Assert.AreEqual(0, updateThreadContext.All <RealmBeatmap>().Count());
                    Assert.AreEqual(0, changesTriggered);

                    liveBeatmap.PerformRead(resolved =>
                    {
                        // retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point.
                        // ReSharper disable once AccessToDisposedClosure
                        Assert.AreEqual(2, updateThreadContext.All <RealmBeatmap>().Count());
                        Assert.AreEqual(1, changesTriggered);

                        // can access properties without a crash.
                        Assert.IsFalse(resolved.Hidden);

                        // ReSharper disable once AccessToDisposedClosure
                        updateThreadContext.Write(r =>
                        {
                            // can use with the main context.
                            r.Remove(resolved);
                        });
                    });
                }

                void gotChange(IRealmCollection <RealmBeatmap> sender, ChangeSet changes, Exception error)
                {
                    changesTriggered++;
                }
            });
        }
Beispiel #5
0
Datei: Skin.cs Projekt: bdach/osu
        private Stream getConfigurationStream()
        {
            string path = SkinInfo.PerformRead(s => s.Files.SingleOrDefault(f => f.Filename.Equals(@"skin.ini", StringComparison.OrdinalIgnoreCase))?.File.GetStoragePath());

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            return(resources?.Files.GetStream(path));
        }
Beispiel #6
0
        private void assertCorrectMetadata(ILive <SkinInfo> import1, string name, string creator, OsuGameBase osu)
        {
            import1.PerformRead(i =>
            {
                Assert.That(i.Name, Is.EqualTo(name));
                Assert.That(i.Creator, Is.EqualTo(creator));

                // for extra safety let's reconstruct the skin, reading from the skin.ini.
                var instance = i.CreateInstance((IStorageResourceProvider)osu.Dependencies.Get(typeof(SkinManager)));

                Assert.That(instance.Configuration.SkinInfo.Name, Is.EqualTo(name));
                Assert.That(instance.Configuration.SkinInfo.Creator, Is.EqualTo(creator));
            });
        }