fix: remove direct msgraph dependency from diagnostics
This commit is contained in:
@@ -11,7 +11,6 @@ using System.IO;
|
|||||||
using C4IT.LIAM;
|
using C4IT.LIAM;
|
||||||
using C4IT.Logging;
|
using C4IT.Logging;
|
||||||
using C4IT.Matrix42.ServerInfo;
|
using C4IT.Matrix42.ServerInfo;
|
||||||
using C4IT.MsGraph;
|
|
||||||
using C4IT_IAM_Engine;
|
using C4IT_IAM_Engine;
|
||||||
using LiamWorkflowActivities;
|
using LiamWorkflowActivities;
|
||||||
using LiamAD;
|
using LiamAD;
|
||||||
@@ -22,6 +21,15 @@ namespace LiamWorkflowDiagnostics
|
|||||||
{
|
{
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
private const int MsTeamsVisibilityPrivate = 0;
|
||||||
|
private const int MsTeamsVisibilityPublic = 1;
|
||||||
|
private const int MsTeamsVisibilityHiddenMembership = 2;
|
||||||
|
private const int MsTeamsCloneAppsFlag = 1;
|
||||||
|
private const int MsTeamsCloneTabsFlag = 2;
|
||||||
|
private const int MsTeamsCloneSettingsFlag = 4;
|
||||||
|
private const int MsTeamsCloneChannelsFlag = 8;
|
||||||
|
private const int MsTeamsCloneMembersFlag = 16;
|
||||||
|
|
||||||
private readonly ObservableCollection<string> _logEntries = new ObservableCollection<string>();
|
private readonly ObservableCollection<string> _logEntries = new ObservableCollection<string>();
|
||||||
private ProviderTestSession _session;
|
private ProviderTestSession _session;
|
||||||
private readonly string _settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LiamWorkflowDiagnostics.settings.json");
|
private readonly string _settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LiamWorkflowDiagnostics.settings.json");
|
||||||
@@ -79,9 +87,15 @@ namespace LiamWorkflowDiagnostics
|
|||||||
AdGroupTypeComboBox.ItemsSource = Enum.GetValues(typeof(ADServiceGroupCreator.ADGroupType))
|
AdGroupTypeComboBox.ItemsSource = Enum.GetValues(typeof(ADServiceGroupCreator.ADGroupType))
|
||||||
.Cast<ADServiceGroupCreator.ADGroupType>();
|
.Cast<ADServiceGroupCreator.ADGroupType>();
|
||||||
AdGroupTypeComboBox.SelectedItem = ADServiceGroupCreator.ADGroupType.Distribution;
|
AdGroupTypeComboBox.SelectedItem = ADServiceGroupCreator.ADGroupType.Distribution;
|
||||||
MsTeamsVisibilityComboBox.ItemsSource = Enum.GetValues(typeof(cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType))
|
MsTeamsVisibilityComboBox.ItemsSource = new[]
|
||||||
.Cast<cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType>();
|
{
|
||||||
MsTeamsVisibilityComboBox.SelectedItem = cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType.Private;
|
new MsTeamsVisibilityOption(MsTeamsVisibilityPrivate, "Private"),
|
||||||
|
new MsTeamsVisibilityOption(MsTeamsVisibilityPublic, "Public"),
|
||||||
|
new MsTeamsVisibilityOption(MsTeamsVisibilityHiddenMembership, "HiddenMembership")
|
||||||
|
};
|
||||||
|
MsTeamsVisibilityComboBox.DisplayMemberPath = nameof(MsTeamsVisibilityOption.Label);
|
||||||
|
MsTeamsVisibilityComboBox.SelectedValuePath = nameof(MsTeamsVisibilityOption.Value);
|
||||||
|
MsTeamsVisibilityComboBox.SelectedValue = MsTeamsVisibilityPrivate;
|
||||||
MsTeamsCloneSettingsCheckBox.IsChecked = true;
|
MsTeamsCloneSettingsCheckBox.IsChecked = true;
|
||||||
MsTeamsCloneChannelsCheckBox.IsChecked = true;
|
MsTeamsCloneChannelsCheckBox.IsChecked = true;
|
||||||
|
|
||||||
@@ -299,8 +313,9 @@ namespace LiamWorkflowDiagnostics
|
|||||||
AdScopeComboBox.SelectedItem = (eLiamAccessRoleScopes)settings.AdScope;
|
AdScopeComboBox.SelectedItem = (eLiamAccessRoleScopes)settings.AdScope;
|
||||||
if (Enum.IsDefined(typeof(ADServiceGroupCreator.ADGroupType), settings.AdGroupType))
|
if (Enum.IsDefined(typeof(ADServiceGroupCreator.ADGroupType), settings.AdGroupType))
|
||||||
AdGroupTypeComboBox.SelectedItem = (ADServiceGroupCreator.ADGroupType)settings.AdGroupType;
|
AdGroupTypeComboBox.SelectedItem = (ADServiceGroupCreator.ADGroupType)settings.AdGroupType;
|
||||||
if (Enum.IsDefined(typeof(cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType), settings.MsTeamsVisibility))
|
MsTeamsVisibilityComboBox.SelectedValue = IsValidMsTeamsVisibility(settings.MsTeamsVisibility)
|
||||||
MsTeamsVisibilityComboBox.SelectedItem = (cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType)settings.MsTeamsVisibility;
|
? settings.MsTeamsVisibility
|
||||||
|
: MsTeamsVisibilityPrivate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveSettings()
|
private void SaveSettings()
|
||||||
@@ -357,7 +372,7 @@ namespace LiamWorkflowDiagnostics
|
|||||||
MsTeamsSourceTeamId = MsTeamsSourceTeamIdTextBox.Text ?? string.Empty,
|
MsTeamsSourceTeamId = MsTeamsSourceTeamIdTextBox.Text ?? string.Empty,
|
||||||
MsTeamsNewName = MsTeamsNewNameTextBox.Text ?? string.Empty,
|
MsTeamsNewName = MsTeamsNewNameTextBox.Text ?? string.Empty,
|
||||||
MsTeamsDescription = MsTeamsDescriptionTextBox.Text ?? string.Empty,
|
MsTeamsDescription = MsTeamsDescriptionTextBox.Text ?? string.Empty,
|
||||||
MsTeamsVisibility = MsTeamsVisibilityComboBox.SelectedItem is cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType visibility ? (int)visibility : (int)cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType.Private,
|
MsTeamsVisibility = GetSelectedMsTeamsVisibility(),
|
||||||
MsTeamsCloneApps = MsTeamsCloneAppsCheckBox.IsChecked ?? false,
|
MsTeamsCloneApps = MsTeamsCloneAppsCheckBox.IsChecked ?? false,
|
||||||
MsTeamsCloneTabs = MsTeamsCloneTabsCheckBox.IsChecked ?? false,
|
MsTeamsCloneTabs = MsTeamsCloneTabsCheckBox.IsChecked ?? false,
|
||||||
MsTeamsCloneSettings = MsTeamsCloneSettingsCheckBox.IsChecked ?? true,
|
MsTeamsCloneSettings = MsTeamsCloneSettingsCheckBox.IsChecked ?? true,
|
||||||
@@ -589,15 +604,13 @@ namespace LiamWorkflowDiagnostics
|
|||||||
var provider = EnsureInitializedProvider<cLiamProviderMsTeams>("MsTeams");
|
var provider = EnsureInitializedProvider<cLiamProviderMsTeams>("MsTeams");
|
||||||
var sourceTeamId = GetRequiredText(MsTeamsSourceTeamIdTextBox.Text, "Source Team ID");
|
var sourceTeamId = GetRequiredText(MsTeamsSourceTeamIdTextBox.Text, "Source Team ID");
|
||||||
var newTeamName = GetRequiredText(MsTeamsNewNameTextBox.Text, "New Team Name");
|
var newTeamName = GetRequiredText(MsTeamsNewNameTextBox.Text, "New Team Name");
|
||||||
var visibility = MsTeamsVisibilityComboBox.SelectedItem is cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType selectedVisibility
|
var visibility = GetSelectedMsTeamsVisibility();
|
||||||
? selectedVisibility
|
|
||||||
: cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType.Private;
|
|
||||||
|
|
||||||
var result = await provider.cloneTeam(
|
var result = await provider.cloneTeam(
|
||||||
sourceTeamId,
|
sourceTeamId,
|
||||||
newTeamName,
|
newTeamName,
|
||||||
NormalizeOptionalText(MsTeamsDescriptionTextBox.Text),
|
NormalizeOptionalText(MsTeamsDescriptionTextBox.Text),
|
||||||
(int)visibility,
|
visibility,
|
||||||
GetSelectedCloneParts(),
|
GetSelectedCloneParts(),
|
||||||
string.Join(";", ParseIdentifierList(MsTeamsAdditionalMembersTextBox.Text, "Additional Members")),
|
string.Join(";", ParseIdentifierList(MsTeamsAdditionalMembersTextBox.Text, "Additional Members")),
|
||||||
string.Join(";", ParseIdentifierList(MsTeamsAdditionalOwnersTextBox.Text, "Additional Owners")));
|
string.Join(";", ParseIdentifierList(MsTeamsAdditionalOwnersTextBox.Text, "Additional Owners")));
|
||||||
@@ -811,18 +824,18 @@ namespace LiamWorkflowDiagnostics
|
|||||||
|
|
||||||
private int GetSelectedCloneParts()
|
private int GetSelectedCloneParts()
|
||||||
{
|
{
|
||||||
var parts = cMsGraphSharepoint.CloneTeamRequest.ClonableTeamParts.None;
|
var parts = 0;
|
||||||
if (MsTeamsCloneAppsCheckBox.IsChecked ?? false)
|
if (MsTeamsCloneAppsCheckBox.IsChecked ?? false)
|
||||||
parts |= cMsGraphSharepoint.CloneTeamRequest.ClonableTeamParts.Apps;
|
parts |= MsTeamsCloneAppsFlag;
|
||||||
if (MsTeamsCloneTabsCheckBox.IsChecked ?? false)
|
if (MsTeamsCloneTabsCheckBox.IsChecked ?? false)
|
||||||
parts |= cMsGraphSharepoint.CloneTeamRequest.ClonableTeamParts.Tabs;
|
parts |= MsTeamsCloneTabsFlag;
|
||||||
if (MsTeamsCloneSettingsCheckBox.IsChecked ?? false)
|
if (MsTeamsCloneSettingsCheckBox.IsChecked ?? false)
|
||||||
parts |= cMsGraphSharepoint.CloneTeamRequest.ClonableTeamParts.Settings;
|
parts |= MsTeamsCloneSettingsFlag;
|
||||||
if (MsTeamsCloneChannelsCheckBox.IsChecked ?? false)
|
if (MsTeamsCloneChannelsCheckBox.IsChecked ?? false)
|
||||||
parts |= cMsGraphSharepoint.CloneTeamRequest.ClonableTeamParts.Channels;
|
parts |= MsTeamsCloneChannelsFlag;
|
||||||
if (MsTeamsCloneMembersCheckBox.IsChecked ?? false)
|
if (MsTeamsCloneMembersCheckBox.IsChecked ?? false)
|
||||||
parts |= cMsGraphSharepoint.CloneTeamRequest.ClonableTeamParts.Members;
|
parts |= MsTeamsCloneMembersFlag;
|
||||||
return (int)parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private object MapResultToken(ResultToken token)
|
private object MapResultToken(ResultToken token)
|
||||||
@@ -857,21 +870,57 @@ namespace LiamWorkflowDiagnostics
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private object MapMsGraphResult(cMsGraphResultBase result)
|
private object MapMsGraphResult(object result)
|
||||||
{
|
{
|
||||||
if (result == null)
|
if (result == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
var resultType = result.GetType();
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
Id = result.ID,
|
Id = ReadPropertyValue<string>(result, resultType, "ID"),
|
||||||
result.DisplayName,
|
DisplayName = ReadPropertyValue<string>(result, resultType, "DisplayName"),
|
||||||
result.ODataId,
|
ODataId = ReadPropertyValue<string>(result, resultType, "ODataId"),
|
||||||
result.Context,
|
Context = ReadPropertyValue<string>(result, resultType, "Context"),
|
||||||
Result = result.Result
|
Result = ReadPropertyValue<object>(result, resultType, "Result")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetSelectedMsTeamsVisibility()
|
||||||
|
{
|
||||||
|
var selectedValue = MsTeamsVisibilityComboBox.SelectedValue;
|
||||||
|
if (selectedValue is int intValue && IsValidMsTeamsVisibility(intValue))
|
||||||
|
return intValue;
|
||||||
|
|
||||||
|
if (selectedValue != null && int.TryParse(selectedValue.ToString(), out var parsedValue) && IsValidMsTeamsVisibility(parsedValue))
|
||||||
|
return parsedValue;
|
||||||
|
|
||||||
|
return MsTeamsVisibilityPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsValidMsTeamsVisibility(int value)
|
||||||
|
{
|
||||||
|
return value == MsTeamsVisibilityPrivate
|
||||||
|
|| value == MsTeamsVisibilityPublic
|
||||||
|
|| value == MsTeamsVisibilityHiddenMembership;
|
||||||
|
}
|
||||||
|
|
||||||
|
private T ReadPropertyValue<T>(object instance, Type instanceType, string propertyName)
|
||||||
|
{
|
||||||
|
var property = instanceType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public);
|
||||||
|
if (property == null)
|
||||||
|
return default(T);
|
||||||
|
|
||||||
|
var value = property.GetValue(instance);
|
||||||
|
if (value == null)
|
||||||
|
return default(T);
|
||||||
|
|
||||||
|
if (value is T typedValue)
|
||||||
|
return typedValue;
|
||||||
|
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
|
||||||
private cLiamProviderData ParseProviderDataFromInput(string input)
|
private cLiamProviderData ParseProviderDataFromInput(string input)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(input))
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
@@ -1386,7 +1435,7 @@ namespace LiamWorkflowDiagnostics
|
|||||||
public string MsTeamsSourceTeamId { get; set; } = string.Empty;
|
public string MsTeamsSourceTeamId { get; set; } = string.Empty;
|
||||||
public string MsTeamsNewName { get; set; } = string.Empty;
|
public string MsTeamsNewName { get; set; } = string.Empty;
|
||||||
public string MsTeamsDescription { get; set; } = string.Empty;
|
public string MsTeamsDescription { get; set; } = string.Empty;
|
||||||
public int MsTeamsVisibility { get; set; } = (int)cMsGraphSharepoint.CloneTeamRequest.TeamVisibilityType.Private;
|
public int MsTeamsVisibility { get; set; } = MsTeamsVisibilityPrivate;
|
||||||
public bool MsTeamsCloneApps { get; set; } = false;
|
public bool MsTeamsCloneApps { get; set; } = false;
|
||||||
public bool MsTeamsCloneTabs { get; set; } = false;
|
public bool MsTeamsCloneTabs { get; set; } = false;
|
||||||
public bool MsTeamsCloneSettings { get; set; } = true;
|
public bool MsTeamsCloneSettings { get; set; } = true;
|
||||||
@@ -1403,5 +1452,18 @@ namespace LiamWorkflowDiagnostics
|
|||||||
public string ExchangeDistributionDisplayName { get; set; } = string.Empty;
|
public string ExchangeDistributionDisplayName { get; set; } = string.Empty;
|
||||||
public string ExchangeDistributionPrimarySmtp { get; set; } = string.Empty;
|
public string ExchangeDistributionPrimarySmtp { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private sealed class MsTeamsVisibilityOption
|
||||||
|
{
|
||||||
|
public MsTeamsVisibilityOption(int value, string label)
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
Label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Value { get; }
|
||||||
|
|
||||||
|
public string Label { get; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user