Skip to content

Commit

Permalink
Finish parser-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bcssov committed Apr 18, 2020
2 parents d946309 + 1a029bd commit ec5faaf
Show file tree
Hide file tree
Showing 25 changed files with 2,051 additions and 45 deletions.
11 changes: 8 additions & 3 deletions src/IronyModManager.DI/JsonConverters/JsonDIConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
// Created : 04-07-2020
//
// Last Modified By : Mario
// Last Modified On : 04-07-2020
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="JsonDIConverter.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;

Expand All @@ -33,8 +34,12 @@ internal class JsonDIConverter : JsonConverter
/// <returns><c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.</returns>
public override bool CanConvert(Type objectType)
{
var registration = DIResolver.GetImplementationType(objectType);
return registration != null;
if (!typeof(IEnumerable).IsAssignableFrom(objectType))
{
var registration = DIResolver.GetImplementationType(objectType);
return registration != null;
}
return false;
}

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion src/IronyModManager.Parser.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 02-16-2020
//
// Last Modified By : Mario
// Last Modified On : 03-31-2020
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="Constants.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -79,6 +79,11 @@ public static class Constants
/// </summary>
public static readonly string OnActionsPath = MergePath(CommonPath, "on_actions");

/// <summary>
/// The parser map path
/// </summary>
public static readonly string ParserMapPath = MergePath("Maps", "{0}ParserMap" + Shared.Constants.JsonExtension);

#endregion Fields

#region Methods
Expand Down
8 changes: 7 additions & 1 deletion src/IronyModManager.Parser.Common/Definitions/IDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 02-16-2020
//
// Last Modified By : Mario
// Last Modified On : 03-23-2020
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="IDefinition.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -86,6 +86,12 @@ public interface IDefinition : ICEFIndexedListItem
/// <value>The type and identifier.</value>
string TypeAndId { get; }

/// <summary>
/// Gets or sets the used parser.
/// </summary>
/// <value>The used parser.</value>
string UsedParser { get; set; }

/// <summary>
/// Gets or sets the type of the value.
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions src/IronyModManager.Parser.Common/IParserMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ***********************************************************************
// Assembly : IronyModManager.Parser.Common
// Author : Mario
// Created : 04-18-2020
//
// Last Modified By : Mario
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="IParserMap.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;

namespace IronyModManager.Parser.Common
{
/// <summary>
/// Interface IParserMap
/// </summary>
public interface IParserMap
{
#region Properties

/// <summary>
/// Gets or sets the directory path.
/// </summary>
/// <value>The directory path.</value>
string DirectoryPath { get; set; }

/// <summary>
/// Gets or sets the preferred parser.
/// </summary>
/// <value>The preferred parser.</value>
string PreferredParser { get; set; }

#endregion Properties
}
}
12 changes: 11 additions & 1 deletion src/IronyModManager.Parser.Common/Parsers/BaseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 02-17-2020
//
// Last Modified By : Mario
// Last Modified On : 04-03-2020
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="BaseParser.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -51,6 +51,16 @@ public BaseParser(ITextParser textParser)

#endregion Constructors

#region Properties

/// <summary>
/// Gets the name of the parser.
/// </summary>
/// <value>The name of the parser.</value>
public abstract string ParserName { get; }

#endregion Properties

#region Methods

/// <summary>
Expand Down
12 changes: 11 additions & 1 deletion src/IronyModManager.Parser.Common/Parsers/IDefaultParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 02-16-2020
//
// Last Modified By : Mario
// Last Modified On : 02-25-2020
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="IDefaultParser.cs" company="Mario">
// Mario
Expand All @@ -24,6 +24,16 @@ namespace IronyModManager.Parser.Common.Parsers
/// </summary>
public interface IDefaultParser
{
#region Properties

/// <summary>
/// Gets the name of the parser.
/// </summary>
/// <value>The name of the parser.</value>
string ParserName { get; }

#endregion Properties

#region Methods

/// <summary>
Expand Down
32 changes: 28 additions & 4 deletions src/IronyModManager.Parser.Tests/ParserManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 02-22-2020
//
// Last Modified By : Mario
// Last Modified On : 03-28-2020
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="ParserManagerTests.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -43,9 +43,11 @@ public void Should_invoke_game_parser()
var manager = new ParserManager(gameParser, genericParser, defaultParser);
var result = manager.Parse(new ParserManagerArgs()
{
File = "fake-game"
File = "fake-game",
GameType = "game"
});
result.First().File.Should().Be("game_parser");
result.First().UsedParser.Should().Be("GameParser");
}

/// <summary>
Expand All @@ -61,9 +63,11 @@ public void Should_invoke_generic_parser()
var manager = new ParserManager(gameParser, genericParser, defaultParser);
var result = manager.Parse(new ParserManagerArgs()
{
File = "fake-generic"
File = "fake-generic",
GameType = "game"
});
result.First().File.Should().Be("generic_parser");
result.First().UsedParser.Should().Be("GenericParser");
}

/// <summary>
Expand All @@ -79,9 +83,11 @@ public void Should_invoke_default_parser()
var manager = new ParserManager(gameParser, genericParser, defaultParser);
var result = manager.Parse(new ParserManagerArgs()
{
File = "fake"
File = "fake",
GameType = "game"
});
result.First().File.Should().Be("default_parser");
result.First().UsedParser.Should().Be("DefaultParser");
}

/// <summary>
Expand All @@ -93,6 +99,12 @@ public void Should_invoke_default_parser()
/// <seealso cref="IronyModManager.Parser.Default.IDefaultParser" />
class DefaultParser : IDefaultParser
{
/// <summary>
/// Gets the name of the parser.
/// </summary>
/// <value>The name of the parser.</value>
public string ParserName => nameof(DefaultParser);

/// <summary>
/// Parses the specified arguments.
/// </summary>
Expand All @@ -115,6 +127,12 @@ public IEnumerable<IDefinition> Parse(ParserArgs args)
/// <seealso cref="IronyModManager.Parser.Generic.IGenericParser" />
class GenericParser : IGenericParser
{
/// <summary>
/// Gets the name of the parser.
/// </summary>
/// <value>The name of the parser.</value>
public string ParserName => nameof(GenericParser);

/// <summary>
/// Gets the priority.
/// </summary>
Expand Down Expand Up @@ -153,6 +171,12 @@ public IEnumerable<IDefinition> Parse(ParserArgs args)
/// <seealso cref="IronyModManager.Parser.Games.IGameParser" />
class GameParser : IGameParser
{
/// <summary>
/// Gets the name of the parser.
/// </summary>
/// <value>The name of the parser.</value>
public string ParserName => nameof(GameParser);

/// <summary>
/// Gets the priority.
/// </summary>
Expand Down
Loading

0 comments on commit ec5faaf

Please sign in to comment.