mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Fix Code-Styling and Validation for Strings
This commit is contained in:
parent
fe3febe660
commit
3be84379d9
1 changed files with 69 additions and 151 deletions
|
|
@ -1,36 +1,24 @@
|
|||
#
|
||||
|
||||
function ConvertTo-Byte()
|
||||
{
|
||||
param(
|
||||
[single]$Value,
|
||||
[string]$Unit #Validation PT PetaByte
|
||||
[string]$Unit
|
||||
);
|
||||
|
||||
switch ($Unit) {
|
||||
Byte {
|
||||
$result = $Value;
|
||||
break;
|
||||
{ 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
|
||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; }
|
||||
default {
|
||||
if (-Not $boolOption) {
|
||||
Throw 'Invalid input';
|
||||
}
|
||||
KiloByte {
|
||||
$result = ($Value * [math]::Pow(10, 3));
|
||||
break;
|
||||
}
|
||||
MegaByte {
|
||||
$result = ($Value * [math]::Pow(10, 6));
|
||||
break;
|
||||
}
|
||||
GigaByte {
|
||||
$result = ($Value * [math]::Pow(10, 9));
|
||||
break;
|
||||
}
|
||||
TeraByte {
|
||||
$result = ($Value * [math]::Pow(10, 12));
|
||||
break;
|
||||
}
|
||||
PetaByte {
|
||||
$result = ($Value * [math]::Pow(10, 15));
|
||||
break;
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
@ -43,31 +31,17 @@ function ConvertTo-KiloByte()
|
|||
);
|
||||
|
||||
switch ($Unit) {
|
||||
Byte {
|
||||
$result = ($Value / 1000);
|
||||
break;
|
||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
{ 'KB', 'KiloByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
|
||||
default {
|
||||
if (-Not $boolOption) {
|
||||
Throw 'Invalid input';
|
||||
}
|
||||
KiloByte {
|
||||
$result = $Value;
|
||||
break;
|
||||
}
|
||||
MegaByte {
|
||||
$result = ($Value * [math]::Pow(10, 3));
|
||||
break;
|
||||
}
|
||||
GigaByte {
|
||||
$result = ($Value * [math]::Pow(10, 6));
|
||||
break;
|
||||
}
|
||||
TeraByte {
|
||||
$result = ($Value * [math]::Pow(10, 9));
|
||||
break;
|
||||
}
|
||||
PetaByte {
|
||||
$result = ($Value * [math]::Pow(10, 12));
|
||||
break;
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
@ -81,31 +55,17 @@ function ConvertTo-MegaByte()
|
|||
);
|
||||
|
||||
switch($Unit) {
|
||||
Byte {
|
||||
$result = ($Value / [math]::Pow(10, 6));
|
||||
break;
|
||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
{ 'MB', 'MegaByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
||||
default {
|
||||
if (-Not $boolOption) {
|
||||
Throw 'Invalid input';
|
||||
}
|
||||
KiloByte {
|
||||
$result = ($Value / [math]::Pow(10, 3));
|
||||
break;
|
||||
}
|
||||
MegaByte {
|
||||
$result = $Value;
|
||||
break;
|
||||
}
|
||||
GigaByte {
|
||||
$result = ($Value * [math]::Pow(10, 3));
|
||||
break;
|
||||
}
|
||||
TeraByte {
|
||||
$result = ($Value * [math]::Pow(10, 6));
|
||||
break;
|
||||
}
|
||||
PetaByte {
|
||||
$result = ($Value * [math]::Pow(10, 9));
|
||||
break;
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
@ -119,31 +79,17 @@ function ConvertTo-GigaByte()
|
|||
);
|
||||
|
||||
switch($Unit) {
|
||||
Byte {
|
||||
$result = ($Value / [math]::Pow(10, 9));
|
||||
break;
|
||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
{ 'GB', 'GigaByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
||||
default {
|
||||
if (-Not $boolOption) {
|
||||
Throw 'Invalid input';
|
||||
}
|
||||
KiloByte {
|
||||
$result = ($Value / [math]::Pow(10, 6));
|
||||
break;
|
||||
}
|
||||
MegaByte {
|
||||
$result = ($Value / [math]::Pow(10, 3));
|
||||
break;
|
||||
}
|
||||
GigaByte {
|
||||
$result = $Value;
|
||||
break;
|
||||
}
|
||||
TeraByte {
|
||||
$result = ($Value * [math]::Pow(10, 3));
|
||||
break;
|
||||
}
|
||||
PetaByte {
|
||||
$result = ($Value * [math]::Pow(10, 6));
|
||||
break;
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
@ -157,31 +103,17 @@ function ConvertTo-TeraByte()
|
|||
);
|
||||
|
||||
switch($Unit) {
|
||||
Byte {
|
||||
$result = ($Value / [math]::Pow(10, 12));
|
||||
break;
|
||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; }
|
||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
{ 'TB', 'TeraByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
default {
|
||||
if (-Not $boolOption) {
|
||||
Throw 'Invalid input';
|
||||
}
|
||||
KiloByte {
|
||||
$result = ($Value / [math]::Pow(10, 9));
|
||||
break;
|
||||
}
|
||||
MegaByte {
|
||||
$result = ($Value / [math]::Pow(10, 6));
|
||||
break;
|
||||
}
|
||||
GigaByte {
|
||||
$result = ($Value / [math]::Pow(10, 3));
|
||||
break;
|
||||
}
|
||||
TeraByte {
|
||||
$result = $Value;
|
||||
break;
|
||||
}
|
||||
PetaByte {
|
||||
$result = ($Value * [math]::Pow(10, 3));
|
||||
break;
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
@ -195,31 +127,17 @@ function ConvertTo-PetaByte()
|
|||
);
|
||||
|
||||
switch($Unit) {
|
||||
Byte {
|
||||
$result = ($Value / [math]::Pow(10, 15));
|
||||
break;
|
||||
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 15)); $boolOption = $true; }
|
||||
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; }
|
||||
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
||||
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
||||
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
||||
{ 'PT', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||
default {
|
||||
if (-Not $boolOption) {
|
||||
Throw 'Invalid input';
|
||||
}
|
||||
KiloByte {
|
||||
$result = ($Value / [math]::Pow(10, 12));
|
||||
break;
|
||||
}
|
||||
MegaByte {
|
||||
$result = ($Value / [math]::Pow(10, 9));
|
||||
break;
|
||||
}
|
||||
GigaByte {
|
||||
$result = ($Value / [math]::Pow(10, 6));
|
||||
break;
|
||||
}
|
||||
TeraByte {
|
||||
$result = ($Value / [math]::Pow(10, 3));
|
||||
break;
|
||||
}
|
||||
PetaByte {
|
||||
$result = $Value;
|
||||
break;
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
|
|||
Loading…
Reference in a new issue