-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart-AutomationProcess.ps1
More file actions
68 lines (60 loc) · 2.49 KB
/
Start-AutomationProcess.ps1
File metadata and controls
68 lines (60 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<#
.SYNOPSIS
Start the Process for XML files.
.DESCRIPTION
Start the Process for XML files.
#>
function Start-AutomationProcess() {
Param(
[Parameter(Mandatory = $true, Position = 0)]
$XmlFolderPath,
[Parameter(Mandatory = $true, Position = 1)]
$Name
)
Begin {
Clear-Host
#Initialize default settings such as, default paths, sql table name, store procedures.
Initialize-ConfigSettings
#Fron this step, Use Write-LogInfo and Write-Exception for the log information and exception respectively.
Initialize-GlobalObjects
}
Process {
$processFileCount = 0;
$fileIssueCount = 0;
$totalFileProcessCount = 0;
$isAllSave = $true;
# $XmlFolderPath = $Global:RootPath + $Global:Resources.XmlPath;
$userTextFilePath = Get-LastOrDefault (Create-File -FolderPath $XmlFolderPath -FileName "$Name.txt");
Write-FilePathsFromDirectory -FolderPath $XmlFolderPath -FilePath $userTextFilePath -Filter '*.xml'
Get-Content $userTextFilePath | ForEach-Object {
$xmlFilePath = $_;
if (Test-Path $xmlFilePath) {
Start-XMLFileProcess -FilePath $xmlFilePath
$isAllSave = $false;
$processFileCount++;
$totalFileProcessCount++;
if ($totalFileProcessCount -eq $Global:Resources.BatchSize) {
Save-ObjectData
$totalFileProcessCount = 0;
$isAllSave = $true;
Write-LogInfo -Message "Continue process to next $($Resources.XmlBatchSize) bunch of File Process." -Separator $true
}
}
else {
$fileDetail = [FileDetailModel]::new($xmlFilePath);
$ProgressMessage = $('FileName: {0}, File not found at: {1}' -f $fileDetail.FileName, $fileDetail.FullPath);
Write-LogInfo -Message $ProgressMessage -Separator $true
$fileIssueCount++;
}
}
if (!$isAllSave) {
Save-DatabaseTableData
$isAllSave = $true;
Write-LogInfo -Message "Save the remaining table data from object of $($Resources.XmlBatchSize)" -Separator $true
}
Write-LogInfo -Message "$totalFileProcessCount XML files has been processed." -Separator $true
Write-LogInfo -Message "$fileIssueCount XML files has not been processed." -Separator $true
}
End {
}
}