Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History UI #281

Merged
merged 6 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class AdminSettingWizardData : WizardData
//logging
private String strLoggingLevel = String.Empty;
private String strLoggingType = String.Empty;

//history
private IList<EnterpriseManagementObjectHistoryTransaction> emoHistoryTransactions;

//management pack guid
private Guid guidEnterpriseManagementObjectID = Guid.Empty;
Expand Down Expand Up @@ -2509,6 +2512,21 @@ public String LoggingType
}
}
}

public IList<EnterpriseManagementObjectHistoryTransaction> SMExcoSettingsHistory
{
get
{
return this.emoHistoryTransactions;
}
set
{
if (this.emoHistoryTransactions != value)
{
this.emoHistoryTransactions = value;
}
}
}

//management pack guid
public Guid EnterpriseManagementObjectID
Expand Down Expand Up @@ -3295,6 +3313,10 @@ returned Type Projection.
//logging
this.LoggingLevel = emoAdminSetting[smletsExchangeConnectorSettingsClass, "LogLevel"].ToString();
this.LoggingType = emoAdminSetting[smletsExchangeConnectorSettingsClass, "LogType"].ToString();

//smlets exchange connector settings history
EnterpriseManagementObject smletsSettings = emg.EntityObjects.GetObject<EnterpriseManagementObject>(smletsExchangeConnectorSettingsClass.Id, ObjectQueryOptions.Default);
this.SMExcoSettingsHistory = emg.EntityObjects.GetObjectHistoryTransactions(smletsSettings);

//load the MP
this.EnterpriseManagementObjectID = emoAdminSetting.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ against the ServiceManager DB to figure out the following strSingletonBaseManage
wizard.AddLast(new WizardStep("Transcription", typeof(AzureSpeech), wizard.WizardData));
wizard.AddLast(new WizardStep("Workflow", typeof(WorkflowSettings), wizard.WizardData));
wizard.AddLast(new WizardStep("Logging", typeof(Logging), wizard.WizardData));
wizard.AddLast(new WizardStep("History", typeof(HistoryForm), wizard.WizardData));
wizard.AddLast(new WizardStep("About", typeof(AboutForm), wizard.WizardData));

//Show the property page
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<wpfwiz:WizardRegularPageBase
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfwiz="clr-namespace:Microsoft.EnterpriseManagement.UI.WpfWizardFramework;assembly=Microsoft.EnterpriseManagement.UI.WpfWizardFramework"
xmlns:smcontrols="clr-namespace:Microsoft.EnterpriseManagement.UI.WpfControls;assembly=Microsoft.EnterpriseManagement.UI.SMControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:Microsoft.EnterpriseManagement.UI.FormsInfra;assembly=Microsoft.EnterpriseManagement.UI.FormsInfra"
xmlns:Custom="http://schemas.microsoft.com/SystemCenter/Common/UI/Wpf"
xmlns:scuictrls="http://schemas.microsoft.com/SystemCenter/Common/UI/Controls"
x:Class="SMLetsExchangeConnectorSettingsUI.HistoryForm"
mc:Ignorable="d" Width="900" Height="460">

<Grid x:Name="ConfigurationGrid" Margin="15,10">
<Label Content="Configuration History" Margin="0,10,10,0" VerticalAlignment="Top" Height="48" FontWeight="Bold" FontSize="26"/>
<TextBlock Margin="10,58,10,0" VerticalAlignment="Top" Height="32" FontWeight="Light" FontSize="14" TextWrapping="Wrap">
<Run Text="View changes made to SMLets Exchange Connector Settings"/>
</TextBlock>

<ListView Name="dgHistory" Margin="0,90,0,0">
<ListView.View>
<GridView >
<!-- DateOccured and UserName we won't show as headers, because that's how we're performing GroupBy seen below -->
<GridViewColumn Header="Property" Width="Auto" DisplayMemberBinding="{Binding Property}" />
<GridViewColumn Header="Old Value" Width="Auto" DisplayMemberBinding="{Binding OldValue}" />
<GridViewColumn Header="New Value" Width="Auto" DisplayMemberBinding="{Binding NewValue}" />
</GridView>
</ListView.View>

<!-- Having created a "PropertyGroupDescription" in the code-behind, use "Binding = Name" to reference the grouped value. In this case, DateOccured -->
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Black" FontSize="12" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</Grid>
</wpfwiz:WizardRegularPageBase>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.EnterpriseManagement.UI.WpfControls;
using Microsoft.EnterpriseManagement.UI.WpfWizardFramework;
using Microsoft.EnterpriseManagement.UI.DataModel;
using Microsoft.EnterpriseManagement.UI;
using Microsoft.EnterpriseManagement.UI.Controls;
using Microsoft.EnterpriseManagement.ServiceManager.Application.Common;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.UI.FormsInfra;
using Microsoft.Win32;
using System.Collections.ObjectModel;

namespace SMLetsExchangeConnectorSettingsUI
{
/// <summary>
/// Interaction logic for HistoryForm.xaml
/// </summary>

public partial class HistoryForm : WizardRegularPageBase
{
private HistoryForm adminSettingWizardData = null;
AdminSettingWizardData settings;

public HistoryForm(WizardData wizardData)
{
InitializeComponent();
this.DataContext = wizardData;
this.adminSettingWizardData = this.DataContext as HistoryForm;

//retrieve smlets exchange connector settings
settings = wizardData as AdminSettingWizardData;

//build a custom list based on SMexco configuration history
//Based on SMlets Get-SCSMObjectHistory - https://github.com/SMLets/SMLets/blob/795242d4a44cf8857957a7628cca67655e2e4252/SMLets.Shared/Code/EntityObjects.cs#L1181-L1216
List<CustomHistoryObject> smexcoConfigHistory = new List<CustomHistoryObject>();

foreach (EnterpriseManagementObjectHistoryTransaction historyItem in settings.SMExcoSettingsHistory)
{
string propertyName = null;
string oldVal = null;
string newVal = null;

foreach (KeyValuePair<Guid, EnterpriseManagementObjectHistory> h in historyItem.ObjectHistory)
{
foreach (EnterpriseManagementObjectClassHistory ch in h.Value.ClassHistory)
{
foreach (KeyValuePair<ManagementPackProperty, Microsoft.EnterpriseManagement.Common.Pair<EnterpriseManagementSimpleObject, EnterpriseManagementSimpleObject>> hpc in ch.PropertyChanges)
{
//Simplify properties to variables
propertyName = hpc.Key.Name;
// propertyName = hpc.Key.DisplayName;
oldVal = hpc.Value.First.Value.ToString();
newVal = hpc.Value.Second.Value.ToString();

//Create a new custom history object
smexcoConfigHistory.Add(new CustomHistoryObject()
{
UserName = historyItem.UserName,
Property = propertyName,
OldValue = oldVal,
NewValue = newVal,
DateOccured = historyItem.DateOccurred.ToLocalTime(),
DateAndUser = historyItem.DateOccurred.ToLocalTime().ToString() + " " + historyItem.UserName
});
}
}
}
}

//With the Custom History Objects created, update the list to all of them. Then define a grouping property for the XAML
dgHistory.ItemsSource = smexcoConfigHistory;
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(dgHistory.ItemsSource);
view.SortDescriptions.Add(new System.ComponentModel.SortDescription("DateOccured", System.ComponentModel.ListSortDirection.Descending));
PropertyGroupDescription groupDescription = new PropertyGroupDescription("DateAndUser");
view.GroupDescriptions.Add(groupDescription);
}

//create a class for a custom history object to display, this is similiar to the MultipleMailboxes XAML and Code behind
public class CustomHistoryObject
{
public string UserName { get; set; }
public string Property { get; set; }
public string OldValue { get; set; }
public string NewValue { get; set; }
public DateTime DateOccured { get; set; }
public string DateAndUser { get; set; }
}

private void WizardRegularPageBase_Loaded(object sender, RoutedEventArgs e)
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<Compile Include="Forms\AzureSpeech.xaml.cs">
<DependentUpon>AzureSpeech.xaml</DependentUpon>
</Compile>
<Compile Include="Forms\HistoryForm.xaml.cs">
<DependentUpon>HistoryForm.xaml</DependentUpon>
</Compile>
<Compile Include="Forms\Logging.xaml.cs">
<DependentUpon>Logging.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -163,6 +166,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Forms\HistoryForm.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Forms\Logging.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down