/// <summary>
        /// Gets the config from the source. Disposes of the stream if used. Caches the configuration if found.
        /// </summary>
        /// <typeparam name="T">The configuration type</typeparam>
        /// <typeparam name="Tm">The configuration metadata type</typeparam>
        /// <param name="configurationMetadata">The metadata related to the configuration, default gathered from Type Data</param>
        /// <returns>The configuration</returns>
        protected virtual T GetConfigurationFromSource <T, Tm>(Tm configurationMetadata)
            where T : IConfiguration <T, Tm>, new()
            where Tm : IConfigurationMetadata <T, Tm>, new()
        {
            T configuration = default(T);

            try
            {
                using (Stream configurationStream = configurationMetadata.UseStream
                                        ? configurationMetadata.GetConfigurationStream()
                                        : File.OpenRead(configurationMetadata.ConfigurationLocation))
                {
                    if (configurationStream == null)
                    {
                        throw new InvalidOperationException("Unable to open configuration stream.");
                    }

                    configuration = SerializationService.DeserializeObject <T>(configurationStream);
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Unable to read or deserialize configuration using " +
                                                    (configurationMetadata.UseStream ? "Stream" : "Filesystem") + ". See Inner Exception for details.", ex);
            }

            configuration.ConfigurationMetadata = configurationMetadata;
            AddConfiguration <T, Tm>(configuration);

            return(configuration);
        }
Exemplo n.º 2
0
        protected Log <T> GetLogFromFile(string logPath)
        {
            Log <T> value = SerializationService.DeserializeObject <Log <T> >(File.ReadAllText(logPath));

            Visited[logPath] = value;
            return(value);
        }