Browse Source

cli: allow multiple EfCoreConfigureMethod

pull/8732/head
Yunus Emre Kalkan 6 years ago
parent
commit
38d66f4dca
  1. 32
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/DbContextFileBuilderConfigureAdder.cs

32
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/DbContextFileBuilderConfigureAdder.cs

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.DependencyInjection;
@ -22,26 +23,32 @@ namespace Volo.Abp.Cli.ProjectModification
{
var file = File.ReadAllText(path);
file = UsingStatementAdder.Add(file, GetNamespace(moduleConfiguration));
var namespaces = moduleConfiguration.Split(", ").Select(GetNamespace);
var configurationLines = moduleConfiguration.Split(", ").Select(GetLineToAdd);
var stringToAdd = GetLineToAdd(moduleConfiguration);
if (!file.Contains(stringToAdd))
var indexToInsert = FindIndexToInsert(file);
if (indexToInsert <= 0 || indexToInsert >= file.Length)
{
var indexToInsert = FindIndexToInsert(file);
Logger.LogWarning($"\"OnModelCreating(ModelBuilder builder)\" method couldn't be found in {path}");
return false;
}
if (indexToInsert <= 0 || indexToInsert >= file.Length)
foreach (var configurationLine in configurationLines)
{
if (file.Contains(configurationLine))
{
Logger.LogWarning($"\"OnModelCreating(ModelBuilder builder)\" method couldn't be found in {path}");
return false;
continue;
}
file = file.Insert(indexToInsert, " " + stringToAdd + Environment.NewLine + " ");
file = file.Insert(indexToInsert, " " + configurationLine + Environment.NewLine + " ");
}
else
foreach (var namespaceOfConfiguration in namespaces)
{
return false;
file = UsingStatementAdder.Add(file, namespaceOfConfiguration);
}
File.WriteAllText(path, file);
return true;
}
@ -49,7 +56,8 @@ namespace Volo.Abp.Cli.ProjectModification
protected int FindIndexToInsert(string file)
{
var indexOfMethodDeclaration = file.IndexOf("OnModelCreating(", StringComparison.Ordinal);
var indexOfOpeningBracket = indexOfMethodDeclaration + file.Substring(indexOfMethodDeclaration).IndexOf('{');
var indexOfOpeningBracket =
indexOfMethodDeclaration + file.Substring(indexOfMethodDeclaration).IndexOf('{');
var stack = 1;
var index = indexOfOpeningBracket;

Loading…
Cancel
Save