internal static XlHlp.XlLocation Add_Members( XlHlp.XlLocation insertAt, Options_AZDO_TFS options) { long startTicks = XlHlp.DisplayInWatchWindow(insertAt); TeamFoundationIdentity everyone = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.EveryoneGroup, MembershipQuery.Direct, ReadIdentityOptions.None); TeamFoundationIdentity licensees = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.LicenseesGroup, MembershipQuery.Direct, ReadIdentityOptions.None); TeamFoundationIdentity namespaceAdministrators = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.NamespaceAdministratorsGroup, MembershipQuery.Direct, ReadIdentityOptions.None); TeamFoundationIdentity serviceUsers = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.ServiceUsersGroup, MembershipQuery.Direct, ReadIdentityOptions.None); if (everyone != null) { insertAt.ClearOffsets(); XlHlp.AddLabeledInfo(insertAt.AddRow(), "Everyone", everyone.Members.Count().ToString()); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), everyone.DisplayName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), everyone.UniqueName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), everyone.Descriptor.IdentityType); insertAt.IncrementRows(); } else { XlHlp.AddLabeledInfo(insertAt.AddRow(), "Everyone", "null"); } if (licensees != null) { insertAt.ClearOffsets(); XlHlp.AddLabeledInfo(insertAt.AddRow(), "Licensees", licensees.Members.Count().ToString()); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), licensees.DisplayName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), licensees.UniqueName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), licensees.Descriptor.IdentityType); insertAt.IncrementRows(); } else { XlHlp.AddLabeledInfoX(insertAt.AddRowX(), "Licensees", "null"); } if (namespaceAdministrators != null) { insertAt.ClearOffsets(); XlHlp.AddLabeledInfo(insertAt.AddRow(), "NamespaceAdministrators", namespaceAdministrators.Members.Count().ToString()); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), namespaceAdministrators.DisplayName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), namespaceAdministrators.UniqueName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), namespaceAdministrators.Descriptor.IdentityType); insertAt.IncrementRows(); } else { XlHlp.AddLabeledInfo(insertAt.AddRow(), "NamespaceAdministrators", "null"); } if (serviceUsers != null) { insertAt.ClearOffsets(); XlHlp.AddLabeledInfo(insertAt.AddRow(), "ServiceUsers", serviceUsers.Members.Count().ToString()); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), serviceUsers.DisplayName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), serviceUsers.UniqueName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), serviceUsers.Descriptor.IdentityType); insertAt.IncrementRows(); } else { XlHlp.AddLabeledInfoX(insertAt.AddRowX(), "ServiceUsers", "null"); } TeamFoundationIdentity everyoneExpanded = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.EveryoneGroup, MembershipQuery.Expanded, ReadIdentityOptions.None); TeamFoundationIdentity everyoneExpanded2 = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.EveryoneGroup, MembershipQuery.Expanded, ReadIdentityOptions.IncludeReadFromSource); if (everyoneExpanded != null) { AZDOHelper.FetchIdentities(everyoneExpanded.Members, _Global_Groups, _Global_Identities); } TeamFoundationIdentity licenseesExpanded = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.LicenseesGroup, MembershipQuery.Expanded, ReadIdentityOptions.None); if (licenseesExpanded != null) { AZDOHelper.FetchIdentities(licenseesExpanded.Members, _Global_Groups, _Global_Identities); } TeamFoundationIdentity serviceUsersExpanded = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.ServiceUsersGroup, MembershipQuery.Expanded, ReadIdentityOptions.None); if (serviceUsersExpanded != null) { AZDOHelper.FetchIdentities(serviceUsersExpanded.Members, _Global_Groups, _Global_Identities); } TeamFoundationIdentity namespaceAdministratorsExpanded = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.NamespaceAdministratorsGroup, MembershipQuery.Expanded, ReadIdentityOptions.None); if (namespaceAdministratorsExpanded != null) { AZDOHelper.FetchIdentities(namespaceAdministratorsExpanded.Members, _Global_Groups, _Global_Identities); } XlHlp.AddLabeledInfoX(insertAt.AddRowX(), "All Groups and Identities", "Lots"); insertAt.MarkStart(XlHlp.MarkType.GroupTable); // Keep in same order as fields, infra. // Group XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 50, "Top Level"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 50, "Group Identifier"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 50, "Group Identity"); // Members XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 15, "IsContainer"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 30, "TeamFoundationId"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 50, "DisplayName"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 80, "UniqueName"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 40, "IdentityType"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 40, "Identity"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 20, "UniqueUserId"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 10, "IsActive"); insertAt.IncrementRows(); foreach (TeamFoundationIdentity identity in _Global_Groups) { Globals.ThisAddIn.Application.StatusBar = "Processing " + identity.DisplayName; foreach (IdentityDescriptor member in identity.Members) { insertAt.ClearOffsets(); // Top Level string topLevel = ""; MatchCollection matches = Regex.Matches(identity.DisplayName, @"\[.*\]"); if (matches.Count == 1) { topLevel = matches[0].Value; } else { topLevel = identity.DisplayName; } XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), topLevel); // Group XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), identity.Descriptor.Identifier); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), identity.DisplayName); // Members XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), _Global_Identities[member].IsContainer.ToString()); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), _Global_Identities[member].TeamFoundationId.ToString()); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), _Global_Identities[member].DisplayName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), _Global_Identities[member].UniqueName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), _Global_Identities[member].Descriptor.IdentityType); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), _Global_Identities[member].Descriptor.Identifier); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), _Global_Identities[member].UniqueUserId.ToString()); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), _Global_Identities[member].IsActive.ToString()); insertAt.IncrementRows(); } } insertAt.MarkEnd(XlHlp.MarkType.GroupTable, string.Format("tblMembers_{0}", insertAt.workSheet.Name)); insertAt.Group(insertAt.OrientVertical); if (!insertAt.OrientVertical) { // Skip past the info just added. insertAt.SetLocation(insertAt.RowStart, insertAt.MarkEndColumn + 1); } XlHlp.DisplayInWatchWindow(insertAt, startTicks, "End"); return(insertAt); }
internal static XlHlp.XlLocation Add_Members( XlHlp.XlLocation insertAt, TeamProject teamProject) { long startTicks = XlHlp.DisplayInWatchWindow(insertAt); try { int currentRows = insertAt.RowsAdded; // Save the location of the count so we can update later after have traversed all items. Range rngTitle = insertAt.GetCurrentRange(); if (insertAt.OrientVertical) { XlHlp.AddSectionInfo(insertAt.AddRow(), "Members Group", ""); } else { XlHlp.AddSectionInfo(insertAt.AddRow(), "Members Group", "", orientation: XlOrientation.xlUpward); insertAt.IncrementColumns(); } TeamFoundationIdentity[] projectGroups = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ListApplicationGroups( teamProject.ArtifactUri.AbsoluteUri, ReadIdentityOptions.None); Dictionary <IdentityDescriptor, object> descriptorSet = new Dictionary <IdentityDescriptor, object>(IdentityDescriptorComparer.Instance); foreach (TeamFoundationIdentity projectGroup in projectGroups) { descriptorSet[projectGroup.Descriptor] = projectGroup.Descriptor; } // Expanded membership of project groups projectGroups = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentities(descriptorSet.Keys.ToArray(), MembershipQuery.Expanded, ReadIdentityOptions.None); // Collect all descriptors foreach (TeamFoundationIdentity projectGroup in projectGroups) { foreach (IdentityDescriptor mem in projectGroup.Members) { descriptorSet[mem] = mem; } } // NOTE(crhodes) // Might need to ensure that _Global_Groups and _Global_Identities already populated. if (Section_TeamProjectCollection._Global_Identities.Count == 0) { TeamFoundationIdentity everyoneExpanded = AzureDevOpsExplorer.Presentation.Views.Server.IdentityManagementService.ReadIdentity( GroupWellKnownDescriptors.EveryoneGroup, MembershipQuery.Expanded, ReadIdentityOptions.None); AZDOHelper.FetchIdentities(everyoneExpanded.Members, Section_TeamProjectCollection._Global_Groups, Section_TeamProjectCollection._Global_Identities); } _TeamProject_Groups.Clear(); _TeamProject_Identities.Clear(); AZDOHelper.FetchIdentities(descriptorSet.Keys.ToArray(), _TeamProject_Groups, _TeamProject_Identities); insertAt.MarkStart(XlHlp.MarkType.GroupTable); // Keep in same order as fields, infra. // Group XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 50, "Identifier"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 50, "Identity"); // Members XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 15, "IsContainer"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 50, "DisplayName"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 80, "UniqueName"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 40, "IdentityType"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 20, "UniqueUserId"); XlHlp.AddColumnHeaderToSheet(insertAt.AddOffsetColumn(), 10, "IsActive"); insertAt.IncrementRows(); foreach (TeamFoundationIdentity identity in _TeamProject_Groups) { foreach (IdentityDescriptor member in identity.Members) { insertAt.ClearOffsets(); try { // Group XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), identity.Descriptor.Identifier); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), identity.DisplayName); // Members // NOTE(crhodes) // This line is throwing exception. Why? XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), Section_TeamProjectCollection._Global_Identities[member].IsContainer.ToString()); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), Section_TeamProjectCollection._Global_Identities[member].DisplayName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), Section_TeamProjectCollection._Global_Identities[member].UniqueName); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), Section_TeamProjectCollection._Global_Identities[member].Descriptor.IdentityType); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), Section_TeamProjectCollection._Global_Identities[member].UniqueUserId.ToString()); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), Section_TeamProjectCollection._Global_Identities[member].IsActive.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } insertAt.IncrementRows(); } } insertAt.MarkEnd(XlHlp.MarkType.GroupTable, string.Format("tblTPMembers_{0}", insertAt.workSheet.Name)); insertAt.Group(insertAt.OrientVertical); // Update counts. -2 covers Header and Table Column Header if (insertAt.OrientVertical) { XlHlp.AddLabeledInfoX(rngTitle, "Members Group", (insertAt.RowsAdded - currentRows - 2).ToString()); } else { XlHlp.AddLabeledInfoX(rngTitle, "Members Group", (insertAt.RowsAdded - currentRows - 2).ToString(), orientation: XlOrientation.xlUpward); } insertAt.EndSectionAndSetNextLocation(insertAt.OrientVertical); //insertAt.AddRow(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } XlHlp.DisplayInWatchWindow(insertAt, startTicks, "End"); return(insertAt); }