RegexPatternService.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using LAPS_XMLQC_Service.Models;
  2. using Microsoft.Extensions.Configuration;
  3. using Npgsql;
  4. using System.Collections.Generic;
  5. namespace LAPS_XMLQC_Service.Services
  6. {
  7. public class RegexPatternService
  8. {
  9. private readonly string _connectionString;
  10. public RegexPatternService(IConfiguration configuration)
  11. {
  12. _connectionString = configuration.GetConnectionString("DbConnection");
  13. }
  14. public List<RegexPattern> GetRegexPatterns()
  15. {
  16. var patterns = new List<RegexPattern>();
  17. using (var connection = new NpgsqlConnection(_connectionString))
  18. {
  19. connection.Open();
  20. using (var command = new NpgsqlCommand("SELECT id, pattern from tblregexpatterns", connection))
  21. {
  22. using (var reader = command.ExecuteReader())
  23. {
  24. while (reader.Read())
  25. {
  26. patterns.Add(new RegexPattern
  27. {
  28. Id = reader.GetInt32(0),
  29. Pattern = reader.GetString(1)
  30. });
  31. }
  32. }
  33. }
  34. }
  35. return patterns;
  36. }
  37. }
  38. }