DesigntimeLicenseContextSerializer.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / CompMod / System / ComponentModel / Design / DesigntimeLicenseContextSerializer.cs / 1 / DesigntimeLicenseContextSerializer.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.ComponentModel.Design { 
    using System.Runtime.Remoting; 
    using System.Runtime.Serialization.Formatters.Binary;
    using System.Runtime.Serialization; 
    using System.Security;
    using System.Security.Permissions;
    using System.Collections;
    using System.ComponentModel; 
    using System.Diagnostics;
    using System; 
    using Microsoft.Win32; 
    using System.IO;
    using System.Diagnostics.CodeAnalysis; 

    /// 
    ///    
    ///       Provides support for design-time license context serialization. 
    ///    
    ///  
    [HostProtection(SharedState = true)] 
    [System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.InheritanceDemand, Name = "FullTrust")]
    [System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name="FullTrust")] 
    public class DesigntimeLicenseContextSerializer {

        // not creatable...
        // 
        private DesigntimeLicenseContextSerializer() {
        } 
 
        /// 
        ///     
        ///       Serializes the licenses within the specified design-time license context
        ///       using the specified key and output stream.
        ///    
        ///  
        public static void Serialize(Stream o, string cryptoKey, DesigntimeLicenseContext context) {
            IFormatter formatter = new BinaryFormatter(); 
            formatter.Serialize(o, new object[] {cryptoKey, context.savedLicenseKeys}); 
        }
 
        [SuppressMessage("Microsoft.Security", "CA2107:ReviewDenyAndPermitOnlyUsage")] // Use of PermitOnly here is appropriate. This was a previous war-approved security bug fix.
        internal static void Deserialize(Stream o, string cryptoKey, RuntimeLicenseContext context) {
            IFormatter formatter = new BinaryFormatter();
 
            object obj;
 
            new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).PermitOnly(); 
            new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).Assert();
            try { 
                obj = formatter.Deserialize(o);
            }
            finally {
                CodeAccessPermission.RevertAssert(); 
                CodeAccessPermission.RevertPermitOnly();
            } 
 
            if (obj is object[]) {
                object[] value = (object[])obj; 
                if (value[0] is string && (string)value[0] == cryptoKey) {
                    context.savedLicenseKeys = (Hashtable)value[1];
                }
            } 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.ComponentModel.Design { 
    using System.Runtime.Remoting; 
    using System.Runtime.Serialization.Formatters.Binary;
    using System.Runtime.Serialization; 
    using System.Security;
    using System.Security.Permissions;
    using System.Collections;
    using System.ComponentModel; 
    using System.Diagnostics;
    using System; 
    using Microsoft.Win32; 
    using System.IO;
    using System.Diagnostics.CodeAnalysis; 

    /// 
    ///    
    ///       Provides support for design-time license context serialization. 
    ///    
    ///  
    [HostProtection(SharedState = true)] 
    [System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.InheritanceDemand, Name = "FullTrust")]
    [System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name="FullTrust")] 
    public class DesigntimeLicenseContextSerializer {

        // not creatable...
        // 
        private DesigntimeLicenseContextSerializer() {
        } 
 
        /// 
        ///     
        ///       Serializes the licenses within the specified design-time license context
        ///       using the specified key and output stream.
        ///    
        ///  
        public static void Serialize(Stream o, string cryptoKey, DesigntimeLicenseContext context) {
            IFormatter formatter = new BinaryFormatter(); 
            formatter.Serialize(o, new object[] {cryptoKey, context.savedLicenseKeys}); 
        }
 
        [SuppressMessage("Microsoft.Security", "CA2107:ReviewDenyAndPermitOnlyUsage")] // Use of PermitOnly here is appropriate. This was a previous war-approved security bug fix.
        internal static void Deserialize(Stream o, string cryptoKey, RuntimeLicenseContext context) {
            IFormatter formatter = new BinaryFormatter();
 
            object obj;
 
            new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).PermitOnly(); 
            new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).Assert();
            try { 
                obj = formatter.Deserialize(o);
            }
            finally {
                CodeAccessPermission.RevertAssert(); 
                CodeAccessPermission.RevertPermitOnly();
            } 
 
            if (obj is object[]) {
                object[] value = (object[])obj; 
                if (value[0] is string && (string)value[0] == cryptoKey) {
                    context.savedLicenseKeys = (Hashtable)value[1];
                }
            } 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK