当前位置: 首页>>代码示例>>C#>>正文


C# FileIOPermissionAccess类代码示例

本文整理汇总了C#中FileIOPermissionAccess的典型用法代码示例。如果您正苦于以下问题:C# FileIOPermissionAccess类的具体用法?C# FileIOPermissionAccess怎么用?C# FileIOPermissionAccess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileIOPermissionAccess类属于命名空间,在下文中一共展示了FileIOPermissionAccess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckFileAccess

        /// <summary>
        /// Checks access to file
        /// </summary>
        /// <param name="filePath">Path to file for check</param>
        /// <param name="permissionAccess">Permission to check</param>
        private static void CheckFileAccess(string filePath, FileIOPermissionAccess permissionAccess)
        {
            if (!Path.IsPathRooted(filePath))
            {
                var currentExecutablePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                if (string.IsNullOrWhiteSpace(currentExecutablePath))
                {
                    throw new ConfigurationException("Failed to determine current executable path");
                }

                filePath = Path.Combine(currentExecutablePath, filePath);
            }

            var configDirectory = Path.GetDirectoryName(filePath);
            if (string.IsNullOrWhiteSpace(configDirectory))
            {
                throw new ConfigurationException("ClusterKit.Web.Nginx.PathToConfig has no defined directory");
            }

            if (!Directory.Exists(configDirectory))
            {
                throw new ConfigurationException($"{configDirectory} does not exists");
            }

            var path = File.Exists(filePath) ? filePath : configDirectory;
            var permission = new FileIOPermission(permissionAccess, path);
            if (!permission.IsGranted())
            {
                throw new ConfigurationException($"Cannot access {path} for writing");
            }
        }
开发者ID:kantora,项目名称:ClusterKit,代码行数:36,代码来源:Installer.cs

示例2: LogStream

 internal LogStream(string path, int bufferSize, LogRetentionOption retention, long maxFileSize, int maxNumOfFiles)
 {
     string fullPath = Path.GetFullPath(path);
     this._fileName = fullPath;
     if (fullPath.StartsWith(@"\\.\", StringComparison.Ordinal))
     {
         throw new NotSupportedException(System.SR.GetString("NotSupported_IONonFileDevices"));
     }
     Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(FileShare.Read);
     int num = 0x100000;
     this._canWrite = true;
     this._pathSav = fullPath;
     this._fAccessSav = 0x40000000;
     this._shareSav = FileShare.Read;
     this._secAttrsSav = secAttrs;
     this._secAccessSav = FileIOPermissionAccess.Write;
     this._modeSav = (retention != LogRetentionOption.SingleFileUnboundedSize) ? FileMode.Create : FileMode.OpenOrCreate;
     this._flagsAndAttributesSav = num;
     this._seekToEndSav = retention == LogRetentionOption.SingleFileUnboundedSize;
     base.bufferSize = bufferSize;
     this._retention = retention;
     this._maxFileSize = maxFileSize;
     this._maxNumberOfFiles = maxNumOfFiles;
     this._Init(fullPath, this._fAccessSav, this._shareSav, this._secAttrsSav, this._secAccessSav, this._modeSav, this._flagsAndAttributesSav, this._seekToEndSav);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:LogStream.cs

示例3: FileIOPermission

	public FileIOPermission(FileIOPermissionAccess flag, String pathList)
			{
				if(pathList == null)
				{
					throw new ArgumentNullException("pathList");
				}
				if((flag & ~(FileIOPermissionAccess.AllAccess)) != 0)
				{
					throw new ArgumentException(_("Arg_FileIOAccess"));
				}
				this.state = PermissionState.None;
				String[] split = EnvironmentPermission.SplitPath(pathList);
				if((flag & FileIOPermissionAccess.Read) != 0)
				{
					readList = split;
				}
				if((flag & FileIOPermissionAccess.Write) != 0)
				{
					writeList = split;
				}
				if((flag & FileIOPermissionAccess.Append) != 0)
				{
					appendList = split;
				}
				if((flag & FileIOPermissionAccess.PathDiscovery) != 0)
				{
					discoveryList = split;
				}
				allLocalFiles = FileIOPermissionAccess.NoAccess;
				allFiles = FileIOPermissionAccess.NoAccess;
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:31,代码来源:FileIOPermission.cs

示例4: Accessible

		/// <summary>
		/// Ensure chosen filepath is not protected before operating
		/// </summary>
		/// <param name="Path">The location to check access to</param>
		/// <param name="ShowDialog">Whether to show an error message</param>
		/// <param name="Permissions">What type of permissions to check for</param>
		/// <returns></returns>
		public static PathType Accessible(
			string Path
			, bool ShowDialog = true
			, FileIOPermissionAccess Permissions = FileIOPermissionAccess.Read | FileIOPermissionAccess.Write)
		{
			PathType pathType = PathType.Invalid;

			try {
				if (!string.IsNullOrWhiteSpace(Path)) {
					if (Directory.Exists(Path)) {
						foreach (string dir in Directory.EnumerateDirectories(Path, "*", SearchOption.TopDirectoryOnly)) {
							(new FileIOPermission(Permissions, dir)).Demand();
						}
						pathType = PathType.ValidDirectory;
					}
					else if (File.Exists(Path)) {
						(new FileIOPermission(Permissions, Path)).Demand();
						pathType = PathType.ValidFile;
					}
				}
			} catch (Exception exc) {
				SQL.LogMessage(exc, SQL.EventType.HandledException, Path);
			}

			if (pathType == PathType.Invalid && ShowDialog) {
				xMessage.ShowError("The indicated HDD location could not be opened. Either it doesn't exist or you don't have permission.\n" + Path);
			}

			return pathType;
		}
开发者ID:emmauss,项目名称:Manga-Organizer,代码行数:37,代码来源:ExtFunctions.cs

示例5: FileIOPermission

        [System.Security.SecuritySafeCritical]  // auto-generated
        public FileIOPermission(FileIOPermissionAccess access, String path)
        {
            VerifyAccess(access);

            String[] pathList = new String[] { path };
            AddPathList(access, pathList, false, true, false);
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:8,代码来源:fileiopermission.cs

示例6: FileIOPermission

		public FileIOPermission (FileIOPermissionAccess access, string[] pathList)
		{
			if (pathList == null)
				throw new ArgumentNullException ("pathList");

			CreateLists ();
			// access and path will be validated in AddPathList
			AddPathList (access, pathList);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:9,代码来源:FileIOPermission.cs

示例7: SetPathList

 public void SetPathList( FileIOPermissionAccess access, String path )
 {
     String[] pathList;
     if(path == null)
         pathList = new String[] {};
     else
         pathList = new String[] { path };
     SetPathList( access, pathList, false );
 }
开发者ID:kouvel,项目名称:coreclr,代码行数:9,代码来源:FileIOPermission.cs

示例8: FileIOPermission

		public FileIOPermission (PermissionState state)
		{
			if (CheckPermissionState (state, true) == PermissionState.Unrestricted) {
				m_Unrestricted = true;
				m_AllFilesAccess = FileIOPermissionAccess.AllAccess;
				m_AllLocalFilesAccess = FileIOPermissionAccess.AllAccess;
			}
			CreateLists ();
		}
开发者ID:runefs,项目名称:Marvin,代码行数:9,代码来源:FileIOPermission.cs

示例9: VerifyVermission

        public static bool VerifyVermission(FileIOPermissionAccess permission, string path)
        {
            var ioPermission = new FileIOPermission(permission, path);

            try
            {
                ioPermission.Demand();
                return true;
            }
            catch (SecurityException s)
            {
                return false;
            }
        }
开发者ID:RodrigoDotNet,项目名称:gerador-de-camadas,代码行数:14,代码来源:IoHelper.cs

示例10: _Init

 internal void _Init(string path, int fAccess, FileShare share, Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs, FileIOPermissionAccess secAccess, FileMode mode, int flagsAndAttributes, bool seekToEnd)
 {
     string fullPath = Path.GetFullPath(path);
     this._fileName = fullPath;
     new FileIOPermission(secAccess, new string[] { fullPath }).Demand();
     int newMode = Microsoft.Win32.UnsafeNativeMethods.SetErrorMode(1);
     try
     {
         this._handle = Microsoft.Win32.UnsafeNativeMethods.SafeCreateFile(fullPath, fAccess, share, secAttrs, mode, flagsAndAttributes, Microsoft.Win32.UnsafeNativeMethods.NULL);
         int errorCode = Marshal.GetLastWin32Error();
         if (this._handle.IsInvalid)
         {
             bool flag = false;
             try
             {
                 new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new string[] { this._fileName }).Demand();
                 flag = true;
             }
             catch (SecurityException)
             {
             }
             if (flag)
             {
                 System.IO.__Error.WinIOError(errorCode, this._fileName);
             }
             else
             {
                 System.IO.__Error.WinIOError(errorCode, Path.GetFileName(this._fileName));
             }
         }
     }
     finally
     {
         Microsoft.Win32.UnsafeNativeMethods.SetErrorMode(newMode);
     }
     base.pos = 0L;
     if (seekToEnd)
     {
         this.SeekCore(0L, SeekOrigin.End);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:41,代码来源:LogStream.cs

示例11: AccessIsSet

 private static bool AccessIsSet(FileIOPermissionAccess access, FileIOPermissionAccess question)
 {
     return (access & question) != 0;
 }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:4,代码来源:fileiopermission.cs

示例12: ExclusiveAccess

        private static void ExclusiveAccess(FileIOPermissionAccess access)
        {
            if (access == FileIOPermissionAccess.NoAccess)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_EnumNotSingleFlag"));
            }

            if (((int)access & ((int)access - 1)) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_EnumNotSingleFlag"));
            }
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:12,代码来源:fileiopermission.cs

示例13: VerifyAccess

 private static void VerifyAccess(FileIOPermissionAccess access)
 {
     if ((access & ~FileIOPermissionAccess.AllAccess) != 0)
         throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access));
 }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:5,代码来源:fileiopermission.cs

示例14: GetPathList

        public String[] GetPathList(FileIOPermissionAccess access)
        {
            VerifyAccess(access);
            ExclusiveAccess(access);

            if (AccessIsSet(access, FileIOPermissionAccess.Read))
            {
                if (m_read == null)
                {
                    return null;
                }
                return m_read.ToStringArray();
            }

            if (AccessIsSet(access, FileIOPermissionAccess.Write))
            {
                if (m_write == null)
                {
                    return null;
                }
                return m_write.ToStringArray();
            }

            if (AccessIsSet(access, FileIOPermissionAccess.Append))
            {
                if (m_append == null)
                {
                    return null;
                }
                return m_append.ToStringArray();
            }

            if (AccessIsSet(access, FileIOPermissionAccess.PathDiscovery))
            {
                if (m_pathDiscovery == null)
                {
                    return null;
                }
                return m_pathDiscovery.ToStringArray();
            }

            // not reached

            return null;
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:45,代码来源:fileiopermission.cs

示例15: AddPathList

        [System.Security.SecurityCritical]  // auto-generated
        internal void AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList)
        {
            if (pathListOrig == null)
            {
                throw new ArgumentNullException("pathList");
            }
            if (pathListOrig.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
            }
            Contract.EndContractBlock();
            // @

            VerifyAccess(access);

            if (m_unrestricted)
                return;

            String[] pathList = pathListOrig;
            if (copyPathList)
            {
                // Make a copy of pathList (in case its value changes after we check for illegal chars)
                pathList = new String[pathListOrig.Length];
                Array.Copy(pathListOrig, pathList, pathListOrig.Length);
            }

            // If we need the full path the standard illegal characters will be checked in StringExpressionSet.
            CheckIllegalCharacters(pathList, onlyCheckExtras: needFullPath);

            // StringExpressionSet will do minor normalization, trimming spaces and replacing alternate
            // directory separators. It will make an attemt to expand short file names and will check
            // for standard colon placement.
            //
            // If needFullPath is true it will call NormalizePath- which performs short name expansion
            // and does the normal validity checks.
            ArrayList pathArrayList = StringExpressionSet.CreateListFromExpressions(pathList, needFullPath);

            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                if (m_read == null)
                {
                    m_read = new FileIOAccess();
                }
                m_read.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                if (m_write == null)
                {
                    m_write = new FileIOAccess();
                }
                m_write.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                if (m_append == null)
                {
                    m_append = new FileIOAccess();
                }
                m_append.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                if (m_pathDiscovery == null)
                {
                    m_pathDiscovery = new FileIOAccess(true);
                }
                m_pathDiscovery.AddExpressions(pathArrayList, checkForDuplicates);
            }

#if FEATURE_MACL
            if ((control & AccessControlActions.View) != 0)
            {
                if (m_viewAcl == null)
                {
                    m_viewAcl = new FileIOAccess();
                }
                m_viewAcl.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((control & AccessControlActions.Change) != 0)
            {
                if (m_changeAcl == null)
                {
                    m_changeAcl = new FileIOAccess();
                }
                m_changeAcl.AddExpressions(pathArrayList, checkForDuplicates);
            }
#endif
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:94,代码来源:fileiopermission.cs


注:本文中的FileIOPermissionAccess类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。