SetPathList() public method

public SetPathList ( FileIOPermissionAccess access, string path ) : void
access FileIOPermissionAccess
path string
return void
 /// <include file='doc\PermissionAttributes.uex' path='docs/doc[@for="FileIOPermissionAttribute.CreatePermission"]/*' />
 public override IPermission CreatePermission()
 {
     if (m_unrestricted)
     {
         return(new FileIOPermission(PermissionState.Unrestricted));
     }
     else
     {
         FileIOPermission perm = new FileIOPermission(PermissionState.None);
         if (m_read != null)
         {
             perm.SetPathList(FileIOPermissionAccess.Read, m_read);
         }
         if (m_write != null)
         {
             perm.SetPathList(FileIOPermissionAccess.Write, m_write);
         }
         if (m_append != null)
         {
             perm.SetPathList(FileIOPermissionAccess.Append, m_append);
         }
         if (m_pathDiscovery != null)
         {
             perm.SetPathList(FileIOPermissionAccess.PathDiscovery, m_pathDiscovery);
         }
         return(perm);
     }
 }
        public void FlatFileListenerWillFallbackIfNotPriviledgesToWrite()
        {
            string fileName = @"trace.log";
            string fullPath = String.Format(@"{0}\{1}", Directory.GetCurrentDirectory(), fileName);

            File.Delete(fileName);

            FileIOPermission fileIOPerm1 = new FileIOPermission(PermissionState.None);
            fileIOPerm1.SetPathList(FileIOPermissionAccess.Read, fullPath);
            fileIOPerm1.PermitOnly();

            try
            {
                FlatFileTraceListener listener = new FlatFileTraceListener(fileName, "---header---", "***footer***",
                    new TextFormatter("DUMMY{newline}DUMMY"));

                // need to go through the source to get a TraceEventCache
                LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
                source.TraceData(TraceEventType.Error, 0,
                    new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null));
                listener.Dispose();
            }
            catch (SecurityException)
            {
                FileIOPermission.RevertAll();
                throw;
            }
        }
 public override IPermission CreatePermission()
 {
     if (base.m_unrestricted)
     {
         return new FileIOPermission(PermissionState.Unrestricted);
     }
     FileIOPermission permission = new FileIOPermission(PermissionState.None);
     if (this.m_read != null)
     {
         permission.SetPathList(FileIOPermissionAccess.Read, this.m_read);
     }
     if (this.m_write != null)
     {
         permission.SetPathList(FileIOPermissionAccess.Write, this.m_write);
     }
     if (this.m_append != null)
     {
         permission.SetPathList(FileIOPermissionAccess.Append, this.m_append);
     }
     if (this.m_pathDiscovery != null)
     {
         permission.SetPathList(FileIOPermissionAccess.PathDiscovery, this.m_pathDiscovery);
     }
     if (this.m_viewAccess != null)
     {
         permission.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.View, new string[] { this.m_viewAccess }, false);
     }
     if (this.m_changeAccess != null)
     {
         permission.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.Change, new string[] { this.m_changeAccess }, false);
     }
     permission.AllFiles = this.m_allFiles;
     permission.AllLocalFiles = this.m_allLocalFiles;
     return permission;
 }
Esempio n. 4
0
        /// <summary>创建并返回一个新的 <see cref="T:System.Security.Permissions.FileIOPermission" />。</summary>
        /// <returns>与此特性对应的 <see cref="T:System.Security.Permissions.FileIOPermission" />。</returns>
        /// <exception cref="T:System.ArgumentException">要保护访问安全的文件或目录的路径信息包含无效的字符或通配说明符。</exception>
        public override IPermission CreatePermission()
        {
            if (this.m_unrestricted)
            {
                return((IPermission) new FileIOPermission(PermissionState.Unrestricted));
            }
            FileIOPermission fileIoPermission = new FileIOPermission(PermissionState.None);

            if (this.m_read != null)
            {
                fileIoPermission.SetPathList(FileIOPermissionAccess.Read, this.m_read);
            }
            if (this.m_write != null)
            {
                fileIoPermission.SetPathList(FileIOPermissionAccess.Write, this.m_write);
            }
            if (this.m_append != null)
            {
                fileIoPermission.SetPathList(FileIOPermissionAccess.Append, this.m_append);
            }
            if (this.m_pathDiscovery != null)
            {
                fileIoPermission.SetPathList(FileIOPermissionAccess.PathDiscovery, this.m_pathDiscovery);
            }
            if (this.m_viewAccess != null)
            {
                fileIoPermission.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.View, new string[1]
                {
                    this.m_viewAccess
                }, 0 != 0);
            }
            if (this.m_changeAccess != null)
            {
                fileIoPermission.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.Change, new string[1]
                {
                    this.m_changeAccess
                }, 0 != 0);
            }
            fileIoPermission.AllFiles      = this.m_allFiles;
            fileIoPermission.AllLocalFiles = this.m_allLocalFiles;
            return((IPermission)fileIoPermission);
        }
Esempio n. 5
0
        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return(new FileIOPermission(PermissionState.Unrestricted));
            }
            else
            {
                FileIOPermission perm = new FileIOPermission(PermissionState.None);
                if (m_read != null)
                {
                    perm.SetPathList(FileIOPermissionAccess.Read, m_read);
                }
                if (m_write != null)
                {
                    perm.SetPathList(FileIOPermissionAccess.Write, m_write);
                }
                if (m_append != null)
                {
                    perm.SetPathList(FileIOPermissionAccess.Append, m_append);
                }
                if (m_pathDiscovery != null)
                {
                    perm.SetPathList(FileIOPermissionAccess.PathDiscovery, m_pathDiscovery);
                }
#if FEATURE_MACL
                if (m_viewAccess != null)
                {
                    perm.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.View, new String[] { m_viewAccess }, false);
                }
                if (m_changeAccess != null)
                {
                    perm.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.Change, new String[] { m_changeAccess }, false);
                }
#endif

                perm.AllFiles      = m_allFiles;
                perm.AllLocalFiles = m_allLocalFiles;
                return(perm);
            }
        }
        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new FileIOPermission(PermissionState.Unrestricted);
            }
            else
            {
                FileIOPermission perm = new FileIOPermission(PermissionState.None);
                if (m_read != null)
                    perm.SetPathList( FileIOPermissionAccess.Read, m_read );
                if (m_write != null)
                    perm.SetPathList( FileIOPermissionAccess.Write, m_write );
                if (m_append != null)
                    perm.SetPathList( FileIOPermissionAccess.Append, m_append );
                if (m_pathDiscovery != null)
                    perm.SetPathList( FileIOPermissionAccess.PathDiscovery, m_pathDiscovery );
#if FEATURE_MACL
                if (m_viewAccess != null)
                    perm.SetPathList( FileIOPermissionAccess.NoAccess, AccessControlActions.View, new String[] { m_viewAccess }, false );
                if (m_changeAccess != null)
                    perm.SetPathList( FileIOPermissionAccess.NoAccess, AccessControlActions.Change, new String[] { m_changeAccess }, false );
#endif

                perm.AllFiles = m_allFiles;
                perm.AllLocalFiles = m_allLocalFiles;
                return perm;
            }
        }
Esempio n. 7
0
 /// <include file='doc\PermissionAttributes.uex' path='docs/doc[@for="FileIOPermissionAttribute.CreatePermission"]/*' />
 public override IPermission CreatePermission()
 {
     if (m_unrestricted)
     {
         return new FileIOPermission(PermissionState.Unrestricted);
     }
     else
     {
         FileIOPermission perm = new FileIOPermission(PermissionState.None);
         if (m_read != null)
             perm.SetPathList( FileIOPermissionAccess.Read, m_read );
         if (m_write != null)
             perm.SetPathList( FileIOPermissionAccess.Write, m_write );
         if (m_append != null)
             perm.SetPathList( FileIOPermissionAccess.Append, m_append );
         if (m_pathDiscovery != null)
             perm.SetPathList( FileIOPermissionAccess.PathDiscovery, m_pathDiscovery );
         return perm;
     }
 }