Example #1
0
        public async Task LoadLibraryAsync(string fileName, bool precache = false)
        {
            try
            {
                LoadProgress?.Invoke(this, new TransitionLibraryProgressEventArgs(0, 1, "loading transitions settings"));
                var transitions = await ConfigParser.ParseAsync(fileName);

                foreach (var transition in transitions)
                {
                    TransitionData?transitionData = null;
                    switch (transition[0])
                    {
                    case "SoundAndGif":
                        float.TryParse(transition[3], out var duration);
                        transitionData = new SoundAndGifTransitionData(transition[1], transition[2], duration);

                        break;
                    }
                    if (transitionData != null)
                    {
                        if (TransitionCache.ContainsKey(transitionData.Hash))
                        {
                            TransitionCache[transitionData.Hash].Count++;
                        }
                        else
                        {
                            TransitionCache.Add(transitionData.Hash, transitionData);
                        }
                    }
                }
                ListReady?.Invoke(this, null);
                if (precache)
                {
                    int current = 0;
                    int total   = TransitionCache.Count();
                    while (current < TransitionCache.Count())
                    {
                        var    toCache = TransitionCache.Skip(current).Take(2).ToList();
                        Task[] tasks   = toCache.Select(tc => tc.Value.PreloadAsync()).ToArray();
                        await Task.WhenAll(tasks);

                        current += toCache.Count();
                        LoadProgress?.Invoke(this, new TransitionLibraryProgressEventArgs(current, total, "Preloading"));
                    }
                }
            }
            catch (Exception ex)
            {
                CustomMainForm.Log($"{ex.StackTrace}");
                CustomMainForm.Log($"{ex.Message}");
            }
            finally
            {
                LoadComplete?.Invoke(this, null);
            }
        }