本文整理汇总了C#中System.Security.Permissions.FileIOPermission类的典型用法代码示例。如果您正苦于以下问题:C# FileIOPermission类的具体用法?C# FileIOPermission怎么用?C# FileIOPermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileIOPermission类属于System.Security.Permissions命名空间,在下文中一共展示了FileIOPermission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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;
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
}
示例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;
}
示例8: Main
static void Main(string[] args)
{
CodeAccessPermission permission = new FileIOPermission(FileIOPermissionAccess.AllAccess,@"c:\");
permission.Deny();
UntrustworthyClass.Method();
CodeAccessPermission.RevertDeny();
}
示例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 + "秒で終わらせてね)");
}
}
示例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;
}
示例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;
}
}
示例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)));
}
示例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;
}
示例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 );
}
}
示例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;
}