本文整理汇总了C#中System.Security.Permissions.SecurityPermission.Assert方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityPermission.Assert方法的具体用法?C# SecurityPermission.Assert怎么用?C# SecurityPermission.Assert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Permissions.SecurityPermission
的用法示例。
在下文中一共展示了SecurityPermission.Assert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clerk
public Clerk(string compensator, string description, CompensatorOptions flags)
{
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
permission.Demand();
permission.Assert();
this.Init(compensator, description, flags);
}
示例2: RunApp
public void RunApp(string FileName, string arg)
{
SecurityPermission SP = new SecurityPermission(SecurityPermissionFlag.AllFlags);
SP.Assert();
//ProcessStartInfo process = new ProcessStartInfo("cmd", "/c " + FileName ));
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
//process.StartInfo.UseShellExecute = false;
//process.StartInfo.RedirectStandardOutput = true;
//process.StartInfo.RedirectStandardError = true;
//process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = FileName;
process.StartInfo.Arguments = arg;
process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(FileName);
//Vista or higher check
if (System.Environment.OSVersion.Version.Major >= 6)
process.StartInfo.Verb = "runas";
try
{
process.Start();
process.WaitForExit();
process.Close();
}
catch (InvalidOperationException)
{
//e.ExceptionObject.ToString();
}
}
示例3: SetAppDomainData
public static void SetAppDomainData()
{
SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.ControlAppDomain);
sp.Assert();
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
}
示例4: ClerkMonitor
public ClerkMonitor()
{
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
permission.Demand();
permission.Assert();
this._monitor = new CrmMonitor();
this._version = 0;
}
示例5: ReadAssembly
/// <summary>
///
/// </summary>
/// <param name="stream"></param>
/// <param name="evidence"></param>
/// <returns></returns>
public static Assembly ReadAssembly(Stream stream, Evidence evidence)
{
SecurityPermission securityPermission = new SecurityPermission(SecurityPermissionFlag.ControlEvidence);
securityPermission.Assert();
int num = (int)stream.Length;
byte[] array = new byte[num];
stream.Read(array, 0, num);
try
{
return Assembly.Load(array, null, evidence);
}
finally
{
CodeAccessPermission.RevertAssert();
}
}
示例6: CreateSafeWin32Exception
internal static Win32Exception CreateSafeWin32Exception(int error) {
Win32Exception newException = null;
// Need to assert SecurtiyPermission, otherwise Win32Exception
// will not be able to get the error message. At this point the right
// permissions have already been demanded.
SecurityPermission securityPermission = new SecurityPermission(PermissionState.Unrestricted);
securityPermission.Assert();
try {
if (error == 0)
newException = new Win32Exception();
else
newException = new Win32Exception(error);
}
finally {
SecurityPermission.RevertAssert();
}
return newException;
}
示例7: FromFileBatch
private CompilerResults FromFileBatch(CompilerParameters options, string[] fileNames) {
if( options == null) {
throw new ArgumentNullException("options");
}
if (fileNames == null)
throw new ArgumentNullException("fileNames");
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
string outputFile = null;
int retValue = 0;
CompilerResults results = new CompilerResults(options.TempFiles);
SecurityPermission perm1 = new SecurityPermission(SecurityPermissionFlag.ControlEvidence);
perm1.Assert();
try {
#pragma warning disable 618
results.Evidence = options.Evidence;
#pragma warning restore 618
}
finally {
SecurityPermission.RevertAssert();
}
bool createdEmptyAssembly = false;
if (options.OutputAssembly == null || options.OutputAssembly.Length == 0) {
string extension = (options.GenerateExecutable) ? "exe" : "dll";
options.OutputAssembly = results.TempFiles.AddExtension(extension, !options.GenerateInMemory);
// Create an empty assembly. This is so that the file will have permissions that
// we can later access with our current credential. If we don't do this, the compiler
// could end up creating an assembly that we cannot open.
new FileStream(options.OutputAssembly, FileMode.Create, FileAccess.ReadWrite).Close();
createdEmptyAssembly = true;
}
#if FEATURE_PAL
string pdbname = "ildb";
#else
string pdbname = "pdb";
#endif
// Don't delete pdbs when debug=false but they have specified pdbonly.
if (options.CompilerOptions!= null
&& -1 != CultureInfo.InvariantCulture.CompareInfo.IndexOf(options.CompilerOptions,"/debug:pdbonly", CompareOptions.IgnoreCase))
results.TempFiles.AddExtension(pdbname, true);
else
results.TempFiles.AddExtension(pdbname);
string args = CmdArgsFromParameters(options) + " " + JoinStringArray(fileNames, " ");
// Use a response file if the compiler supports it
string responseFileArgs = GetResponseFileCmdArgs(options, args);
string trueArgs = null;
if (responseFileArgs != null) {
trueArgs = args;
args = responseFileArgs;
}
Compile(options,
RedistVersionInfo.GetCompilerPath(provOptions, CompilerName),
CompilerName,
args,
ref outputFile,
ref retValue,
trueArgs);
results.NativeCompilerReturnValue = retValue;
// only look for errors/warnings if the compile failed or the caller set the warning level
if (retValue != 0 || options.WarningLevel > 0) {
// The output of the compiler is in UTF8
string [] lines = ReadAllLines(outputFile, Encoding.UTF8, FileShare.ReadWrite);
foreach (string line in lines) {
results.Output.Add(line);
ProcessCompilerOutputLine(results, line);
}
// Delete the empty assembly if we created one
if (retValue != 0 && createdEmptyAssembly)
File.Delete(options.OutputAssembly);
}
if (results.Errors.HasErrors || !options.GenerateInMemory) {
results.PathToAssembly = options.OutputAssembly;
return results;
}
// Read assembly into memory:
byte[] assemblyBuff = File.ReadAllBytes(options.OutputAssembly);
// Read symbol file into mempory and ignore any errors that may be encountered:
// (This functionality was added in NetFx 4.5, errors must be ignored to ensure compatibility)
byte[] symbolsBuff = null;
try {
String symbFileName = options.TempFiles.BasePath + "." + pdbname;
//.........这里部分代码省略.........
示例8: GetColumnOrder
/// <summary>
/// Retrieve the order in which columns appear
/// </summary>
/// <returns>Current display order of column indices</returns>
protected int[] GetColumnOrder()
{
IntPtr lPar = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * Columns.Count);
SecurityPermission perm = new
SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
// The method itself is attached with the security permission
// Deny for unmanaged code, which will override
// the Assert permission in this stack frame.
perm.Assert();
IntPtr res = NativeMethods.SendMessage(Handle, NativeMethods.GetColumnOrderArray, new IntPtr(Columns.Count), lPar);
if (res.ToInt32() == 0) // Something went wrong
{
Marshal.FreeHGlobal(lPar);
return null;
}
int [] order = new int[Columns.Count];
Marshal.Copy(lPar, order, 0, Columns.Count);
Marshal.FreeHGlobal(lPar);
return order;
}
示例9: GetCurrentOEMCPEncoding
private static string GetCurrentOEMCPEncoding(int code)
{
SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Assert();//Blessed Assert
try
{
int cp = UnsafeNativeMethods.GetOEMCP();
return CharacterEncoding(cp, code);
}
finally
{
SecurityPermission.RevertAssert();
}
}
示例10: unchecked
private const int _COMPlusExceptionCode = unchecked((int)0xe0524f54); // Win32 exception code for COM+ exceptions
internal virtual String InternalToString()
{
try
{
SecurityPermission sp= new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.ControlPolicy);
sp.Assert();
}
catch
{
}
return ToString();
}
示例11: InternalToString
internal virtual string InternalToString()
{
try
{
SecurityPermission securityPermission = new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.ControlPolicy);
securityPermission.Assert();
}
catch
{
}
bool needFileLineInfo = true;
return this.ToString(needFileLineInfo);
}
示例12: InternalToString
[System.Security.SecurityCritical] // auto-generated
internal virtual String InternalToString()
{
try
{
#pragma warning disable 618
SecurityPermission sp= new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.ControlPolicy);
#pragma warning restore 618
sp.Assert();
}
catch
{
//under normal conditions there should be no exceptions
//however if something wrong happens we still can call the usual ToString
}
// Get the current stack trace string. On CoreCLR we don't bother
// to try and include file/line-number information because all AppDomains
// are sandboxed, and so this won't succeed in most (or all) cases. Therefore the
// Demand and exception overhead is a waste.
// We currently have some bugs in watson bucket generation where the SecurityException
// here causes us to lose saved bucket parameters. By not even doing the demand
// we avoid those problems (although there are deep underlying problems that need to
// be fixed there - relying on this to avoid problems is incomplete and brittle).
bool fGetFileLineInfo = true;
#if FEATURE_CORECLR
fGetFileLineInfo = false;
#endif
return ToString(fGetFileLineInfo, true);
}
示例13: FromFileBatch
private CompilerResults FromFileBatch(CompilerParameters options, string[] fileNames) {
if( options == null) {
throw new ArgumentNullException("options");
}
if (fileNames == null)
throw new ArgumentNullException("fileNames");
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
string outputFile = null;
int retValue = 0;
CompilerResults results = new CompilerResults(options.TempFiles);
SecurityPermission perm1 = new SecurityPermission(SecurityPermissionFlag.ControlEvidence);
perm1.Assert();
try {
results.Evidence = options.Evidence;
}
finally {
SecurityPermission.RevertAssert();
}
bool createdEmptyAssembly = false;
if (options.OutputAssembly == null || options.OutputAssembly.Length == 0) {
string extension = (options.GenerateExecutable) ? "exe" : "dll";
options.OutputAssembly = results.TempFiles.AddExtension(extension, !options.GenerateInMemory);
// Create an empty assembly. This is so that the file will have permissions that
// we can later access with our current credential. If we don't do this, the compiler
// could end up creating an assembly that we cannot open.
new FileStream(options.OutputAssembly, FileMode.Create, FileAccess.ReadWrite).Close();
createdEmptyAssembly = true;
}
string pdbname = "ildb";
// Don't delete pdbs when debug=false but they have specified pdbonly.
if (options.CompilerOptions!= null && CultureInfo.InvariantCulture.CompareInfo.IndexOf(options.CompilerOptions,"/debug:pdbonly", CompareOptions.IgnoreCase) != -1)
results.TempFiles.AddExtension(pdbname, true);
else
results.TempFiles.AddExtension(pdbname);
string args = CmdArgsFromParameters(options) + " " + JoinStringArray(fileNames, " ");
// Use a response file if the compiler supports it
string responseFileArgs = GetResponseFileCmdArgs(options, args);
string trueArgs = null;
if (responseFileArgs != null) {
trueArgs = args;
args = responseFileArgs;
}
Compile(options, Executor.GetRuntimeInstallDirectory(), CompilerName, args, ref outputFile, ref retValue, trueArgs);
results.NativeCompilerReturnValue = retValue;
// only look for errors/warnings if the compile failed or the caller set the warning level
if (retValue != 0 || options.WarningLevel > 0) {
FileStream outputStream = new FileStream(outputFile, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);
try {
if (outputStream.Length > 0) {
// The output of the compiler is in UTF8
StreamReader sr = new StreamReader(outputStream, Encoding.UTF8);
string line;
do {
line = sr.ReadLine();
if (line != null) {
results.Output.Add(line);
ProcessCompilerOutputLine(results, line);
}
} while (line != null);
}
}
finally {
outputStream.Close();
}
// Delete the empty assembly if we created one
if (retValue != 0 && createdEmptyAssembly)
File.Delete(options.OutputAssembly);
}
if (!results.Errors.HasErrors && options.GenerateInMemory) {
FileStream fs = new FileStream(options.OutputAssembly, FileMode.Open, FileAccess.Read, FileShare.Read);
try {
int fileLen = (int)fs.Length;
byte[] b = new byte[fileLen];
fs.Read(b, 0, fileLen);
SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.ControlEvidence);
perm.Assert();
try {
results.CompiledAssembly = Assembly.Load(b,null,options.Evidence);
}
finally {
SecurityPermission.RevertAssert();
}
}
//.........这里部分代码省略.........
示例14: InstallAssembly
public void InstallAssembly(RegistrationConfig regConfig, object obSync)
{
Assembly asm = null;
ApplicationSpec spec = null;
CatalogSync sync = null;
bool flag = false;
bool flag2 = false;
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
try
{
permission.Demand();
permission.Assert();
ICatalogObject app = null;
this.PrepArguments(regConfig);
asm = this.NewLoadAssembly(regConfig.AssemblyFile);
spec = new ApplicationSpec(asm, regConfig);
if (spec.ConfigurableTypes == null)
{
regConfig.Application = null;
regConfig.TypeLibrary = null;
}
else
{
if (obSync != null)
{
if (!(obSync is CatalogSync))
{
throw new ArgumentException(Resource.FormatString("Err_obSync"));
}
sync = (CatalogSync) obSync;
}
this.PrepDriver(ref spec);
string message = string.Empty;
if (!this.ValidateBitness(spec, out message))
{
throw new RegistrationException(message);
}
if ((regConfig.InstallationFlags & InstallationFlags.Register) != InstallationFlags.Default)
{
flag = !this.IsAssemblyRegistered(spec);
this.ClassicRegistration(spec.Assembly);
if ((regConfig.InstallationFlags & InstallationFlags.ExpectExistingTypeLib) != InstallationFlags.Default)
{
RegisterTypeLibrary(spec.TypeLib);
}
else
{
flag2 = true;
GenerateTypeLibrary(spec.Assembly, spec.TypeLib, new Report(this.ReportWarning));
}
}
if (((regConfig.InstallationFlags & InstallationFlags.Install) != InstallationFlags.Default) && (spec.ConfigurableTypes != null))
{
if ((regConfig.InstallationFlags & InstallationFlags.CreateTargetApplication) != InstallationFlags.Default)
{
app = this.CreateApplication(spec, true);
}
else if ((regConfig.InstallationFlags & InstallationFlags.FindOrCreateTargetApplication) != InstallationFlags.Default)
{
app = this.FindOrCreateApplication(spec, (regConfig.InstallationFlags & InstallationFlags.ReconfigureExistingApplication) != InstallationFlags.Default);
}
this.InstallTypeLibrary(spec);
if (sync != null)
{
sync.Set();
}
}
if (((regConfig.InstallationFlags & InstallationFlags.Configure) != InstallationFlags.Default) && (spec.ConfigurableTypes != null))
{
this.ConfigureComponents(spec);
if (sync != null)
{
sync.Set();
}
}
if (app != null)
{
this.PostProcessApplication(app, spec);
}
this.CleanupDriver();
}
}
catch (Exception exception)
{
if ((exception is NullReferenceException) || (exception is SEHException))
{
throw;
}
if (((exception is SecurityException) || (exception is UnauthorizedAccessException)) || ((exception.InnerException != null) && ((exception.InnerException is SecurityException) || (exception.InnerException is UnauthorizedAccessException))))
{
exception = new RegistrationException(Resource.FormatString("Reg_Unauthorized"), exception);
}
if (flag && (null != asm))
{
try
{
this.ClassicUnregistration(asm);
}
catch (Exception exception2)
{
//.........这里部分代码省略.........
示例15: rtfcontrol_Load
private void rtfcontrol_Load(object sender, System.EventArgs e)
{
//new FileIOPermission(PermissionState.Unrestricted).Assert();
PrincipalPermission P = new PrincipalPermission(PermissionState.Unrestricted);
if(!P.IsUnrestricted())
Msg("Assigning Principal failed!");
else
Msg("Assigning Principal passed!!");
SecurityPermission SP = new SecurityPermission(PermissionState.Unrestricted);
if(!SP.IsUnrestricted())
Msg("Assigning SecurityPermission failed!");
else
Msg("Assigning SecurityPermission passed!!");
try
{
SP.Assert();
}
catch(Exception Err)
{
throw new Exception(Err.Message,Err.InnerException);
}
ListViewItem LVI = listView1.Items.Add(System.DateTime.Now.ToShortTimeString());
LVI.SubItems.Add("Contacting Server please wait...");
CodeAccessPermission.RevertAssert();
}