HamRadioLibrary.psm1
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
$ErrorActionPreference = "Stop" #Import-Module $PSScriptRoot/HamRadioLibrary.dll function Start-HrdQsoCallBandMode { [CmdletBinding()] param ( [Parameter(Position = 0, Mandatory = $true)] [String] $AdifFile, [Parameter(Position = 1, Mandatory = $false)] [String] $CsvFileOmContacts, [Parameter(Position = 2, Mandatory = $false)] [String] $AdifFileOmContacts ) begin { Write-Verbose "Start Module : [$($MyInvocation.MyCommand)] *************************************" if (!$CsvFileOmContacts ) { $CsvFileOmContacts = ".\OmContacts.csv" } if (!$AdifFileOmContacts ) { $AdifFileOmContacts = ".\OmContacts.adi" } Write-Warning("Starting analyze, during analyse table statistics there is a lock (no read/write allowed) on the HrdLogbook table.") Start-HrdTableOptimize Write-Host("") Write-Host("Reading ADIF file : ""$($AdifFile)"", wait .............") -ForegroundColor Yellow $AdifRecords = Get-AdiReadFile -FileName $AdifFile $OmContacts = $AdifRecords Write-Host("Start comparing OM records with the HrdLogbook database") -ForegroundColor Yellow Write-Host("") $Id = 1 $Activity = "Comparing records with the HrdLogbook database" $StatusBlock = "Reading ADIF file : $AdifFile" $RecordCounter = 0 $TotalOmContacts = $OmContacts.Count $StartTime = Get-Date $AdifNotFoundArray = @() foreach ($OmContact in $OmContacts) { Write-Progress -Id $Id -Activity $Activity -Status ($StatusBlock) -PercentComplete ($RecordCounter / $TotalOmContacts * 100) $RecordCounter++ Write-Host("Doing: $($OmContact.Call)") $OmRecord = Get-HrdSearch -Call $OmContact.Call -Band $OmContact.Band -Mode $OmContact.Mode if ($OmRecord) { } else { Write-Host("NOT Found : $($OmContact.Call)") -ForegroundColor Red $AdifNotFoundArray += $OmContact } } Write-Progress -Id $Id -Activity $Activity -Status "Ready" -Completed #Disconnect-HrdDatabase Write-Host("") Write-Host("Readed ADIF records : $($TotalAdifRecords)") -ForegroundColor Yellow Write-Host("Writed ADIF records : $($AdifNotFoundArray.Count)") -ForegroundColor Yellow Write-Host "Completed in $((Get-Date).Subtract($StartTime).Minutes) minute(s) and $((Get-Date).Subtract($StartTime).Seconds) second(s)" -ForegroundColor Green Write-Host("") Write-Host("Writing CSV file : ""$($CsvFileOmContacts)""") -ForegroundColor Yellow $AdifNotFoundArray | Export-Csv -Path $CsvFileOmContacts -Encoding ASCII -NoTypeInformation Write-Host("Writing ADIF file : ""$($AdifFileOmContacts)""") -ForegroundColor Yellow Convert-CsvToAdif -CsvFileName $CsvFileOmContacts -AdifFileName $AdifFileOmContacts -Swl -QslMsgCopyToComment Write-Verbose "End Module : [$($MyInvocation.MyCommand)] *************************************" } } function Start-HrdSwlContacts { [CmdletBinding()] param ( [Parameter(Position = 0, Mandatory = $true)] [String] $AdifFile, [Parameter(Position = 1, Mandatory = $false)] [String] $CsvFileSwlContacts, [Parameter(Position = 2, Mandatory = $false)] [String] $AdifFileSwlContacts ) begin { Write-Verbose "Start Module : [$($MyInvocation.MyCommand)] *************************************" if (!$CsvFileSwlContacts ) { $CsvFileSwlContacts = ".\SwlContacts.csv" } if (!$AdifFileSwlContacts ) { $AdifFileSwlContacts = ".\SwlContacts.adi" } Write-Warning("Starting analyze, during analyse table statistics there is a lock (no read/write allowed) on the HrdLogbook table.") Start-HrdTableOptimize Write-Host("") Write-Host("Reading ADIF file : ""$($AdifFile)"", wait .............") -ForegroundColor Yellow $AdifRecords = Get-AdiReadFile -FileName $AdifFile $SwlContacts = $AdifRecords | Where-Object { $PSItem.QSLMSG -like "*wkd*" -or $PSItem.QSLMSG -like "*working*" -or $PSItem.QSLMSG -like "*wsl*" -or $PSItem.QSLMSG -like "*heard*" -or $PSItem.QSLMSG -like "*report*" } Write-Host("Start comparing SWL records with the HrdLogbook database") -ForegroundColor Yellow Write-Host("") $Id = 1 $Activity = "Comparing records with the HrdLogbook database" $StatusBlock = "Reading ADIF file : $AdifFile" $RecordCounter = 0 $TotalSwlContacts = $SwlContacts.Count $StartTime = Get-Date $AdifNotFoundArray = @() foreach ($SwlContact in $SwlContacts) { Write-Progress -Id $Id -Activity $Activity -Status ($StatusBlock) -PercentComplete ($RecordCounter / $TotalSwlContacts * 100) $RecordCounter++ Write-Host("Doing: $($SwlContact.Call)") $SwlRecord = Get-HrdSearch -Call $SwlContact.Call -Band $SwlContact.Band -Mode $SwlContact.Mode -Date $SwlContact.QsoDate -IncludeSwl if ($SwlRecord) { } else { Write-Host("NOT Found : $($SwlContact.Call)") -ForegroundColor Red $AdifNotFoundArray += $SwlContact } } Write-Progress -Id $Id -Activity $Activity -Status "Ready" -Completed #Disconnect-HrdDatabase Write-Host("") Write-Host("Readed ADIF records : $($TotalAdifRecords)") -ForegroundColor Yellow Write-Host("Writed ADIF records : $($AdifNotFoundArray.Count)") -ForegroundColor Yellow Write-Host "Completed in $((Get-Date).Subtract($StartTime).Minutes) minute(s) and $((Get-Date).Subtract($StartTime).Seconds) second(s)" -ForegroundColor Green Write-Host("") Write-Host("Writing CSV file : ""$($CsvFileSwlContacts)""") -ForegroundColor Yellow $AdifNotFoundArray | Export-Csv -Path $CsvFileSwlContacts -Encoding ASCII -NoTypeInformation Write-Host("Writing ADIF file : ""$($AdifFileSwlContacts)""") -ForegroundColor Yellow Convert-CsvToAdif -CsvFileName $CsvFileSwlContacts -AdifFileName $AdifFileSwlContacts -Swl -QslMsgCopyToComment Write-Verbose "End Module : [$($MyInvocation.MyCommand)] *************************************" } } function Get-XlsReportQsoYearMode { [CmdletBinding()] param ( [Parameter(Position = 0, Mandatory = $true)] [String] $ExcelFile, [Parameter(Position = 1, Mandatory = $false)] [Switch] $AutoOpen, [Parameter(Position = 2, Mandatory = $false)] [String] $StartDate, [Parameter(Position = 3, Mandatory = $false)] [String] $EndDate ) begin { Write-Verbose "Start Module : [$($MyInvocation.MyCommand)] *************************************" $ModuleName = "ImportExcel" $ModuleExcel = Get-Module -Name $ModuleName if ($ModuleExcel) { } else { Write-Warning("Module NOT installed, run as Administrator first : Install-Module -Name ImportExcel and Import-Module -Name ImportExcel -Force") Break } Remove-Item -Path $ExcelFile -Force -ErrorAction Ignore $Report = Get-HrdReportQsoYearMode -StartDate $StartDate -EndDate $EndDate $Report | Export-Excel -Path $ExcelFile Write-Host("Writing Excel file : ""$($ExcelFile)""") -ForegroundColor Yellow if ($AutoOpen) { # start Excel $excel = New-Object -comobject Excel.Application #open file $FilePath = (Get-ChildItem -Path $ExcelFile).FullName $Workbook = $Excel.Workbooks.Open($FilePath) #make it visible (just to check what is happening) $Excel.Visible = $true } Write-Verbose "End Module : [$($MyInvocation.MyCommand)] *************************************" } } Export-ModuleMember -function Start-HrdQsoCallBandMode Export-ModuleMember -function Start-HrdSwlContacts Export-ModuleMember -function Get-XlsReportQsoYearMode |