protected override List <string> GetDescriptionValues(Entity entityInput, string behavior, bool withManaged, bool withSolutionInfo, bool withUrls, Action <List <string>, Entity, bool, bool, bool> action)
        {
            var entity = entityInput.ToEntity <RolePrivileges>();

            List <string> values = new List <string>();

            var businessUnit = EntityDescriptionHandler.GetAttributeString(entity, "role.businessunitid");

            if (!entity.Attributes.Contains("businessunit.parentbusinessunitid"))
            {
                businessUnit = "Root Organization";
            }

            values.AddRange(new[]
            {
                EntityDescriptionHandler.GetAttributeString(entity, "role.name")
                , businessUnit
                , EntityDescriptionHandler.GetAttributeString(entity, "privilege.name")
                , RolePrivilegesRepository.GetPrivilegeDepthMaskName(entity.PrivilegeDepthMask.Value)
                , behavior
            });

            action(values, entity, withUrls, withManaged, withSolutionInfo);

            return(values);
        }
        public override string GetDisplayName(SolutionComponent component)
        {
            var entity = GetEntity <RolePrivileges>(component.ObjectId.Value);

            if (entity != null)
            {
                return(RolePrivilegesRepository.GetPrivilegeDepthMaskName(entity.ToEntity <RolePrivileges>().PrivilegeDepthMask.Value));
            }

            return(base.GetDisplayName(component));
        }
예제 #3
0
        private List <string> CompareRolePrivileges(
            IEnumerable <RolePrivileges> enumerableRolePriv1
            , IEnumerable <RolePrivileges> enumerableRolePriv2
            , IEnumerable <Privilege> commonPrivileges
            , Dictionary <string, Privilege> listPrivilege1
            , Dictionary <string, Privilege> listPrivilege2
            , PrivilegeNameComparer privilegeNameComparer
            )
        {
            var result = new List <string>();

            var tableOnlyIn1 = new FormatTextTableHandler("PrivilegeName", "PrivilegeType", "Depth", "Linked Entities");

            var tableOnlyIn2 = new FormatTextTableHandler("PrivilegeName", "PrivilegeType", "Depth", "Linked Entities");

            var tableDifferent = new FormatTextTableHandler("PrivilegeName", "PrivilegeType", Connection1.Name, Connection2.Name, "Linked Entities");

            var tableFullDifferences = new FormatTextTableHandler("PrivilegeName", "PrivilegeType", Connection1.Name, Connection2.Name, "Linked Entities");

            foreach (var priv in commonPrivileges.OrderBy(s => s.LinkedEntitiesSorted).OrderBy(s => s.Name, privilegeNameComparer))
            {
                var priv1 = listPrivilege1[priv.Name];
                var priv2 = listPrivilege2[priv.Name];

                RolePrivileges rolePriv1 = null;
                RolePrivileges rolePriv2 = null;

                if (enumerableRolePriv1 != null)
                {
                    rolePriv1 = enumerableRolePriv1.FirstOrDefault(i => i.PrivilegeId == priv1?.PrivilegeId);
                }

                if (enumerableRolePriv2 != null)
                {
                    rolePriv2 = enumerableRolePriv2.FirstOrDefault(i => i.PrivilegeId == priv2?.PrivilegeId);
                }

                if (rolePriv1 != null && rolePriv2 == null)
                {
                    var privilegedepthmask = rolePriv1.PrivilegeDepthMask.GetValueOrDefault();

                    tableOnlyIn1.AddLine(priv.Name
                                         , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                         , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask)
                                         , priv.LinkedEntitiesSorted
                                         );
                    tableOnlyIn2.CalculateLineLengths(priv.Name
                                                      , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                                      , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask)
                                                      , priv.LinkedEntitiesSorted
                                                      );
                }
                else if (rolePriv1 == null && rolePriv2 != null)
                {
                    var privilegedepthmask = rolePriv2.PrivilegeDepthMask.GetValueOrDefault();

                    tableOnlyIn2.AddLine(priv.Name
                                         , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                         , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask)
                                         , priv.LinkedEntitiesSorted
                                         );
                    tableOnlyIn1.CalculateLineLengths(priv.Name
                                                      , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                                      , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask)
                                                      , priv.LinkedEntitiesSorted
                                                      );
                }
                else if (rolePriv1 != null && rolePriv2 != null)
                {
                    var privilegedepthmask1 = rolePriv1.PrivilegeDepthMask.GetValueOrDefault();
                    var privilegedepthmask2 = rolePriv2.PrivilegeDepthMask.GetValueOrDefault();

                    if (privilegedepthmask1 != privilegedepthmask2)
                    {
                        tableDifferent.AddLine(priv.Name
                                               , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                               , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask1)
                                               , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask2)
                                               , priv.LinkedEntitiesSorted
                                               );

                        tableFullDifferences.CalculateLineLengths(priv.Name
                                                                  , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                                                  , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask1)
                                                                  , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask2)
                                                                  , priv.LinkedEntitiesSorted
                                                                  );
                    }
                }

                var privilegedepthmaskValue1 = rolePriv1?.PrivilegeDepthMask;
                var privilegedepthmaskValue2 = rolePriv2?.PrivilegeDepthMask;

                if (privilegedepthmaskValue1 != privilegedepthmaskValue2)
                {
                    tableFullDifferences.AddLine(priv.Name
                                                 , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                                 , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmaskValue1)
                                                 , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmaskValue2)
                                                 , priv.LinkedEntitiesSorted
                                                 );

                    tableDifferent.CalculateLineLengths(priv.Name
                                                        , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                                        , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmaskValue1)
                                                        , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmaskValue2)
                                                        , priv.LinkedEntitiesSorted
                                                        );
                }
            }

            if (tableFullDifferences.Count > 0)
            {
                if (result.Count > 0)
                {
                    result.Add(string.Empty);
                }

                result.Add(string.Format("Full Differences privileges in {0} and {1}: {2}", Connection1.Name, Connection2.Name, tableFullDifferences.Count));
                tableFullDifferences.GetFormatedLines(false).ForEach(s => result.Add(tabSpacer + s));
            }

            if (tableOnlyIn1.Count > 0)
            {
                if (result.Count > 0)
                {
                    result.Add(string.Empty);
                }

                result.Add(string.Format("Privileges ONLY in {0}: {1}", Connection1.Name, tableOnlyIn1.Count));
                tableOnlyIn1.GetFormatedLines(false).ForEach(s => result.Add(tabSpacer + s));
            }

            if (tableOnlyIn2.Count > 0)
            {
                if (result.Count > 0)
                {
                    result.Add(string.Empty);
                }

                result.Add(string.Format("Privileges ONLY in {0}: {1}", Connection2.Name, tableOnlyIn2.Count));
                tableOnlyIn2.GetFormatedLines(false).ForEach(s => result.Add(tabSpacer + s));
            }

            if (tableDifferent.Count > 0)
            {
                if (result.Count > 0)
                {
                    result.Add(string.Empty);
                }

                result.Add(string.Format("Different privileges in {0} and {1}: {2}", Connection1.Name, Connection2.Name, tableDifferent.Count));
                tableDifferent.GetFormatedLines(false).ForEach(s => result.Add(tabSpacer + s));
            }

            return(result);
        }
        public List <string> CompareRolePrivileges(
            IEnumerable <RolePrivilege> enumerableRolePriv1
            , IEnumerable <RolePrivilege> enumerableRolePriv2
            , IEnumerable <Privilege> commonPrivileges
            , PrivilegeNameComparer privilegeNameComparer
            )
        {
            List <string> result = new List <string>();

            FormatTextTableHandler tableOnlyIn1 = new FormatTextTableHandler();

            tableOnlyIn1.SetHeader("PrivilegeName", "PrivilegeType", "Depth", "Linked Entities");

            FormatTextTableHandler tableOnlyIn2 = new FormatTextTableHandler();

            tableOnlyIn2.SetHeader("PrivilegeName", "PrivilegeType", "Depth", "Linked Entities");

            FormatTextTableHandler tableDifferent = new FormatTextTableHandler();

            tableDifferent.SetHeader("PrivilegeName", "PrivilegeType", Entity1Name, Entity2Name, "Linked Entities");

            foreach (var priv in commonPrivileges.OrderBy(s => s.LinkedEntitiesSorted).OrderBy(s => s.Name, privilegeNameComparer))
            {
                RolePrivilege rolePriv1 = null;
                RolePrivilege rolePriv2 = null;

                if (enumerableRolePriv1 != null)
                {
                    rolePriv1 = enumerableRolePriv1.FirstOrDefault(i => i.PrivilegeId == priv.PrivilegeId);
                }

                if (enumerableRolePriv2 != null)
                {
                    rolePriv2 = enumerableRolePriv2.FirstOrDefault(i => i.PrivilegeId == priv.PrivilegeId);
                }

                if (rolePriv1 != null && rolePriv2 == null)
                {
                    var privilegedepthmask = rolePriv1.Depth;

                    tableOnlyIn1.AddLine(priv.Name
                                         , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                         , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask)
                                         , priv.LinkedEntitiesSorted
                                         );
                    tableOnlyIn2.CalculateLineLengths(priv.Name
                                                      , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                                      , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask)
                                                      , priv.LinkedEntitiesSorted
                                                      );
                }
                else if (rolePriv1 == null && rolePriv2 != null)
                {
                    var privilegedepthmask = rolePriv2.Depth;

                    tableOnlyIn2.AddLine(priv.Name
                                         , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                         , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask)
                                         , priv.LinkedEntitiesSorted
                                         );
                    tableOnlyIn1.CalculateLineLengths(priv.Name
                                                      , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                                      , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask)
                                                      , priv.LinkedEntitiesSorted
                                                      );
                }
                else if (rolePriv1 != null && rolePriv2 != null)
                {
                    var privilegedepthmask1 = rolePriv1.Depth;
                    var privilegedepthmask2 = rolePriv2.Depth;

                    if (privilegedepthmask1 != privilegedepthmask2)
                    {
                        tableDifferent.AddLine(priv.Name
                                               , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty
                                               , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask1)
                                               , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask2)
                                               , priv.LinkedEntitiesSorted
                                               );
                    }
                }
            }

            if (tableOnlyIn1.Count > 0)
            {
                if (result.Count > 0)
                {
                    result.Add(string.Empty);
                }

                result.Add(string.Format("RolePrivileges ONLY in {0}: {1}", Entity1Name, tableOnlyIn1.Count));
                tableOnlyIn1.GetFormatedLines(false).ForEach(s => result.Add(_tabSpacer + s));
            }

            if (tableOnlyIn2.Count > 0)
            {
                if (result.Count > 0)
                {
                    result.Add(string.Empty);
                }

                result.Add(string.Format("RolePrivileges ONLY in {0}: {1}", Entity2Name, tableOnlyIn2.Count));
                tableOnlyIn2.GetFormatedLines(false).ForEach(s => result.Add(_tabSpacer + s));
            }

            if (tableDifferent.Count > 0)
            {
                if (result.Count > 0)
                {
                    result.Add(string.Empty);
                }

                result.Add(string.Format("Different RolePrivileges in {0} and {1}: {2}", Entity1Name, Entity2Name, tableDifferent.Count));
                tableDifferent.GetFormatedLines(false).ForEach(s => result.Add(_tabSpacer + s));
            }

            if (tableOnlyIn1.Count == 0 &&
                tableOnlyIn2.Count == 0 &&
                tableDifferent.Count == 0
                )
            {
                result.Add(string.Format("No difference RolePrivileges in {0} and {1}", Entity1Name, Entity2Name));
            }

            return(result);
        }