/// <summary>
        /// Adds <see cref="ConsoleSerializer"/> the to <paramref name="logFactory"/>.
        /// </summary>
        /// <param name="logFactory">Log factory to extend.</param>
        /// <param name="formatter">Optional formatter.</param>
        /// <param name="filter">Optional filter.</param>
        /// <returns><see cref="ILogFactory.AddSerializer"/>.</returns>
        public static ILogFactory AddConsole(this ILogFactory logFactory, ILogFormatter formatter = null, ILogFilter filter = null)
        {
            Ensure.NotNull(logFactory, "logFactory");

            ILogSerializer serializer;

            if (formatter == null)
            {
                serializer = new ConsoleSerializer();
            }
            else
            {
                serializer = new ConsoleSerializer(formatter, filter ?? new AllowedLogFilter());
            }

            return(logFactory.AddSerializer(serializer));
        }
Exemple #2
0
        /// <summary>
        /// Gets the specified console using it's name as an identifier.
        /// </summary>
        /// <param name="name">The name of the console to get.</param>
        /// <param name="validate">if set to <c>true</c> [validate].</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public HyperValidator.Models.Console Get(String name, Boolean validate = false)
        {
            var console = new HyperValidator.Models.Console()
            {
                Name = name
            };

            var databasePath = PathUtility.Combine(Settings.HyperSpinRootLocation, "databases", console.Name, $"{console.Name}.xml");
            var database     = DatabaseSerializer.DeserializeFromFile(databasePath);

            console.Database = database;

            var settingsPath = PathUtility.Combine(Settings.HyperSpinRootLocation, "settings", $"{console.Name}.ini");

            if (!FileUtility.Exists(settingsPath))
            {
                throw new Exception($"Failed to find settings file for {name}");
            }

            var settings = ConsoleSerializer.DeserializeFromFile(settingsPath);

            console.Settings = settings;

            console.Status = ConsoleValidator.Validate(console);

            if (validate)
            {
                foreach (var game in console.Database.Games)
                {
                    var status = GameValidator.Validate(console, game);
                    OnGameValidated(status);
                    game.Status = status;
                }
                OnValidationComplete();
            }

            return(console);
        }