From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../ConfigurationFileCache.cs | 133 --------------------- 1 file changed, 133 deletions(-) delete mode 100644 Gestor.Infrastructure/Gestor.Infrastructure.Configuration/ConfigurationFileCache.cs (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Configuration/ConfigurationFileCache.cs') diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Configuration/ConfigurationFileCache.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Configuration/ConfigurationFileCache.cs deleted file mode 100644 index 4864edc..0000000 --- a/Gestor.Infrastructure/Gestor.Infrastructure.Configuration/ConfigurationFileCache.cs +++ /dev/null @@ -1,133 +0,0 @@ -using Gestor.Common.Helpers; -using NHibernate.Cfg; -using System; -using System.ComponentModel; -using System.Data.SqlClient; -using System.IO; -using System.Reflection; -using System.Runtime.Serialization.Formatters.Binary; - -namespace Gestor.Infrastructure.Configuration -{ - public class ConfigurationFileCache - { - private readonly string _cacheFile; - - private readonly Assembly _definitionsAssembly; - - private bool IsConfigurationFileValid - { - get - { - string location; - if (!File.Exists(this._cacheFile)) - { - return false; - } - FileInfo fileInfo = new FileInfo(this._cacheFile); - Assembly assembly = this._definitionsAssembly; - if (assembly != null) - { - location = assembly.Location; - } - else - { - location = null; - } - string str = location; - if (str == null) - { - return false; - } - FileInfo fileInfo1 = new FileInfo(str); - if (fileInfo.Length < (long)5120) - { - return false; - } - return fileInfo.LastWriteTime >= fileInfo1.LastWriteTime; - } - } - - public ConfigurationFileCache(string connectionString) - { - if (connectionString == null) - { - return; - } - this._definitionsAssembly = Assembly.GetExecutingAssembly(); - SqlConnection sqlConnection = new SqlConnection(connectionString); - string str = string.Concat("Data_", sqlConnection.Database, ".cfg"); - sqlConnection.Dispose(); - this._cacheFile = string.Concat(AppDomain.CurrentDomain.BaseDirectory, str); - } - - public void DeleteCacheFile() - { - try - { - if (File.Exists(this._cacheFile)) - { - File.Delete(this._cacheFile); - } - } - catch (Exception exception) - { - } - } - - public NHibernate.Cfg.Configuration LoadConfigurationFromFile() - { - NHibernate.Cfg.Configuration configuration; - if (!this.IsConfigurationFileValid) - { - return null; - } - try - { - using (FileStream fileStream = File.Open(this._cacheFile, FileMode.Open, FileAccess.Read)) - { - using (MemoryStream memoryStream = new MemoryStream(ConfigurationFileCache.ReadFully(fileStream).DecryptBytes())) - { - configuration = (new BinaryFormatter()).Deserialize(memoryStream) as NHibernate.Cfg.Configuration; - } - } - } - catch (Exception exception) - { - this.DeleteCacheFile(); - configuration = null; - } - return configuration; - } - - private static byte[] ReadFully(Stream inputStream) - { - byte[] array; - using (MemoryStream memoryStream = new MemoryStream()) - { - inputStream.CopyTo(memoryStream); - array = memoryStream.ToArray(); - } - return array; - } - - public void SaveConfigurationToFile(NHibernate.Cfg.Configuration configuration) - { - try - { - using (FileStream fileStream = File.Open(this._cacheFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) - { - using (MemoryStream memoryStream = new MemoryStream()) - { - (new BinaryFormatter()).Serialize(memoryStream, configuration); - byte[] numArray = memoryStream.ToArray().EncryptBytes(); - fileStream.Write(numArray, 0, (int)numArray.Length); - } - } - } - catch (Exception exception) - { - } - } - } -} \ No newline at end of file -- cgit v1.2.3