Exemplo n.º 1
0
        /// <summary>
        /// Read a multi-line value.
        /// </summary>
        /// <param name="parser"></param>
        /// <returns></returns>
        public static string ReadValueMultiLine(IIniParser parser)
        {
            StringBuilder buffer      = new StringBuilder();
            string        currentChar = string.Empty;

            // Read until ":" colon.
            while (currentChar != IniParserConstants.DoubleQuote)
            {
                // Escape char
                if (currentChar == IniParserConstants.Escape)
                {
                    currentChar = parser.Read().ToString();
                    buffer.Append(currentChar);
                }
                else
                {
                    buffer.Append(currentChar);
                }

                currentChar = parser.Read().ToString();
            }

            // Error out if current char is not ":".
            if (parser.CurrentChar != IniParserConstants.DoubleQuote)
            {
                parser.Errors.Add("Expected double quote '\"' to end multi-line value at : " + parser.CurrentCharIndex);
            }

            return(buffer.ToString());
        }
Exemplo n.º 2
0
        public ReadToOneBufferBenchmark()
        {
            if (Directory.Exists(TestDirectory))
            {
                Directory.Delete(TestDirectory, true);
            }

            Directory.CreateDirectory(TestDirectory);
            var fixture       = new Fixture();
            var customization = new SupportMutableValueTypesCustomization();

            var newParser = $"{TestDirectory}newParser";
            var oldParser = $"{TestDirectory}oldParser";

            customization.Customize(fixture);
            _iniParser    = new IniWrapper.ParserWrapper.IniParser(newParser, 1024);
            _oldIniParser = new OldParserWrapper.IniParser(oldParser, 1024);

            var configuration = fixture.Create <OldParserWrapper.Configuration>();

            var iniWrapper = new IniWrapperFactory().CreateWithDefaultIniParser(x =>
            {
                x.IniFilePath = newParser;
            });

            var oldIni = new IniWrapperFactory().CreateWithDefaultIniParser(x =>
            {
                x.IniFilePath = oldParser;
            });

            iniWrapper.SaveConfiguration(configuration);
            oldIni.SaveConfiguration(configuration);
        }
Exemplo n.º 3
0
        public static IIniWrapper CreateWithFileSystem(IIniParser iniParser)
        {
            var fileSystem = Substitute.For <IFileSystem>();

            fileSystem.File.Exists(Arg.Any <string>()).Returns(true);
            return(Create(iniParser, fileSystem));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Read the IniGroup name.
        /// [group1]
        /// </summary>
        /// <param name="parser"></param>
        /// <returns></returns>
        public static string ReadKey(IIniParser parser)
        {
            StringBuilder buffer = new StringBuilder();

            int iterationCount = 0;

            // Read until ":" colon.
            while (parser.CurrentChar != IniParserConstants.Colon.ToString() &&
                   iterationCount <= parser.Settings.MaxLengthOfKey)
            {
                buffer.Append(parser.CurrentChar);
                iterationCount++;

                // Advance the parser to next char.
                parser.Read();
            }

            // Error out if current char is not ":".
            if (parser.CurrentChar != IniParserConstants.Colon.ToString())
            {
                parser.Errors.Add("Expected colon ':' at : " + parser.CurrentCharIndex);
            }
            else
            {
                // Advance the parser to after the ":" colon.
                parser.Read();
            }

            return(buffer.ToString());
        }
Exemplo n.º 5
0
        public ReadBenchmark()
        {
            Directory.CreateDirectory(TestDirectory);
            _rawIniParser = new IniParser($"{TestDirectory}rawBenchmark.ini", BufferSize);
            _iniWrapper   = new IniWrapperFactory().CreateWithDefaultIniParser(x =>
            {
                x.IniFilePath = $"{TestDirectory}benchmark.ini";
                x.DefaultIniWrapperBufferSize = BufferSize;
            });

            _configurationBenchmark = new ConfigurationBenchmark()
            {
                Test        = 10,
                Age         = 20,
                Description = "TestDescription",
                ListInt     = new List <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
                },
                InnerConfiguration = new InnerConfiguration()
                {
                    Description = "Description1234",
                    Age         = 100
                }
            };

            _iniWrapper.SaveConfiguration(_configurationBenchmark);
        }
Exemplo n.º 6
0
        internal IIniWrapper CreateWithFileSystem(IniSettings iniSettings, IIniParser iniParser, IFileSystem fileSystem)
        {
            var converterFactory = new IniConverterFactory(new TypeManager(), iniSettings);

            var savingManager = new SavingManager(new IniValueManager(new IniValueAttributeManager()), iniParser, converterFactory);

            var readingManager = new ReadingManager(new IniValueManager(new IniValueAttributeManager()), converterFactory, iniParser);

            var defaultConfigurationCreationStrategy = new ConfigurationLoadingChecker(fileSystem, iniSettings);

            var iniWrapperInternal = new IniWrapperInternal(savingManager, readingManager);

            var iniWrapperForImmutableTypeFactory = new IniWrapperForImmutableTypeFactory(iniWrapperInternal, readingManager);
            var iniInternalFactory = new IniWrapperInternalFactory(new IniConstructorChecker(), iniWrapperInternal, iniWrapperForImmutableTypeFactory);

            var iniWrapper = new IniWrapper(defaultConfigurationCreationStrategy, iniInternalFactory, new MemberInfoFactory());

            var iniWrapperWithCustomMemberInfoForImmutableTypeFactory = new IniWrapperWithCustomMemberInfoForImmutableTypeFactory(iniWrapperInternal, readingManager);
            var iniWrapperWithCustomMemberInfoManager = new IniWrapperWithCustomMemberInfoManager(iniWrapperInternal,
                                                                                                  new IniConstructorChecker(),
                                                                                                  iniWrapperWithCustomMemberInfoForImmutableTypeFactory);

            converterFactory.IniWrapper = iniWrapper;
            converterFactory.IniWrapperWithCustomMemberInfo = iniWrapperWithCustomMemberInfoManager;

            return(iniWrapper);
        }
 public IniFileReader(
     ITextFileReader fileReader,
     IIniParser parser)
 {
     this.fileReader = fileReader;
     this.parser     = parser;
 }
Exemplo n.º 8
0
 public ReadingManager(IIniValueManager iniValueManager,
                       IIniConverterFactory iniConverterFactory,
                       IIniParser iniParser)
 {
     _iniValueManager     = iniValueManager;
     _iniConverterFactory = iniConverterFactory;
     _iniParser           = iniParser;
 }
Exemplo n.º 9
0
        public IIniWrapper Create(Action <IniSettings> iniSettings, IIniParser iniParser)
        {
            var settings = new IniSettings();

            iniSettings(settings);

            return(Create(settings, iniParser));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Read the IniGroup name.
        /// [group1]
        /// </summary>
        /// <param name="parser"></param>
        /// <returns></returns>
        public static string ReadComment(IIniParser parser)
        {
            StringBuilder buffer = new StringBuilder();

            // Exclude the "[" bracket from consuming the token("group name").
            string comment = parser.ReadTokenToEndOfLine();

            return(comment);
        }
Exemplo n.º 11
0
 public IniContext(IMemberInfoWrapper memberInfoWrapper,
                   TypeDetailsInformation typeDetailsInformation,
                   IniValue iniValue,
                   IIniParser iniParser,
                   IIniConverter defaultConverter)
 {
     MemberInfoWrapper      = memberInfoWrapper;
     TypeDetailsInformation = typeDetailsInformation;
     IniValue         = iniValue;
     IniParser        = iniParser;
     DefaultConverter = defaultConverter;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Read the IniGroup name.
        /// [group1]
        /// </summary>
        /// <param name="parser"></param>
        /// <returns></returns>
        public static string ReadValue(IIniParser parser)
        {
            StringBuilder buffer = new StringBuilder();

            // Get rid of starting whitespace.
            parser.ConsumeWhiteSpace();

            if (parser.CurrentChar != IniParserConstants.DoubleQuote)
            {
                return(parser.ReadTokenToEndOfLine());
            }

            return(ReadValueMultiLine(parser));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Read the IniGroup name.
        /// [group1]
        /// </summary>
        /// <param name="parser"></param>
        /// <returns></returns>
        public static string ReadGroup(IIniParser parser)
        {
            StringBuilder buffer = new StringBuilder();

            // Exclude the "[" bracket from consuming the token("group name").
            if (parser.CurrentChar == IniParserConstants.BracketLeft)
            {
                parser.Read();
            }

            int iterationCount = 0;

            // Read until "]" right bracket.
            while (parser.CurrentChar != IniParserConstants.BracketRight &&
                   iterationCount <= parser.Settings.MaxLengthOfGroup)
            {
                buffer.Append(parser.CurrentChar);
                iterationCount++;

                // Advance the parser to next char.
                parser.Read();
            }

            // Error out if current char is not "]".
            if (parser.CurrentChar != IniParserConstants.BracketRight)
            {
                parser.Errors.Add("Expected closing bracket ']' at : " + parser.CurrentCharIndex);
            }
            else
            {
                // Advance the parser to after the "]" closing bracket.
                parser.Read();
            }

            return(buffer.ToString());
        }
Exemplo n.º 14
0
 public static IIniWrapper Create(IIniParser iniParser, IFileSystem fileSystem)
 {
     return(Create(new IniSettings(), iniParser, fileSystem));
 }
Exemplo n.º 15
0
 public IIniWrapper Create(IIniParser iniParser)
 {
     return(Create(new IniSettings(), iniParser));
 }
Exemplo n.º 16
0
 public SavingManager(IIniValueManager iniValueManager, IIniParser iniParser, IIniConverterFactory iniConverterFactory)
 {
     _iniValueManager     = iniValueManager;
     _iniParser           = iniParser;
     _iniConverterFactory = iniConverterFactory;
 }
Exemplo n.º 17
0
 public FileIniParser(IIniParser iniParser)
 => _parser = iniParser;
Exemplo n.º 18
0
        public IIniWrapper Create(IniSettings iniSettings, IIniParser iniParser)
        {
            CheckSettings(iniSettings);

            return(CreateWithFileSystem(iniSettings, iniParser, new FileSystem()));
        }
Exemplo n.º 19
0
 public void SetUp()
 {
     _iniParser  = Substitute.For <IIniParser>();
     _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser);
 }
Exemplo n.º 20
0
 public static IIniWrapper Create(IniSettings iniSettings, IIniParser iniParser, IFileSystem fileSystem)
 {
     return(new IniWrapperFactory().CreateWithFileSystem(iniSettings, iniParser, fileSystem));
 }