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 --- Gestor.Application/Migration/Migrator.cs | 189 ------------------------------- 1 file changed, 189 deletions(-) delete mode 100644 Gestor.Application/Migration/Migrator.cs (limited to 'Gestor.Application/Migration/Migrator.cs') diff --git a/Gestor.Application/Migration/Migrator.cs b/Gestor.Application/Migration/Migrator.cs deleted file mode 100644 index eab28a3..0000000 --- a/Gestor.Application/Migration/Migrator.cs +++ /dev/null @@ -1,189 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Infrastructure.Repository.Interface; -using Gestor.Infrastructure.UnitOfWork.Generic; -using Gestor.Infrastructure.UnitOfWork.Logic; -using Gestor.Model.Helper; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -namespace Gestor.Application.Migration -{ - public class Migrator - { - private readonly Assembly _executingAssembly; - - private static string _connection - { - get; - set; - } - - public Migrator() - { - this._executingAssembly = Assembly.GetExecutingAssembly(); - } - - public async Task Execute() - { - bool flag; - try - { - string[] allFiles = await this.GetAllFiles(); - flag = await this.ExecuteFiles(allFiles); - return flag; - } - catch (Exception exception) - { - } - flag = false; - return flag; - } - - private async Task ExecuteFiles(IEnumerable filesToExecute) - { - bool flag; - IEnumerable strs = filesToExecute; - foreach (string str in - from x in strs - orderby x - select x) - { - using (Stream manifestResourceStream = this._executingAssembly.GetManifestResourceStream(str)) - { - if (manifestResourceStream != null) - { - Encoding encoding = Encoding.GetEncoding("ISO-8859-1"); - Encoding uTF8 = Encoding.UTF8; - using (StreamReader streamReader = new StreamReader(manifestResourceStream)) - { - byte[] bytes = uTF8.GetBytes(streamReader.ReadToEnd()); - byte[] numArray = Encoding.Convert(uTF8, encoding, bytes); - if (await Migrator.ExecuteScript(encoding.GetString(numArray))) - { - string str1 = str; - char[] chrArray = new char[] { '\u005F' }; - if (!await Migrator.SaveUpdate((long)ValidationHelper.ToInt(ValidationHelper.Clear(ValidationHelper.Index(str1.Split(chrArray), 1))))) - { - flag = false; - return flag; - } - } - else - { - flag = false; - return flag; - } - } - streamReader = null; - } - else - { - continue; - } - } - manifestResourceStream = null; - } - flag = true; - return flag; - } - - private static async Task ExecuteScript(string scriptText) - { - bool flag1 = await Task.Run(() => { - bool flag; - IEnumerable strs = Regex.Split(scriptText, "^\\s*GO\\s*$", RegexOptions.IgnoreCase | RegexOptions.Multiline); - try - { - if (string.IsNullOrEmpty(Migrator._connection)) - { - Migrator._connection = Connection.GetConnection(true); - } - using (SqlConnection sqlConnection = new SqlConnection(Migrator._connection)) - { - sqlConnection.Open(); - using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) - { - foreach (string str in strs) - { - if (str.Trim() == "") - { - continue; - } - sqlCommand.CommandText = str; - sqlCommand.ExecuteNonQuery(); - } - } - } - flag = true; - } - catch (Exception exception) - { - flag = false; - } - return flag; - }); - return flag1; - } - - private async Task GetAllFiles() - { - string str = string.Concat(this._executingAssembly.GetName().Name, ".Migration.Files"); - long num1 = await Migrator.LastUpdate(); - string[] array = this._executingAssembly.GetManifestResourceNames().Where((string r) => { - long num = (long)0; - if (r.StartsWith(str) && r.EndsWith(".SQL")) - { - num = (long)ValidationHelper.ToInt(ValidationHelper.Clear(ValidationHelper.Index(r.Split(new char[] { '\u005F' }), 1))); - } - return num > num1; - }).ToArray(); - return array; - } - - private static async Task LastUpdate() - { - long num1 = await Task.Run(() => { - long num; - using (UnitOfWork commited = Instancia.Commited) - { - num = commited.get_AtualizacaoRepository().FindLastUpdate(); - } - return num; - }); - return num1; - } - - private static async Task SaveUpdate(long fileId) - { - bool flag1 = await Task.Run(() => { - bool flag; - using (UnitOfWork commited = Instancia.Commited) - { - try - { - commited.get_AtualizacaoRepository().Save(fileId); - commited.Commit(); - return true; - } - catch (Exception exception) - { - commited.Rollback(); - flag = false; - } - } - return flag; - }); - return flag1; - } - } -} \ No newline at end of file -- cgit v1.2.3