-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXrmSyncOptions.cs
More file actions
139 lines (115 loc) · 4.84 KB
/
XrmSyncOptions.cs
File metadata and controls
139 lines (115 loc) · 4.84 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
using Microsoft.Extensions.Logging;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
[assembly: InternalsVisibleTo("Tests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
namespace XrmSync.Model;
public record XrmSyncConfiguration(bool DryRun, LogLevel LogLevel, bool CiMode, List<ProfileConfiguration> Profiles)
{
public static XrmSyncConfiguration Empty => new(false, LogLevel.Information, false, []);
/// <summary>
/// Resolves the effective profile using fallback logic:
/// 1. If a name is requested and matches, use it
/// 2. If no name is requested, fall back to "default"
/// 3. If only one profile exists, use it automatically
/// Returns null when no profiles are configured.
/// </summary>
public ProfileConfiguration? ResolveProfile(string? requestedName)
{
if (Profiles.Count == 0)
{
return requestedName != null
? throw new Exceptions.XrmSyncException($"Profile '{requestedName}' not found. No profiles are configured.")
: null;
}
// Explicit profile name requested — must match exactly
if (requestedName != null)
{
return Profiles.FirstOrDefault(p => p.Name.Equals(requestedName, StringComparison.OrdinalIgnoreCase))
?? throw new Exceptions.XrmSyncException($"Profile '{requestedName}' not found. Available profiles: {string.Join(", ", Profiles.Select(p => p.Name))}");
}
// No name specified — try "default", then single-profile auto-select
var defaultProfile = Profiles.FirstOrDefault(p => p.Name.Equals("default", StringComparison.OrdinalIgnoreCase));
if (defaultProfile != null)
{
return defaultProfile;
}
if (Profiles.Count == 1)
{
return Profiles[0];
}
throw new Exceptions.XrmSyncException("Multiple profiles found. Use --profile to specify which profile to use, name a profile 'default', or run 'xrmsync config list' to see available profiles.");
}
}
public record ProfileConfiguration(string Name, string SolutionName, List<SyncItem> Sync)
{
public static ProfileConfiguration Empty => new(string.Empty, string.Empty, []);
}
[JsonPolymorphic(TypeDiscriminatorPropertyName = "Type")]
[JsonDerivedType(typeof(PluginSyncItem), typeDiscriminator: PluginSyncItem.TypeName)]
[JsonDerivedType(typeof(PluginAnalysisSyncItem), typeDiscriminator: PluginAnalysisSyncItem.TypeName)]
[JsonDerivedType(typeof(WebresourceSyncItem), typeDiscriminator: WebresourceSyncItem.TypeName)]
[JsonDerivedType(typeof(IdentitySyncItem), typeDiscriminator: IdentitySyncItem.TypeName)]
public abstract record SyncItem
{
[JsonIgnore]
public abstract string SyncType { get; }
}
public record PluginSyncItem(string AssemblyPath) : SyncItem
{
public const string TypeName = "Plugin";
public static PluginSyncItem Empty => new(string.Empty);
[JsonIgnore]
public override string SyncType => TypeName;
}
public record PluginAnalysisSyncItem(string AssemblyPath, string PublisherPrefix, bool PrettyPrint) : SyncItem
{
public const string TypeName = "PluginAnalysis";
public static PluginAnalysisSyncItem Empty => new(string.Empty, "new", false);
[JsonIgnore]
public override string SyncType => TypeName;
}
public record WebresourceSyncItem(string FolderPath, List<string>? FileExtensions = null) : SyncItem
{
public const string TypeName = "Webresource";
public static WebresourceSyncItem Empty => new(string.Empty);
[JsonIgnore]
public override string SyncType => TypeName;
}
public record SharedOptions(string? ProfileName)
{
public static SharedOptions Empty => new((string?)null);
}
// Command-specific options that can be populated from CLI or profile
public record PluginSyncCommandOptions(string AssemblyPath, string SolutionName)
{
public static PluginSyncCommandOptions Empty => new(string.Empty, string.Empty);
}
public record PluginAnalysisCommandOptions(string AssemblyPath, string PublisherPrefix, bool PrettyPrint)
{
public static PluginAnalysisCommandOptions Empty => new(string.Empty, "new", false);
}
public record WebresourceSyncCommandOptions(string FolderPath, string SolutionName, List<string>? FileExtensions = null)
{
public static WebresourceSyncCommandOptions Empty => new(string.Empty, string.Empty);
}
public enum IdentityOperation
{
Remove,
Ensure
}
public record IdentitySyncItem(IdentityOperation Operation, string AssemblyPath, string? ClientId = null, string? TenantId = null) : SyncItem
{
public const string TypeName = "Identity";
public static IdentitySyncItem Empty => new(IdentityOperation.Remove, string.Empty);
[JsonIgnore]
public override string SyncType => $"{TypeName} ({Operation})";
}
public record IdentityCommandOptions(IdentityOperation Operation, string AssemblyPath, string SolutionName, string? ClientId = null, string? TenantId = null)
{
public static IdentityCommandOptions Empty => new(IdentityOperation.Remove, string.Empty, string.Empty);
}
public record ExecutionModeOptions(bool DryRun)
{
public static ExecutionModeOptions Empty => new(false);
}