Skip to content

Commit dd22096

Browse files
committed
Melhorias nas mensagens de depuração e configuração
Adicionadas mensagens de depuração detalhadas em várias partes do código, incluindo a verificação de conexão SQL e a criação de usuários SharePoint. A lógica de verificação de argumentos de linha de comando foi simplificada para sempre considerar "daily". Mensagens de progresso foram incluídas em `SPOList.cs` e `SQLInteraction.cs`, facilitando o rastreamento do fluxo de execução. Além disso, a string de conexão no arquivo `UserConfig.xml` foi alterada de "LAKEDB" para "Student", indicando uma mudança no ambiente de banco de dados.
1 parent 5659b5a commit dd22096

5 files changed

Lines changed: 58 additions & 34 deletions

File tree

‎SPOtoSQL-Snapshots/ConsoleApp1/SPODataQuality/RefreshSPOLists.cs‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,41 @@ private static void Main(string[] args)
2222

2323
// Test SQL connection before proceeding
2424
TestSQLConnection();
25+
Console.WriteLine("DEBUG: Main: SQL connection test completed");
2526

2627
// Retrieve SharePoint credentials (username and password) from a configuration source
2728
var (username, password) = ConfigurationReader.GetSharePointCredentials();
2829
SPOUser spoUser = new SPOUser(username, password); // Create a SharePoint user object
29-
Console.WriteLine("DEBUG: SPOUser created"); // When Username and Password are filled correctly, this line will be printed
30+
Console.WriteLine("DEBUG: Main: SPOUser created"); // When Username and Password are filled correctly, this line will be printed
3031

3132
// Initialize two SharePoint list objects and assign the user credentials to them
3233
var list1 = new SPOList();
3334
list1.SPOUser = spoUser;
34-
Console.WriteLine("DEBUG: First SPOList configured");
35+
Console.WriteLine("DEBUG: Main: First SPOList configured");
3536

3637
var list2 = new SPOList();
3738
list2.SPOUser = spoUser;
38-
Console.WriteLine("DEBUG: Second SPOList configured");
39+
Console.WriteLine("DEBUG: Main: Second SPOList configured");
3940

4041
// Check if command-line arguments are provided
41-
if ((uint)args.Length > 0U)
42+
// if ((uint)args.Length > 0U)
43+
if (true)
4244
{
43-
string lower = args[0].ToLower(); // Convert the first argument to lowercase
44-
Console.WriteLine("DEBUG: Received argument - " + lower);
45+
// string lower = args[0].ToLower(); // Convert the first argument to lowercase
46+
string lower = "daily";
47+
Console.WriteLine("DEBUG: Main: Received argument - " + lower);
4548

4649
// Decide which update to perform based on the argument
4750
if (lower == "daily")
4851
{
4952
// Perform a daily update from SharePoint to SQL Server
50-
Console.WriteLine("DEBUG: Executing daily");
53+
Console.WriteLine("DEBUG: Main: Executing daily");
5154
RefreshSQLLists.SPOtoSQLUpdate(true);
5255
}
5356
else if (lower == "monthly")
5457
{
5558
// Perform a monthly update from SharePoint to SQL Server
56-
Console.WriteLine("DEBUG: Executing monthly");
59+
Console.WriteLine("DEBUG: Main: Executing monthly");
5760
RefreshSQLLists.SPOtoSQLUpdate(false);
5861
}
5962
else
@@ -132,6 +135,7 @@ private static void TestSQLConnection()
132135
Console.WriteLine($"Error number: {ex.Number}");
133136
Console.WriteLine($"State: {ex.State}");
134137
Console.WriteLine($"Procedure: {ex.Procedure}");
138+
Console.WriteLine("The Execution is stoping.");
135139
throw; // Re-throw to stop execution
136140
}
137141
catch (Exception ex)

‎SPOtoSQL-Snapshots/ConsoleApp1/Sharepoint/SPOList.cs‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,26 @@ public class SPOList : Context
2424

2525
public void Build()
2626
{
27-
if (this.web == null || this.Ctx.Site.Context.Url != "https://bringglobal.sharepoint.com/" + this.Site)
28-
this.BuildContext();
27+
Console.WriteLine("SPOList.Build: Building list: " + this.Name + " - site: " + this.Site);
28+
if (this.web == null || this.Ctx.Site.Context.Url != "https://bringglobal.sharepoint.com/" + this.Site)
29+
{
30+
Console.WriteLine("SPOList.Build: Vou para BuildContext");
31+
this.BuildContext();
32+
Console.WriteLine("SPOList.Build: Vim de BuildContext");
33+
}
2934
CamlQuery camlQuery;
3035
if (this.CAMLQuery == null)
3136
{
32-
camlQuery = CamlQuery.CreateAllItemsQuery();
37+
Console.WriteLine("SPOList.Build: Vou para CamlQuery 1.");
38+
camlQuery = CamlQuery.CreateAllItemsQuery();
39+
Console.WriteLine("SPOList.Build: Vim de CamlQuery 1.");
3340
}
3441
else
3542
{
36-
camlQuery = new CamlQuery();
37-
camlQuery.ViewXml = this.CAMLQuery;
43+
Console.WriteLine("SPOList.Build: Vou para CamlQuery 2.");
44+
camlQuery = new CamlQuery();
45+
camlQuery.ViewXml = this.CAMLQuery;
46+
Console.WriteLine("SPOList.Build: Vim de CamlQuery 2.");
3847
}
3948
CamlQuery query = camlQuery;
4049
this.list = this.web.Lists.GetByTitle(this.Name);
@@ -43,7 +52,17 @@ public void Build()
4352
this.Ctx.Load<List>(this.list, Array.Empty<Expression<Func<List, object>>>());
4453
this.Ctx.Load<ListItemCollection>(this.ItemCollection, Array.Empty<Expression<Func<ListItemCollection, object>>>());
4554
this.Ctx.Load<FieldCollection>(this.Fields, Array.Empty<Expression<Func<FieldCollection, object>>>());
46-
this.Ctx.ExecuteQuery();
55+
Console.WriteLine("SPOList.Build: Vou para ExecuteQuery");
56+
try
57+
{
58+
this.Ctx.ExecuteQuery();
59+
}
60+
catch
61+
{
62+
System.Console.WriteLine("SPOList.Build: O executeQuery deu erro");
63+
throw;
64+
}
65+
Console.WriteLine("SPOList.Build: Vim de ExecuteQuery");
4766
}
4867

4968
public void Update()

‎SPOtoSQL-Snapshots/ConsoleApp1/Sharepoint/SPOUser.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public SPOUser(string username, string password)
3636
if (password == null)
3737
throw new ArgumentNullException(nameof(password), "Password cannot be null.");
3838

39-
Console.WriteLine($"Initializing SPOUser for: {username}");
39+
Console.WriteLine($"SPOUser: Initializing SPOUser for: {username}");
4040

4141
this.Username = username;
4242

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ internal class RefreshSQLLists
1010
// Method to initiate the update process from SharePoint to SQL Server
1111
public static void SPOtoSQLUpdate(bool daily)
1212
{
13-
Console.WriteLine("Starting SPO to SQL update. Daily: " + daily);
13+
Console.WriteLine("SPOtoSQLUpdate: Starting SPO to SQL update. Daily: " + daily);
1414

1515
// Retrieve SharePoint credentials from the configuration file
1616
var (username, password) = ConfigurationReader.GetSharePointCredentials();
1717
// Create a SharePoint user object with the retrieved credentials
18+
Console.WriteLine($"SPOtoSQLUpdate: {username} {password}");
1819
SPOUser user = new SPOUser(username, password);
1920

2021
// Iterate through all keys in the AppSettings section of the configuration file
@@ -23,28 +24,28 @@ public static void SPOtoSQLUpdate(bool daily)
2324
{
2425
string listName = allKey; // The key is the SharePoint list name
2526
string ctxURL = ConfigurationManager.AppSettings[allKey]; // The value is the SharePoint site URL
26-
Console.WriteLine($"Processing list: {listName} with URL: {ctxURL}");
27+
Console.WriteLine($"SPOtoSQLUpdate: Processing list: {listName} with URL: {ctxURL}");
2728
// Call the method to refresh the SQL data for this specific list
2829
RefreshSQLLists.RefreshListsSQL(listName, ctxURL, user, daily);
2930
}
3031

31-
Console.WriteLine("SPO to SQL update completed.");
32+
Console.WriteLine("SPOtoSQLUpdate: SPO to SQL update completed.");
3233
}
3334

3435
// Method to handle the update process for a specific SharePoint list to SQL Server
3536
public static void RefreshListsSQL(string listName, string ctxURL, SPOUser user, bool daily)
3637
{
3738
try
3839
{
39-
Console.WriteLine($"Initializing SPO list for: {listName}");
40+
Console.WriteLine($"RefreshListsSQL: Initializing SPO list for: {listName}");
4041

4142
// Create a new SPOList object to represent the SharePoint list
4243
SPOList spoList = new SPOList();
4344
spoList.Site = ctxURL; // Set the SharePoint site URL
4445
spoList.SPOUser = user; // Assign the SharePoint user credentials
4546
spoList.Name = listName; // Set the name of the SharePoint list
4647

47-
Console.WriteLine("SPOList initialized:");
48+
Console.WriteLine("RefreshListsSQL: SPOList initialized:");
4849
Console.WriteLine($" Site: {spoList.Site}");
4950
Console.WriteLine($" Name: {spoList.Name}");
5051

@@ -54,30 +55,30 @@ public static void RefreshListsSQL(string listName, string ctxURL, SPOUser user,
5455
List = spoList // Assign the SharePoint list to the SQLInteraction object
5556
};
5657

57-
Console.WriteLine("Building SQL interaction...");
58+
Console.WriteLine("RefreshListsSQL: Building SQL interaction...");
5859
// Build the SQL interaction, likely setting up the SQL connection and table structure
5960
sqlInteraction.Build();
6061

6162
// Perform the appropriate update based on the 'daily' flag
6263
if (daily)
6364
{
64-
Console.WriteLine("Performing daily update...");
65+
Console.WriteLine("RefreshListsSQL: Performing daily update...");
6566
// Execute a daily update, possibly deleting and re-inserting all data
6667
sqlInteraction.DailyUpdate();
6768
}
6869
else
6970
{
70-
Console.WriteLine("Performing current time update...");
71+
Console.WriteLine("RefreshListsSQL: Performing current time update...");
7172
// Execute an update based on the current timestamp
7273
sqlInteraction.CurrentTimeUpdate();
7374
}
7475

75-
Console.WriteLine($"Update for list '{listName}' completed.");
76+
Console.WriteLine($"RefreshListsSQL: Update for list '{listName}' completed.");
7677
}
7778
catch (Exception ex)
7879
{
7980
// Handle and log any exceptions that occur during the update process
80-
Console.WriteLine($"Error updating list '{listName}': {ex.Message}");
81+
Console.WriteLine($"RefreshListsSQL: Error updating list '{listName}': {ex.Message}");
8182
}
8283
}
8384
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ internal class SQLInteraction
3838
/// </summary>
3939
public void Build()
4040
{
41-
Console.WriteLine("Starting SQL build for list: " + this.List.Name);
41+
Console.WriteLine("SQLInteraction.Build: Starting SQL build for list: " + this.List.Name);
4242

4343
// Convert list name to PascalCase to use as the SQL table name
4444
this.TableName = this.ToPascalCase(this.List.Name, false);
4545

4646
// Open database connection and begin transaction
4747
this.Connection = new SqlConnection(ConfigurationReader.GetSqlConnectionString());
48-
Console.WriteLine("Opening SQL connection...");
48+
Console.WriteLine("SQLInteraction.Build: Opening SQL connection...");
4949
this.Connection.Open();
5050

5151
this.Command = this.Connection.CreateCommand();
@@ -57,23 +57,23 @@ public void Build()
5757
this.CurrentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
5858

5959
// Load SharePoint list metadata
60-
Console.WriteLine("Building SPO list...");
60+
Console.WriteLine("SQLInteraction.Build: Building SPO list...");
6161
this.List.Build();
6262

6363
// Build dictionary of columns based on fields
6464
this.FNDictionary = new Dictionary<string, Field>(StringComparer.OrdinalIgnoreCase);
65-
Console.WriteLine("Building dictionary of fields...");
65+
Console.WriteLine("SQLInteraction.Build: Building dictionary of fields...");
6666
this.BuildDictionary();
6767

6868
// Create or update table schema
6969
if (!this.TableExists(this.TableName))
7070
{
71-
Console.WriteLine("Table doesn't exist. Creating table: " + this.TableName);
71+
Console.WriteLine("SQLInteraction.Build: Table doesn't exist. Creating table: " + this.TableName);
7272
this.CreateTable();
7373
}
7474
else
7575
{
76-
Console.WriteLine("Table exists. Updating table design...");
76+
Console.WriteLine("SQLInteraction.Build: Table exists. Updating table design...");
7777
this.UpdateTableDesign();
7878
}
7979
}
@@ -86,7 +86,7 @@ public void DailyUpdate()
8686
{
8787
try
8888
{
89-
Console.WriteLine("Performing daily update...");
89+
Console.WriteLine("SQLInteraction.DailyUpdate: Performing daily update...");
9090

9191
// Remove previous snapshot marker rows
9292
this.Command.CommandText = "DELETE FROM [" + this.TableName + "] WHERE Snapshot = '2100-01-01 00:00:00.000'";
@@ -99,11 +99,11 @@ public void DailyUpdate()
9999
}
100100
catch (Exception ex)
101101
{
102-
Console.WriteLine("Daily update failed: " + ex.Message);
102+
Console.WriteLine("SQLInteraction.DailyUpdate: Daily update failed: " + ex.Message);
103103
this.Transaction.Rollback();
104104
}
105105

106-
Console.WriteLine("Daily Update done for: " + this.TableName);
106+
Console.WriteLine("SQLInteraction.DailyUpdate: Daily Update done for: " + this.TableName);
107107
}
108108

109109
/// <summary>

0 commit comments

Comments
 (0)