Skip to content

Commit 3e2bfa9

Browse files
committed
Start implementation of the retrival of the procedures
1 parent dd8676e commit 3e2bfa9

16 files changed

+348
-0
lines changed

MGR.CommandLineParser.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MGR.CommandLineParser.Hosti
4141
EndProject
4242
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "docs", "docs\docs.csproj", "{405858FA-1E78-48C7-9915-B558D0F15CAE}"
4343
EndProject
44+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MGR.CommandLineParser.Command.OracleProcedure", "src\MGR.CommandLineParser.Command.OracleProcedure\MGR.CommandLineParser.Command.OracleProcedure.csproj", "{738CC3C0-16C1-45FB-B1D0-A21E8FA9D7D9}"
45+
EndProject
4446
Global
4547
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4648
Debug|Any CPU = Debug|Any CPU
@@ -79,6 +81,10 @@ Global
7981
{405858FA-1E78-48C7-9915-B558D0F15CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
8082
{405858FA-1E78-48C7-9915-B558D0F15CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
8183
{405858FA-1E78-48C7-9915-B558D0F15CAE}.Release|Any CPU.Build.0 = Release|Any CPU
84+
{738CC3C0-16C1-45FB-B1D0-A21E8FA9D7D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
85+
{738CC3C0-16C1-45FB-B1D0-A21E8FA9D7D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
86+
{738CC3C0-16C1-45FB-B1D0-A21E8FA9D7D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
87+
{738CC3C0-16C1-45FB-B1D0-A21E8FA9D7D9}.Release|Any CPU.Build.0 = Release|Any CPU
8288
EndGlobalSection
8389
GlobalSection(SolutionProperties) = preSolution
8490
HideSolutionNode = FALSE
@@ -92,6 +98,7 @@ Global
9298
{9F5A0142-E0A1-45A2-961E-55611B4440AD} = {FB795A12-C939-492F-9377-4C468D01EF3C}
9399
{40EAA8E2-7AFE-4ED1-A961-35BD7E424985} = {FB795A12-C939-492F-9377-4C468D01EF3C}
94100
{405858FA-1E78-48C7-9915-B558D0F15CAE} = {172E24C2-BF99-4DA9-A7DF-8C0BB44C138D}
101+
{738CC3C0-16C1-45FB-B1D0-A21E8FA9D7D9} = {FB795A12-C939-492F-9377-4C468D01EF3C}
95102
EndGlobalSection
96103
GlobalSection(ExtensibilityGlobals) = postSolution
97104
SolutionGuid = {827031C5-AE76-4B4C-9503-E13F15B497E9}

docs/procedure/oracle/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Use Oracle procedure commands
2+
3+
You can use stored procedure from Oracle database to represent your commands.
4+
5+
This allow you to call stored procedures via the parser
6+
(to create command-line or web-based tool).
7+
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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.Common;
4+
using MGR.CommandLineParser.Extensibility.Command;
5+
6+
namespace MGR.CommandLineParser.Command.OracleProcedure
7+
{
8+
internal class CommandObjectBuilder : ICommandObjectBuilder
9+
{
10+
private IEnumerable<ICommandOptionMetadata> _options;
11+
private IEnumerable<Parameter> _outParameters;
12+
private DbConnection _dbConnection;
13+
14+
public CommandObjectBuilder(IEnumerable<ICommandOptionMetadata> options, IEnumerable<Parameter> outParameters, DbConnection dbConnection)
15+
{
16+
_options = options;
17+
_outParameters = outParameters;
18+
_dbConnection = dbConnection;
19+
}
20+
21+
public void AddArguments(string argument) => throw new NotImplementedException("Oracle procedures does not define unamed arguments");
22+
public ICommandOption FindOption(string optionName)
23+
{
24+
throw new NotImplementedException();
25+
}
26+
27+
public ICommandOption FindOptionByShortName(string optionShortName)
28+
{
29+
throw new NotImplementedException($"Oracle procedures does not define 'short name' for the parameters ('{ optionShortName }')");
30+
}
31+
32+
public ICommandObject GenerateCommandObject()
33+
{
34+
throw new NotImplementedException();
35+
}
36+
37+
public CommandValidationResult Validate(IServiceProvider serviceProvider)
38+
{
39+
throw new NotImplementedException();
40+
}
41+
}
42+
}
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.Common;
4+
using MGR.CommandLineParser.Extensibility.Command;
5+
6+
namespace MGR.CommandLineParser.Command.OracleProcedure
7+
{
8+
internal class CommandType : ICommandType
9+
{
10+
private readonly IEnumerable<Parameter> _outParameters;
11+
private readonly DbConnection _dbConnection;
12+
13+
public CommandType(CommandMetadata commandMetadata, IEnumerable<CommandOptionMetadata> options, IEnumerable<Parameter> outParameters, DbConnection dbConnection)
14+
{
15+
Metadata = commandMetadata;
16+
Options = options;
17+
_outParameters = outParameters;
18+
_dbConnection = dbConnection;
19+
}
20+
public ICommandMetadata Metadata { get; }
21+
22+
public IEnumerable<ICommandOptionMetadata> Options { get; }
23+
24+
public ICommandObjectBuilder CreateCommandObjectBuilder(IServiceProvider serviceProvider)
25+
{
26+
return new CommandObjectBuilder(Options, _outParameters, _dbConnection);
27+
}
28+
}
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.Collections.Generic;
2+
using System.Data.Common;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using MGR.CommandLineParser.Extensibility.Command;
6+
using Microsoft.EntityFrameworkCore;
7+
8+
namespace MGR.CommandLineParser.Command.OracleProcedure
9+
{
10+
internal class CommandTypeProvider : ICommandTypeProvider
11+
{
12+
private readonly OracleSystemContext _dbContext;
13+
14+
public CommandTypeProvider(OracleSystemContext dbContext)
15+
{
16+
_dbContext = dbContext;
17+
}
18+
public async Task<IEnumerable<ICommandType>> GetAllCommandTypes()
19+
{
20+
var procedures = await _dbContext.Procedures.Include(procedure => procedure.Parameters).ToListAsync();
21+
return procedures.Select(procedure => MapProcedureToCommandType(procedure, _dbContext.Database.GetDbConnection()));
22+
}
23+
public async Task<ICommandType> GetCommandType(string commandName)
24+
{
25+
var procedure = await _dbContext.Procedures.Include(procedure => procedure.Parameters).Where(procedure => procedure.Name == commandName).SingleOrDefaultAsync();
26+
if (procedure != null)
27+
{
28+
return MapProcedureToCommandType(procedure, _dbContext.Database.GetDbConnection());
29+
}
30+
return null;
31+
}
32+
33+
private static CommandType MapProcedureToCommandType(Procedure procedure, DbConnection dbConnection)
34+
{
35+
return new CommandType(
36+
new CommandMetadata(procedure.Name),
37+
procedure.Parameters
38+
.Where(parameter => parameter.Direction.HasFlag(Direction.In))
39+
.Select(parameter => new CommandOptionMetadata(
40+
new OptionDisplayInfo(parameter.Name),
41+
!parameter.HasDefaultValue,
42+
parameter.DefaultValue
43+
)
44+
),
45+
procedure.Parameters
46+
.Where(parameter => parameter.Direction.HasFlag(Direction.Out)),
47+
dbConnection
48+
);
49+
}
50+
}
51+
}
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Oracle.EntityFrameworkCore" Version="2.19.80" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\MGR.CommandLineParser\MGR.CommandLineParser.csproj" />
13+
</ItemGroup>
14+
15+
</Project>

0 commit comments

Comments
 (0)