Ejemplo n.º 1
0
        protected virtual void OnError(FileLoadExceptionContext context)
        {
            Ensure.That(context, nameof(context)).IsNotNull();

            if (context.Exception == null || context.Ignore)
            {
                return;
            }

            GD.Print("Failed to load configuration file: " + context.Exception);
            GD.Print(context.Exception.StackTrace);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the default configuration file if it's missing.
        /// </summary>
        /// <returns></returns>
        private void CreateDefaultConfigurationFile(FileLoadExceptionContext fileContext)
        {
            if (fileContext.Exception is FileNotFoundException)
            {
                _createDefaultConfigurationFileNeeded = true;

                _logger.LogWarning($"Missing configuration file {ConfigurationFileName}, creating one with default values.");

                //default file created, no need to throw error
                fileContext.Ignore = true;
            }
            else
            {
                throw new ForgeBuilderException("Invalid settings file", fileContext.Exception);
            }
        }
Ejemplo n.º 3
0
        private static IDictionary <string, string> CreateAndSaveDefaultValues(
            string fullPath)
        {
            using (var stream = new FileStream(fullPath, FileMode.Open))
            {
                try
                {
                    Load(stream);
                }
                catch (Exception e)
                {
                    bool ignoreException = false;
                    if (Source.OnLoadException != null)
                    {
                        var exceptionContext = new FileLoadExceptionContext
                        {
                            Provider  = this,
                            Exception = e
                        };
                        Source.OnLoadException.Invoke(exceptionContext);
                        ignoreException = exceptionContext.Ignore;
                    }
                    if (!ignoreException)
                    {
                        throw e;
                    }
                }
            }

            // Quotes (c)2005 Universal Pictures: Serenity
            // https://www.uphe.com/movies/serenity
            var configValues = new Dictionary <string, string>
            {
                { "quote1", "I aim to misbehave." },
                { "quote2", "I swallowed a bug." },
                { "quote3", "You can't stop the signal, Mal." }
            };

            return(configValues);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the default configuration file if it's missing.
        /// </summary>
        /// <returns></returns>
        private void CreateDefaultConfigurationFile(HostBuilderContext hostingContext, FileLoadExceptionContext context)
        {
            this.createDefaultConfigurationFileNeeded = true;
            this.ConfigurationFileName = context.Provider.Source.Path;

            //default file created, no need to throw error
            context.Ignore = true;
        }
Ejemplo n.º 5
0
 protected virtual void OnError([NotNull] FileLoadExceptionContext context)
 {
 }