Skip to content

Commit f0945b2

Browse files
committed
Adicionar suporte para colunas ignoradas na replicação
Implementa a propriedade `IgnoredColumns` em `SQLInteraction.cs` para armazenar colunas a serem ignoradas. Atualiza a lógica de carregamento de colunas selecionadas e ignoradas, e ajusta a contagem de campos ignorados no método `BuildDictionary`. Adiciona o método `GetIgnoredColumns` em `ConfigHelper.cs` para carregar colunas ignoradas a partir da configuração XML, com mensagens de log para feedback durante o processo.
1 parent e776321 commit f0945b2

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ internal class SQLInteraction
2727
public Dictionary<string, Field> FNDictionary { get; set; }
2828
public string CurrentTime { get; set; }
2929

30-
// Store selected columns from configuration
30+
// Store selected and ignored columns from configuration
3131
private HashSet<string> SelectedColumns { get; set; }
32+
private HashSet<string> IgnoredColumns { get; set; }
3233

3334
/// <summary>
3435
/// Initializes the SQL table for the specified SharePoint list,
@@ -40,9 +41,12 @@ public void Build()
4041

4142
try
4243
{
43-
// Load selected columns from configuration
44+
// Load selected and ignored columns from configuration
4445
this.SelectedColumns = ConfigurationReader.GetSelectedColumns();
46+
this.IgnoredColumns = ConfigurationReader.GetIgnoredColumns();
47+
4548
LogInfo("Build", $"Selected columns from config: {(this.SelectedColumns == null ? "All" : string.Join(", ", this.SelectedColumns))}");
49+
LogInfo("Build", $"Ignored columns from config: {(this.IgnoredColumns == null ? "None" : string.Join(", ", this.IgnoredColumns))}");
4650

4751
this.TableName = this.ToPascalCase(this.List.Name, false);
4852

@@ -218,6 +222,7 @@ private void BuildDictionary()
218222
LogInfo("BuildDictionary", "Building field name dictionary...");
219223
int processedFields = 0;
220224
int skippedFields = 0;
225+
int ignoredFields = 0;
221226

222227
foreach (Field field in this.List.Fields)
223228
{
@@ -227,6 +232,14 @@ private void BuildDictionary()
227232
{
228233
string columnName = this.GetActualColName(field);
229234

235+
// Skip if the column is in the ignored list
236+
if (this.IgnoredColumns != null && this.IgnoredColumns.Contains(columnName))
237+
{
238+
ignoredFields++;
239+
LogInfo("BuildDictionary", $"Ignored field: {columnName}");
240+
continue;
241+
}
242+
230243
// Only add the field if it's selected in configuration or if no specific columns are selected
231244
if (this.SelectedColumns == null || this.SelectedColumns.Contains(columnName))
232245
{
@@ -252,7 +265,9 @@ private void BuildDictionary()
252265
}
253266
}
254267

255-
LogInfo("BuildDictionary", $"Dictionary built. Processed: {processedFields}, Skipped: {skippedFields}");
268+
LogInfo("BuildDictionary",
269+
$"Dictionary built. Processed: {processedFields}, " +
270+
$"Skipped: {skippedFields}, Ignored: {ignoredFields}");
256271
}
257272

258273
private bool TableExists(string listName)

‎SPOtoSQL-Snapshots/ConsoleApp1/XmlConfig/ConfigHelper.cs‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,55 @@ public static HashSet<string> GetSelectedColumns()
9191
}
9292
}
9393

94+
/// <summary>
95+
/// Gets the list of columns that should be ignored during replication.
96+
/// </summary>
97+
/// <returns>A HashSet of column names to ignore, or null if no columns should be ignored.</returns>
98+
public static HashSet<string> GetIgnoredColumns()
99+
{
100+
LoadConfig();
101+
102+
try
103+
{
104+
var columnNodes = _xmlDoc.SelectNodes("//Configuration/ReplicationConfiguration/GlobalIgnore/Column");
105+
106+
// If no ignore nodes exist, return null to indicate no columns should be ignored
107+
if (columnNodes == null || columnNodes.Count == 0)
108+
{
109+
Console.WriteLine("No columns configured to ignore.");
110+
return null;
111+
}
112+
113+
// Create case-insensitive HashSet for ignored column names
114+
var ignoredColumns = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
115+
116+
foreach (XmlNode node in columnNodes)
117+
{
118+
if (!string.IsNullOrWhiteSpace(node.InnerText))
119+
{
120+
string columnName = node.InnerText.Trim();
121+
ignoredColumns.Add(columnName);
122+
Console.WriteLine($"Added ignored column: {columnName}");
123+
}
124+
}
125+
126+
// Return null if no valid columns were added to ignore
127+
if (ignoredColumns.Count == 0)
128+
{
129+
Console.WriteLine("No valid columns specified to ignore.");
130+
return null;
131+
}
132+
133+
Console.WriteLine($"Total ignored columns: {ignoredColumns.Count}");
134+
return ignoredColumns;
135+
}
136+
catch (Exception ex)
137+
{
138+
Console.WriteLine($"Error reading ignored columns: {ex.Message}");
139+
throw new Exception($"Error reading ignored columns configuration: {ex.Message}");
140+
}
141+
}
142+
94143
/// <summary>
95144
/// Retrieves SharePoint credentials (username and password) from the configuration file.
96145
/// </summary>

0 commit comments

Comments
 (0)