| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using Microsoft.Data.SqlClient;
- using Quadarax.Application.QLiberace.Base;
- using Quadarax.Foundation.Core.QConsole.Command.Base;
- using Quadarax.Foundation.Core.QConsole;
- using Quadarax.Foundation.Core.Value;
- using Microsoft.EntityFrameworkCore;
- namespace Quadarax.Application.QLiberace.Console.Commands.Base
- {
- internal abstract class DbContextCommand : AbstractCommand
- {
- #region *** Properties ***
- #endregion
- #region *** Constructor ***
- public DbContextCommand(Engine engine) : base(engine)
- {
- }
- #endregion
-
- #region *** EXECUTE ***
- protected override Result OnExecute()
- {
- var options = new DbContextOptions<QlbrcDbContext>();
- using (var context = new QlbrcDbContext(options))
- {
- return OnExecute(context);
- }
- }
- protected abstract Result OnExecute(QlbrcDbContext context);
- #endregion
- #region *** Private operations ***
- protected Result HandleConnectionException(SqlException e)
- {
- if (e.Message.Contains("A network-related or instance-specific error occurred while establishing a connection to SQL Server"))
- {
- WriteError(e);
- return new Result(Constants.ReturnCodes.CannotConnectToServer);
- }
- throw e;
- }
- #endregion
- }
- }
|