Ejemplo n.º 1
0
        /// <inheritdoc />
        public void LoadDirectory(ResourcePath path)
        {
            var sawmill = Logger.GetSawmill("eng");

            _hasEverBeenReloaded = true;
            var yamlStreams = _resources.ContentFindFiles(path).ToList().AsParallel()
                              .Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith("."))
                              .Select(filePath =>
            {
                try
                {
                    using var reader = new StreamReader(_resources.ContentFileRead(filePath), EncodingHelpers.UTF8);
                    var yamlStream   = new YamlStream();
                    yamlStream.Load(reader);

                    var result = ((YamlStream? yamlStream, ResourcePath?))(yamlStream, filePath);

                    LoadedData?.Invoke(yamlStream, filePath.ToString());

                    return(result);
                }
                catch (YamlException e)
                {
                    sawmill.Error("YamlException whilst loading prototypes from {0}: {1}", filePath, e.Message);
                    return(null, null);
                }
            })
                              .Where(p => p.yamlStream != null) // Filter out loading errors.
                              .ToList();

            foreach (var(stream, filePath) in yamlStreams)
            {
                for (var i = 0; i < stream.Documents.Count; i++)
                {
                    try
                    {
                        LoadFromDocument(stream.Documents[i]);
                    }
                    catch (Exception e)
                    {
                        Logger.ErrorS("eng", $"Exception whilst loading prototypes from {filePath}#{i}:\n{e}");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void LoadFromStream(TextReader stream)
        {
            _hasEverBeenReloaded = true;
            var yaml = new YamlStream();

            yaml.Load(stream);

            for (int i = 0; i < yaml.Documents.Count; i++)
            {
                try
                {
                    LoadFromDocument(yaml.Documents[i]);
                }
                catch (Exception e)
                {
                    throw new PrototypeLoadException(string.Format("Failed to load prototypes from document#{0}", i), e);
                }
            }

            LoadedData?.Invoke(yaml, "anonymous prototypes YAML stream");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Normally a <pre>video</pre> element doesn't have a <pre>change</pre> event.
        /// We force one and a use it as a proxy for all the Media Events.
        /// </summary>
        /// <param name="args">The event args - Value contains our JSON</param>
        protected virtual void OnChange(ChangeEventArgs args)
        {
            var            ThisEvent = args?.Value?.ToString();
            VideoEventData videoData = new VideoEventData();

            try
            {
                videoData = JsonSerializer.Deserialize <VideoEventData>(ThisEvent, serializationOptions);
            }
            catch (Exception ex)
            {
                LoggerFactory
                .CreateLogger(nameof(VideoExComponentBase))
                .LogError(ex, "Failed to convert the JSON: {0}", ThisEvent);
            }

            switch (videoData.EventName)
            {
            case VideoEvents.Abort:
                Abort?.Invoke(videoData.State);
                AbortEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.CanPlay:
                CanPlay?.Invoke(videoData.State);
                CanPlayEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.CanPlayThrough:
                CanPlayThrough?.Invoke(videoData.State);
                CanPlayThroughEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.DurationChange:
                DurationChange?.Invoke(videoData.State);
                DurationChangeEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Emptied:
                Emptied?.Invoke(videoData.State);
                EmptiedEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Ended:
                Ended?.Invoke(videoData.State);
                EndedEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Error:
                Error?.Invoke(videoData.State);
                ErrorEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.LoadedData:
                LoadedData?.Invoke(videoData.State);
                LoadedDataEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.LoadedMetadata:
                LoadedMetadata?.Invoke(videoData.State);
                LoadedMetadataEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.LoadStart:
                LoadStart?.Invoke(videoData.State);
                LoadStartEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Pause:
                Pause?.Invoke(videoData.State);
                PauseEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Play:
                Play?.Invoke(videoData.State);
                PlayEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Playing:
                Playing?.Invoke(videoData.State);
                PlayingEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Progress:
                Progress?.Invoke(videoData.State);
                ProgressEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.RateChange:
                RateChange?.Invoke(videoData.State);
                RateChangeEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Seeked:
                Seeking?.Invoke(videoData.State);
                SeekingEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Seeking:
                Seeking?.Invoke(videoData.State);
                SeekingEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Stalled:
                Stalled?.Invoke(videoData.State);
                StalledEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Suspend:
                Suspend?.Invoke(videoData.State);
                SuspendEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.TimeUpdate:
                TimeUpdate?.Invoke(videoData.State);
                TimeUpdateEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.VolumeChange:
                VolumeChange?.Invoke(videoData.State);
                VolumeChangeEvent.InvokeAsync(videoData.State);
                break;

            case VideoEvents.Waiting:
                Waiting?.Invoke(videoData.State);
                WaitingEvent.InvokeAsync(videoData.State);
                break;

            default:
                break;
            }
            // Here is our catch-all event handler call!
            EventFired?.Invoke(videoData);
        }