Stephanevg / PSClassUtils

A set of utilities to work with Powershell Classes
http://powershelldistrict.com/how-to-generate-a-uml-diagram-using-powershell/
91 stars 23 forks source link

-Show compistion doesn't work when static methods #108

Open Stephanevg opened 5 years ago

Stephanevg commented 5 years ago

Result of image below image

Stephanevg commented 4 years ago

Another example:


Enum RunSourceType {
    json
    xml
    database
}

Class PCCRunDocument {

    [String]$ComputerName
    [String]$PackageName
    [DateTime]$Executiondate
    [RunSourceType]$FileType
    [Object]$Data
    Hidden [String]$Source
    #[PCCRunDocument]::New('C:\Users\taavast3\OneDrive\Repo\Projects\Clients\Swisscom\ESC\PCCComplianceChecks\Tests\PCC_SAGITTA5170017_PCC.chk.esc.win.spdn_20191023-172317.json')

    PccRunDocument([system.io.fileInfo]$Document){
        $d = $Document.Name.Split('_')
        $This.ComputerName = $d[1]
        $This.PackageName = $d[2]
        If($d[3] -match "^(?'year'\d{4})(?'month'\d{2})(?'day'\d{2})-(?'hour'\d{2})(?'minute'\d{2})(?'second'\d{2}).*$"){
            $this.Executiondate = Get-date -Year $Matches.Year -Month $Matches.Month -Day $Matches.Day -Hour $Matches.Hour -Minute $Matches.minute -Second $Matches.second
        }
        $This.FileType = $Document.Extension.Replace(".","")
        $this.Data = gc $Document.FullName | ConvertFrom-Json
        $This.Source = $Document
    }

    <#

    static [PccRunDocument[]]  GetPccRunDocument([System.IO.DirectoryInfo]$Folder){

        $RunDocuments = Find-pccRunDocument -Path $Folder
        $AllDocuments = @()
        Foreach($Doc in $RunDocuments){
            $AllDocuments = [PCCRunDocument]::New($Doc)
        }

        Return $AllDocuments
    }
    #>

}

Class PCCRunDocumentFactory{

    <#
        static [PCCRunDocument[]] Create([String]$Path){
        $Item = Get-Item -Path $Path
        $Return = @()
        Switch($Item.GetType().FullName){
            "system.io.FileInfo"{
                $Return += [PCCRunDocument]::New($Item)
            }
            "system.io.DirectoryInfo"{
                $Files = Find-pccRunDocument -Path $Item.FullName
                Foreach($File in $Files){

                    $Return += [PCCRunDocument]::New($File)
                }
            }
        }

        return $Return
    }
    #>

    static [PCCRunDocuments] Create([String]$Path){
        $Item = Get-Item -Path $Path
        $Return = [PccRunDocuments]::New()
        Switch($Item.GetType().FullName){
            "system.io.FileInfo"{
                $Return.AddRunDocument([PCCRunDocument]::New($Item))
            }
            "system.io.DirectoryInfo"{
                $Files = Find-pccRunDocument -Path $Item.FullName
                Foreach($File in $Files){

                    $Return.AddRunDocument([PCCRunDocument]::New($File))
                }
            }
        }

        return $Return
    }

}

Class PCCRunDocuments {
    [System.Collections.Generic.List[PCCRunDocument]]$RunDocuments = @()

    PccRunDocuments(){

    }

    AddRunDocument([PccRunDocument[]]$Document){

        Foreach($doc in $Document){
            $this.RunDocuments.Add($doc)
        }
    }

    [System.Collections.Generic.List[PCCRunDocument]]GetRunDocuments(){
        return $This.RunDocuments
    }

    [PCCRunDocument[]] GetRunDocumentsOfComputer([String]$ComputerName){
        $Return = @()

        $Return += $This.RunDocuments | ? {$_.ComputerName -eq $ComputerName}

        return $Return
    }

    [PCCRunDocument[]] GetRunDocumentsOfPackage([String]$PackageName){
        $Return = @()

        $Return += $This.RunDocuments | ? {$_.PackageName -eq $PackageName}

        return $Return
    }
}

REturns

image

Write-CUClassDiagram -Path C:\Users\taavast3\OneDrive\Repo\Projects\Clients\Swisscom\ESC\PCCComplianceChecks\Code\Classes\Class.PCCPackage.ps1 -Show -ShowComposition -Verbose