コード例 #1
0
ファイル: securitymanager.cs プロジェクト: ArildF/masters
        static public PolicyLevel LoadPolicyLevelFromFile( String path, PolicyLevelType type )
        {
			 if (path == null)
               throw new ArgumentNullException( "path" );

            ConfigId id = SharedStatics.GetNextConfigId();

            ConfigRetval retval = Config.InitData( id, path );

            if ((retval & ConfigRetval.ConfigFile) == 0)
                throw new ArgumentException( Environment.GetResourceString( "Argument_PolicyFileDoesNotExist" ) );

            String name = Enum.GetName( typeof( PolicyLevelType ), type );

            if (name == null)
                return null;

            String fullPath = Path.GetFullPath( path );

            FileIOPermission perm = new FileIOPermission( PermissionState.None );
            perm.AddPathList( FileIOPermissionAccess.Read, fullPath );
            perm.AddPathList( FileIOPermissionAccess.Write, fullPath );
            perm.Demand();

            PolicyLevel level = new PolicyLevel( name, id, type == PolicyLevelType.Machine );
            level.ThrowOnLoadError = true;
            level.CheckLoaded( false );
            return level;
        }