本文整理汇总了C#中System.Security.Permissions.FileIOPermission.Demand方法的典型用法代码示例。如果您正苦于以下问题:C# FileIOPermission.Demand方法的具体用法?C# FileIOPermission.Demand怎么用?C# FileIOPermission.Demand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Permissions.FileIOPermission
的用法示例。
在下文中一共展示了FileIOPermission.Demand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: 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)));
}
示例4: 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;
}
示例5: 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 );
}
}
示例6: 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;
}
示例7: WebTransform
/// <summary>
/// Creates a new WebTransform.
/// </summary>
public WebTransform()
{
//[IsolatedStorageFilePermissionAttribute(SecurityAction.Demand, Unrestricted=true)]
FileIOPermission filePerm = new FileIOPermission(PermissionState.None);
RegistryPermission regPerm = new RegistryPermission(PermissionState.None);
filePerm.Demand();
regPerm.Demand();
}
示例8: ShowFileReadUI
private void ShowFileReadUI()
{
MessageBox.Show("Before calling demand");
FileIOPermission myPerm = new FileIOPermission(FileIOPermissionAccess.Read, "C:\\");
myPerm.Demand();
// All callers must have read permission to C drive.
// Note: Using imperative syntax
// Code to show UI
MessageBox.Show("Showing FileRead UI");
// This is executed only if the demand is successful.
}
示例9: RunSecurityDemands
public static bool RunSecurityDemands()
{
FileIOPermission fPer = new FileIOPermission(PermissionState.None);
fPer.AllLocalFiles = FileIOPermissionAccess.AllAccess;
fPer.AllFiles = FileIOPermissionAccess.AllAccess;
try
{
fPer.Demand();
}
catch (SecurityException s)
{
Common.DebugHelper.WriteLine("File IO Permission Error: {0}", s.Message);
return false;
}
System.Security.Permissions.FileDialogPermission fdPer = new FileDialogPermission(FileDialogPermissionAccess.None);
fdPer.Access = FileDialogPermissionAccess.OpenSave;
try
{
fdPer.Demand();
}
catch (System.Security.SecurityException s)
{
Common.DebugHelper.WriteLine("File Dialog Persmission Error: {0}", s.Message);
return false;
}
System.Security.Permissions.RegistryPermission rPer = new RegistryPermission(PermissionState.None);
rPer.SetPathList(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE");
try
{
fPer.Demand();
}
catch (System.Security.SecurityException s)
{
Common.DebugHelper.WriteLine("Registry Access Permission Error: {0}", s.Message);
return false;
}
return true;
}
示例10: FillRights
/// <summary>
/// Returns a dictionary of right names and the roles associated with them.
/// </summary>
/// <returns></returns>
public override IDictionary<string, IEnumerable<string>> FillRights()
{
var path = string.Format("{0}rights.xml", BlogConfig.StorageLocation);
if (!VirtualPathUtility.IsAppRelative(path))
{
throw new ArgumentException("rights must be app-relative");
}
var fullyQualifiedPath =
VirtualPathUtility.Combine(
VirtualPathUtility.AppendTrailingSlash(HttpRuntime.AppDomainAppVirtualPath), path);
fullyQualifiedPath = HostingEnvironment.MapPath(fullyQualifiedPath);
var rightsDict = new Dictionary<string, IEnumerable<string>>();
if (File.Exists(fullyQualifiedPath))
{
// Make sure we have permission to read the XML data source and
// throw an exception if we don't
var permission = new FileIOPermission(FileIOPermissionAccess.Write, fullyQualifiedPath);
permission.Demand();
var doc = new XmlDocument();
doc.Load(fullyQualifiedPath);
foreach (XmlNode rightNode in doc.GetElementsByTagName("right"))
{
var rightName = rightNode.Attributes["name"].Value;
var roleList = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (XmlNode roleNode in rightNode.ChildNodes)
{
if (roleNode.Name.Equals("role", StringComparison.OrdinalIgnoreCase))
{
var roleName = roleNode.Attributes["name"].Value;
roleName = roleName.Trim();
roleList.Add(roleName);
}
}
rightsDict.Add(rightName, roleList);
}
}
return rightsDict;
}
示例11: ImperativeCAS
private static void ImperativeCAS()
{
FileIOPermission f = new FileIOPermission(PermissionState.None);
f.AllLocalFiles = FileIOPermissionAccess.Read;
try
{
f.Demand();
}
catch (SecurityException e)
{
Console.WriteLine(e.Message);
}
}
示例12: Run
public void Run()
{
var f = new FileIOPermission(PermissionState.None);
f.AllLocalFiles = FileIOPermissionAccess.Read;
try
{
f.Demand();
}
catch (SecurityException s)
{
Console.WriteLine(s.Message);
}
}
示例13: 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;
}
}
示例14: CASImerativeExample
private void CASImerativeExample()
{
Console.WriteLine("Example of Imperative approach");
FileIOPermission f = new FileIOPermission(PermissionState.None);
f.AllLocalFiles = FileIOPermissionAccess.Read;
try
{
f.Demand();
}
catch(SecurityException ex)
{
Console.WriteLine(ex.Message);
}
}
示例15: GetResourceSetEntities
/// <summary>Gets a list of resources for the specified resource set.</summary>
/// <param name="resourceSetName">The name of the resource set to get resources for.</param>
/// <returns>List of resources for the specified resource set. Note that if such resource set was not yet seen by this context
/// it will get created (with empty list).</returns>
public IList GetResourceSetEntities(string resourceSetName)
{
List<object> entities;
if (resourceSetName != typeof(Design).Name)
{
if (!this.resourceSetsStorage.TryGetValue(resourceSetName, out entities))
{
entities = new List<object>();
this.resourceSetsStorage[resourceSetName] = entities;
}
}
else
{
entities = new List<object>();
entities.Add(new Design(){ Data="", FileName="new_design"
//, FileURL=""
});
//se están pidiendo los diseños grabados en el servidor. Tengo que elaborar la lista.
// Create a StringBuilder used to create the result string
StringBuilder resultText = new StringBuilder();
// Create an FileIOPermission for accessing the HttpContext.Current.Server.MapPath("/storage") folder
String folderPath = HttpContext.Current.Server.MapPath(Servidor.STORAGE_RELATIVE_PATH);
FileIOPermission permFileIO = new FileIOPermission(FileIOPermissionAccess.AllAccess, folderPath);
try
{
// Demand the permission to access the C:\Temp folder.
permFileIO.Demand();
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(folderPath);
foreach (var fileInfo in di.GetFiles("*.design"))
{
Design ds = new Design() { FileName = fileInfo.Name.Replace(".design",""), TimeStamp = fileInfo.LastWriteTime.ToString("dd/MM/yyyy hh:mm")
//, FileURL = fileInfo.FullName.Replace(HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"], "/").Replace(@"\", "/")
};
entities.Add(ds);
}
}
catch (SecurityException se)
{
resultText.Append("The demand for permission to access the " + folderPath + " folder failed.\nException message: ");
resultText.Append(se.Message);
resultText.Append("\n\n");
}
}
return entities;
}