Skip to content

Commit ea97fa6

Browse files
committed
Melhora no rastreamento e segurança do código
Adiciona mensagens de log no `RefreshSQLLists.cs` para melhor rastreamento do processo de atualização do SQL a partir do SPO e remove credenciais hardcoded para aumentar a segurança. No `SQLInteraction.cs`, inclui mensagens de log para a construção da interação SQL, atualização do design da tabela e transferência de dados. Simplifica a estrutura do método `Build` e aprimora a lógica de atualização diária e de tempo atual. Melhora a verificação da existência da tabela e a criação de novas colunas, além de simplificar a função `SQLFieldType`.
1 parent a7add4e commit ea97fa6

2 files changed

Lines changed: 357 additions & 321 deletions

File tree

‎SPOtoSQL-Snapshots/ConsoleApp1/Sqlserver/RefreshSQLLists.cs‎

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,65 @@
1111

1212
namespace Bring.Sqlserver
1313
{
14-
internal class RefreshSQLLists
15-
{
16-
public static void SPOtoSQLUpdate(bool daily)
14+
internal class RefreshSQLLists
1715
{
18-
SPOUser user = new SPOUser("Guilherme.sales@bringglobal.com", "UtKid_3AV^r]H+"); // FJ -> APAGUEI AS CREDENCIAIS QUE ESTÂO EM USO
19-
foreach (string allKey in ConfigurationManager.AppSettings.AllKeys)
20-
RefreshSQLLists.RefreshListsSQL(allKey, ConfigurationManager.AppSettings[allKey], user, daily);
21-
}
16+
public static void SPOtoSQLUpdate(bool daily)
17+
{
18+
Console.WriteLine("Starting SPO to SQL update. Daily: " + daily);
2219

23-
public static void RefreshListsSQL(string listName, string ctxURL, SPOUser user, bool daily)
24-
{
25-
try
26-
{
27-
SPOList spoList1 = new SPOList();
28-
spoList1.Site = ctxURL;
29-
spoList1.SPOUser = user;
30-
spoList1.Name = listName;
31-
SPOList spoList2 = spoList1;
32-
SQLInteraction sqlInteraction = new SQLInteraction()
20+
SPOUser user = new SPOUser("Guilherme.sales@bringglobal.com", "UtKid_3AV^r]H+"); // NOTE: Remove hardcoded credentials for security
21+
22+
foreach (string allKey in ConfigurationManager.AppSettings.AllKeys)
23+
{
24+
string listName = allKey;
25+
string ctxURL = ConfigurationManager.AppSettings[allKey];
26+
Console.WriteLine($"Processing list: {listName} with URL: {ctxURL}");
27+
RefreshSQLLists.RefreshListsSQL(listName, ctxURL, user, daily);
28+
}
29+
30+
Console.WriteLine("SPO to SQL update completed.");
31+
}
32+
33+
public static void RefreshListsSQL(string listName, string ctxURL, SPOUser user, bool daily)
3334
{
34-
List = spoList2
35-
};
36-
sqlInteraction.Build();
37-
if (daily)
38-
sqlInteraction.DailyUpdate();
39-
else
40-
sqlInteraction.CurrentTimeUpdate();
41-
}
42-
catch (Exception ex)
43-
{
44-
Console.WriteLine(ex.Message);
45-
}
35+
try
36+
{
37+
Console.WriteLine($"Initializing SPO list for: {listName}");
38+
39+
SPOList spoList = new SPOList();
40+
spoList.Site = ctxURL;
41+
spoList.SPOUser = user;
42+
spoList.Name = listName;
43+
44+
Console.WriteLine("SPOList initialized:");
45+
Console.WriteLine($" Site: {spoList.Site}");
46+
Console.WriteLine($" Name: {spoList.Name}");
47+
48+
SQLInteraction sqlInteraction = new SQLInteraction()
49+
{
50+
List = spoList
51+
};
52+
53+
Console.WriteLine("Building SQL interaction...");
54+
sqlInteraction.Build();
55+
56+
if (daily)
57+
{
58+
Console.WriteLine("Performing daily update...");
59+
sqlInteraction.DailyUpdate();
60+
}
61+
else
62+
{
63+
Console.WriteLine("Performing current time update...");
64+
sqlInteraction.CurrentTimeUpdate();
65+
}
66+
67+
Console.WriteLine($"Update for list '{listName}' completed.");
68+
}
69+
catch (Exception ex)
70+
{
71+
Console.WriteLine($"Error updating list '{listName}': {ex.Message}");
72+
}
73+
}
4674
}
47-
}
4875
}

0 commit comments

Comments
 (0)