• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Permissions.FileIOPermission类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Main

        static void Main()
        {
            FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.Write, AppConst.BASE_PATH);
            if (!SecurityManager.IsGranted(writePermission))
            {
                MessageBox.Show("Please run this software by administrator permission");
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            string email = Utility.ReadAppRegistry("settv", "ru_email");
            string key = Utility.ReadAppRegistry("settv", "ru_key");
            if (Register.RegisterUser(email, key) == false)
            {

                DialogResult trial_running = MessageBox.Show("Do you want to run trial?", "Saterllite TV Trial", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (trial_running == DialogResult.Yes)
                    Application.Run(new MainApp());
                else
                    Application.Run(new RegisterForm());
            }
            else
                Application.Run(new MainApp());
        }
开发者ID:nghoang,项目名称:settv,代码行数:25,代码来源:Program.cs


示例2: Parse

        public IPermission Parse(JToken token)
        {
            var accessList = token as JArray;

            if (accessList == null)
            {
                return null;
            }

            var result = new FileIOPermission(PermissionState.None);

            foreach (var item in accessList)
            {
                var obj = item as JObject;
                if (obj == null)
                {
                    continue;
                }

                var access = obj["access"].ToObject<string[]>();
                var paths = obj["paths"].ToObject<string[]>();

                var fileAccess = FileIOPermissionAccess.NoAccess;
                if (access.Contains("read")) fileAccess |= FileIOPermissionAccess.Read;
                if (access.Contains("write")) fileAccess |= FileIOPermissionAccess.Write;
                if (access.Contains("discover")) fileAccess |= FileIOPermissionAccess.PathDiscovery;
                if (access.Contains("append")) fileAccess |= FileIOPermissionAccess.Append;

                result.AddPathList(fileAccess, paths);
            }

            return result;
        }
开发者ID:renini,项目名称:hadouken,代码行数:33,代码来源:FileIoPermissionItemParser.cs


示例3: FileExists

        private static string _strRootFolder;  //定义操作的根目录

        /// <summary>
        /// 文件是否存在
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <returns></returns>
        public static bool FileExists(string filePath)
        {
            if (File.Exists(filePath))
            {
                return true;
            }

            FileIOPermission permission = null;
            try
            {
                permission = new FileIOPermission(FileIOPermissionAccess.Read, filePath);
            }
            catch
            {
                return false;
            }
            try
            {
                permission.Demand();

            }
            catch (Exception exception)
            {
                // Foe.Common.Log.ErrorFormat(string.Format("FileManager doesn't have the right to read the config file \"{0}\". Cause : {1}", filePath, exception.Message), exception);
            }
            return false;
        }
开发者ID:NameIsBad,项目名称:wuliao,代码行数:34,代码来源:FileManager.cs


示例4: Init

    /// <summary>
    ///   Initializes the permissions manager with the permissions required by an install script.
    /// </summary>
    internal static void Init()
    {
      permissions = new PermissionSet(PermissionState.None);
      //do the following paths need to add to this?
      // savesPath - fallout 3
      var fipFilePermission = new FileIOPermission(FileIOPermissionAccess.AllAccess, new[]
      {
        Program.tmpPath,
        Path.GetTempPath(),
        Program.GameMode.InstallInfoDirectory,
        Program.GameMode.PluginsPath
      });

      var lstPaths = new List<string>(Program.GameMode.SettingsFiles.Values);
      lstPaths.AddRange(Program.GameMode.AdditionalPaths.Values);
      fipFilePermission.AddPathList(FileIOPermissionAccess.AllAccess, lstPaths.ToArray());
      fipFilePermission.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory);

      permissions.AddPermission(fipFilePermission);
      permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
      permissions.AddPermission(new UIPermission(UIPermissionWindow.AllWindows));

      // Not sure what permissions are needed for GetTempFileName() to work, so we add them all.
      permissions.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
    }
开发者ID:IntegralLee,项目名称:fomm,代码行数:28,代码来源:PermissionsManager.cs


示例5: CanWriteToFolder

 private static bool CanWriteToFolder(string folder)
 {
     var permission = new FileIOPermission(FileIOPermissionAccess.Write, folder);
     var permissionSet = new PermissionSet(PermissionState.None);
     permissionSet.AddPermission(permission);
     return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
 }
开发者ID:Acruid,项目名称:NovalogicTools,代码行数:7,代码来源:Program.cs


示例6: ScanImage

         public Image ScanImage(ImageFormat outputFormat, string fileName)
         {
              if (outputFormat == null)
                   throw new ArgumentNullException("outputFormat");

              FileIOPermission filePerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, fileName);
              filePerm.Demand();

              ImageFile imageObject = null;

              try
              {
                   if (WiaManager == null)
                        WiaManager = new CommonDialogClass();

                   imageObject =
                        WiaManager.ShowAcquireImage(WiaDeviceType.ScannerDeviceType,
                             WiaImageIntent.GrayscaleIntent, WiaImageBias.MaximizeQuality, 
                             outputFormat.Guid.ToString("B"), false, true, true);

                   imageObject.SaveFile(fileName);
                   return Image.FromFile(fileName);
              }
              catch (COMException ex)
              {
                   string message = "Error scanning image";
                   throw new WiaOperationException(message, ex);
              }
              finally
              {
                   if (imageObject != null)
                        Marshal.ReleaseComObject(imageObject);
              }
         }
开发者ID:nguyenq,项目名称:VietOCR3.NET,代码行数:34,代码来源:WiaScannerAdapter.cs


示例7: CreateAnalyzerDomain

        private AppDomain CreateAnalyzerDomain()
        {
            AppDomainSetup ads = new AppDomainSetup();
            AppDomain result;
            PermissionSet perms;
            ads.ApplicationBase = Environment.CurrentDirectory;
            ads.ShadowCopyDirectories = "shadow";
            ads.ShadowCopyFiles = "shadow";
            ads.DisallowCodeDownload = true;

            perms = new PermissionSet(PermissionState.None);
            FileIOPermission fiop = new FileIOPermission(PermissionState.Unrestricted);
            perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.AllFlags));
            fiop.AddPathList(FileIOPermissionAccess.PathDiscovery, Environment.CurrentDirectory);
            fiop.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory);
            fiop.AddPathList(FileIOPermissionAccess.PathDiscovery, Environment.CurrentDirectory + "Extensions\\");
            fiop.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory + "Extensions\\");
            //fiop.AllLocalFiles = FileIOPermissionAccess.AllAccess
            //fiop.AllFiles = FileIOPermissionAccess.AllAccess
            perms.AddPermission(fiop);
            perms.AddPermission(new UIPermission(UIPermissionWindow.AllWindows, UIPermissionClipboard.OwnClipboard));
            perms.AddPermission(new ReflectionPermission(PermissionState.Unrestricted));

            PolicyLevel policy = PolicyLevel.CreateAppDomainLevel();
            policy.RootCodeGroup.PolicyStatement = new PolicyStatement(perms);

            // create the Domain
            result = AppDomain.CreateDomain("analyzer", null, ads);
            result.SetAppDomainPolicy(policy);
            return result;
        }
开发者ID:hapm,项目名称:IrcShark,代码行数:32,代码来源:ExtensionAnalyzer.cs


示例8: Main

 static void Main(string[] args)
 {
     CodeAccessPermission permission = new FileIOPermission(FileIOPermissionAccess.AllAccess,@"c:\");
      permission.Deny();
      UntrustworthyClass.Method();
      CodeAccessPermission.RevertDeny();
 }
开发者ID:alannet,项目名称:example,代码行数:7,代码来源:Class1.cs


示例9: InThread

        private void InThread(ControllerContext context, Action<ControllerContext> functor)
        {
            var timeout = int.Parse(ConfigurationManager.AppSettings["SandboxTimeout"] ?? "5");
            var thread = new Thread(()=>
            {
                try
                {
                    var fileIo = new FileIOPermission(FileIOPermissionAccess.Read,AppDomain.CurrentDomain.BaseDirectory);
                    fileIo.AllLocalFiles = FileIOPermissionAccess.NoAccess;
                    fileIo.PermitOnly();

                    functor(context);
                }
                catch(Exception e)
                {
                    // 全部書きだす
                    context.HttpContext.Response.Write(e.Message);
                }
            });
            thread.Start();
            thread.Join(timeout*1000);
            if(thread.IsAlive)
            {
                thread.Abort();
                throw new HttpException((int)HttpStatusCode.InternalServerError, "処理が長すぎ(" + timeout + "秒で終わらせてね)");
            }
        }
开发者ID:takepara,项目名称:RazorDoIt,代码行数:27,代码来源:WebPageController.cs


示例10: CopyFile

        public static bool CopyFile(string newFile, string oldFile)
        {
            var newfile = new FileInfo(newFile);
            var oldfile = new FileInfo(oldFile);
            string errorMsg = "";
            var f2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, oldFile);
            f2.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, newFile);

            try
            {
                f2.Demand();
            }
            catch (SecurityException s)
            {
                Console.WriteLine(s.Message);
            }

               for (int x = 0; x < 100; x++)
               {
                    try
                    {
                       File.Delete(oldfile.FullName);
                       newfile.CopyTo(oldfile.FullName, true);
                       return true;
                    }
                    catch(Exception e)
                    {
                        errorMsg = e.Message + " :   " + e.InnerException;
                        Thread.Sleep(200);
                    }
               }
            Data.Logger(errorMsg);
               return false;
        }
开发者ID:cengonurozkan,项目名称:vFenseAgent-win,代码行数:34,代码来源:Tools.cs


示例11: FlatFileListenerWillFallbackIfNotPriviledgesToWrite

        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;
            }
        }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:28,代码来源:FlatFileTraceListenerFixture.2008.cs


示例12: Initialize

        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            base.Initialize(name, config);

            if (string.IsNullOrEmpty(config["dataStorePath"]))
                throw new ProviderException("dataStorePath config attribute is required.");

            this._dataStorePath = config["dataStorePath"];

            if (!VirtualPathUtility.IsAppRelative(this._dataStorePath))
                throw new ArgumentException("dataStorePath must be app-relative");

            string fullyQualifiedPath = VirtualPathUtility.Combine(
                VirtualPathUtility.AppendTrailingSlash(HttpRuntime.AppDomainAppVirtualPath),
                this._dataStorePath);

            this._dataStorePath = HostingEnvironment.MapPath(fullyQualifiedPath);

            config.Remove("dataStorePath");

            // Make sure we have permission to read the XML data source and
            // throw an exception if we don't
            if (!Directory.Exists(this._dataStorePath))
                Directory.CreateDirectory(this._dataStorePath);

            FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.AllAccess, this._dataStorePath);
            permission.Demand();

            if (config.Count > 0)
                throw new ProviderException(string.Format("Unknown config attribute '{0}'", config.GetKey(0)));
        }
开发者ID:kohku,项目名称:codefactory,代码行数:31,代码来源:XmlUploadStorageProvider.cs


示例13: FileExists

 // Methods
 public static bool FileExists(string filePath)
 {
     if (File.Exists(filePath))
     {
         return true;
     }
     FileIOPermission permission = null;
     try
     {
         permission = new FileIOPermission(FileIOPermissionAccess.AllAccess, filePath);
     }
     catch
     {
         return false;
     }
     try
     {
         permission.Demand();
     }
     catch (Exception exception)
     {
         //
     }
     return false;
 }
开发者ID:abdojobs,项目名称:enterprise-architect-2-openerp,代码行数:26,代码来源:XmlUtility.cs


示例14: Capture

        public void Capture( OnlineCaptureInfo info )
        {
            try
            {
                // Ensure permission to write to the archive directory.
                FileIOPermission p = new FileIOPermission( FileIOPermissionAccess.Write,
                    new FileInfo( info.ArchiveDir ).FullName );
                p.Demand();

                logger = info.Logger;

                string html = CaptureText( info.AccountName, info.Credentials );

                // Write HTML results to file

                string filename = Path.Combine( info.ArchiveDir, info.BaseName + ".htm" );
                info.CapturedFiles.Add( Path.GetFileName( filename ) );

                File.WriteAllText( filename, html );
            }
            catch( SecurityException ex )
            {
                throw new OnlineReaderException( "Security violation: " + ex.Message, ex );
            }
        }
开发者ID:tkrehbiel,项目名称:UvMoney,代码行数:25,代码来源:OnlineLegacyReader.cs


示例15: CreatePermission

 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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:FileIOPermissionAttribute.cs


示例16: Setup

 public virtual void Setup()
 {
     var sp = new FileIOPermission(PermissionState.Unrestricted);
     sp.Assert();
     string prefix;
     if (Environment.CurrentDirectory.EndsWith("target"))
     {
         prefix = "../../";
     }
     else
     {
         prefix = "../../../";
     }
     sp.Deny();
     Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
     BridgeSetup setup=new BridgeSetup (false){Verbose = true, Debug = true};
     setup.IgnoreJavaHome = true;
     setup.AddJVMOption("-Xmx512m");
     setup.AddClassPath(prefix + "jni4net.j/target/classes");
     setup.AddClassPath(prefix + "jni4net.tested.j/target/classes");
     setup.AddClassPath(prefix + "jni4net.test.j/target/test-classes");
     //setup.JavaHome = @"c:\Program Files (x86)\Java\ibm_sdk60";
     env = Bridge.CreateJVM(setup);
     Bridge.RegisterAssembly(typeof(TestBase).Assembly);
     Bridge.RegisterAssembly(typeof(JavaInstanceFields).Assembly);
 }
开发者ID:Mazrick,项目名称:jni4net,代码行数:26,代码来源:TestBase.cs


示例17: CreateStackWalk

 protected override IStackWalk CreateStackWalk()
 {
     FileIOPermission permission = new FileIOPermission(PermissionState.Unrestricted);
     permission.AllFiles = attribute.AllFiles;
     permission.AllLocalFiles = attribute.AllLocalFiles;
     return permission;
 }
开发者ID:BackupTheBerlios,项目名称:mbunit-svn,代码行数:7,代码来源:DenyFileIOAttribute.cs


示例18: NeedsAdministratorRights

        public static bool NeedsAdministratorRights()
        {
            var permissionSet = new PermissionSet(PermissionState.None);
            var writePermission = new FileIOPermission(FileIOPermissionAccess.Write, HostsFileManager.Filename);
            permissionSet.AddPermission(writePermission);

            return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
        }
开发者ID:roydejong,项目名称:HostsManager,代码行数:8,代码来源:WindowsSecurity.cs


示例19: EnsureActivateContextCreated

        private static bool EnsureActivateContextCreated()
        {
            lock (typeof(EnableThemingInScope))
            {
                if (!contextCreationSucceeded)
                {
                    // Pull manifest from the .NET Framework install
                    // directory

                    string assemblyLoc = null;

                    FileIOPermission fiop = new FileIOPermission(PermissionState.None);
                    fiop.AllFiles = FileIOPermissionAccess.PathDiscovery;
                    fiop.Assert();
                    try
                    {
                        assemblyLoc = typeof(Object).Assembly.Location;
                    }
                    finally
                    {
                        CodeAccessPermission.RevertAssert();
                    }

                    string manifestLoc = null;
                    string installDir = null;
                    if (assemblyLoc != null)
                    {
                        installDir = Path.GetDirectoryName(assemblyLoc);
                        const string manifestName = "XPThemes.manifest";
                        manifestLoc = Path.Combine(installDir, manifestName);
                    }

                    if (manifestLoc != null && installDir != null)
                    {
                        enableThemingActivationContext = new ACTCTX();
                        enableThemingActivationContext.cbSize = Marshal.SizeOf(typeof(ACTCTX));
                        enableThemingActivationContext.lpSource = manifestLoc;

                        // Set the lpAssemblyDirectory to the install
                        // directory to prevent Win32 Side by Side from
                        // looking for comctl32 in the application
                        // directory, which could cause a bogus dll to be
                        // placed there and open a security hole.
                        enableThemingActivationContext.lpAssemblyDirectory = installDir;
                        enableThemingActivationContext.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;

                        // Note this will fail gracefully if file specified
                        // by manifestLoc doesn't exist.
                        hActCtx = CreateActCtx(ref enableThemingActivationContext);
                        contextCreationSucceeded = (hActCtx != new IntPtr(-1));
                    }
                }

                // If we return false, we'll try again on the next call into
                // EnsureActivateContextCreated(), which is fine.
                return contextCreationSucceeded;
            }
        }
开发者ID:FrankeCoffee,项目名称:Windows7APICodePack,代码行数:58,代码来源:EnableThemingInScope.cs


示例20: canRead

 private static bool canRead(String path)
 {
     FileIOPermission readPermission = new FileIOPermission(FileIOPermissionAccess.Read, path);
     if (SecurityManager.IsGranted(readPermission))
     {
         return true;
     }
     return false;
 }
开发者ID:rlong,项目名称:dotnet.lib.HttpLibrary,代码行数:9,代码来源:ConfigurationService.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Permissions.IsolatedStorageFilePermission类代码示例发布时间:2022-05-26
下一篇:
C# Permissions.EnvironmentPermission类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap