The Labs \ Source Viewer \ SSCLI \ System.Security \ HostProtectionException

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*=============================================================================
  16. **
  17. ** Class: HostProtectionException
  18. **
  19. ** Purpose: Exception class for HostProtection
  20. **
  21. **
  22. =============================================================================*/
  23. namespace System.Security
  24. {
  25.     using System.Security;
  26.     using System;
  27.     using System.Runtime.Serialization;
  28.     using System.Security.Permissions;
  29.     using System.Reflection;
  30.     using System.Text;
  31.    
  32.     [System.Runtime.InteropServices.ComVisible(true)]
  33.     [Serializable()]
  34.     public class HostProtectionException : SystemException
  35.     {
  36.         private HostProtectionResource m_protected;
  37.         private HostProtectionResource m_demanded;
  38.        
  39.         private const string ProtectedResourcesName = "ProtectedResources";
  40.         private const string DemandedResourcesName = "DemandedResources";
  41.        
  42.         public HostProtectionException() : base()
  43.         {
  44.             m_protected = HostProtectionResource.None;
  45.             m_demanded = HostProtectionResource.None;
  46.         }
  47.        
  48.         public HostProtectionException(string message) : base(message)
  49.         {
  50.             m_protected = HostProtectionResource.None;
  51.             m_demanded = HostProtectionResource.None;
  52.         }
  53.        
  54.         public HostProtectionException(string message, Exception e) : base(message, e)
  55.         {
  56.             m_protected = HostProtectionResource.None;
  57.             m_demanded = HostProtectionResource.None;
  58.         }
  59.        
  60.         protected HostProtectionException(SerializationInfo info, StreamingContext context) : base(info, context)
  61.         {
  62.             if (info == null)
  63.                 throw new ArgumentNullException("info");
  64.            
  65.             m_protected = (HostProtectionResource)info.GetValue(ProtectedResourcesName, typeof(HostProtectionResource));
  66.             m_demanded = (HostProtectionResource)info.GetValue(DemandedResourcesName, typeof(HostProtectionResource));
  67.         }
  68.        
  69.         public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(message)
  70.         {
  71.             SetErrorCode(__HResults.COR_E_HOSTPROTECTION);
  72.             m_protected = protectedResources;
  73.             m_demanded = demandedResources;
  74.         }
  75.        
  76.         // Called from the VM to create a HP Exception
  77.         private HostProtectionException(HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(SecurityException.GetResString("HostProtection_HostProtection"))
  78.         {
  79.             SetErrorCode(__HResults.COR_E_HOSTPROTECTION);
  80.             m_protected = protectedResources;
  81.             m_demanded = demandedResources;
  82.         }
  83.        
  84.        
  85.         public HostProtectionResource ProtectedResources {
  86.             get { return m_protected; }
  87.         }
  88.        
  89.         public HostProtectionResource DemandedResources {
  90.             get { return m_demanded; }
  91.         }
  92.        
  93.         private string ToStringHelper(string resourceString, object attr)
  94.         {
  95.             if (attr == null)
  96.                 return "";
  97.             StringBuilder sb = new StringBuilder();
  98.             sb.Append(Environment.NewLine);
  99.             sb.Append(Environment.NewLine);
  100.             sb.Append(Environment.GetResourceString(resourceString));
  101.             sb.Append(Environment.NewLine);
  102.             sb.Append(attr);
  103.             return sb.ToString();
  104.         }
  105.        
  106.         public override string ToString()
  107.         {
  108.             StringBuilder sb = new StringBuilder();
  109.             sb.Append(base.ToString());
  110.            
  111.             sb.Append(ToStringHelper("HostProtection_ProtectedResources", ProtectedResources));
  112.             sb.Append(ToStringHelper("HostProtection_DemandedResources", DemandedResources));
  113.            
  114.             return sb.ToString();
  115.         }
  116.        
  117.         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
  118.         public override void GetObjectData(SerializationInfo info, StreamingContext context)
  119.         {
  120.             if (info == null)
  121.                 throw new ArgumentNullException("info");
  122.            
  123.             base.GetObjectData(info, context);
  124.            
  125.             info.AddValue(ProtectedResourcesName, ProtectedResources, typeof(HostProtectionResource));
  126.             info.AddValue(DemandedResourcesName, DemandedResources, typeof(HostProtectionResource));
  127.         }
  128.     }
  129. }

Developer Fusion