Skip to content

Commit

Permalink
User Table Overhaul Begins.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Dec 9, 2019
1 parent 6bac588 commit 19f9c83
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 42 deletions.
47 changes: 41 additions & 6 deletions SuperGrate/Classes/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,58 @@ public static Task<Dictionary<string, string>> GetUsersFromHost(string Host)
}
});
}
static public Task<Dictionary<string, string>> GetUsersFromStore(string StorePath)
static public Task<UserTable.UserRows> GetUsersFromStore(string StorePath)
{
return Task.Run(() =>
{
try
{
Logger.Information("Listing users from store: " + StorePath + "...");
Dictionary<string, string> results = new Dictionary<string, string>();
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<UserTable.ColumnType, string> 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)
{
Expand Down
26 changes: 0 additions & 26 deletions SuperGrate/Classes/UserListViews.cs

This file was deleted.

53 changes: 53 additions & 0 deletions SuperGrate/Classes/UserTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Windows.Forms;

namespace SuperGrate
{
class UserTable
{
public class UserRow : Dictionary<ColumnType, string> { }
public class UserRows : List<UserRow> { }
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<ColumnType, string> 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
}
}
}
22 changes: 13 additions & 9 deletions SuperGrate/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> users = await Misc.GetUsersFromHost(tbSourceComputer.Text);
Expand Down Expand Up @@ -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<string, string> 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<UserTable.ColumnType, string> column in row)
{
lvRow.SubItems.Add(column.Value);
}
}
listUsers.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
listUsers.EndUpdate();
Expand Down
2 changes: 1 addition & 1 deletion SuperGrate/SuperGrate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<Compile Include="Classes\Logger.cs" />
<Compile Include="Classes\Misc.cs" />
<Compile Include="Classes\Remote.cs" />
<Compile Include="Classes\UserListViews.cs" />
<Compile Include="Classes\UserTable.cs" />
<Compile Include="Classes\USMT.cs" />
<Compile Include="Controls\About.cs">
<SubType>Form</SubType>
Expand Down

0 comments on commit 19f9c83

Please sign in to comment.