-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListModelsCommand.cs
More file actions
80 lines (65 loc) · 3.29 KB
/
Copy pathListModelsCommand.cs
File metadata and controls
80 lines (65 loc) · 3.29 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
using CommandLine;
using ShapeDiver.SDK.PlatformBackend;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using PDTO = ShapeDiver.SDK.PlatformBackend.DTO;
namespace DotNetSdkSampleConsoleApp.Commands
{
/// <summary>
/// List identifiers of ShapeDiver models from the platform.
/// </summary>
[Verb("list-models", isDefault: false, HelpText = "List ShapeDiver models, sorted by descending date of creation.")]
class ListModelsCommand : BaseCommand, ICommand
{
[Option('u', "user", HelpText = "Filter models owned by you")]
public bool FilterUser { get; set; }
[Option('l', "limit", HelpText = "Limit for the number of models to list, defaults to 10")]
public int? Limit { get; set; }
[Option('o', "offset", HelpText = "Offset for continuing query")]
public string Offset { get; set; }
[Option('v', "visibility", HelpText = "Visibility of the model, one of \"private\", \"organization\", \"shared\", or \"public\"")]
public string Visibility { get; set; }
[Option('q', "search", HelpText = "Search string, used for searching models by slug, title, and model view URL")]
public string SearchString { get; set; }
public async Task Execute()
{
await WrapExceptions(async () =>
{
// get authenticated SDK
var sdk = await GetAuthenticatedSDK();
// prepare query
var query = sdk.PlatformClient.ModelApi.CreateQueryBody(Limit == null ? 10 : Limit.Value, true /* attain limit */, Offset);
query.AddSorter(SorterType.Created_At, SortOrder.Desc);
query.AddFilter(ex => ex.Property(m => m.DeletedAt).IsNull());
query.AddFilter(ex => ex.Property(m => m.Status).InArray(new List<PDTO.ModelStatusEnum>() { PDTO.ModelStatusEnum.Done, PDTO.ModelStatusEnum.Confirmed }));
if (FilterUser)
query.AddFilter(ex => ex.Property(m => m.UserId).EqualTo(sdk.AuthenticationClient.GetUserId()));
if (!String.IsNullOrEmpty(Visibility))
query.AddFilter(ex => ex.Property(m => m.Visibility).EqualTo(Visibility));
if (!String.IsNullOrEmpty(SearchString))
query.AddFilter(ex => ex.Property(m => m.Slug).Like(SearchString).Or().Property(m => m.Title).Like(SearchString));
// query model call
var result = (await sdk.PlatformClient.ModelApi.Query<PDTO.ModelPublicDto>(query)).Data;
if (result.Result.Count == 0)
{
Console.WriteLine("No matching models found.");
return;
}
Console.WriteLine($"Id;Slug;Title");
foreach (var model in result.Result)
{
Console.WriteLine($"{model.Id};{model.Slug};{model.Title}");
}
if (!String.IsNullOrEmpty(result.Pagination.NextOffset))
{
Console.WriteLine($"Offset for continuing query: {result.Pagination.NextOffset}");
}
else
{
Console.WriteLine($"No more matching models found.");
}
});
}
}
}