Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Authenticated Control

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Licensing Support
View previous topic :: View next topic  
Author Message
Andy500



Joined: 24 Sep 2010
Posts: 11

PostPosted: Wed Nov 03, 2010 10:56 pm    Post subject: Authenticated Control Reply with quote

In your samples, you have a demo for a Licensed control (not authenticated) - can you provide a C# demo showing how to do authentication with a control? This of course should be such that the control doesn't ask to be relicensed for each application it is used in.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Nov 04, 2010 9:49 pm    Post subject: Reply with quote

The logic would be exactly the same for an authenticated control licensing except that instead of using the EncryptedLicenseProvider you use the AuthenticatedLicenseProvider. I have converted the sample control class code below to illustrate.

Note that one potential issue with using Authenticated Licensing for controls is that because the authentication mechanism uses web services it requires the Full .NET Framework to be installed (ie not just the client profile). This wouldn't be a problem for developers (who would always have the full framework installed), however Visual Studio will not allow projects to target the client profile if they reference assemblies that use System.Web. This means that you would be requiring your clients applications to use the full framework. If this is OK then there is not an issue.

Code:
    /// <summary>
    /// Sample Control which illustrates using the Infralution Licensing System (ILS) to license a control
    /// </summary>
    /// <remarks>
    /// To test the control licensing:
    /// 1.  Build this project
    /// 2.  Copy the output DLL into the GAC (typically C:\Windows\assembly) using Windows Explorer
    /// 3.  Create a test WindowsApplication project
    /// 4.  Add the DLL to the IDE toolbox (using Add/Remove items)   
    /// 5.  Drag the control onto the form (this should display the license install form)
    /// 6.  Generate a license key using the License Key Generator (the product password is "TEST")
    /// </remarks>
    [LicenseProvider(typeof(Infralution.Licensing.AuthenticatedLicenseProvider))]
    public class MyControl : System.Windows.Forms.UserControl
    {

        /// <summary>
        /// License Validation Parameters String copied from the License Key Generator
        /// </summary>
          const string LICENSE_PARAMETERS =
            @"<AuthenticatedLicenseParameters>
                 <EncryptedLicenseParameters>
                   <ProductName>My Product</ProductName>
                   <RSAKeyValue>
                     <Modulus>zX4VW8ukM8aBMgIeYOhBsH6s+UlbYM3jv3kGy59NA5vBDxa
                        CRclowIXkHC+Ue+ua0am7brgWss/N7PetcaleXWUJacRaisC5yjl3W
                        K2UWoPQ37HjKijXM++eCOq+mEProZYO7Ux2Q8aA13glAXn5Ry9OePA
                        3YmD4f+658k0x1AE=</Modulus>
                     <Exponent>AQAB</Exponent>
                   </RSAKeyValue>
                   <DesignSignature>VyWFO92791568I4C/iw5bNi8y4yhv0GE4/m+5MWMs
                        AlOdIe7GWr3v57rxtMo9iPyfMyHJhLLJHBkuANsI0gWUiaAfyMhpHd
                        M893mkc4PEz8KS+ZSvUCVklNWiPWPQUT0cDd6FSxCVjujBoZmIGYe4
                        KglA8vjd2YxtHm7ZgTPYG4=</DesignSignature>
                   <RuntimeSignature>YCO+TnF/qnmLuY+NiINXPal3uSZiBuCvlI6RUDts
                        oVxSV5eld0P4ava+m9+viKYMBLd/tOIiNH+Jh1ZQIMeWtDNndxyoRr
                        2S1eRp0fb5XYHk8bvUUJB81a9eSrJ366YgZwzXuL2oNw4hilZBQCgU
                        gDWEwD4c2meD0dkE5MkTOdI=</RuntimeSignature>
                   <KeyStrength>7</KeyStrength>
                   <ShortSerialNo>False</ShortSerialNo>
                 </EncryptedLicenseParameters>
                 <AuthenticationServerURL>http://localhost:2142/AuthenticationService.asmx</AuthenticationServerURL>
                 <ServerRSAKeyValue>
                   <Modulus>1jNA0H1IvMUmotD8SFWEmG8DyOH9RDabaiikStpysvuZC2uj9
                        +te/VpjL0OEvW+MZ7beUxoaSHp7vp5WGfxF75axnWshnrMpo620/Cz
                        C+pd8xl1t2/EQ3r9OLGjY1Qt+G6BduWJ4kHQrddfEfx9LjWZycmRBa
                        LxHF0VxKBG0Ucs=</Modulus>
                   <Exponent>AQAB</Exponent>
                 </ServerRSAKeyValue>
               </AuthenticatedLicenseParameters>";

        /// <summary>
        /// The license context last time we checked the license
        /// </summary>
        /// <remarks>
        /// This is used to reduce the number of times the license check needs to be done.
        /// If your control is likely to be used in multiple places (eg like a text box) then checking the license each
        /// time a control is created can be very annoying when in evaluation mode.
        /// </remarks>
        static LicenseContext _lastDesignContext = null;
        static bool _licenseChecked = false;
               
        /// <summary>
        /// Control constructor - checks for a valid license key
        /// </summary>                                                                                                                                                                                                                                                 
        public MyControl()
        {
            InitializeComponent();

            // set the parameters used to validate the license
            //
            AuthenticatedLicenseProvider.SetParameters(LICENSE_PARAMETERS);
            if (LicenseManager.CurrentContext.UsageMode == LicenseUsageMode.Designtime)
            {
                // at design time we must check the license every time or else our license may not
                // get compiled into the application resources
                //
                if (!LicenseManager.IsLicensed(typeof(MyControl)))
                {
                    // only show the evaluation dialog if we haven't already done so for this form
                    //
                    if (LicenseManager.CurrentContext != _lastDesignContext)
                    {
                        // Display the evaluation dialog until the user installs a license or
                        // selects Exit or Continue
                        //
                        AuthenticatedLicense license = null;
                        while (license == null)
                        {
                            EvaluationMonitor evaluationMonitor = new RegistryEvaluationMonitor("MyControlEvaluationPassword");
                            EvaluationDialog evaluationDialog = new EvaluationDialog(evaluationMonitor, "My Control");
                            EvaluationDialogResult dialogResult = evaluationDialog.ShowDialog();
                            if (dialogResult == EvaluationDialogResult.Exit)
                                throw new LicenseException(typeof(MyControl), this, "Control not Licensed");
                            if (dialogResult == EvaluationDialogResult.Continue) break; // exit the loop
                            if (dialogResult == EvaluationDialogResult.InstallLicense)
                            {
                                AuthenticatedLicenseInstallForm licenseForm = new AuthenticatedLicenseInstallForm();
                                license = licenseForm.ShowDialog("My Control", typeof(MyControl), null);
                            }
                        }
                        _lastDesignContext = LicenseManager.CurrentContext;
                    }
                }
            }
            else
            {
                // at runtime only check the license if we haven't already done so
                //
                if (!_licenseChecked)
                {
                    // show a nag screen if the control is not licensed
                    //
                    if (!LicenseManager.IsLicensed(typeof(MyControl)))
                    {
                        MessageBox.Show("This application was created using an unlicensed version of MyControl", "Unlicensed Application");
                    }
                }
            }
            _licenseChecked = true;;
        }


        #region Component Designer generated code

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;
        protected System.Windows.Forms.Label _labelControl;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
     
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this._labelControl = new System.Windows.Forms.Label();
            this.SuspendLayout();
            //
            // _labelControl
            //
            this._labelControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this._labelControl.Dock = System.Windows.Forms.DockStyle.Fill;
            this._labelControl.Location = new System.Drawing.Point(0, 0);
            this._labelControl.Name = "_labelControl";
            this._labelControl.Size = new System.Drawing.Size(150, 150);
            this._labelControl.TabIndex = 1;
            this._labelControl.Text = "My Control";
            this._labelControl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            // MyControl
            //
            this.Controls.Add(this._labelControl);
            this.Name = "MyControl";
            this.ResumeLayout(false);

        }
        #endregion
    }

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Licensing Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group