Beispiel #1
0
        /// <summary>
        /// Reads the mappings file from the file system
        /// and returns its contents in a <see cref="FileStream" />.
        /// </summary>
        /// <param name="name">The file name of the mappings file.</param>
        /// <param name="location">The relative or absolute path to the folder
        /// that includes the file.</param>
        /// <returns>A <see cref="FileStream" /> pointing to the mappings file contents,
        /// or null if the file is not found.</returns>
        public Stream GetMappingsFile(string name, string location)
        {
            string fullname = FileSystemMappingsReader.ParseFileName(name, location);

            try
            {
                FileStream stream = new FileStream(fullname, FileMode.Open);
                if (stream == null)
                {
                    throw new MappingsReaderException(READER_EXCEPTION);
                }

                return(stream);
            }
            catch (Exception ex)
            {
                throw new MappingsReaderException(READER_EXCEPTION, ex);
            }
        }
		private static IMappingsReader GetMappingsReader()
		{
			ConfigurationSettings settings = ConfigurationSettings.Settings;
			MappingsFileSource location = settings.MappingsFileSource;

			IMappingsReader reader;
			switch (location)
			{
				case MappingsFileSource.Assembly:
					reader = new AssemblyMappingsReader();
					break;
				case MappingsFileSource.FileSystem:
					reader = new FileSystemMappingsReader();
					break;
				default:
					throw new ConfigurationErrorsException("Specified Mappings File Source in configuration file is unknown or invalid.");
			}

			return reader;
		}
		public void GetFileSystemMappings()
		{
			IMappingsReader reader = new FileSystemMappingsReader();
			reader.GetMappingsFile("Mappings.config", AppDomain.CurrentDomain.BaseDirectory);
		}