diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Gestor.Application/Migration | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Gestor.Application/Migration')
| -rw-r--r-- | Gestor.Application/Migration/Migrator.cs | 189 |
1 files changed, 0 insertions, 189 deletions
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<bool> 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<bool> ExecuteFiles(IEnumerable<string> filesToExecute)
- {
- bool flag;
- IEnumerable<string> 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<bool> ExecuteScript(string scriptText)
- {
- bool flag1 = await Task.Run<bool>(() => {
- bool flag;
- IEnumerable<string> 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<string[]> GetAllFiles()
- {
- string str = string.Concat(this._executingAssembly.GetName().Name, ".Migration.Files");
- long num1 = await Migrator.LastUpdate();
- string[] array = this._executingAssembly.GetManifestResourceNames().Where<string>((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<string>();
- return array;
- }
-
- private static async Task<long> LastUpdate()
- {
- long num1 = await Task.Run<long>(() => {
- long num;
- using (UnitOfWork commited = Instancia.Commited)
- {
- num = commited.get_AtualizacaoRepository().FindLastUpdate();
- }
- return num;
- });
- return num1;
- }
-
- private static async Task<bool> SaveUpdate(long fileId)
- {
- bool flag1 = await Task.Run<bool>(() => {
- 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 |