Skip to content

Commit 2d4776a

Browse files
authored
Merge pull request #53 from Corsinvest/release/v9.1.1
Release v9.1.1
2 parents 53c4ec5 + 149b9c5 commit 2d4776a

File tree

15 files changed

+63
-73
lines changed

15 files changed

+63
-73
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFrameworks>net8.0;net9.0;net10.0;netstandard2.0</TargetFrameworks>
44
<LangVersion>latest</LangVersion>
55
<ImplicitUsings>enable</ImplicitUsings>
6-
<Version>9.1.0</Version>
6+
<Version>9.1.1</Version>
77
<!--<NoWarn>$(NoWarn);CS1591;CS0436</NoWarn>-->
88

99
<Company>Corsinvest Srl</Company>

src/Corsinvest.ProxmoxVE.Api.Console/Helpers/ShellHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ public static (string StandardOutput, int ExitCode) Execute(string cmd,
8888

8989
if (dryRun)
9090
{
91-
return ("", 0);
91+
return (string.Empty, 0);
9292
}
9393
else
9494
{
9595
process.Start();
96-
var standardOutput = redirectStandardOutput ? process.StandardOutput.ReadToEnd() : "";
96+
var standardOutput = redirectStandardOutput
97+
? process.StandardOutput.ReadToEnd()
98+
: string.Empty;
9799
var exitCode = 0;
98100
if (waitForExit)
99101
{

src/Corsinvest.ProxmoxVE.Api.Extension/ClientExtension.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static async Task<IEnumerable<IClusterResourceVm>> GetVmsAsync(this PveCl
114114
/// <param name="vmId"></param>
115115
/// <returns></returns>
116116
public static async Task<IClusterResourceVm> GetVmAsync(this PveClient client, long vmId)
117-
=> await client.GetVmAsync(vmId + "");
117+
=> await client.GetVmAsync(vmId + string.Empty);
118118

119119
/// <summary>
120120
/// Get VM/CT from id or name.
@@ -185,8 +185,8 @@ async Task<IEnumerable<IClusterResourceVm>> GetVmsFromIdAsync(string id)
185185
{
186186
//all in specific tag
187187
var tagName = id[5..];
188-
data = allVms.Where(a => (a.Tags + "").ToLower().Split(';').Contains(tagName.ToLower())
189-
|| (a.Tags + "").Split(';').Contains(tagName));
188+
data = allVms.Where(a => (a.Tags + string.Empty).ToLower().Split(';').Contains(tagName.ToLower())
189+
|| (a.Tags + string.Empty).Split(';').Contains(tagName));
190190
}
191191
else
192192
{
@@ -372,7 +372,7 @@ public static async Task<IEnumerable<string>> GetVmIdsAsync(this PveClient clien
372372
}
373373

374374
var vms = resources.Where(a => a.ResourceType == ClusterResourceType.Vm && !a.IsUnknown);
375-
if (addVmId) { vmIds.AddRange(vms.Select(a => a.VmId + "").OrderBy(a => a)); }
375+
if (addVmId) { vmIds.AddRange(vms.Select(a => a.VmId + string.Empty).OrderBy(a => a)); }
376376
if (addVmName) { vmIds.AddRange(vms.Select(a => a.Name).OrderBy(a => a)); }
377377

378378
return vmIds.Distinct();

src/Corsinvest.ProxmoxVE.Api.Extension/Utils/ApiExplorerHelper.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public string ToTable(bool verbose, TableGenerator.Output output)
176176
? ["name", "description", "command", "args", "sys"]
177177
: new[] { "name", "description", "sys" };
178178

179-
static string EncodeSystem(bool system) => system ? "X" : "";
179+
static string EncodeSystem(bool system) => system ? "X" : string.Empty;
180180

181181
var rows = Alias.OrderByDescending(a => a.System)
182182
.ThenBy(a => a.Name)
@@ -395,16 +395,17 @@ private static string CreateTableDynamic(dynamic data, string[] keys, TableGener
395395
{
396396
var columns = new List<string>();
397397
var rows = new List<object[]>();
398+
var print = false;
398399

399400
if (data is ExpandoObject)
400401
{
401-
//dictionary
402402
var dic = (IDictionary<string, object>)data;
403403

404404
columns.Add("key");
405405
columns.Add("value");
406406

407407
keys ??= [.. dic.Select(a => a.Key)];
408+
print = true;
408409

409410
foreach (var key in keys.OrderBy(a => a))
410411
{
@@ -438,25 +439,29 @@ private static string CreateTableDynamic(dynamic data, string[] keys, TableGener
438439
value = GetValue(value, title, returnParameters);
439440
}
440441

441-
value ??= "";
442+
value ??= string.Empty;
442443
row.Add(value);
443444
}
444445

445-
rowsTmp.Add(new KeyValuePair<object, object[]>(row[0] + "", [.. row]));
446+
rowsTmp.Add(new KeyValuePair<object, object[]>(row[0] + string.Empty, [.. row]));
446447
}
447448

448449
//order row by first column
449450
rows.AddRange([.. rowsTmp.OrderBy(a => a.Key).Select(a => a.Value)]);
450-
if (rows.Count == 0) { data = ""; }
451+
if (rows.Count == 0) { data = string.Empty; }
451452
}
452453

453454
if (rows.Count > 0)
454455
{
455456
return TableGenerator.To(columns, rows, output);
456457
}
458+
else if (print)
459+
{
460+
return string.Empty;
461+
}
457462
else
458463
{
459-
return data;
464+
return data + string.Empty;
460465
}
461466
}
462467

@@ -491,7 +496,7 @@ private static void CreateTable(IEnumerable<ParameterApi> parameters, StringBuil
491496
if (!string.IsNullOrWhiteSpace(param.TypeText))
492497
{
493498
//explicit text
494-
partsType = JoinWord(param.TypeText.Split(' '), 18, "");
499+
partsType = JoinWord(param.TypeText.Split(' '), 18, string.Empty);
495500
}
496501
else if (param.EnumValues.Any())
497502
{
@@ -501,9 +506,9 @@ private static void CreateTable(IEnumerable<ParameterApi> parameters, StringBuil
501506

502507
for (var i = 0; i < Math.Max(partsType.Length, partsComment.Length); i++)
503508
{
504-
values.Add([ i == 0 ? param.Name : "",
505-
i < partsType.Length ? partsType[i] : "",
506-
i < partsComment.Length ? partsComment[i] : "" ]);
509+
values.Add([ i == 0 ? param.Name : string.Empty,
510+
i < partsType.Length ? partsType[i] : string.Empty,
511+
i < partsComment.Length ? partsComment[i] : string.Empty ]);
507512
}
508513
}
509514

@@ -550,7 +555,7 @@ public static string Usage(ClassApi classApiRoot,
550555
//only parameters no keys
551556
var parameters = method.Parameters.Where(a => !classApi.Keys.Contains(a.Name));
552557

553-
var opts = string.Join("", parameters.Where(a => !a.Optional).Select(a => $" {a.Name}:<{a.Type}>"));
558+
var opts = string.Join(string.Empty, parameters.Where(a => !a.Optional).Select(a => $" {a.Name}:<{a.Type}>"));
554559
if (!string.IsNullOrWhiteSpace(opts)) { ret.Append(opts); }
555560

556561
//optional parameter
@@ -609,7 +614,7 @@ private static string[] JoinWord(string[] words, int numChar, string separator)
609614
string resource)
610615
{
611616
var values = new List<(string Attribute, string Value)>();
612-
var error = "";
617+
var error = string.Empty;
613618

614619
var classApi = ClassApi.GetFromResource(classApiRoot, resource);
615620
if (classApi == null)
@@ -645,15 +650,15 @@ private static string[] JoinWord(string[] words, int numChar, string separator)
645650
var returnLinkHRef = classApi.Methods.FirstOrDefault(a => a.IsGet).ReturnLinkHRef;
646651
if (!string.IsNullOrWhiteSpace(returnLinkHRef))
647652
{
648-
key = returnLinkHRef.Replace("{", "").Replace("}", "");
653+
key = returnLinkHRef.Replace("{", string.Empty).Replace("}", string.Empty);
649654
}
650655
}
651656

652657
if (result.ToData() != null && !string.IsNullOrWhiteSpace(key))
653658
{
654659
var data = new List<object>();
655660
foreach (IDictionary<string, object> item in result.ToData()) { data.Add(item[key]); }
656-
foreach (var item in data.OrderBy(a => a)) { values.Add((attribute, item + "")); }
661+
foreach (var item in data.OrderBy(a => a)) { values.Add((attribute, item + string.Empty)); }
657662
}
658663
}
659664
}
@@ -679,7 +684,9 @@ public static async Task<string> ListAsync(PveClient client, ClassApi classApiRo
679684
{
680685
var (values, error) = await ListValuesAsync(client, classApiRoot, resource);
681686
return string.Join(Environment.NewLine, values.Select(a => $"{a.Attribute} {a.Value}")) +
682-
(string.IsNullOrWhiteSpace(error) ? "" : Environment.NewLine + error) +
687+
(string.IsNullOrWhiteSpace(error)
688+
? string.Empty
689+
: Environment.NewLine + error) +
683690
Environment.NewLine;
684691
}
685692
}

src/Corsinvest.ProxmoxVE.Api.Extension/Utils/VmHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static bool CheckIdOrName(IClusterResourceVm data, string vmIdOrName)
108108
{
109109
//string check name
110110
var name = data.Name.ToLower();
111-
var vmIdOrNameLower = vmIdOrName.Replace("%", "").ToLower();
111+
var vmIdOrNameLower = vmIdOrName.Replace("%", string.Empty).ToLower();
112112
if (vmIdOrName.Contains('%'))
113113
{
114114
if (vmIdOrName.StartsWith("%") && vmIdOrName.EndsWith("%")) { return name.Contains(vmIdOrNameLower); }
@@ -196,7 +196,7 @@ public static async Task<IEnumerable<string>> GetVmsJollyKeysAsync(PveClient cli
196196
}
197197

198198
var vms = resources.Where(a => a.ResourceType == ClusterResourceType.Vm && !a.IsUnknown);
199-
if (addVmId) { vmIds.AddRange(vms.Select(a => a.VmId + "").OrderBy(a => a)); }
199+
if (addVmId) { vmIds.AddRange(vms.Select(a => a.VmId + string.Empty).OrderBy(a => a)); }
200200
if (addVmName) { vmIds.AddRange(vms.Select(a => a.Name).OrderBy(a => a)); }
201201

202202
return vmIds.Distinct();

src/Corsinvest.ProxmoxVE.Api.Metadata/ClassApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ClassApi
2626
public ClassApi(JToken token, ClassApi parent)
2727
{
2828
Name = token["text"].ToString().Replace("-", "_");
29-
IndexName = Name.Replace("{", "").Replace("}", "");
29+
IndexName = Name.Replace("{", string.Empty).Replace("}", string.Empty);
3030
Parent = parent;
3131
Resource = token["path"].ToString();
3232

src/Corsinvest.ProxmoxVE.Api.Metadata/MethodApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public MethodApi(JToken token, ClassApi classApi)
2121
{
2222
MethodType = token["method"].ToString();
2323
MethodName = token["name"].ToString();
24-
Comment = token["description"] + "";
24+
Comment = token["description"] + string.Empty;
2525
ClassApi = classApi;
2626

2727
var returns = token["returns"];
2828
if (returns != null)
2929
{
30-
ReturnType = returns["type"] + "";
30+
ReturnType = returns["type"] + string.Empty;
3131

3232
if (returns["properties"] != null)
3333
{

src/Corsinvest.ProxmoxVE.Api.Metadata/ParameterApi.cs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ public class ParameterApi
2222
public ParameterApi(JToken token)
2323
{
2424
Name = ((JProperty)token.Parent).Name;
25-
NameIndexed = Name.Replace("[n]", "");
25+
NameIndexed = Name.Replace("[n]", string.Empty);
2626
IsIndexed = Name.EndsWith("[n]");
27-
Description = token["description"] + "";
28-
VerboseDescription = token["verbose_description"] + "";
27+
Description = token["description"] + string.Empty;
28+
VerboseDescription = token["verbose_description"] + string.Empty;
2929
Optional = (token["optional"] ?? 0).ToString() == "1";
30-
Type = token["type"] + "";
31-
TypeText = token["typetext"] + "";
30+
Type = token["type"] + string.Empty;
31+
TypeText = token["typetext"] + string.Empty;
3232
Maximum = token["maximum"] == null ? null : (long?)token["maximum"];
3333
Minimum = token["minimum"] == null ? null : (int?)token["minimum"];
34-
Renderer = token["renderer"] + "";
35-
Default = token["default"] == null ? null : token["default"] + "";
34+
Renderer = token["renderer"] + string.Empty;
35+
Default = token["default"] == null ? null : token["default"] + string.Empty;
3636

3737
if (token["properties"] != null)
3838
{
@@ -111,11 +111,11 @@ public object RendererValue(object value)
111111
case "fraction_as_percentage":
112112
value = double.TryParse(value.ToString(), out var perValue) && perValue > 0
113113
? Math.Round(perValue * 100, 2) + "%"
114-
: "";
114+
: string.Empty;
115115
break;
116116

117117
case "bytes":
118-
if (long.TryParse(value.ToString(), out var bytesValue) && bytesValue > 0)
118+
if (value != null && long.TryParse(value.ToString(), out var bytesValue) && bytesValue > 0)
119119
{
120120
var sizes = new string[] { "B", "KiB", "MiB", "GiB", "TiB" };
121121
var order = 0;
@@ -125,36 +125,17 @@ public object RendererValue(object value)
125125
bytesValue /= 1024;
126126
}
127127
value = $"{bytesValue} {sizes[order]}";
128-
129-
130-
// if (bytesValue > Math.Pow(1024, 4))
131-
// {
132-
// value = Math.Round(bytesValue / Math.Pow(1024, 4), 2) + " TiB";
133-
// }
134-
// else if (bytesValue > Math.Pow(1024, 3))
135-
// {
136-
// value = Math.Round(bytesValue / Math.Pow(1024, 3), 2) + " GiB";
137-
// }
138-
// else if (bytesValue > Math.Pow(1024, 2))
139-
// {
140-
// value = Math.Round(bytesValue / Math.Pow(1024, 2), 2) + " MiB";
141-
// }
142-
// else if (bytesValue > 1024)
143-
// {
144-
// value = Math.Round(bytesValue / 1024.0, 0) + " KiB";
145-
// }
146-
// else { value = bytesValue + " B"; }
147128
}
148129
else
149130
{
150-
value = "";
131+
value = string.Empty;
151132
}
152133
break;
153134

154135
case "duration":
155136
value = int.TryParse(value.ToString(), out var duration) && duration > 0
156137
? new TimeSpan(0, 0, duration).ToString(@"d\d\ h\h\ m\m\ ss\s")
157-
: "";
138+
: string.Empty;
158139
break;
159140

160141
case "timestamp": break;

src/Corsinvest.ProxmoxVE.Api.Metadata/ParameterFormatApi.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public class ParameterFormatApi
1919
public ParameterFormatApi(JToken token)
2020
{
2121
Name = ((JProperty)token.Parent).Name;
22-
Description = token["description"] + "";
22+
Description = token["description"] + string.Empty;
2323
Optional = (token["optional"] ?? 0).ToString() == "1";
24-
Type = token["type"] + "";
24+
Type = token["type"] + string.Empty;
2525
Maximum = token["maximum"] == null ? null : (int?)token["maximum"];
2626
Minimum = token["minimum"] == null ? null : (int?)token["minimum"];
27-
DefaultKey = token["default_key"] + "";
28-
FormatDescription = token["format_description"] + "";
29-
Format = token["format"] + "";
30-
Alias = token["alias"] + "";
27+
DefaultKey = token["default_key"] + string.Empty;
28+
FormatDescription = token["format_description"] + string.Empty;
29+
Format = token["format"] + string.Empty;
30+
Alias = token["alias"] + string.Empty;
3131
MaxLength = token["maxLength"] == null ? null : (int?)token["maxLength"];
3232

3333
#region create enum values

src/Corsinvest.ProxmoxVE.Api.Shared/Models/Cluster/ClusterExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static void ImproveData(this IClusterResourceBase data)
6060
var s when s == PveConstants.KeyApiStorage => $"{((IStorageItem)data).Storage} ({data.Node})",
6161
var s when s == PveConstants.KeyApiQemu || s == PveConstants.KeyApiLxc => $"{((IVmBase)data).VmId} ({((IVmBase)data).Name})",
6262
var s when s == PveConstants.KeyApiPool => ((IPoolItem)data).Pool,
63-
_ => "",
63+
_ => string.Empty,
6464
};
6565

6666
data.IsUnknown = data.Status == PveConstants.StatusUnknown;

0 commit comments

Comments
 (0)