private void OUBox_SelectionChangeCommitted(object sender, EventArgs e) { startBox.Text = OUBox.Text; whoBox.Items.Clear(); if (domainBox.Text.Length == 0 || OUBox.Text.Length == 0) { Console.WriteLine("Listing users aborted. domain/OU=" + domainBox.Text + "/" + OUBox.Text); return; } DirectoryEntry de = ((Domain)domainBox.SelectedItem).GetDirectoryEntry(); foreach (DirectoryEntry de_ in de.Children) { if (de_.Properties["name"].Value.ToString().Equals(OUBox.Text)) { de = de_; break; } } Cursor.Current = Cursors.WaitCursor; Console.WriteLine("Listing users in " + de.Name + "..."); USERS.Clear(); USERS.FindAll(de); whoBox.Items.AddRange(USERS.getUsers()); string me_user = UserPrincipal.Current.SamAccountName.ToUpper(); string me_domain = UserPrincipal.Current.UserPrincipalName.Split(new [] { '@', '.' })[1].ToUpper(); string me_domainuser = me_domain + "\\" + me_user; if (USERS.FindOneDomainUser(me_domainuser)) { whoBox.Items.Add(USERS.getDisplaynameFromUsername(me_user)); whoBox.Text = USERS.getDisplaynameFromUsername(me_user); } Cursor.Current = Cursors.Default; }
private FlowLayoutPanel addAction(String actionStr, String actionCmd, String user, bool decentralized, Image pic) { FlowLayoutPanel panel = new FlowLayoutPanel(); panel.Size = new Size(500, 50); Button button = new Button(); button.Size = new Size(450, 46); panel.Controls.Add(button); button.Text = actionStr; if (decentralized) { button.BackColor = System.Drawing.Color.LightCoral; } myWPF.LyncControl lync = null; string pres = ""; if (actionCmd.Equals("UNLOCK") || actionCmd.Equals("EXPIRING")) { bool found = false; foreach (Control c in actionsPanel.Controls) { if (c is FlowLayoutPanel && c.Controls.Count > 0 && c.Controls[0] is Button && c.Controls[0].Text.Equals(actionStr)) { found = true; break; } } if (found) { return(null); } button.Image = pic; if (button.Image != null) { panel.Size = new Size(500, 100); button.Size = new Size(450, 96); } string desc = usersInfo.getDisplaynameFromUsername(user); string sip = usersInfo.getSipFromDisplayname(desc); if (sip != null && sip.Length > 0) { lync = AuditSec.newLyncControl(this, sip, button.Parent); pres = lync.getPresenceStatus(); Console.WriteLine(sip + " = " + pres); panel.Size = new Size(500, 100); } } button.Click += delegate { button.Enabled = false; switch (actionCmd) { case "UNLOCK": if (!usersInfo.unlockAD(user)) { Cursor.Current = Cursors.Default; speak("FAILED to unlock account " + user); MessageBox.Show("FAILED to unlock account " + user, "Locked User Detection"); button.ForeColor = Color.Red; button.Enabled = true; } else { Cursor.Current = Cursors.Default; speak("Successfully unlocked account " + user); MessageBox.Show("Successfully unlocked account " + user, "Locked User Detection"); actionsPanel.Controls.Remove(button.Parent); } break; case "EXPIRING": if (lync != null) { lync.openIMWindow(); } speak("Invite user " + user + " to change the password."); MessageBox.Show("Invite user " + user + " to change the password.", "Expiring User Detection"); actionsPanel.Controls.Remove(button.Parent); break; default: actionsPanel.Controls.Remove(button.Parent); break; }//switch }; //+=Click string speech = actionStr.Replace(actionCmd + ": ", ""); speech = Regex.Replace(speech, "(.*), (.*)'s ", "$2 $1's "); speech = Regex.Replace(speech, @"\*\*\*(.*)\*\*\*", "Beware, this staff is $1."); switch (pres) { case "Free": speech += ". This user is ONLINE and free."; break; case "Busy": speech += ". This user is ONLINE but busy."; break; case "DoNotDisturb": speech += ". This user is ONLINE but very busy."; break; case "Away": speech += ". This user is ONLINE but away."; break; case "Offline": speech += ". This user is offline."; break; case "None": speech += ". This user is offline."; break; default: Console.WriteLine("status not coded: " + pres); break; } speechs.Add(speech); return(panel); }