-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetModelCommand.cs
More file actions
169 lines (152 loc) · 7.53 KB
/
Copy pathGetModelCommand.cs
File metadata and controls
169 lines (152 loc) · 7.53 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using CommandLine;
using DotNetSdkSampleConsoleApp.Util;
using Newtonsoft.Json;
using System;
using System.Linq;
using System.Threading.Tasks;
using PDTO = ShapeDiver.SDK.PlatformBackend.DTO;
namespace DotNetSdkSampleConsoleApp.Commands
{
/// <summary>
/// Get information about a ShapeDiver model from the platform.
/// </summary>
[Verb("get-model", isDefault: false, HelpText = "Get information about a ShapeDiver model.")]
class GetModelCommand : BaseCommand, ICommand
{
[Option('i', "identifier", HelpText = "Identifier of the model (slug, model id, geometry backend model id, or ticket)", Required = false)]
public string Identifier { get; set; }
[Option('e', "embed", HelpText = "Request all available embed fields")]
public bool EmbedFields { get; set; }
[Option('j', "json", HelpText = "Output JSON instead of text")]
public bool JsonOutput { get; set; }
public async Task Execute()
{
await WrapExceptions(async () =>
{
// get identifier
if (String.IsNullOrEmpty(Identifier))
{
Console.Write("Model identifier (slug, model id, geometry backend model id): ");
Identifier = Console.ReadLine();
}
if (String.IsNullOrEmpty(Identifier))
{
throw new Exception($"Refusing to proceed without a model identifier");
}
// in case the identifier is a url, guess the slug from it
if (Identifier.StartsWith("https://"))
Identifier = Identifier.Split('/').Last();
// get authenticated SDK
var sdk = await GetAuthenticatedSDK();
// in case a ticket was given, try to decrypt it
if (Identifier.Length > 100 && Identifier.Split('-').Count() == 2 && Identifier.ToLowerInvariant() == Identifier)
{
if (!JsonOutput)
Console.WriteLine($"Looks like a ticket, trying to decrypt it...");
var ticketDecrypted = await sdk.PlatformClient.ModelApi.DecryptTicket(Identifier);
Identifier = ticketDecrypted.Model.Id;
}
// get model call
if (!JsonOutput)
Console.WriteLine($"Get model information...");
var model = (await sdk.PlatformClient.ModelApi.Get<PDTO.ModelDto>(Identifier)).Data;
if (JsonOutput && !EmbedFields)
{
Console.WriteLine(JsonConvert.SerializeObject(model, Formatting.Indented));
return;
}
if (!JsonOutput)
{
Console.WriteLine();
Console.WriteLine($"Model id (platform): {model.Id}");
Console.WriteLine($"Title: {model.Title}");
Console.WriteLine($"Slug: {model.Slug}");
Console.WriteLine($"Description: {model.Description}");
Console.WriteLine($"Visibility: {model.Visibility}");
Console.WriteLine($"VisibilityNominal: {model.VisibilityNominal}");
Console.WriteLine($"Thumbnail: {model.ThumbnailUrl}");
if (model.Permissions.Contains(PDTO.PermissionModelEnum.GetRestModelOwner))
{
Console.WriteLine($"Status: {model.Status}");
Console.WriteLine($"Created at: {model.CreatedAt}");
Console.WriteLine($"Updated at: {model.UpdatedAt}");
Console.WriteLine($"Embedding enabled: {model.UseGlobalAccessdomains}");
Console.WriteLine($"Private link sharing slug: {model.LinkSharingSlug}");
Console.WriteLine($"Backend access enabled: {model.BackendAccess}");
Console.WriteLine($"JWT required: {model.RequireToken}");
}
}
if (!EmbedFields || (model.Status != PDTO.ModelStatusEnum.Confirmed && model.Status != PDTO.ModelStatusEnum.Done))
return;
// check which permissions we have, add embed fields
if (!JsonOutput)
{
Console.WriteLine();
Console.WriteLine($"Get extended model information...");
}
var embedFields = PlatformBackendUtils.MapModelPermissionsToEmbedFields(model);
model = (await sdk.PlatformClient.ModelApi.Get<PDTO.ModelDto>(Identifier, embedFields.ToArray())).Data;
if (JsonOutput)
{
Console.WriteLine(JsonConvert.SerializeObject(model, Formatting.Indented));
return;
}
if (model.Accessdomains?.Count() > 0)
{
Console.WriteLine();
Console.WriteLine($"Per-model domains from which the model may be embedded:");
model.Accessdomains.ForEach(d => Console.WriteLine($"\t{d.Name}"));
}
if (model.GlobalAccessdomains?.Count() > 0)
{
Console.WriteLine();
Console.WriteLine($"Per-account domains from which the model may be embedded:");
model.GlobalAccessdomains.ForEach(d => Console.WriteLine($"\t{d.Name}"));
}
if (model.BackendProperties != null)
{
Console.WriteLine();
Console.WriteLine($"Geometry backend properties:");
Console.WriteLine(JsonConvert.SerializeObject(model.BackendProperties, Formatting.Indented));
}
if (model.BackendSystem != null)
{
Console.WriteLine();
Console.WriteLine($"Geometry backend system:");
Console.WriteLine($"\tAlias: {model.BackendSystem.Alias}");
Console.WriteLine($"\tModel view URL: {model.BackendSystem.ModelViewUrl}");
Console.WriteLine($"\tDescription: {model.BackendSystem.Description}");
}
if (model.Bookmark != null)
{
Console.WriteLine();
Console.WriteLine($"Bookmark: {model.Bookmark.Bookmarked}");
}
if (model.Decoration != null)
{
Console.WriteLine();
Console.WriteLine($"Decoration:");
model.Decoration.ForEach(d => Console.WriteLine($"\t{d.Url}"));
}
if (model.Organization != null)
{
Console.WriteLine();
Console.WriteLine($"Organization properties:");
Console.WriteLine(JsonConvert.SerializeObject(model.Organization, Formatting.Indented));
}
if (model.User != null)
{
Console.WriteLine();
Console.WriteLine($"User properties:");
Console.WriteLine(JsonConvert.SerializeObject(model.User, Formatting.Indented));
}
if (model.Tags?.Count() > 0)
{
Console.WriteLine();
Console.WriteLine($"Tags:");
model.Tags.ForEach(d => Console.WriteLine($"\t{d.Name}"));
}
});
}
}
}