-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from KevinMarquette/feature/record !deploy
Feature/record
- Loading branch information
Showing
14 changed files
with
912 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function Format-KeyName | ||
{ | ||
[OutputType('System.String')] | ||
[cmdletbinding()] | ||
param( | ||
[Parameter(Position = 0)] | ||
[string] | ||
$InputObject | ||
) | ||
begin | ||
{ | ||
$translate = @{ | ||
Damping = 'Damping' | ||
K = 'K' | ||
URL = 'URL' | ||
} | ||
} | ||
process | ||
{ | ||
$InputObject = $InputObject.ToLower() | ||
if ( $translate.ContainsKey( $InputObject ) ) | ||
{ | ||
return $translate[ $InputObject ] | ||
} | ||
return $InputObject | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
|
||
Enum EntityType | ||
{ | ||
Name | ||
Value | ||
TypeName | ||
} | ||
|
||
Function Entity | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Convert an object into a PSGraph Record | ||
.DESCRIPTION | ||
Convert an object into a PSGraph Record | ||
.PARAMETER InputObject | ||
The object to convert into a record | ||
.PARAMETER Name | ||
The name of the node | ||
.PARAMETER Show | ||
The different details to show in the record. | ||
Name : The property name | ||
Value : The property name and value | ||
TypeName : The property name and the value type | ||
.PARAMETER Property | ||
The list of properties to display. Default is to list them all. | ||
Supports wildcards. | ||
.EXAMPLE | ||
$sample = [pscustomobject]@{ | ||
first = 1 | ||
second = 'two' | ||
} | ||
graph { | ||
$sample | Entity -Show TypeName | ||
} | export-PSGraph -ShowGraph | ||
.NOTES | ||
General notes | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[parameter( | ||
ValueFromPipeline, | ||
position = 0 | ||
)] | ||
$InputObject, | ||
|
||
[string] | ||
$Name, | ||
|
||
[string[]] | ||
$Property, | ||
|
||
[EntityType] | ||
$Show = [EntityType]::TypeName | ||
) | ||
|
||
end | ||
{ | ||
if([string]::isnullorempty($Name) ) | ||
{ | ||
$Name = $InputObject.GetType().Name | ||
} | ||
|
||
if($InputObject -is [System.Collections.IDictionary]) | ||
{ | ||
$members = $InputObject.keys | ||
} | ||
else | ||
{ | ||
$Members = $InputObject.PSObject.Properties.Name | ||
} | ||
|
||
$rows = foreach ($propertyName in $members) | ||
{ | ||
if($null -ne $Property) | ||
{ | ||
$matches = $property | Where-Object {$propertyName -like $_} | ||
if($null -eq $matches) | ||
{ | ||
continue | ||
} | ||
} | ||
|
||
$value = $inputobject.($propertyName) | ||
switch ($Show) | ||
{ | ||
Name | ||
{ | ||
Row "<B>$propertyName</B>" -Name $propertyName | ||
} | ||
TypeName | ||
{ | ||
if($null -ne $value) | ||
{ | ||
$type = $value.GetType().Name | ||
} | ||
else | ||
{ | ||
$type = 'null' | ||
} | ||
Row ('<B>{0}</B> <I>[{1}]</I>' -f $propertyName, $type) -Name $propertyName | ||
} | ||
Value | ||
{ | ||
if([string]::IsNullOrEmpty($value)) | ||
{ | ||
$value = ' ' | ||
} | ||
elseif ($value.count -gt 1) | ||
{ | ||
$value = '[object[]]' | ||
} | ||
Row ('<B>{0}</B> : <I>{1}</I>' -f $propertyName, ([System.Net.WebUtility]::HtmlEncode($value))) -Name $propertyName | ||
} | ||
} | ||
} | ||
|
||
Record -Name $Name -Row $rows | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
|
||
function Record | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Creates a record object | ||
.DESCRIPTION | ||
Creates a record object that contains rows of data. | ||
.PARAMETER Name | ||
The node name for this record | ||
.PARAMETER Label | ||
The label to use for the headder of the record. | ||
.PARAMETER Row | ||
An array of strings/objects to place in this record | ||
.PARAMETER RowScript | ||
A script to run on each row | ||
.PARAMETER ScriptBlock | ||
A sub expression that contains Row commands | ||
.EXAMPLE | ||
graph { | ||
Record Components1 @( | ||
'Name' | ||
'Environment' | ||
'Test <I>[string]</I>' | ||
) | ||
Record Components2 { | ||
Row Name | ||
Row 'Environment <B>test</B>' | ||
'Test' | ||
} | ||
Edge Components1:Name -to Components2:Name | ||
Echo one two three | Record Fish | ||
Record Cow red,blue,green | ||
} | Export-PSGraph -ShowGraph | ||
.NOTES | ||
Early release version of this command. | ||
A lot of stuff is hard coded that should be exposed as attributes | ||
#> | ||
[OutputType('System.String')] | ||
[cmdletbinding(DefaultParameterSetName = 'Script')] | ||
param( | ||
[Parameter( | ||
Mandatory, | ||
Position = 0 | ||
)] | ||
[alias('ID', 'Node')] | ||
[string] | ||
$Name, | ||
|
||
[Parameter( | ||
Position = 1, | ||
ValueFromPipeline, | ||
ParameterSetName = 'Strings' | ||
)] | ||
[alias('Rows')] | ||
[Object[]] | ||
$Row, | ||
|
||
[Parameter( | ||
Position = 1, | ||
ParameterSetName = 'Script' | ||
)] | ||
[ScriptBlock] | ||
$ScriptBlock, | ||
|
||
[Parameter( | ||
Position = 2 | ||
)] | ||
[ScriptBlock] | ||
$RowScript, | ||
|
||
[string] | ||
$Label | ||
) | ||
begin | ||
{ | ||
$tableData = [System.Collections.ArrayList]::new() | ||
if ( [string]::IsNullOrEmpty($Label) ) | ||
{ | ||
$Label = $Name | ||
} | ||
} | ||
process | ||
{ | ||
if ( $null -ne $ScriptBlock ) | ||
{ | ||
$Row = $ScriptBlock.Invoke() | ||
} | ||
|
||
if ( $null -ne $RowScript ) | ||
{ | ||
$Row = foreach ( $node in $Row ) | ||
{ | ||
@($node).ForEach($RowScript) | ||
} | ||
} | ||
|
||
$results = foreach ( $node in $Row ) | ||
{ | ||
Row -Label $node | ||
} | ||
|
||
foreach ( $node in $results ) | ||
{ | ||
[void]$tableData.Add($node) | ||
} | ||
} | ||
end | ||
{ | ||
$html = '<TABLE CELLBORDER="1" BORDER="0" CELLSPACING="0"><TR><TD bgcolor="black" align="center"><font color="white"><B>{0}</B></font></TD></TR>{1}</TABLE>' -f $Label, ($tableData -join '') | ||
Node $Name @{label = $html; shape = 'none'; fontname = "Courier New"; style = "filled"; penwidth = 1; fillcolor = "white"} | ||
} | ||
} | ||
|
Oops, something went wrong.