Imports System Imports System.Net Imports System.Collections Imports System.Text Imports System.IO Imports Codice.Client.Common Imports Codice.CM.Common Namespace Codice.Client.BaseCommands Public Class AclInfoPrinter Public Sub CalcAclInfo(info As AclInfo, server As String, wkInfo As WorkspaceInfo, isInherited As Boolean) Dim spg As New SpecGenerator() If (info.Entries IsNot Nothing) AndAlso (info.Entries.Length > 0) Then Dim inheritedFrom As String = spg.GetSpecFromObjectInfo(info.CreatorObject, server, wkInfo) For Each entry As AclEntry In info.Entries CalcPermissions(entry, entry.Perm.OverrideGranted, False, False, isInherited, inheritedFrom) CalcPermissions(entry, entry.Perm.OverrideDenied, False, False, isInherited, inheritedFrom) CalcPermissions(entry, entry.Perm.Granted, True, False, isInherited, inheritedFrom) CalcPermissions(entry, entry.Perm.Denied, False, True, isInherited, inheritedFrom) Next End If If (info.Inheritance IsNot Nothing) AndAlso (info.Inheritance.Length > 0) Then For Each inh As AclInfo In info.Inheritance CalcAclInfo(inh, server, wkInfo, True) Next End If End Sub Public Function CalcExtendedAclInfo(info As AclInfo, indent As Integer, server As String, wkInfo As WorkspaceInfo) As String Dim spg As New SpecGenerator() Dim result As New StringBuilder() Dim indentstr As String = "{0,-" + indent + "}" result.Append(String.Format(indentstr + "ACL: {1}" & vbLf, "", info.AclId)) indent += 2 indentstr = "{0,-" + indent + "}" result.Append(String.Format(indentstr + "Creator {1}" & vbLf, " ", spg.GetSpecFromObjectInfo(info.CreatorObject, server, wkInfo))) If (info.Entries IsNot Nothing) AndAlso (info.Entries.Length > 0) Then result.Append(String.Format(indentstr + "Entries" & vbLf, " ")) For Each entry As AclEntry In info.Entries CalcAclEntry(result, indentstr, entry) Next End If If (info.Inheritance IsNot Nothing) AndAlso (info.Inheritance.Length > 0) Then result.Append(String.Format(indentstr + "Inherited" & vbLf, " ")) For Each inh As AclInfo In info.Inheritance result.Append(CalcExtendedAclInfo(inh, indent + 2, server, wkInfo)) Next End If Return result.ToString() End Function Public Shared Function GetPrintableSeidName(seidKey As SEID) As String Dim name As String If seidKey.Equals(SEIDConsts.EVERYBODY_SEID) Then Return SEIDConsts.EVERYBODY_SEID_NAME End If If seidKey.Equals(SEIDConsts.OWNER_SEID) Then Return SEIDConsts.OWNER_SEID_NAME End If Try name = UserInfo.[Get]().GetNameFromSEID(seidKey) Catch 'Seid cannot be resolved name = seidKey.Data End Try Return name End Function Public Function GetString() As String Dim result As New StringBuilder() result.Append(String.Format(STR_FORMAT, Localization.GetString("USER_KEY"), Localization.GetString("PERMISSION_KEY"), Localization.GetString("ALLOWED_KEY"), Localization.GetString("DENIED_KEY"), Localization.GetString("INHERITED_FROM_KEY"))) For Each entry As PrintableEntry In mTable.Values GetEntryString(result, entry) Next Return result.ToString() End Function Public Function GetEntries() As SortedList Return mTable End Function Private Sub CalcAclEntry(result As StringBuilder, indentstr As String, entry As AclEntry) result.Append(String.Format(indentstr + " {1}:" & vbLf, " ", GetPrintableSeidName(entry.Seid))) If entry.Perm.Granted <> Permissions.NO_PERMISSIONS Then result.Append(String.Format(indentstr + " Allowed:" & vbLf, " ")) result.Append(String.Format(indentstr + " {1}" & vbLf, " ", GetString(ClientPermissions.GetPermissionNames(entry.Perm.Granted)))) End If If entry.Perm.Denied <> Permissions.NO_PERMISSIONS Then result.Append(String.Format(indentstr + " Denied:" & vbLf, " ")) result.Append(String.Format(indentstr + " {1}" & vbLf, " ", GetString(ClientPermissions.GetPermissionNames(entry.Perm.Denied)))) End If If entry.Perm.OverrideGranted <> Permissions.NO_PERMISSIONS Then result.Append(String.Format(indentstr + " Override Allowed:" & vbLf, " ")) result.Append(String.Format(indentstr + " {1}" & vbLf, " ", GetString(ClientPermissions.GetPermissionNames(entry.Perm.OverrideGranted)))) End If If entry.Perm.OverrideDenied <> Permissions.NO_PERMISSIONS Then result.Append(String.Format(indentstr + " Override Denied:" & vbLf, " ")) result.Append(String.Format(indentstr + " {1}" & vbLf, " ", GetString(ClientPermissions.GetPermissionNames(entry.Perm.OverrideDenied)))) End If End Sub Private Sub CalcPermissions(entry As AclEntry, permissions As Permissions, bGranted As Boolean, bDenied As Boolean, isInherited As Boolean, inheritedFrom As String) Dim permNames As ArrayList = DirectCast(ClientPermissions.GetPermissionNames(permissions), ArrayList) For Each perm As String In permNames Dim aclEntry As New PrintableEntry(GetPrintableSeidName(entry.Seid), perm, bGranted, bDenied, isInherited, inheritedFrom) Add(aclEntry) Next End Sub Private Sub Add(entry As PrintableEntry) Dim key As String = entry.user + entry.permission + entry.inherited If mTable(key) Is Nothing Then mTable.Add(key, entry) Return End If TryCast(mTable(key), PrintableEntry).denied = entry.denied TryCast(mTable(key), PrintableEntry).granted = entry.granted End Sub Private Function GetString(list As IList) As String Dim result As String = String.Empty If list.Count = 0 Then Return String.Empty End If For Each s As String In list result += s + " " Next Return result End Function Private Sub GetEntryString(result As StringBuilder, entry As PrintableEntry) If entry.granted Then result.Append(String.Format(STR_FORMAT, entry.user, entry.permission, Localization.GetString("True"), "", entry.inherited)) Return End If If entry.denied Then result.Append(String.Format(STR_FORMAT, entry.user, entry.permission, "", Localization.GetString("True"), entry.inherited)) Return End If result.Append(String.Format(STR_FORMAT, entry.user, entry.permission, "", "", entry.inherited)) End Sub Friend Sub CalculateOperationsToApply(srcDiffs As SemanticDifferences) CalculateDeletesToApply(srcDiffs) CalculateMovesToApply(srcDiffs) CalculateAddsToApply(srcDiffs) CalculateRenamesToApply(srcDiffs) CalculateModifiesToApply(srcDiffs) End Sub Private Const STR_FORMAT As String = "{0,-12}{1,-15} {2,-7} {3,-6} {4,-15}" & vbLf 'Table with ACL entries for print 'The key is User+Permission+inherited Private mTable As New SortedList() End Class Public Class PrintableEntry Public user As String Public permission As String Public granted As Boolean Public denied As Boolean Public inherited As String Public Enum NodeTypeImageEnum Comment [Enum] [Interface] Constructor Method [Property] Field [Class] [Namespace] [Using] End Enum Public Sub New(user As String, permission As String, granted As Boolean, denied As Boolean, inherited As Boolean, inheritedFrom As String) Me.user = user Me.permission = permission Me.granted = granted Me.denied = denied If inherited Then Me.inherited = inheritedFrom Else Me.inherited = "--" End If End Sub End Class End Namespace