using System.Data;
using System.Xml;
namespace AZToolBox.Xml
{
public class XmlConnection : IDbConnection
{
private bool open = false;
internal XmlReader? Reader;
private bool disposedValue;
public XmlConnection() : this(null)
{
}
public XmlConnection(string? connectionString)
{
if (connectionString
is null) {
ConnectionString = string.Empty;
}
else
{
ConnectionString = connectionString;
}
}
public string ConnectionString { get; set; }
public int ConnectionTimeout =>
throw new NotImplementedException
();
public string Database =>
throw new NotImplementedException
();
public ConnectionState State
{
get
{
if (open)
{
return ConnectionState.Open;
}
else
{
return ConnectionState.Closed;
}
}
}
public IDbTransaction BeginTransaction()
{
throw new NotImplementedException
();
}
public IDbTransaction BeginTransaction(IsolationLevel il)
{
throw new NotImplementedException
();
}
public void ChangeDatabase(string databaseName)
{
throw new NotImplementedException
();
}
public void Close()
{
{
Reader.Close();
Reader.Dispose();
Reader = null;
}
open = false;
}
public IDbCommand CreateCommand()
{
return new XmlCommand
(this);
}
public void Open()
{
Reader = XmlReader.Create(ConnectionString);
open = true;
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
// TODO: supprimer l'état managé (objets managés)
Close();
}
// TODO: libérer les ressources non managées (objets non managés) et substituer le finaliseur
// TODO: affecter aux grands champs une valeur null
disposedValue = true;
}
}
// // TODO: substituer le finaliseur uniquement si 'Dispose(bool disposing)' a du code pour libérer les ressources non managées
// ~XmlConnection()
// {
// // Ne changez pas ce code. Placez le code de nettoyage dans la méthode 'Dispose(bool disposing)'
// Dispose(disposing: false);
// }
public void Dispose()
{
// Ne changez pas ce code. Placez le code de nettoyage dans la méthode 'Dispose(bool disposing)'
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}