-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvailableOptions.cs
More file actions
86 lines (77 loc) · 3.43 KB
/
Copy pathAvailableOptions.cs
File metadata and controls
86 lines (77 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CommandLine;
using CommandLine.Text;
using static nyoka_Client.Constants;
namespace nyoka_Client
{
[Verb("available", HelpText = "List available resources from the repository server.")]
public class AvailableOptions
{
public static ResourceType? resourceType;
public static string prefix;
public static int Available()
{
listAvailableResources(prefix: prefix, listType: resourceType);
return 0;
}
public static void listAvailableResources(string prefix,ResourceType? listType)
{
try
{
List<ResourceType> resourcesToList = listType.HasValue ?
new List<ResourceType> { listType.Value } :
new List<ResourceType> { ResourceType.Code, ResourceType.Data, ResourceType.Model };
PrintTable printTable = new PrintTable {
{Constants.HeaderStringType, 6},
{Constants.HeaderStringNameOfResource, 21},
{Constants.HeaderStringLatestVersion, 16},
{Constants.HeaderStringLocalVersion, 2},
{Constants.HeaderStringFileSize, 11},
};
foreach (ResourceType resourceType in resourcesToList)
{
var availableResources = NetworkUtils.getAvailableResources(prefix,resourceType);
foreach (string resourceName in availableResources.resourceDescriptions.Keys.OrderBy(k => k))
{
string localVersionStr;
bool resourceExistsLocally = ResourceTypes.resourceFileExists(resourceType, resourceName);
if (resourceExistsLocally)
{
if (ResourceTypes.resourceVersionFileExists(resourceType, resourceName))
{
localVersionStr = ResourceTypes.getResourceVersion(resourceType, resourceName);
}
else
{
localVersionStr = "Unknown version";
}
}
else
{
localVersionStr = "Not present";
}
printTable.addRow(
PrintTable.doFormat(resourceType.ToString()),
PrintTable.doFormat(resourceName),
PrintTable.doFormat(availableResources.resourceDescriptions[resourceName].versionStr),
PrintTable.doFormat(localVersionStr),
PrintTable.doFormat(ResourceTypes.bytesToString(availableResources.resourceDescriptions[resourceName].byteCount))
);
}
}
Logger.logTable(printTable);
}
catch (NetworkUtils.NetworkUtilsException ex)
{
Logger.logError($"Network Error: {ex.Message}");
}
catch (Exception ex)
{
Logger.logError($"File System Error: " + ex.Message);
}
}
}
}