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


C# PermissionSet.Assert方法代码示例

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


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

示例1: XmlILModule

        static XmlILModule() {
            AssemblyName asmName;
            AssemblyBuilder asmBldr;

            CreateModulePermissionSet = new PermissionSet(PermissionState.None);
            // CreateDelegate demands MemberAccess permission
            CreateModulePermissionSet.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
            // DynamicMethod constructor demands ControlEvidence permissions. 
            // Emitting symbols in DefineDynamicModule (to allow to debug the stylesheet) requires UnmanagedCode permission. 
            CreateModulePermissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.UnmanagedCode));

            AssemblyId = 0;

            // 1. LRE assembly only needs to execute
            // 2. No temp files need be created
            // 3. Never allow assembly to Assert permissions
            asmName = CreateAssemblyName();
            asmBldr = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);

            try {
                CreateModulePermissionSet.Assert();

                // Add custom attribute to assembly marking it as security transparent so that Assert will not be allowed
                // and link demands will be converted to full demands.
                asmBldr.SetCustomAttribute(new CustomAttributeBuilder(XmlILConstructors.Transparent, new object[] {}));

                // Store LREModule once.  If multiple threads are doing this, then some threads might get different
                // modules.  This is OK, since it's not mandatory to share, just preferable.
                LREModule = asmBldr.DefineDynamicModule("System.Xml.Xsl.CompiledQuery", false);
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:34,代码来源:XmlILModule.cs

示例2: Open

      public void Open()
      {
         if(State != CommunicationState.Created)
         {
            return;
         }
         try
         {
            Opening(this,EventArgs.Empty);

            //Permission required to read the providers application name and access config
            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal));
            permissions.AddPermission(new FileIOPermission(PermissionState.Unrestricted));

            permissions.Assert();

            m_ServiceHostActivator.MembershipApplicationName = Membership.ApplicationName;
            if(Roles.Enabled)
            {
               m_ServiceHostActivator.RolesApplicationName = Roles.ApplicationName;
            }
            PermissionSet.RevertAssert();

            m_ServiceHostActivator.Open();

            State = CommunicationState.Opened;

            Opened(this,EventArgs.Empty);
         }
         catch
         {
            State = CommunicationState.Faulted;
         }
      }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:35,代码来源:AppDomainHost.cs

示例3: GetApplicationInstanceId

		private static string GetApplicationInstanceId(this Assembly entry)
		{
			var set = new PermissionSet(PermissionState.None);
			set.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
			set.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
			set.Assert();

			var typeLibGuidForAssembly = Marshal.GetTypeLibGuidForAssembly(entry);
			var strArray = entry.GetName().Version.ToString().Split(".".ToCharArray());
			PermissionSet.RevertAssert();

			return typeLibGuidForAssembly + strArray[0] + "." + strArray[1];
		}
开发者ID:matteomigliore,项目名称:HSDK,代码行数:13,代码来源:SingleInstance.cs

示例4: Socket

        public static void Socket()
        {
            var set = new PermissionSet(PermissionState.None);
            set.AddPermission(new DnsPermission(PermissionState.Unrestricted));
            set.AddPermission(new SocketPermission(NetworkAccess.Connect, TransportType.Tcp, "173.194.32.38", 80));
            set.Assert();

            var client = new TcpClient();
            client.Connect("173.194.32.38", 80);

            Console.WriteLine("Connected to google: {0}", client.Connected);

            client.Close();

            CodeAccessPermission.RevertAssert();
        }
开发者ID:vktr,项目名称:appdomain-isolation,代码行数:16,代码来源:Magic.cs

示例5: SetBackgroundImage

        private void SetBackgroundImage() {
            // needed for OleInitialize
            Application.OleRequired();

            NativeMethods.LVBKIMAGE lvbkImage = new NativeMethods.LVBKIMAGE();
            lvbkImage.xOffset = 0;
            lvbkImage.yOffset = 0;

            // first, is there an existing temporary file to delete, remember its name
            // so that we can delete it if the list control doesn't...
            string fileNameToDelete = this.backgroundImageFileName;

            if (this.BackgroundImage != null) {

                // the list view needs these permissions when the app runs on an UNC share
                // and the list view creates / destroys temporary files for its background image

                // SECREVIEW : Safe to assert FileIO & Environment permissions here, just creating/deleting temp files.
                //
                EnvironmentPermission envPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "TEMP");
                FileIOPermission fiop = new FileIOPermission(PermissionState.Unrestricted);
                System.Security.PermissionSet permSet = new System.Security.PermissionSet(PermissionState.Unrestricted);
                permSet.AddPermission(envPermission);
                permSet.AddPermission(fiop);
                permSet.Assert();

                // save the image to a temporary file name
                try {
                    string tempDirName = System.IO.Path.GetTempPath();
                    System.Text.StringBuilder sb = new System.Text.StringBuilder(1024);
                    UnsafeNativeMethods.GetTempFileName(tempDirName, this.GenerateRandomName(), 0, sb);

                    this.backgroundImageFileName = sb.ToString();

                    this.BackgroundImage.Save(this.backgroundImageFileName, System.Drawing.Imaging.ImageFormat.Bmp);
                } finally {
                    System.Security.PermissionSet.RevertAssert();
                }

                lvbkImage.pszImage = this.backgroundImageFileName;
                lvbkImage.cchImageMax = this.backgroundImageFileName.Length + 1;
                lvbkImage.ulFlags = NativeMethods.LVBKIF_SOURCE_URL;
                if (BackgroundImageTiled)
                    lvbkImage.ulFlags |= NativeMethods.LVBKIF_STYLE_TILE;
                else
                    lvbkImage.ulFlags |= NativeMethods.LVBKIF_STYLE_NORMAL;

            } else {
                lvbkImage.ulFlags = NativeMethods.LVBKIF_SOURCE_NONE;
                this.backgroundImageFileName = String.Empty;
            }

            UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), NativeMethods.LVM_SETBKIMAGE, 0, lvbkImage);

            if (String.IsNullOrEmpty(fileNameToDelete)) {
                return;
            }

            // we need to cause a paint message on the win32 list view. This way the win 32 list view gives up
            // its reference to the previous image file it was hanging on to.
            // vsWhidbey 243708

            // 8 strings should be good enough for us
            if (this.bkImgFileNames == null) {
                this.bkImgFileNames = new string[BKIMGARRAYSIZE];
                this.bkImgFileNamesCount = -1;
            }

            if (this.bkImgFileNamesCount == BKIMGARRAYSIZE - 1) {
                // it should be fine to delete the file name that was added first.
                // if it's not fine, then increase BKIMGARRAYSIZE
                this.DeleteFileName(this.bkImgFileNames[0]);
                this.bkImgFileNames[0] = this.bkImgFileNames[1];
                this.bkImgFileNames[1] = this.bkImgFileNames[2];
                this.bkImgFileNames[2] = this.bkImgFileNames[3];
                this.bkImgFileNames[3] = this.bkImgFileNames[4];
                this.bkImgFileNames[4] = this.bkImgFileNames[5];
                this.bkImgFileNames[5] = this.bkImgFileNames[6];
                this.bkImgFileNames[6] = this.bkImgFileNames[7];
                this.bkImgFileNames[7] = null;

                this.bkImgFileNamesCount --;
            }

            this.bkImgFileNamesCount ++;
            this.bkImgFileNames[this.bkImgFileNamesCount] = fileNameToDelete;

            // now force the paint
            this.Refresh();
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:90,代码来源:ListView.cs

示例6: GetSystemSound

        private string GetSystemSound(string soundName)
        {
            string soundFile = null;
            string regPath = string.Format(CultureInfo.InvariantCulture, SYSTEM_SOUNDS_REGISTRY_LOCATION, soundName);
            PermissionSet permissions = new PermissionSet(null);
            permissions.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, SYSTEM_SOUNDS_REGISTRY_BASE));
            permissions.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
            permissions.Assert();
            try
            {
                using (RegistryKey soundKey = Registry.CurrentUser.OpenSubKey(regPath))
                {
                    if (soundKey != null)
                    {
                        soundFile = (string)(soundKey.GetValue(""));
                    }
                }
            }
            // When the value of the register key is empty, the IndexOutofRangeException is thrown.
            // Please see Dev10 bug 586158 for more details.
            catch (System.IndexOutOfRangeException)
            {
            }
            finally
            {
               CodeAccessPermission.RevertAssert();
            }

            return soundFile;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:30,代码来源:Application.cs

示例7: GetTempAssemblyPath

        internal static string GetTempAssemblyPath(string baseDir, Assembly assembly, string defaultNamespace) {
            if (assembly.IsDynamic) {
                throw new InvalidOperationException(Res.GetString(Res.XmlPregenAssemblyDynamic));
            }

            PermissionSet perms = new PermissionSet(PermissionState.None);
            perms.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
            perms.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
            perms.Assert();

            try {
                if (baseDir != null && baseDir.Length > 0) {
                    // check that the dirsctory exists
                    if (!Directory.Exists(baseDir)) {
                        throw new UnauthorizedAccessException(Res.GetString(Res.XmlPregenMissingDirectory, baseDir));
                    }
                }
                else {
                    baseDir = Path.GetTempPath();
                    // check that the dirsctory exists
                    if (!Directory.Exists(baseDir)) {
                        throw new UnauthorizedAccessException(Res.GetString(Res.XmlPregenMissingTempDirectory));
                    }
                }

#if MONO
                baseDir = Path.Combine (baseDir, GetTempAssemblyName(assembly.GetName(), defaultNamespace));
#else
                if (baseDir.EndsWith("\\", StringComparison.Ordinal))
                    baseDir += GetTempAssemblyName(assembly.GetName(), defaultNamespace);
                else 
                    baseDir += "\\" + GetTempAssemblyName(assembly.GetName(), defaultNamespace);
#endif
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
            return baseDir + ".dll";
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:39,代码来源:Compiler.cs

示例8: Generate

 public void Generate()
 {
     if (this._resourceList == null)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ResourceWriterSaved"));
     }
     BinaryWriter writer = new BinaryWriter(this._output, Encoding.UTF8);
     List<string> types = new List<string>();
     writer.Write(ResourceManager.MagicNumber);
     writer.Write(ResourceManager.HeaderVersionNumber);
     MemoryStream output = new MemoryStream(240);
     BinaryWriter writer2 = new BinaryWriter(output);
     writer2.Write(MultitargetingHelpers.GetAssemblyQualifiedName(typeof(ResourceReader), this.typeConverter));
     writer2.Write(ResourceManager.ResSetTypeName);
     writer2.Flush();
     writer.Write((int) output.Length);
     writer.Write(output.GetBuffer(), 0, (int) output.Length);
     writer.Write(2);
     int count = this._resourceList.Count;
     if (this._preserializedData != null)
     {
         count += this._preserializedData.Count;
     }
     writer.Write(count);
     int[] keys = new int[count];
     int[] items = new int[count];
     int index = 0;
     MemoryStream stream2 = new MemoryStream(count * 40);
     BinaryWriter writer3 = new BinaryWriter(stream2, Encoding.Unicode);
     Stream stream3 = null;
     string path = null;
     PermissionSet set = new PermissionSet(PermissionState.None);
     set.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
     set.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
     try
     {
         set.Assert();
         path = Path.GetTempFileName();
         File.SetAttributes(path, FileAttributes.NotContentIndexed | FileAttributes.Temporary);
         stream3 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 0x1000, FileOptions.SequentialScan | FileOptions.DeleteOnClose);
     }
     catch (UnauthorizedAccessException)
     {
         stream3 = new MemoryStream();
     }
     catch (IOException)
     {
         stream3 = new MemoryStream();
     }
     finally
     {
         PermissionSet.RevertAssert();
     }
     using (stream3)
     {
         BinaryWriter store = new BinaryWriter(stream3, Encoding.UTF8);
         IFormatter objFormatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Persistence | StreamingContextStates.File));
         SortedList list2 = new SortedList(this._resourceList, FastResourceComparer.Default);
         if (this._preserializedData != null)
         {
             foreach (KeyValuePair<string, PrecannedResource> pair in this._preserializedData)
             {
                 list2.Add(pair.Key, pair.Value);
             }
         }
         IDictionaryEnumerator enumerator = list2.GetEnumerator();
         while (enumerator.MoveNext())
         {
             keys[index] = FastResourceComparer.HashFunction((string) enumerator.Key);
             items[index++] = (int) writer3.Seek(0, SeekOrigin.Current);
             writer3.Write((string) enumerator.Key);
             writer3.Write((int) store.Seek(0, SeekOrigin.Current));
             object obj2 = enumerator.Value;
             ResourceTypeCode typeCode = this.FindTypeCode(obj2, types);
             Write7BitEncodedInt(store, (int) typeCode);
             PrecannedResource resource = obj2 as PrecannedResource;
             if (resource != null)
             {
                 store.Write(resource.Data);
             }
             else
             {
                 this.WriteValue(typeCode, obj2, store, objFormatter);
             }
         }
         writer.Write(types.Count);
         for (int i = 0; i < types.Count; i++)
         {
             writer.Write(types[i]);
         }
         Array.Sort<int, int>(keys, items);
         writer.Flush();
         int num4 = ((int) writer.BaseStream.Position) & 7;
         if (num4 > 0)
         {
             for (int j = 0; j < (8 - num4); j++)
             {
                 writer.Write("PAD"[j % 3]);
             }
         }
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:ResourceWriter.cs

示例9: OpenRead

        static Stream OpenRead(Uri resourceUri) {
            Stream result = null;
#if !DISABLE_CAS_USE
            PermissionSet perms = new PermissionSet(PermissionState.Unrestricted);

            perms.Assert();
#endif
            try {
                WebClient webClient = new WebClient();
                webClient.Credentials = CredentialCache.DefaultCredentials;
                result = webClient.OpenRead(resourceUri.ToString());
            }
            catch (Exception e) {
                Debug.Fail(e.ToString());
            }
#if !DISABLE_CAS_USE
            finally {
                CodeAccessPermission.RevertAssert();
            }
#endif
            return result;
        }
开发者ID:stormleoxia,项目名称:referencesource,代码行数:22,代码来源:DesigntimeLicenseContext.cs

示例10: FindCustomCategory

        internal bool FindCustomCategory(string category, out PerformanceCounterCategoryType categoryType) {
            RegistryKey key = null;
            RegistryKey baseKey = null;
            categoryType = PerformanceCounterCategoryType.Unknown;
            
            if (this.customCategoryTable == null) {
                Interlocked.CompareExchange(ref this.customCategoryTable, new Hashtable(StringComparer.OrdinalIgnoreCase), null);
            }

            if (this.customCategoryTable.ContainsKey(category)) {
                categoryType= (PerformanceCounterCategoryType) this.customCategoryTable[category];
                return true;
            }
            else {
                //SECREVIEW: Whoever is able to call this function, must already
                //                         have demanded PerformanceCounterPermission
                //                         we can therefore assert the RegistryPermission.
                PermissionSet ps = new PermissionSet(PermissionState.None);
                ps.AddPermission(new RegistryPermission(PermissionState.Unrestricted));
                ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
                ps.Assert();
                try {
                    string keyPath = ServicePath + "\\" + category + "\\Performance";
                    if (machineName == "." || String.Compare(this.machineName, ComputerName, StringComparison.OrdinalIgnoreCase) == 0) {
                        key = Registry.LocalMachine.OpenSubKey(keyPath);
                    }
                    else {
                        baseKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "\\\\" + this.machineName);
                        if (baseKey != null) {
                            try {
                                key = baseKey.OpenSubKey(keyPath);
                            } catch (SecurityException) {
                                // we may not have permission to read the registry key on the remote machine.  The security exception  
                                // is thrown when RegOpenKeyEx returns ERROR_ACCESS_DENIED or ERROR_BAD_IMPERSONATION_LEVEL
                                //
                                // In this case we return an 'Unknown' category type and 'false' to indicate the category is *not* custom.
                                //
                                categoryType = PerformanceCounterCategoryType.Unknown;
                                this.customCategoryTable[category] = categoryType;
                                return false;
                            }
                        }
                    }

                    if (key != null) {
                        object systemDllName = key.GetValue("Library", null, RegistryValueOptions.DoNotExpandEnvironmentNames);
                        if (systemDllName != null && systemDllName is string 
                            && (String.Compare((string)systemDllName, PerformanceCounterLib.PerfShimName, StringComparison.OrdinalIgnoreCase) == 0
                              || ((string)systemDllName).EndsWith(PerformanceCounterLib.PerfShimFullNameSuffix, StringComparison.OrdinalIgnoreCase))) {
                            
                            object isMultiInstanceObject = key.GetValue("IsMultiInstance");
                            if (isMultiInstanceObject != null) {
                                categoryType = (PerformanceCounterCategoryType) isMultiInstanceObject;
                                if (categoryType < PerformanceCounterCategoryType.Unknown || categoryType > PerformanceCounterCategoryType.MultiInstance)
                                    categoryType = PerformanceCounterCategoryType.Unknown;
                            }
                            else
                                categoryType = PerformanceCounterCategoryType.Unknown;
                                
                            object objectID = key.GetValue("First Counter");
                            if (objectID != null) {
                                int firstID = (int)objectID;

                                this.customCategoryTable[category] = categoryType;
                                return true;
                            }
                        }
                    }
                }
                finally {
                    if (key != null) key.Close();
                    if (baseKey != null) baseKey.Close();
                    PermissionSet.RevertAssert();
                }
            }
            return false;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:77,代码来源:PerformanceCounterLib.cs

示例11: TIPsWantToRun

        private static bool TIPsWantToRun()
        {
            object obj;
            RegistryKey key;
            bool tipsWantToRun = false;

            PermissionSet ps = new PermissionSet(PermissionState.None);
            ps.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\CTF"));
            ps.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_CURRENT_USER\\Software\\Microsoft\\CTF"));
            ps.Assert(); // BlessedAssert: 
            try
            {
                key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\CTF", false);

                // Is cicero disabled completely for the current user?
                if (key != null)
                {
                    obj = key.GetValue("Disable Thread Input Manager");

                    if (obj is int && (int)obj != 0)
                        return false;
                }

                // Loop through all the TIP entries for machine and current user.
                tipsWantToRun = IterateSubKeys(Registry.LocalMachine, "SOFTWARE\\Microsoft\\CTF\\TIP",new IterateHandler(SingleTIPWantsToRun), true) == EnableState.Enabled;
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }

            return tipsWantToRun;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:33,代码来源:TextServicesLoader.cs

示例12: LoadRecognizerDll

        private static bool LoadRecognizerDll()
        {
            // ISSUE-2005/01/14-WAYNEZEN,
            // We may hit the problem when an application already load mshwgst.dll from somewhere rather than the
            // directory we are looking for. The options to resolve this -
            //  1. We fail the recognition functionality.
            //  2. We unload the previous mshwgst.dll
            //  3. We switch the DllImport usage to the new dynamic PInvoke mechanism in Whidbey. Please refer to the blog
            //     http://blogs.msdn.com/junfeng/archive/2004/07/14/181932.aspx. Then we don't have to unload the existing
            //     mshwgst.dll.
            String path = null;
            System.Security.PermissionSet permissionSet = new PermissionSet(null);
            permissionSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read,
                                                        System.Security.AccessControl.AccessControlActions.View,
                                                        GestureRecognizerFullPath));
            permissionSet.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
            permissionSet.Assert();  // BlessedAssert:
            try
            {
                RegistryKey regkey = Registry.LocalMachine;
                RegistryKey recognizerKey = regkey.OpenSubKey(GestureRecognizerPath);
                if (recognizerKey != null)
                {
                    try
                    {
                        // Try to read the recognizer path subkey
                        path = recognizerKey.GetValue(GestureRecognizerValueName) as string;
                        if (path == null)
                        {
                            return false;
                        } 
                    }
                    finally
                    {
                        recognizerKey.Close();
                    }
                }
                else
                {
                    // we couldn't find the path in the registry
                    // no key to close
                    return false;
                }
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
 
            if (path != null)
            {
                IntPtr hModule = MS.Win32.UnsafeNativeMethods.LoadLibrary(path);

                // Check whether GetAlternateList exists in the loaded Dll.
                s_GetAlternateListExists = false;
                if ( hModule != IntPtr.Zero )
                {
                    s_GetAlternateListExists = MS.Win32.UnsafeNativeMethods.GetProcAddressNoThrow(
                        new HandleRef(null, hModule), "GetAlternateList") != IntPtr.Zero ?
                        true : false;
                }

                return hModule != IntPtr.Zero ? true : false; 
            }
            return false; //path was null 
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:66,代码来源:NativeRecognizer.cs

示例13: GetContract

        internal IContract GetContract()
        {
            if (_contract != null)
                return _contract;

            // in direct connect, the contract has not been created.  Create it now.
            Object hav = _havReference.Target;
            if (hav == null)
                throw new InvalidOperationException(Res.AddInNoLongerAvailable);

            // Assert permission to the contracts, AddInSideAdapters, AddInViews and specific Addin directories only.
            PermissionSet permissionSet = new PermissionSet(PermissionState.None);
            permissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery,
                Path.Combine(_token.PipelineRootDirectory, AddInStore.ContractsDirName)));
            permissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery,
                Path.Combine(_token.PipelineRootDirectory, AddInStore.AddInAdaptersDirName)));
            permissionSet.Assert();

            Assembly.LoadFrom(_token._contract.Location);
            Assembly addinAdapterAssembly = Assembly.LoadFrom(_token._addinAdapter.Location);
            CodeAccessPermission.RevertAssert();

            // Create the AddIn adapter for the addin
            ActivationWorker worker = new ActivationWorker(_token);
            _contract = worker.CreateAddInAdapter(hav, addinAdapterAssembly);
            return _contract;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:27,代码来源:AddInControllerImpl.cs

示例14: SetBackgroundImage

 private void SetBackgroundImage()
 {
     Application.OleRequired();
     System.Windows.Forms.NativeMethods.LVBKIMAGE lParam = new System.Windows.Forms.NativeMethods.LVBKIMAGE {
         xOffset = 0,
         yOffset = 0
     };
     string backgroundImageFileName = this.backgroundImageFileName;
     if (this.BackgroundImage != null)
     {
         EnvironmentPermission perm = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "TEMP");
         FileIOPermission permission2 = new FileIOPermission(PermissionState.Unrestricted);
         PermissionSet set = new PermissionSet(PermissionState.Unrestricted);
         set.AddPermission(perm);
         set.AddPermission(permission2);
         set.Assert();
         try
         {
             string tempPath = Path.GetTempPath();
             StringBuilder sb = new StringBuilder(0x400);
             System.Windows.Forms.UnsafeNativeMethods.GetTempFileName(tempPath, this.GenerateRandomName(), 0, sb);
             this.backgroundImageFileName = sb.ToString();
             this.BackgroundImage.Save(this.backgroundImageFileName, ImageFormat.Bmp);
         }
         finally
         {
             PermissionSet.RevertAssert();
         }
         lParam.pszImage = this.backgroundImageFileName;
         lParam.cchImageMax = this.backgroundImageFileName.Length + 1;
         lParam.ulFlags = 2;
         if (this.BackgroundImageTiled)
         {
             lParam.ulFlags |= 0x10;
         }
         else
         {
             lParam.ulFlags = lParam.ulFlags;
         }
     }
     else
     {
         lParam.ulFlags = 0;
         this.backgroundImageFileName = string.Empty;
     }
     System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), System.Windows.Forms.NativeMethods.LVM_SETBKIMAGE, 0, lParam);
     if (!string.IsNullOrEmpty(backgroundImageFileName))
     {
         if (this.bkImgFileNames == null)
         {
             this.bkImgFileNames = new string[8];
             this.bkImgFileNamesCount = -1;
         }
         if (this.bkImgFileNamesCount == 7)
         {
             this.DeleteFileName(this.bkImgFileNames[0]);
             this.bkImgFileNames[0] = this.bkImgFileNames[1];
             this.bkImgFileNames[1] = this.bkImgFileNames[2];
             this.bkImgFileNames[2] = this.bkImgFileNames[3];
             this.bkImgFileNames[3] = this.bkImgFileNames[4];
             this.bkImgFileNames[4] = this.bkImgFileNames[5];
             this.bkImgFileNames[5] = this.bkImgFileNames[6];
             this.bkImgFileNames[6] = this.bkImgFileNames[7];
             this.bkImgFileNames[7] = null;
             this.bkImgFileNamesCount--;
         }
         this.bkImgFileNamesCount++;
         this.bkImgFileNames[this.bkImgFileNamesCount] = backgroundImageFileName;
         this.Refresh();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:71,代码来源:ListView.cs

示例15: GetStringTable

 private Hashtable GetStringTable(bool isHelp)
 {
     Hashtable hashtable;
     RegistryKey performanceData;
     PermissionSet set = new PermissionSet(PermissionState.None);
     set.AddPermission(new RegistryPermission(PermissionState.Unrestricted));
     set.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
     set.Assert();
     if (string.Compare(this.machineName, ComputerName, StringComparison.OrdinalIgnoreCase) == 0)
     {
         performanceData = Registry.PerformanceData;
     }
     else
     {
         performanceData = RegistryKey.OpenRemoteBaseKey(RegistryHive.PerformanceData, this.machineName);
     }
     try
     {
         string[] strArray = null;
         int num = 14;
         int millisecondsTimeout = 0;
         while (num > 0)
         {
             try
             {
                 if (!isHelp)
                 {
                     strArray = (string[]) performanceData.GetValue("Counter " + this.perfLcid);
                 }
                 else
                 {
                     strArray = (string[]) performanceData.GetValue("Explain " + this.perfLcid);
                 }
                 if ((strArray != null) && (strArray.Length != 0))
                 {
                     break;
                 }
                 num--;
                 if (millisecondsTimeout == 0)
                 {
                     millisecondsTimeout = 10;
                 }
                 else
                 {
                     Thread.Sleep(millisecondsTimeout);
                     millisecondsTimeout *= 2;
                 }
                 continue;
             }
             catch (IOException)
             {
                 strArray = null;
                 break;
             }
             catch (InvalidCastException)
             {
                 strArray = null;
                 break;
             }
         }
         if (strArray == null)
         {
             return new Hashtable();
         }
         hashtable = new Hashtable(strArray.Length / 2);
         for (int i = 0; i < (strArray.Length / 2); i++)
         {
             int num4;
             string str = strArray[(i * 2) + 1];
             if (str == null)
             {
                 str = string.Empty;
             }
             if (!int.TryParse(strArray[i * 2], NumberStyles.Integer, CultureInfo.InvariantCulture, out num4))
             {
                 if (isHelp)
                 {
                     throw new InvalidOperationException(SR.GetString("CategoryHelpCorrupt", new object[] { strArray[i * 2] }));
                 }
                 throw new InvalidOperationException(SR.GetString("CounterNameCorrupt", new object[] { strArray[i * 2] }));
             }
             hashtable[num4] = str;
         }
     }
     finally
     {
         performanceData.Close();
     }
     return hashtable;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:90,代码来源:PerformanceCounterLib.cs


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