first commit
This commit is contained in:
156
Program.cs
Normal file
156
Program.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using EFCDesk.Classes;
|
||||
using EFCDesk.Forms;
|
||||
using System.Threading;
|
||||
|
||||
namespace EFCDesk
|
||||
{
|
||||
public static class Globales
|
||||
{
|
||||
public static MonitorCarpetas gMonitor;
|
||||
public static ProcessLogger logger = new ProcessLogger();
|
||||
public static ConfiguracionJSON configJson = ConfiguracionJSON.LoadFromJson();
|
||||
public static string accesToken = "";
|
||||
public static string refresToken = "";
|
||||
}
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static async Task Main()
|
||||
{
|
||||
|
||||
/**/
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
string carpetaBase = @"C:\EFC";
|
||||
if (!Directory.Exists(Globales.configJson.FolderExpediente))
|
||||
{
|
||||
string folder = "C:" + Path.DirectorySeparatorChar + "EFC";
|
||||
// Asigna el valor al objeto de configuraci<63>n
|
||||
Globales.configJson.FolderExpediente = folder;
|
||||
|
||||
// Guarda los cambios en el archivo JSON
|
||||
Globales.configJson.SaveToJson();
|
||||
|
||||
Directory.CreateDirectory(folder);
|
||||
carpetaBase = folder;
|
||||
}
|
||||
else
|
||||
{
|
||||
carpetaBase = Globales.configJson.FolderExpediente;
|
||||
}
|
||||
|
||||
Properties.Settings.Default.urlEFC = Globales.configJson.DominioExp;
|
||||
Properties.Settings.Default.Save();
|
||||
|
||||
Globales.gMonitor = new MonitorCarpetas(
|
||||
carpetaBase: carpetaBase,
|
||||
maxConcurrent: 10,
|
||||
perFileTimeoutSeconds: 30,
|
||||
maxReintentos: 10
|
||||
);
|
||||
|
||||
|
||||
//string? data = SecureDataHandler.ReadDataAsPlainText();
|
||||
//if (string.IsNullOrEmpty(data))
|
||||
//{
|
||||
// Application.Run(new Login());
|
||||
|
||||
//} else if (!SecureDataHandler.IsDataValid())
|
||||
//{
|
||||
// MessageBox.Show("Id Usuario incorrecto. favor de revisar.","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
|
||||
// Application.Run(new Login());
|
||||
|
||||
//} else
|
||||
//{
|
||||
// // Antes de llamar a cualquier m<>todo sobre Globales.gMonitor, verifica que no sea null
|
||||
// if (Globales.gMonitor != null && !Globales.gMonitor.ExisteConfiguracionExpediente())
|
||||
// {
|
||||
// Application.Run(new Login());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (Globales.gMonitor != null)
|
||||
// {
|
||||
// Application.Run(new FormMain(Globales.gMonitor));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// MessageBox.Show("Error interno: el monitor de carpetas no est<73> inicializado.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
// Application.Exit();
|
||||
// }
|
||||
// }
|
||||
// // Al terminar la aplicaci<63>n, liberar el recurso manualmente
|
||||
// Globales.gMonitor?.Dispose();
|
||||
//}
|
||||
|
||||
bool Esvalido = Utils.Util.StringsValidos(Globales.configJson.UsuarioExp, Globales.configJson.PasswordExp);
|
||||
|
||||
if (!Esvalido)
|
||||
{
|
||||
MessageBox.Show("Debe ingresar Usuario y contraseña.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Application.Run(new Login());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Intentar login automático para obtener tokens
|
||||
bool loginExitoso = await Utils.Util.Login(Globales.configJson.UsuarioExp ?? "", Globales.configJson.PasswordExp ?? "");
|
||||
|
||||
if (!loginExitoso)
|
||||
{
|
||||
MessageBox.Show("Error en el inicio de sesión automático. Por favor, verifique sus credenciales.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Application.Run(new Login());
|
||||
return;
|
||||
}
|
||||
|
||||
// Antes de llamar a cualquier m<>todo sobre Globales.gMonitor, verifica que no sea null
|
||||
if (Globales.gMonitor != null && !Globales.gMonitor.ExisteConfiguracionExpediente())
|
||||
{
|
||||
Application.Run(new Login());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Globales.gMonitor != null)
|
||||
{
|
||||
Application.Run(new FormMain(Globales.gMonitor));
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Error interno: el monitor de carpetas no está inicializado.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Application.Exit();
|
||||
}
|
||||
}
|
||||
// Al terminar la aplicaci<63>n, liberar el recurso manualmente
|
||||
Globales.gMonitor?.Dispose();
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// // Antes de llamar a cualquier m<>todo sobre Globales.gMonitor, verifica que no sea null
|
||||
// if (Globales.gMonitor != null && !Globales.gMonitor.ExisteConfiguracionExpediente())
|
||||
// {
|
||||
// Application.Run(new Login());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (Globales.gMonitor != null)
|
||||
// {
|
||||
// Application.Run(new FormMain(Globales.gMonitor));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// MessageBox.Show("Error interno: el monitor de carpetas no est<73> inicializado.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
// Application.Exit();
|
||||
// }
|
||||
// }
|
||||
// // Al terminar la aplicaci<63>n, liberar el recurso manualmente
|
||||
// Globales.gMonitor?.Dispose();
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user