Добавлены mermaid диаграммы
This commit is contained in:
73
SQLLinter/Infrastructure/Diagram/SqlDiagramProcessor.cs
Normal file
73
SQLLinter/Infrastructure/Diagram/SqlDiagramProcessor.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using SQLLinter.Core.Interfaces;
|
||||
using SQLLinter.Infrastructure.Interfaces;
|
||||
using SQLLinter.Infrastructure.Parser;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Diagram;
|
||||
|
||||
public class SqlDiagramProcessor : ISqlDiagramProcessor
|
||||
{
|
||||
private readonly BpmnDiagram _bpmnDiagram;
|
||||
private readonly IFragmentBuilder _fragmentBuilder;
|
||||
private readonly ISqlStreamReaderBuilder _sqlStreamReaderBuilder;
|
||||
|
||||
public SqlDiagramProcessor(IFragmentBuilder fragmentBuilder, BpmnDiagram bpmnDiagram)
|
||||
: this(fragmentBuilder, bpmnDiagram, new SqlStreamReaderBuilder()) { }
|
||||
|
||||
public SqlDiagramProcessor(IFragmentBuilder fragmentBuilder, BpmnDiagram bpmnDiagram, ISqlStreamReaderBuilder sqlStreamReaderBuilder)
|
||||
{
|
||||
_fragmentBuilder = fragmentBuilder;
|
||||
_bpmnDiagram = bpmnDiagram;
|
||||
_sqlStreamReaderBuilder = sqlStreamReaderBuilder;
|
||||
|
||||
}
|
||||
|
||||
public void ProcessList(List<string> filePaths)
|
||||
{
|
||||
foreach (var path in filePaths)
|
||||
{
|
||||
ProcessFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
public void ProcessPath(string path)
|
||||
{
|
||||
ProcessFile(path);
|
||||
}
|
||||
|
||||
private void ProcessFile(string filePath)
|
||||
{
|
||||
var fileStream = GetFileContents(filePath);
|
||||
HandleProcessing(filePath, fileStream);
|
||||
}
|
||||
|
||||
public void ProcessList(Dictionary<string, Stream> files)
|
||||
{
|
||||
foreach (var file in files)
|
||||
{
|
||||
HandleProcessing(file.Key, file.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleProcessing(string filePath, Stream fileStream)
|
||||
{
|
||||
var fragment = _fragmentBuilder.GetFragment(filePath, GetSqlTextReader(fileStream), out var errors);
|
||||
|
||||
if (fragment == null || errors.Count > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var diagramm = BpmnBuilder.Build(fragment);
|
||||
_bpmnDiagram.Subprocesses.Add(diagramm.Main);
|
||||
}
|
||||
|
||||
private Stream GetFileContents(string filePath)
|
||||
{
|
||||
return File.OpenRead(filePath);
|
||||
}
|
||||
|
||||
private StreamReader GetSqlTextReader(Stream sqlFileStream)
|
||||
{
|
||||
return _sqlStreamReaderBuilder.CreateReader(sqlFileStream);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user