Esempio n. 1
0
        /// <summary>
        /// Robustly parse simple license properties that return string values.
        ///
        /// http://msdn.microsoft.com/en-us/library/hh535287(v=vs.85).aspx#IPC_LI_CONTENT_ID
        /// http://msdn.microsoft.com/en-us/library/hh535287(v=vs.85).aspx#IPC_LI_OWNER
        /// http://msdn.microsoft.com/en-us/library/hh535287(v=vs.85).aspx#IPC_LI_REFERRAL_INFO_URL
        /// </summary>
        /// <returns>String description of the property</returns>
        private string getSimpleProperty(LicensePropertyType propertyType)
        {
            string returnValue;

            returnValue = "<" + propertyType.ToString() + " not present>";

            try
            {
                switch (propertyType)
                {
                case LicensePropertyType.ContentId:
                    returnValue = SafeNativeMethods.IpcGetSerializedLicenseContentId(FileLicense, KeyHandle);

                    break;

                case LicensePropertyType.Owner:
                    returnValue = SafeNativeMethods.IpcGetSerializedLicenseOwner(FileLicense);

                    break;

                case LicensePropertyType.ReferralInfoUrl:
                    returnValue = SafeNativeMethods.IpcGetSerializedLicenseReferralInfoUrl(FileLicense);

                    break;
                }
            }
            catch
            {
            }

            return(returnValue);
        }
        /// <summary>
        /// Robustly parse simple license properties that return string values.
        /// 
        /// http://msdn.microsoft.com/en-us/library/hh535287(v=vs.85).aspx#IPC_LI_CONTENT_ID
        /// http://msdn.microsoft.com/en-us/library/hh535287(v=vs.85).aspx#IPC_LI_OWNER
        /// http://msdn.microsoft.com/en-us/library/hh535287(v=vs.85).aspx#IPC_LI_REFERRAL_INFO_URL
        /// </summary>
        /// <returns>String description of the property</returns>
        private string getSimpleProperty(LicensePropertyType propertyType)
        {
            string      returnValue;

            returnValue = "<" + propertyType.ToString() + " not present>";

            try
            {
                switch(propertyType)
                {
                    case LicensePropertyType.ContentId:
                        returnValue = SafeNativeMethods.IpcGetSerializedLicenseContentId(FileLicense);

                        break;

                    case LicensePropertyType.Owner:
                        returnValue = SafeNativeMethods.IpcGetSerializedLicenseOwner(FileLicense);

                        break;

                    case LicensePropertyType.ReferralInfoUrl:
                        returnValue = SafeNativeMethods.IpcGetSerializedLicenseReferralInfoUrl(FileLicense);

                        break;
                }
            }
            catch
            {
            }

            return returnValue;
        }
        private static NameValueCollection IpcGetSerializedLicenseAppSpecificData(byte[] license, SafeInformationProtectionKeyHandle keyHandle, LicensePropertyType type)
        {
            NameValueCollection applicationSpecificData = new NameValueCollection();
            int hr = 0;

            IntPtr licenseInfoPtr = IntPtr.Zero;
            SafeIpcBuffer ipcBuffer = MarshalIpcBufferToNative(license);
            try
            {
                hr = UnsafeNativeMethods.IpcGetSerializedLicenseProperty(
                                (IpcBuffer)ipcBuffer,
                                (uint)type,
                                keyHandle,
                                0,
                                out licenseInfoPtr);
                ThrowOnErrorCode(hr);

                MarshalNameValueListToManaged(licenseInfoPtr, applicationSpecificData);
            }
            finally
            {
                UnsafeNativeMethods.IpcFreeMemory(licenseInfoPtr);
                ipcBuffer.Dispose();
            }

            return applicationSpecificData;
        }