summaryrefslogtreecommitdiff
path: root/Gestor.Infrastructure/Gestor.Infrastructure.Configuration/ConfigurationFileCache.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Gestor.Infrastructure/Gestor.Infrastructure.Configuration/ConfigurationFileCache.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Configuration/ConfigurationFileCache.cs')
-rw-r--r--Gestor.Infrastructure/Gestor.Infrastructure.Configuration/ConfigurationFileCache.cs133
1 files changed, 0 insertions, 133 deletions
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