-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathMetadataTypes.cs
More file actions
727 lines (650 loc) · 27 KB
/
Copy pathMetadataTypes.cs
File metadata and controls
727 lines (650 loc) · 27 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using ServiceStack.DataAnnotations;
namespace ServiceStack
{
[Exclude(Feature.Soap)]
public class MetadataTypesConfig
{
public MetadataTypesConfig(
string baseUrl = null,
bool makePartial = true,
bool makeVirtual = true,
bool addReturnMarker = true,
bool convertDescriptionToComments = true,
bool addDataContractAttributes = false,
bool addIndexesToDataMembers = false,
bool addGeneratedCodeAttributes = false,
string addDefaultXmlNamespace = null,
string baseClass = null,
string package = null,
bool addResponseStatus = false,
bool addServiceStackTypes = true,
bool addModelExtensions = true,
bool addPropertyAccessors = true,
bool excludeGenericBaseTypes = false,
bool settersReturnThis = true,
bool makePropertiesOptional = true,
bool makeDataContractsExtensible = false,
bool initializeCollections = true,
int? addImplicitVersion = null)
{
BaseUrl = baseUrl;
MakePartial = makePartial;
MakeVirtual = makeVirtual;
AddReturnMarker = addReturnMarker;
AddDescriptionAsComments = convertDescriptionToComments;
AddDataContractAttributes = addDataContractAttributes;
AddDefaultXmlNamespace = addDefaultXmlNamespace;
BaseClass = baseClass;
Package = package;
MakeDataContractsExtensible = makeDataContractsExtensible;
AddIndexesToDataMembers = addIndexesToDataMembers;
AddGeneratedCodeAttributes = addGeneratedCodeAttributes;
InitializeCollections = initializeCollections;
AddResponseStatus = addResponseStatus;
AddServiceStackTypes = addServiceStackTypes;
AddModelExtensions = addModelExtensions;
AddPropertyAccessors = addPropertyAccessors;
ExcludeGenericBaseTypes = excludeGenericBaseTypes;
SettersReturnThis = settersReturnThis;
MakePropertiesOptional = makePropertiesOptional;
AddImplicitVersion = addImplicitVersion;
}
public string BaseUrl { get; set; }
public string UsePath { get; set; }
public bool MakePartial { get; set; }
public bool MakeVirtual { get; set; }
public bool MakeInternal { get; set; }
public string BaseClass { get; set; }
public string Package { get; set; }
public bool AddReturnMarker { get; set; }
public bool AddDescriptionAsComments { get; set; }
public bool AddDataContractAttributes { get; set; }
public bool AddIndexesToDataMembers { get; set; }
public bool AddGeneratedCodeAttributes { get; set; }
public int? AddImplicitVersion { get; set; }
public bool AddResponseStatus { get; set; }
public bool AddServiceStackTypes { get; set; }
public bool AddModelExtensions { get; set; }
public bool AddPropertyAccessors { get; set; }
public bool ExcludeGenericBaseTypes { get; set; }
public bool SettersReturnThis { get; set; }
public bool MakePropertiesOptional { get; set; }
public bool ExportAsTypes { get; set; }
public bool ExcludeImplementedInterfaces { get; set; }
public string AddDefaultXmlNamespace { get; set; }
public bool MakeDataContractsExtensible { get; set; }
public bool InitializeCollections { get; set; }
public List<string> AddNamespaces { get; set; }
public List<string> DefaultNamespaces { get; set; }
public List<string> DefaultImports { get; set; }
public List<string> IncludeTypes { get; set; }
public List<string> ExcludeTypes { get; set; }
public List<string> TreatTypesAsStrings { get; set; }
public bool ExportValueTypes { get; set; }
public string GlobalNamespace { get; set; }
public bool ExcludeNamespace { get; set; }
public string DataClass { get; set; }
public string DataClassJson { get; set; }
public HashSet<Type> IgnoreTypes { get; set; }
public HashSet<Type> ExportTypes { get; set; }
public HashSet<Type> ExportAttributes { get; set; }
public List<string> IgnoreTypesInNamespaces { get; set; }
}
[Exclude(Feature.Soap)]
public class MetadataTypes
{
public MetadataTypes()
{
Types = new List<MetadataType>();
Operations = new List<MetadataOperationType>();
Namespaces = new List<string>();
}
public MetadataTypesConfig Config { get; set; }
public List<string> Namespaces { get; set; }
public List<MetadataType> Types { get; set; }
public List<MetadataOperationType> Operations { get; set; }
}
[Exclude(Feature.Soap)]
public class AppMetadata : IMeta
{
public AppInfo App { get; set; }
public UiInfo Ui { get; set; }
public ConfigInfo Config { get; set; }
public Dictionary<string, string> ContentTypeFormats { get; set; }
public Dictionary<string, string> HttpHandlers { get; set; }
public PluginInfo Plugins { get; set; }
public Dictionary<string,CustomPluginInfo> CustomPlugins { get; set; }
public MetadataTypes Api { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class ConfigInfo : IMeta
{
public bool? DebugMode { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class PluginInfo : IMeta
{
public List<string> Loaded { get; set; }
public AuthInfo Auth { get; set; }
public AutoQueryInfo AutoQuery { get; set; }
public ValidationInfo Validation { get; set; }
public SharpPagesInfo SharpPages { get; set; }
public RequestLogsInfo RequestLogs { get; set; }
public AdminUsersInfo AdminUsers { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class LinkInfo
{
public string Id { get; set; }
public string Href { get; set; }
public string Label { get; set; }
public ImageInfo Icon { get; set; }
}
[Exclude(Feature.Soap)]
public class ImageInfo
{
public string Svg { get; set; }
public string Uri { get; set; }
public string Alt { get; set; }
public string Cls { get; set; }
}
[Exclude(Feature.Soap)]
public class AuthInfo : IMeta
{
public bool? HasAuthSecret { get; set; }
public bool? HasAuthRepository { get; set; }
public bool? IncludesRoles { get; set; }
public bool? IncludesOAuthTokens { get; set; }
public string HtmlRedirect { get; set; }
public List<MetaAuthProvider> AuthProviders { get; set; }
public Dictionary<string, List<LinkInfo>> RoleLinks { get; set; }
public Dictionary<string,string[]> ServiceRoutes { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class AutoQueryInfo : IMeta
{
public int? MaxLimit { get; set; }
public bool? UntypedQueries { get; set; }
public bool? RawSqlFilters { get; set; }
public bool? AutoQueryViewer { get; set; }
public bool? Async { get; set; }
public bool? OrderByPrimaryKey { get; set; }
public bool? CrudEvents { get; set; }
public bool? CrudEventsServices { get; set; }
public string AccessRole { get; set; }
public string NamedConnection { get; set; }
public List<AutoQueryConvention> ViewerConventions { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class ValidationInfo : IMeta
{
public bool? HasValidationSource { get; set; }
public bool? HasValidationSourceAdmin { get; set; }
public Dictionary<string,string[]> ServiceRoutes { get; set; }
public List<ScriptMethodType> TypeValidators { get; set; }
public List<ScriptMethodType> PropertyValidators { get; set; }
public string AccessRole { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class SharpPagesInfo : IMeta
{
public string ApiPath { get; set; }
public string ScriptAdminRole { get; set; }
public string MetadataDebugAdminRole { get; set; }
public bool? MetadataDebug { get; set; }
public bool? SpaFallback { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class RequestLogsInfo : IMeta
{
public string[] RequiredRoles { get; set; }
public string RequestLogger { get; set; }
public Dictionary<string,string[]> ServiceRoutes { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class AdminUsersInfo : IMeta
{
public string AccessRole { get; set; }
public List<string> Enabled { get; set; }
public MetadataType UserAuth { get; set; }
public List<string> AllRoles { get; set; }
public List<string> AllPermissions { get; set; }
public List<string> QueryUserAuthProperties { get; set; }
public List<MediaRule> QueryMediaRules { get; set; }
public List<List<InputInfo>> UserFormLayout { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class InputInfo : IMeta
{
public string Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Value { get; set; }
public string Placeholder { get; set; }
public string Help { get; set; }
public string Label { get; set; }
public string Title { get; set; }
public string Size { get; set; }
public string Pattern { get; set; }
public bool? ReadOnly { get; set; }
public bool? Required { get; set; }
public bool? Disabled { get; set; }
public string Autocomplete { get; set; }
public string Autofocus { get; set; }
public string Min { get; set; }
public string Max { get; set; }
public int? Step { get; set; }
public int? MinLength { get; set; }
public int? MaxLength { get; set; }
public string[] AllowableValues { get; set; }
public KeyValuePair<string,string>[] AllowableEntries { get; set; }
public Dictionary<string, string> Meta { get; set; }
public InputInfo() { }
public InputInfo(string id) => Id = id;
public InputInfo(string id, string type)
{
Id = id;
Type = type;
}
}
[Exclude(Feature.Soap)]
public class MediaRule : IMeta
{
public string Size { get; set; }
public string Rule { get; set; }
public string[] ApplyTo { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
/// <summary>
/// Generic template for adding metadata info about custom plugins
/// </summary>
[Exclude(Feature.Soap)]
public class CustomPluginInfo : IMeta
{
/// <summary>
/// Which User Roles have access to this Plugins Services. See RoleNames for built-in Roles.
/// </summary>
public string AccessRole { get; set; }
/// <summary>
/// What Services Types (and their user-defined routes) are enabled in this plugin
/// </summary>
public Dictionary<string,string[]> ServiceRoutes { get; set; }
/// <summary>
/// List of enabled features in this plugin
/// </summary>
public List<string> Enabled { get; set; }
/// <summary>
/// Additional custom metadata about this plugin
/// </summary>
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class ScriptMethodType
{
public string Name { get; set; }
public string[] ParamNames { get; set; }
public string[] ParamTypes { get; set; }
public string ReturnType { get; set; }
}
[Exclude(Feature.Soap)]
public class AutoQueryConvention
{
public string Name { get; set; }
public string Value { get; set; }
public string Types { get; set; }
public string ValueType { get; set; }
}
/// <summary>
/// App Info and
/// </summary>
[Exclude(Feature.Soap)]
public class AppInfo : IMeta
{
/// <summary>
/// The App's BaseUrl
/// </summary>
public string BaseUrl { get; set; }
/// <summary>
/// The ServiceStack Version
/// </summary>
public string ServiceStackVersion => Text.Env.VersionString;
/// <summary>
/// Name of the ServiceStack Instance
/// </summary>
public string ServiceName { get; set; }
/// <summary>
/// Textual description of the ServiceStack App (shown in Home Services list)
/// </summary>
public string ServiceDescription { get; set; }
/// <summary>
/// Icon for this ServiceStack App (shown in Home Services list)
/// </summary>
public string ServiceIconUrl { get; set; }
/// <summary>
/// Link to your website users can click to find out more about you
/// </summary>
public string BrandUrl { get; set; }
/// <summary>
/// A custom logo or image that users can click on to visit your site
/// </summary>
public string BrandImageUrl { get; set; }
/// <summary>
/// The default color of text
/// </summary>
public string TextColor { get; set; }
/// <summary>
/// The default color of links
/// </summary>
public string LinkColor { get; set; }
/// <summary>
/// The default background color of each screen
/// </summary>
public string BackgroundColor { get; set; }
/// <summary>
/// The default background image of each screen anchored to the bottom left
/// </summary>
public string BackgroundImageUrl { get; set; }
/// <summary>
/// The default icon for each of your App's Services
/// </summary>
public string IconUrl { get; set; }
/// <summary>
/// The configured JsConfig.TextCase
/// </summary>
public string JsTextCase { get; set; }
/// <summary>
/// Custom User-Defined Attributes
/// </summary>
public Dictionary<string, string> Meta { get; set; }
}
/// <summary>
/// App Info and
/// </summary>
[Exclude(Feature.Soap)]
public class UiInfo : IMeta
{
/// <summary>
/// The brand icon to use with App brand name
/// </summary>
public ImageInfo BrandIcon { get; set; }
/// <summary>
/// Hide APIs with tags
/// </summary>
public List<string> HideTags { get; set; }
/// <summary>
/// Always hide APIs with tags (inc DebugMode)
/// </summary>
public List<string> AlwaysHideTags { get; set; }
/// <summary>
/// Admin UI Links
/// </summary>
public List<LinkInfo> AdminLinks { get; set; }
/// <summary>
/// Custom User-Defined Attributes
/// </summary>
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class MetaAuthProvider : IMeta
{
public string Name { get; set; }
public string Label { get; set; }
public string Type { get; set; }
public NavItem NavItem { get; set; }
public ImageInfo Icon { get; set; }
public List<InputInfo> FormLayout { get; set; }
public Dictionary<string, string> Meta { get; set; }
}
[Exclude(Feature.Soap)]
public class MetadataOperationType
{
public MetadataType Request { get; set; }
public MetadataType Response { get; set; }
public List<string> Actions { get; set; }
public bool ReturnsVoid { get; set; }
public string Method { get; set; }
public MetadataTypeName ReturnType { get; set; }
public List<MetadataRoute> Routes { get; set; }
public MetadataTypeName DataModel { get; set; }
public MetadataTypeName ViewModel { get; set; }
public bool RequiresAuth { get; set; }
public List<string> RequiredRoles { get; set; }
public List<string> RequiresAnyRole { get; set; }
public List<string> RequiredPermissions { get; set; }
public List<string> RequiresAnyPermission { get; set; }
public List<string> Tags { get; set; }
public List<List<InputInfo>> FormLayout { get; set; }
}
[Exclude(Feature.Soap)]
public class MetadataType : IMeta
{
[IgnoreDataMember]
public Type Type { get; set; }
[IgnoreDataMember]
public Dictionary<string, object> Items { get; set; }
[IgnoreDataMember]
public MetadataOperationType RequestType { get; set; }
[IgnoreDataMember]
public bool IsClass => Type?.IsClass ?? !(IsEnum == true || IsInterface == true);
public string Name { get; set; }
public string Namespace { get; set; }
public string[] GenericArgs { get; set; }
public MetadataTypeName Inherits { get; set; }
public MetadataTypeName[] Implements { get; set; }
public string DisplayType { get; set; }
public string Description { get; set; }
public string Notes { get; set; }
public bool? IsNested { get; set; }
public bool? IsEnum { get; set; }
public bool? IsEnumInt { get; set; }
public bool? IsInterface { get; set; }
public bool? IsAbstract { get; set; }
public MetadataDataContract DataContract { get; set; }
public List<MetadataPropertyType> Properties { get; set; }
public List<MetadataAttribute> Attributes { get; set; }
public List<MetadataTypeName> InnerTypes { get; set; }
public List<string> EnumNames { get; set; }
public List<string> EnumValues { get; set; }
public List<string> EnumMemberValues { get; set; }
public List<string> EnumDescriptions { get; set; }
public Dictionary<string, string> Meta { get; set; }
public string GetFullName() => Namespace + "." + Name;
protected bool Equals(MetadataType other)
{
return Name == other.Name && Namespace == other.Namespace;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((MetadataType) obj);
}
public override int GetHashCode()
{
unchecked
{
return ((Name != null ? Name.GetHashCode() : 0) * 397) ^ (Namespace != null ? Namespace.GetHashCode() : 0);
}
}
}
[Exclude(Feature.Soap)]
public class MetadataTypeName
{
[IgnoreDataMember]
public Type Type { get; set; }
public string Name { get; set; }
public string Namespace { get; set; }
public string[] GenericArgs { get; set; }
}
[Exclude(Feature.Soap)]
public class MetadataRoute
{
[IgnoreDataMember]
public RouteAttribute RouteAttribute { get; set; }
public string Path { get; set; }
public string Verbs { get; set; }
public string Notes { get; set; }
public string Summary { get; set; }
}
[Exclude(Feature.Soap)]
public class MetadataDataContract
{
public string Name { get; set; }
public string Namespace { get; set; }
}
[Exclude(Feature.Soap)]
public class MetadataDataMember
{
public string Name { get; set; }
public int? Order { get; set; }
public bool? IsRequired { get; set; }
public bool? EmitDefaultValue { get; set; }
}
[Exclude(Feature.Soap)]
public class MetadataPropertyType
{
[IgnoreDataMember]
public PropertyInfo PropertyInfo { get; set; }
[IgnoreDataMember]
public Type PropertyType { get; set; }
[IgnoreDataMember]
public Dictionary<string, object> Items { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public bool? IsValueType { get; set; }
public bool? IsSystemType { get; set; }
public bool? IsEnum { get; set; }
public bool? IsPrimaryKey { get; set; }
public string TypeNamespace { get; set; }
public string[] GenericArgs { get; set; }
public string Value { get; set; }
public string Description { get; set; }
public MetadataDataMember DataMember { get; set; }
public bool? ReadOnly { get; set; }
public string ParamType { get; set; }
public string DisplayType { get; set; }
public bool? IsRequired { get; set; }
public string[] AllowableValues { get; set; }
public int? AllowableMin { get; set; }
public int? AllowableMax { get; set; }
public List<MetadataAttribute> Attributes { get; set; }
public InputInfo Input { get; set; }
}
[Exclude(Feature.Soap)]
public class MetadataAttribute
{
[IgnoreDataMember]
public Attribute Attribute { get; set; }
public string Name { get; set; }
public List<MetadataPropertyType> ConstructorArgs { get; set; }
public List<MetadataPropertyType> Args { get; set; }
}
public static class MetadataTypeExtensions
{
public static bool InheritsAny(this MetadataType type, params string[] typeNames) =>
type.Inherits != null && typeNames.Contains(type.Inherits.Name);
public static bool ImplementsAny(this MetadataType type, params string[] typeNames) =>
type.Implements != null && type.Implements.Any(i => typeNames.Contains(i.Name));
public static bool ReferencesAny(this MetadataOperationType op, params string[] typeNames) =>
(op.Request.Inherits != null && (typeNames.Contains(op.Request.Inherits.Name) ||
op.Request.Inherits.GenericArgs?.Length > 0 &&
op.Request.Inherits.GenericArgs.Any(typeNames.Contains)))
||
(op.Response != null && (typeNames.Contains(op.Response.Name) ||
op.Response.GenericArgs?.Length > 0 &&
op.Response.GenericArgs.Any(typeNames.Contains)))
||
(op.Request.Implements != null && op.Request.Implements.Any(i =>
i.GenericArgs?.Length > 0 && i.GenericArgs.Any(typeNames.Contains)))
||
(op.Response?.Inherits != null && (typeNames.Contains(op.Response.Inherits.Name) ||
op.Response.Inherits.GenericArgs?.Length > 0 &&
op.Response.Inherits.GenericArgs.Any(typeNames.Contains)));
public static List<MetadataRoute> GetRoutes(this List<MetadataOperationType> operations, MetadataType type) =>
operations.FirstOrDefault(x => ReferenceEquals(x.Request, type))?.Routes ?? operations.GetRoutes(type.Name);
public static List<MetadataRoute> GetRoutes(this List<MetadataOperationType> operations, string typeName)
{
return operations.FirstOrDefault(x => x.Request.Name == typeName)?.Routes;
}
public static string ToScriptSignature(this ScriptMethodType method)
{
var paramCount = method.ParamNames?.Length ?? 0;
var firstParam = method.ParamNames?.Length > 0 ? method.ParamNames[0] : null;
var ret = method.ReturnType != null && method.ReturnType != "StopExecution" ? " -> " + method.ReturnType : "";
var sig = paramCount == 0
? $"{method.Name}{ret}"
: paramCount == 1
? $"{firstParam} |> {method.Name}{ret}"
: $"{firstParam} |> {method.Name}(" + string.Join(", ", method.ParamNames?.Skip(1) ?? new string[0]) + $"){ret}";
return sig;
}
public static List<MetadataOperationType> GetOperationsByTags(this MetadataTypes types, string[] tags) =>
types.Operations.Where(x => x.Tags != null && x.Tags.Any(t => Array.IndexOf(tags, t) >= 0)).ToList();
private static readonly char[] SystemTypeChars = { '<', '>', '+' };
public static bool IsSystemOrServiceStackType(this MetadataTypeName metaRef)
{
if (metaRef.Namespace == null)
return false;
return metaRef.Namespace.StartsWith("System") ||
metaRef.Namespace.StartsWith("ServiceStack") ||
metaRef.Name.IndexOfAny(SystemTypeChars) >= 0;
}
}
public static class AppMetadataUtils
{
public static async Task<AppMetadata> GetAppMetadataAsync(this string baseUrl)
{
string appResponseJson = null;
try
{
appResponseJson = await baseUrl.CombineWith("/metadata/app.json")
.GetJsonFromUrlAsync();
if (!appResponseJson.Trim().StartsWith("{"))
throw new Exception("Not a remote ServiceStack Instance");
}
catch (Exception appEx)
{
string ssMetadata;
try
{
ssMetadata = await baseUrl.CombineWith("/metadata")
.GetStringFromUrlAsync(requestFilter:req => req.UserAgent = "ServiceStack");
}
catch (Exception ssEx)
{
throw new Exception("Not a remote ServiceStack Instance", ssEx);
}
if (ssMetadata.IndexOf("https://servicestack.net", StringComparison.Ordinal) == -1)
throw new Exception("Not a remote ServiceStack Instance");
throw new Exception("ServiceStack Instance v5.10 or higher required", appEx);
}
AppMetadata appMetadata;
try
{
appMetadata = appResponseJson.FromJson<AppMetadata>();
}
catch (Exception e)
{
throw new Exception("Could not read AppMetadata, try upgrading this App or remote ServiceStack Instance", e);
}
return appMetadata;
}
}
}