コード例 #1
0
        /// <summary>
        ///    <para>Gets a license for the instance of the component and determines if it is valid.</para>
        /// </summary>
        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);
        }
コード例 #2
0
        /// <summary>
        ///    <para>Gets a license for the instance of the component and determines if it is valid.</para>
        /// </summary>
        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;
        }
コード例 #3
0
        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            LicFileLicense license = null;

            if (context != null)
            {
                if (context.UsageMode == LicenseUsageMode.Runtime)
                {
                    string savedLicenseKey = context.GetSavedLicenseKey(type, null);
                    if ((savedLicenseKey != null) && this.IsKeyValid(savedLicenseKey, type))
                    {
                        license = new LicFileLicense(this, savedLicenseKey);
                    }
                }
                if (license != null)
                {
                    return(license);
                }
                string path = null;
                if (context != null)
                {
                    ITypeResolutionService service = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService));
                    if (service != null)
                    {
                        path = service.GetPathOfAssembly(type.Assembly.GetName());
                    }
                }
                if (path == null)
                {
                    path = type.Module.FullyQualifiedName;
                }
                string str4 = Path.GetDirectoryName(path) + @"\" + type.FullName + ".lic";
                if (File.Exists(str4))
                {
                    Stream       stream = new FileStream(str4, FileMode.Open, FileAccess.Read, FileShare.Read);
                    StreamReader reader = new StreamReader(stream);
                    string       key    = reader.ReadLine();
                    reader.Close();
                    if (this.IsKeyValid(key, type))
                    {
                        license = new LicFileLicense(this, this.GetKey(type));
                    }
                }
                if (license != null)
                {
                    context.SetSavedLicenseKey(type, license.LicenseKey);
                }
            }
            return(license);
        }