33 StringBuilder output =
new StringBuilder();
34 for (
int index = 0; index < items.Length; ++index)
40 output.Append(items[index]);
42 return output.ToString();
87 Console.WriteLine(
"Mediator Exercise");
95 Console.WriteLine(
" Operation 1: Show all groups");
100 Console.WriteLine(
" Operation 2: Show all users");
105 Console.WriteLine(
" Operation 3: Determine if a user is a member of a specific group.");
106 string userName =
"Arthur";
107 string groupName =
"admins";
108 Console.Write(
" Is user '{0}' in the '{1}' group?", userName, groupName);
109 Console.WriteLine(
" {0}", mediator.
IsUserInGroup(userName, groupName) ?
"Yes" :
"No");
113 Console.WriteLine(
" Operation 4: Show all users in a specific group.");
116 Console.WriteLine(
" All users in '{0}' group: {1}", groupName,
_ListToString(userNames));
120 Console.WriteLine(
" Operation 5: Show all groups containing a specific user.");
123 Console.WriteLine(
" All groups with user '{0}': {1}", userName,
_ListToString(groupNames));
127 Console.WriteLine(
" Operation 6: Remove a user from a group.");
129 groupName =
"Power Users";
131 Console.WriteLine(
" Removed user '{0}' from group '{1}'", userName, groupName);
133 Console.WriteLine(
" All groups with user '{0}': {1}", userName,
_ListToString(groupNames));
137 Console.WriteLine(
" Operation 7: Add a user to a group.");
139 Console.WriteLine(
" Adding user '{0}' to group '{1}'.", userName, groupName);
142 Console.WriteLine(
" All groups with user '{0}': {1}", userName,
_ListToString(groupNames));
146 Console.WriteLine(
" Operation 8: Remove a user from all groups.");
149 Console.WriteLine(
" Removing user '{0}' from all groups.", userName);
150 Console.WriteLine(
" Start: all groups with user '{0}': {1}", userName,
_ListToString(groupNames));
151 Console.WriteLine(
" Removing...");
154 Console.WriteLine(
" End: all groups with user '{0}': {1}", userName,
_ListToString(groupNames));
158 Console.WriteLine(
" Operation 9: Remove a user (also removes the user from all groups).");
160 Console.WriteLine(
" Removing user '{0}'.", userName);
164 foreach (
string name
in groupNames)
166 userNames = mediator.GetUsersInGroup(name);
167 Console.WriteLine(
" Users in group '{0}': {1}", name,
_ListToString(userNames));
171 Console.WriteLine(
" Done.");
The namespace containing all Design Pattern Examples implemented in C#.