public object Resolve(object source, Dictionary <string, IResolver> resolvers = null, bool recursive = false)
        {
            Object result = null;

            //source is either Security instance or SiteGroup instance
            var userCollection = source?.GetPublicInstancePropertyValue(this.collectionName);
            var clearItems     = source?.GetPublicInstancePropertyValue(this.clearItemsPropertyName);

            if (null != userCollection && (((ICollection)userCollection).Count > 0 || (Boolean)clearItems))
            {
                var siteSecurityUsersCollectionTypeName = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.UsersList, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                var siteSecurityUsersCollectionType     = Type.GetType(siteSecurityUsersCollectionTypeName, true);
                var siteSecurityUserTypeName            = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.User, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                var siteSecurityUserType = Type.GetType(siteSecurityUserTypeName, true);

                result = Activator.CreateInstance(siteSecurityUsersCollectionType);

                var resolver = new CollectionFromModelToSchemaTypeResolver(siteSecurityUserType);
                result.SetPublicInstancePropertyValue("User",
                                                      resolver.Resolve(userCollection, resolvers, true));

                result.SetPublicInstancePropertyValue("ClearExistingItems", clearItems);
            }

            return(result);
        }
예제 #2
0
        public object Resolve(object source, Dictionary <string, IResolver> resolvers = null, bool recursive = false)
        {
            Object  result      = null;
            Boolean anySecurity = false;
            var     security    = source.GetPublicInstancePropertyValue("Security") as Model.ObjectSecurity;

            if (security != null)
            {
                var securityTypeName             = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.ObjectSecurity, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                var securityType                 = Type.GetType(securityTypeName, true);
                var breakRoleInheritanceTypeName = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.ObjectSecurityBreakRoleInheritance, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                var breakRoleInheritanceType     = Type.GetType(breakRoleInheritanceTypeName, true);
                var roleAssignmentTypeName       = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.RoleAssignment, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                var roleAssignmentType           = Type.GetType(roleAssignmentTypeName, true);


                result = Activator.CreateInstance(securityType);
                var breakRoleInheritance = Activator.CreateInstance(breakRoleInheritanceType);

                breakRoleInheritance.SetPublicInstancePropertyValue("CopyRoleAssignments", security.CopyRoleAssignments);
                breakRoleInheritance.SetPublicInstancePropertyValue("ClearSubscopes", security.ClearSubscopes);

                var resolver         = new CollectionFromModelToSchemaTypeResolver(roleAssignmentType);
                var roleAssignements = resolver.Resolve(security.RoleAssignments, null, true);
                breakRoleInheritance.SetPublicInstancePropertyValue("RoleAssignment", roleAssignements);

                anySecurity = (security.ClearSubscopes || security.CopyRoleAssignments ||
                               security.RoleAssignments != null && security.RoleAssignments.Count > 0);

                result.SetPublicInstancePropertyValue("BreakRoleInheritance", breakRoleInheritance);
            }

            return(anySecurity ? result : null);
        }
        public object Resolve(object source, Dictionary <String, IResolver> resolvers = null, Boolean recursive = false)
        {
            Object result = null;

            // Try with the tenant-wide AppCatalog
            var aad   = source as Model.AzureActiveDirectory.ProvisioningAzureActiveDirectory;
            var users = aad?.Users;

            if (null != users)
            {
                var aadUsersTypeName = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.AADUsersUser, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                var aadUsersType     = Type.GetType(aadUsersTypeName, true);

                var resolver = new CollectionFromModelToSchemaTypeResolver(aadUsersType);
                result = resolver.Resolve(users, resolvers, true);
            }

            return(result);
        }
        public object Resolve(object source, Dictionary <string, IResolver> resolvers = null, bool recursive = false)
        {
            Object result = null;

            var security = (source as Team)?.Security;

            if (null != security)
            {
                var teamSecurityTypeName      = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.TeamSecurity, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                var teamSecurityType          = Type.GetType(teamSecurityTypeName, true);
                var teamSecurityUsersTypeName = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.TeamSecurityUsers, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                var teamSecurityUsersType     = Type.GetType(teamSecurityUsersTypeName, true);
                var teamSecurityUserTypeName  = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.TeamSecurityUsersUser, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                var teamSecurityUserType      = Type.GetType(teamSecurityUserTypeName, true);

                result = Activator.CreateInstance(teamSecurityType);

                if (security.Owners != null && security.Owners.Count > 0)
                {
                    var owners = Activator.CreateInstance(teamSecurityUsersType);
                    owners.SetPublicInstancePropertyValue("ClearExistingItems", security.ClearExistingOwners);

                    var usersResolver = new CollectionFromModelToSchemaTypeResolver(teamSecurityUserType);
                    owners.SetPublicInstancePropertyValue("User", usersResolver.Resolve(security.Owners));

                    result.SetPublicInstancePropertyValue("Owners", owners);
                }

                if (security.Members != null && security.Members.Count > 0)
                {
                    var members = Activator.CreateInstance(teamSecurityUsersType);
                    members.SetPublicInstancePropertyValue("ClearExistingItems", security.ClearExistingOwners);

                    var usersResolver = new CollectionFromModelToSchemaTypeResolver(teamSecurityUserType);
                    members.SetPublicInstancePropertyValue("User", usersResolver.Resolve(security.Members));

                    result.SetPublicInstancePropertyValue("Members", members);
                }
            }

            return(result);
        }