Skip to content

Commit f18a044

Browse files
committed
Start implementation of the retrival of the procedures
1 parent b3ca10f commit f18a044

15 files changed

+274
-21
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using MGR.CommandLineParser.Extensibility.Command;
2+
3+
namespace MGR.CommandLineParser.Command.OracleProcedure
4+
{
5+
internal class CommandMetadata : ICommandMetadata
6+
{
7+
public CommandMetadata(string name)
8+
{
9+
Name = name;
10+
Description = name;
11+
Samples = new string[0];
12+
}
13+
public string Name { get; }
14+
15+
public string Description { get; }
16+
17+
public string Usage => string.Empty;
18+
19+
public string[] Samples { get; }
20+
21+
public bool HideFromHelpListing => false;
22+
}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using MGR.CommandLineParser.Extensibility.Command;
5+
6+
namespace MGR.CommandLineParser.Command.OracleProcedure
7+
{
8+
class CommandObjectBuilder : ICommandObjectBuilder
9+
{
10+
public CommandObjectBuilder(IEnumerable<CommandOption> options, )
11+
{
12+
13+
}
14+
public void AddArguments(string argument) => throw new NotImplementedException("Oracle procedures does not define unamed arguments");
15+
public ICommandOption FindOption(string optionName) => throw new NotImplementedException();
16+
public ICommandOption FindOptionByShortName(string optionShortName) => throw new NotImplementedException("Oracle procedures does not define 'short name' for the parameters");
17+
public ICommandObject GenerateCommandObject() => throw new NotImplementedException();
18+
public CommandValidationResult Validate(IServiceProvider serviceProvider) => throw new NotImplementedException();
19+
}
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using MGR.CommandLineParser.Extensibility.Command;
3+
4+
namespace MGR.CommandLineParser.Command.OracleProcedure
5+
{
6+
internal class CommandOption : ICommandOption
7+
{
8+
public bool ShouldProvideValue => throw new NotImplementedException();
9+
10+
public ICommandOptionMetadata Metadata => throw new NotImplementedException();
11+
12+
public void AssignValue(string optionValue) => throw new NotImplementedException();
13+
}
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using MGR.CommandLineParser.Extensibility.Command;
2+
3+
namespace MGR.CommandLineParser.Command.OracleProcedure
4+
{
5+
internal class CommandOptionMetadata : ICommandOptionMetadata
6+
{
7+
public CommandOptionMetadata(OptionDisplayInfo displayInfo, bool isRequired, string defaultValue)
8+
{
9+
DisplayInfo = displayInfo;
10+
IsRequired = isRequired;
11+
DefaultValue = defaultValue;
12+
}
13+
public bool IsRequired { get; }
14+
15+
public CommandOptionCollectionType CollectionType => CommandOptionCollectionType.None;
16+
17+
public IOptionDisplayInfo DisplayInfo { get; }
18+
19+
public string DefaultValue { get; }
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using MGR.CommandLineParser.Extensibility.Command;
4+
5+
namespace MGR.CommandLineParser.Command.OracleProcedure
6+
{
7+
internal class CommandType : ICommandType
8+
{
9+
private readonly IEnumerable<Parameter> _outParameters;
10+
11+
public CommandType(CommandMetadata commandMetadata, IEnumerable<CommandOptionMetadata> options, IEnumerable<Parameter> outParameters)
12+
{
13+
Metadata = commandMetadata;
14+
Options = options;
15+
_outParameters = outParameters;
16+
}
17+
public ICommandMetadata Metadata { get; }
18+
19+
public IEnumerable<ICommandOptionMetadata> Options { get; }
20+
21+
public ICommandObjectBuilder CreateCommandObjectBuilder(IServiceProvider serviceProvider) => throw new NotImplementedException();
22+
}
23+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using MGR.CommandLineParser.Extensibility.Command;
5+
using Microsoft.EntityFrameworkCore;
6+
7+
namespace MGR.CommandLineParser.Command.OracleProcedure
8+
{
9+
internal class CommandTypeProvider : ICommandTypeProvider
10+
{
11+
private readonly OracleSystemContext _dbContext;
12+
13+
public CommandTypeProvider(OracleSystemContext dbContext)
14+
{
15+
_dbContext = dbContext;
16+
}
17+
public async Task<IEnumerable<ICommandType>> GetAllCommandTypes()
18+
{
19+
var procedures = _dbContext.Procedures.Include(procedure => procedure.Parameters).ToListAsync();
20+
return procedures.Select(MapProcedureToCommandType);
21+
}
22+
public ICommandType GetCommandType(string commandName)
23+
{
24+
var procedure = _dbContext.Procedures.Include(procedure => procedure.Parameters).Where(procedure => procedure.Name == commandName).SingleOrDefault();
25+
if (procedure != null)
26+
{
27+
return MapProcedureToCommandType(procedure);
28+
}
29+
return null;
30+
}
31+
32+
private static CommandType MapProcedureToCommandType(Procedure procedure) => new CommandType(new CommandMetadata(procedure.Name),
33+
procedure.Parameters.Where(parameter => parameter.Direction.HasFlag(Direction.In)).Select(parameter => new CommandOptionMetadata(
34+
new OptionDisplayInfo(parameter.Name),
35+
!parameter.HasDefaultValue,
36+
parameter.DefaultValue)),
37+
procedure.Parameters.Where(parameter => parameter.Direction.HasFlag(Direction.Out));
38+
}
39+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace MGR.CommandLineParser.Command.OracleProcedure
4+
{
5+
[Flags]
6+
internal enum Direction
7+
{
8+
In = 1,
9+
Out = 2,
10+
InOut = 3
11+
}
12+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
5+
6+
namespace MGR.CommandLineParser.Command.OracleProcedure.Mapping
7+
{
8+
internal class ParameterMap : IEntityTypeConfiguration<Parameter>
9+
{
10+
public void Configure(EntityTypeBuilder<Parameter> builder)
11+
{
12+
builder.ToTable("USER_ARGUMENTS");
13+
14+
builder.Property(_ => _.Name)
15+
.HasColumnName("OBJECT_NAME");
16+
17+
var defaultValueConverter = new BoolToStringConverter("N", "Y");
18+
builder.Property(_ => _.HasDefaultValue)
19+
.HasColumnName("DEFAULTED")
20+
.HasConversion(defaultValueConverter);
21+
22+
builder.Property(_ => _.DefaultValue)
23+
.HasColumnName("DEFAULT_VALUE");
24+
25+
builder.Property(_ => _.DataType)
26+
.HasColumnName("DATA_TYPE");
27+
28+
var directionConverter = new ValueConverter<Direction, string>(
29+
_ => _.ToString(),
30+
value => ParseDirection(value));
31+
builder.Property(_ => _.Direction)
32+
.HasColumnName("IN_OUT")
33+
.HasConversion(directionConverter);
34+
}
35+
private static Direction ParseDirection(string value) => value
36+
switch
37+
{
38+
"IN" => Direction.In,
39+
"OUT" => Direction.Out,
40+
"IN/OUT" => Direction.InOut,
41+
_ => throw new ArgumentOutOfRangeException(nameof(value))
42+
};
43+
}
44+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
3+
4+
namespace MGR.CommandLineParser.Command.OracleProcedure.Mapping
5+
{
6+
internal class ProcedureMap : IEntityTypeConfiguration<Procedure>
7+
{
8+
public void Configure(EntityTypeBuilder<Procedure> builder)
9+
{
10+
builder.ToTable("ALL_OBJETS");
11+
12+
builder.Property(_ => _.Name)
13+
.HasColumnName("OBJECT_NAME");
14+
15+
builder.HasQueryFilter(_ => EF.Property<string>(_, "OBJECT_TYPE") == "PROCEDURE");
16+
}
17+
}
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using MGR.CommandLineParser.Extensibility.Command;
4+
5+
namespace MGR.CommandLineParser.Command.OracleProcedure
6+
{
7+
internal class OptionDisplayInfo : IOptionDisplayInfo
8+
{
9+
public OptionDisplayInfo(string name)
10+
{
11+
Name = name;
12+
Description = name;
13+
}
14+
public string Name { get; }
15+
16+
public IEnumerable<string> AlternateNames => Enumerable.Empty<string>();
17+
18+
public string ShortName => string.Empty;
19+
20+
public string Description { get; }
21+
}
22+
}

0 commit comments

Comments
 (0)