# glog.psm1 module
<#
 This module contains a debug log function that manages an external log file that vcan be used to diagnose
 psec-v4 truoubles without polluting the command window.

 It is sugested an external editor that can reload change files be used to look at the log file created.

 5 versions of the dlog-psec.txt file produced are kept (dlog-psec-v1.txt .. dlog-psec-v5.txt), v5 being the oldest.

 permanent copies of a particular file can be maintained by renaming it to a different pattern.

 The dlog.close function is used to cycle the filenames and write the current contents and flush the buffer.

 The dlog.flush command simply flushes the buffer to the current file, and clears the buffer.


History:
  EC2512 - initial version
#>

<##.mod-doc
gui-utils.psm1
==============

_PSEC version 0.0.9_

#### General Purpose GUI Utility Function ####

This script module contains the routines that handle the GUI utility functions

#>

using namespace System.Collections;

[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
[reflection.assembly]::LoadWithPartialName("System.Drawing.Icon")
Add-Type -AssemblyName PresentationCore,PresentationFramework


set-strictmode -version 2.0

<#.md
.desc
The DlogObj used to manage a versioned debug file.
.details
This DlogObj is typically stored ion a GLOBAL object so that access from many modules is convenient.

If multiple threads are open, duplicate files are created (with a dup tag to identify them).

The primary debug file is versioned in that 5 previous versions are retained.
#>
class DLogObj { $lines = $null; [string] $basePath = $null; [string] $fileName = $null; [string] $filePath = $null; <#.md .desc Creates the DlogObj object sed to manage a versioned debug file. .details This object is used to manage a Debug file that is populated with debug statements. If multiple threads are open, duplicate files are created (with a dup tag to identify them). The primary debug file is versioned in that 5 previous versions are retained. #> [DlogObj] static create([string] $path,[string]$jamPath) { #jayehlogReal("dlog.create $path jam $jamPath"); $dlog = [DlogObj]::new(); $dlog.lines = [ArrayList]::new(); $dlog.basePath = $path; if ($jamPath -eq "") { $dup = $dlog.getDlogDupStr() $dlog.fileName = "dlog-psec-v4$($dup)"; $dlog.filePath = "$($dlog.basePath)/$($dlog.fileName).txt"; #hlogReal("creating $path dlog $($dlog.basePath) $($dlog.filePath)"); $dlog.cycle(); } else { $dlog.fileName = $jamPath | Split-Path -Leaf $dlog.filePath = $jamPath if (test-path $dlog.filePath) {remove-item -path $dlog.filePath}; #we do not have versioning with jammed log files #hlogReal("jam.create $path dlog $($dlog.basePath) $($dlog.filePath)"); } return $dlog; } <#.md .desc This is used to create a unique dlog file based on concurrent PSEC windows. For convenience it tries to use the basic name. #>
[string] getDlogDupStr() { $objs = (Get-Process | Where-Object {$_.mainModule -match "powershell[.]exe"}) #$objs | Format-Table Id, Name, mainWindowtitle, MainModule, StartInfo -AutoSize $dups = 0; forEach($ps in $objs) { if (($null -ne $ps.mainWindowTitle) -and ("" -ne $ps.mainWindowTitle)) {$dups += 1} } ##hlog("dups $($objs.length) counts=$dups") if ($dups -lt 2) {return "";} $dups -= 1; return "-dup$($dups)" } <#.md .desc adds `line` to internal line array. #>
[void] info([string]$line) { $this.lines.add($line) } <#.md .desc flushes internal line array to persistant storage. Expensive. #>
[void] flush() { [string]$str = ($this.lines | out-string) $this.append($str); $this.lines = [ArrayList]::new(); } <#.md .desc appends string to persistant storage. Expensive. #>
[void]append($str) { [void]($str | Out-File -FilePath $this.filePath -encoding ascii -Append) } <#.md .desc remove oldest file, rename previous files and allow new generation to be created. #>
[void] cycle() { $strv5 = "$($this.basePath)\$($this.fileName)-v5.txt"; if (test-path $strv5) {remove-item -path $strv5}; $strv4 = "$($this.basePath)\$($this.fileName)-v4.txt"; if (test-path $strv4) {rename-item -path $strv4 -newName $strv5}; $strv3 = "$($this.basePath)\$($this.fileName)-v3.txt"; if (test-path $strv3) {rename-item -path $strv3 -newName $strv4}; $strv2 = "$($this.basePath)\$($this.fileName)-v2.txt"; if (test-path $strv2) {rename-item -path $strv2 -newName $strv3}; $strv1 = "$($this.basePath)\$($this.fileName)-v1.txt"; if (test-path $strv1) {rename-item -path $strv1 -newName $strv2}; if (test-path $this.filePath) {rename-item -path $this.filePath -newName $strv1} } } function dlogVersion() { "dlog loaded. Version V1 from $($args[0])" }
X
PSEC - Powershell Enhanced Capability
1.2.1
  src: dlog.psm1

Copyright © 2018-2021, 2022, Rexcel System Inc.