From 19f9c83a93a7bf8fc3ef57b36086fb5110033dcc Mon Sep 17 00:00:00 2001 From: Dylan Bickerstaff Date: Mon, 9 Dec 2019 10:10:47 -0500 Subject: [PATCH] User Table Overhaul Begins. --- SuperGrate/Classes/Misc.cs | 47 +++++++++++++++++++++---- SuperGrate/Classes/UserListViews.cs | 26 -------------- SuperGrate/Classes/UserTable.cs | 53 +++++++++++++++++++++++++++++ SuperGrate/Main.cs | 22 +++++++----- SuperGrate/SuperGrate.csproj | 2 +- 5 files changed, 108 insertions(+), 42 deletions(-) delete mode 100644 SuperGrate/Classes/UserListViews.cs create mode 100644 SuperGrate/Classes/UserTable.cs diff --git a/SuperGrate/Classes/Misc.cs b/SuperGrate/Classes/Misc.cs index 63f0bce..b8892f9 100644 --- a/SuperGrate/Classes/Misc.cs +++ b/SuperGrate/Classes/Misc.cs @@ -122,23 +122,58 @@ public static Task> GetUsersFromHost(string Host) } }); } - static public Task> GetUsersFromStore(string StorePath) + static public Task GetUsersFromStore(string StorePath) { return Task.Run(() => { try { Logger.Information("Listing users from store: " + StorePath + "..."); - Dictionary results = new Dictionary(); + UserTable.UserRows rows = new UserTable.UserRows(); foreach (string directory in Directory.EnumerateDirectories(StorePath)) { + UserTable.UserRow row = new UserTable.UserRow(); DirectoryInfo info = new DirectoryInfo(directory); - string user = GetUserByIdentity(info.Name); - Logger.Verbose("Found: " + user); - results.Add(info.Name, user); + foreach(KeyValuePair HeaderColumn in UserTable.CurrentHeaderRow) + { + if (HeaderColumn.Key == UserTable.ColumnType.Tag) + { + row.Add(HeaderColumn.Key, info.Name); + } + if (HeaderColumn.Key == UserTable.ColumnType.NTAccount) + { + row.Add(HeaderColumn.Key, File.ReadAllText(Path.Combine(directory, "ntaccount"))); + } + if (HeaderColumn.Key == UserTable.ColumnType.SourceComputer) + { + + } + if (HeaderColumn.Key == UserTable.ColumnType.DestinationComputer) + { + + } + if (HeaderColumn.Key == UserTable.ColumnType.MigratedBy) + { + + } + if (HeaderColumn.Key == UserTable.ColumnType.ImportedOn) + { + + } + if (HeaderColumn.Key == UserTable.ColumnType.ExportedOn) + { + + } + if (HeaderColumn.Key == UserTable.ColumnType.Size) + { + + } + } + rows.Add(row); + //Logger.Verbose("Found: " + user); } Logger.Success("Users listed successfully."); - return results; + return rows; } catch (Exception e) { diff --git a/SuperGrate/Classes/UserListViews.cs b/SuperGrate/Classes/UserListViews.cs deleted file mode 100644 index 567d334..0000000 --- a/SuperGrate/Classes/UserListViews.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Windows.Forms; - -namespace SuperGrate -{ - class UserListViews - { - static public void SetSourceComputer(ListView Owner) - { - Owner.Columns.Clear(); - Owner.Columns.Add("User Name"); - Owner.Columns.Add("Last Logon"); - Owner.Columns.Add("Size"); - } - static public void SetStore(ListView Owner) - { - Owner.Columns.Clear(); - Owner.Columns.Add("User Name"); - Owner.Columns.Add("Source Computer"); - Owner.Columns.Add("Destination Computer"); - Owner.Columns.Add("Migrated By"); - Owner.Columns.Add("Imported On"); - Owner.Columns.Add("Exported On"); - Owner.Columns.Add("Size"); - } - } -} diff --git a/SuperGrate/Classes/UserTable.cs b/SuperGrate/Classes/UserTable.cs new file mode 100644 index 0000000..1da9fb9 --- /dev/null +++ b/SuperGrate/Classes/UserTable.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; +using System.Windows.Forms; + +namespace SuperGrate +{ + class UserTable + { + public class UserRow : Dictionary { } + public class UserRows : List { } + public static UserRow CurrentHeaderRow = null; + public static UserRow HeaderRowComputerSource = new UserRow() + { + { ColumnType.Tag, null }, + { ColumnType.NTAccount, "User Name" }, + { ColumnType.LastLogon, "Last Logon" }, + { ColumnType.Size, "Size" } + }; + public static UserRow HeaderRowStoreSource = new UserRow() + { + { ColumnType.Tag, null }, + { ColumnType.NTAccount, "User Name" }, + { ColumnType.SourceComputer, "Source Computer" }, + { ColumnType.DestinationComputer, "Destination Computer" }, + { ColumnType.MigratedBy, "Migrated By" }, + { ColumnType.ImportedOn, "Imported On" }, + { ColumnType.ExportedOn, "Exported On" }, + { ColumnType.Size, "Size" } + }; + static public void SetColumns(ListView Owner, UserRow Row) + { + Owner.Columns.Clear(); + foreach(KeyValuePair Column in Row) + { + if (Column.Value != null) + { + Owner.Columns.Add(Column.Value); + } + } + CurrentHeaderRow = Row; + } + public enum ColumnType { + NTAccount, + SourceComputer, + DestinationComputer, + LastLogon, + Size, + MigratedBy, + ImportedOn, + ExportedOn, + Tag + } + } +} diff --git a/SuperGrate/Main.cs b/SuperGrate/Main.cs index 3993e43..9bf11ab 100644 --- a/SuperGrate/Main.cs +++ b/SuperGrate/Main.cs @@ -145,7 +145,7 @@ private async void BtnListSource_Click(object sender, EventArgs e) { Running = RunningTask.Unknown; listUsers.BeginUpdate(); - UserListViews.SetSourceComputer(listUsers); + UserTable.SetColumns(listUsers, UserTable.HeaderRowComputerSource); listUsers.Items.Clear(); lblUserList.Text = "Users on Source Computer:"; Dictionary users = await Misc.GetUsersFromHost(tbSourceComputer.Text); @@ -182,16 +182,20 @@ private async void BtnListStore_Click(object sender, EventArgs e) listUsers.BeginUpdate(); listUsers.Items.Clear(); lblUserList.Text = "Users in Migration Store:"; - Dictionary results = await Misc.GetUsersFromStore(Config.Settings["MigrationStorePath"]); - if(results != null) + UserTable.SetColumns(listUsers, UserTable.HeaderRowStoreSource); + UserTable.UserRows rows = await Misc.GetUsersFromStore(Config.Settings["MigrationStorePath"]); + if(rows != null) { - UserListViews.SetStore(listUsers); - //lbxUsers.Tag = results.Keys.ToArray(); - //lbxUsers.Items.AddRange(results.Values.ToArray()); - listUsers.Tag = results.Keys.ToArray(); - foreach(string userNames in results.Values) + foreach(UserTable.UserRow row in rows) { - listUsers.Items.Add(userNames); + ListViewItem lvRow = listUsers.Items.Add(row[0]); + row.Remove(0); + lvRow.Tag = row[UserTable.ColumnType.Tag]; + row.Remove(UserTable.ColumnType.Tag); + foreach(KeyValuePair column in row) + { + lvRow.SubItems.Add(column.Value); + } } listUsers.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listUsers.EndUpdate(); diff --git a/SuperGrate/SuperGrate.csproj b/SuperGrate/SuperGrate.csproj index c5d3a01..48b3373 100644 --- a/SuperGrate/SuperGrate.csproj +++ b/SuperGrate/SuperGrate.csproj @@ -113,7 +113,7 @@ - + Form