Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / CompMod / System / ComponentModel / LicFileLicenseProvider.cs / 1 / LicFileLicenseProvider.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.ComponentModel { using System; using System.ComponentModel.Design; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.Remoting; using System.Security.Permissions; ////// /// [HostProtection(SharedState = true)] public class LicFileLicenseProvider : LicenseProvider { ///Provides an implementation of a ///. The provider works in /// a similar fashion to Microsoft .NET Framework standard licensing module. /// /// protected virtual bool IsKeyValid(string key, Type type) { if (key != null) { return key.StartsWith(GetKey(type)); } return false; } ///Determines if the key retrieved by the ///method is valid /// for the specified type. /// /// Creates a key for the specified type. /// protected virtual string GetKey(Type type) { // This string should not be localized. // return string.Format(CultureInfo.InvariantCulture, "{0} is a licensed component.", type.FullName); } ////// /// public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { LicFileLicense lic = null; Debug.Assert(context != null, "No context provided!"); if (context != null) { if (context.UsageMode == LicenseUsageMode.Runtime) { string key = context.GetSavedLicenseKey(type, null); if (key != null && IsKeyValid(key, type)) { lic = new LicFileLicense(this, key); } } if (lic == null) { string modulePath = null; if (context != null) { ITypeResolutionService resolver = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService)); if (resolver != null) { modulePath = resolver.GetPathOfAssembly(type.Assembly.GetName()); } } if (modulePath == null) { modulePath = type.Module.FullyQualifiedName; } string moduleDir = Path.GetDirectoryName(modulePath); string licenseFile = moduleDir + "\\" + type.FullName + ".lic"; Debug.WriteLine("Looking for license in: " + licenseFile); if (File.Exists(licenseFile)) { Stream licStream = new FileStream(licenseFile, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(licStream); string s = sr.ReadLine(); sr.Close(); if (IsKeyValid(s, type)) { lic = new LicFileLicense(this, GetKey(type)); } } if (lic != null) { context.SetSavedLicenseKey(type, lic.LicenseKey); } } } return lic; } private class LicFileLicense : License { private LicFileLicenseProvider owner; private string key; public LicFileLicense(LicFileLicenseProvider owner, string key) { this.owner = owner; this.key = key; } public override string LicenseKey { get { return key; } } public override void Dispose() { } } } }Gets a license for the instance of the component and determines if it is valid. ///
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- UpdatePanelTrigger.cs
- OracleTransaction.cs
- TdsParserStateObject.cs
- TextBoxBase.cs
- UnmanagedMemoryStreamWrapper.cs
- DataGridViewCellStateChangedEventArgs.cs
- EdmItemCollection.cs
- basevalidator.cs
- ResourcePool.cs
- IArgumentProvider.cs
- ValidationSummary.cs
- DataMemberConverter.cs
- FileAuthorizationModule.cs
- Int32Converter.cs
- UInt64.cs
- DbXmlEnabledProviderManifest.cs
- DescendantQuery.cs
- WebExceptionStatus.cs
- StringAnimationBase.cs
- DrawingImage.cs
- RepeatBehavior.cs
- MatchingStyle.cs
- ImageList.cs
- SqlColumnizer.cs
- ExtendedPropertyDescriptor.cs
- SqlRowUpdatedEvent.cs
- DynamicRenderer.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- DesignerResources.cs
- ModuleElement.cs
- ApplicationHost.cs
- WebZone.cs
- XPathParser.cs
- DocumentXmlWriter.cs
- SecurityDocument.cs
- ProfileService.cs
- CSharpCodeProvider.cs
- TabItem.cs
- HuffmanTree.cs
- KeyValueSerializer.cs
- ChangeTracker.cs
- FrameworkElementAutomationPeer.cs
- IdentifierCreationService.cs
- SqlDataReader.cs
- SqlLiftWhereClauses.cs
- DependencyPropertyHelper.cs
- DragStartedEventArgs.cs
- BamlRecordHelper.cs
- StringValueSerializer.cs
- BehaviorEditorPart.cs
- NamedPipeTransportManager.cs
- SynchronizationLockException.cs
- _ChunkParse.cs
- RepeaterItem.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- DataControlFieldHeaderCell.cs
- AutoGeneratedField.cs
- PropertyValueUIItem.cs
- ProcessModelSection.cs
- TypographyProperties.cs
- TagPrefixAttribute.cs
- ColorEditor.cs
- CngKey.cs
- ContextMenu.cs
- TypeDefinition.cs
- HelloOperation11AsyncResult.cs
- securitycriticaldataClass.cs
- MissingManifestResourceException.cs
- XmlNamedNodeMap.cs
- DataReceivedEventArgs.cs
- OutputScopeManager.cs
- ArgumentException.cs
- SendMailErrorEventArgs.cs
- TextElementCollectionHelper.cs
- PathSegmentCollection.cs
- Base64Decoder.cs
- AttachedAnnotationChangedEventArgs.cs
- DataIdProcessor.cs
- VirtualPath.cs
- SafeLibraryHandle.cs
- GeneralTransform2DTo3DTo2D.cs
- URIFormatException.cs
- ComponentResourceManager.cs
- TimerEventSubscriptionCollection.cs
- SafeHandles.cs
- SelectionHighlightInfo.cs
- ButtonChrome.cs
- ClientRuntimeConfig.cs
- NavigationHelper.cs
- ThrowHelper.cs
- SizeLimitedCache.cs
- WpfXamlType.cs
- RowTypeElement.cs
- MenuCommands.cs
- UnmanagedMemoryStreamWrapper.cs
- EntityDataSourceSelectingEventArgs.cs
- CircleHotSpot.cs
- XmlValidatingReader.cs
- XmlSchemaSequence.cs
- MachineSettingsSection.cs