示例#1
0
        static void Main(string[] args)
        {
            try
            {
                Init();
                LexActivator.SetLicenseCallback(LicenseCallback);
                int status = LexActivator.IsLicenseGenuine();
                if (LexStatusCodes.LA_OK == status)
                {
                    Console.WriteLine("License is genuinely activated!");
                    uint expiryDate = LexActivator.GetLicenseExpiryDate();
                    int  daysLeft   = (int)(expiryDate - DateTimeOffset.Now.ToUnixTimeSeconds()) / 86400;
                    Console.WriteLine("Days left:" + daysLeft);

                    // Checking for software release update
                    // LexActivator.CheckForReleaseUpdate("windows", "1.0.0", "stable", SoftwareReleaseUpdateCallback);
                }
                else if (LexStatusCodes.LA_EXPIRED == status)
                {
                    Console.WriteLine("License is genuinely activated but has expired!");
                }
                else if (LexStatusCodes.LA_GRACE_PERIOD_OVER == status)
                {
                    Console.WriteLine("License is genuinely activated but grace period is over!");
                }
                else if (LexStatusCodes.LA_SUSPENDED == status)
                {
                    Console.WriteLine("License is genuinely activated but has been suspended!");
                }
                else
                {
                    int trialStatus;
                    trialStatus = LexActivator.IsTrialGenuine();
                    if (LexStatusCodes.LA_OK == trialStatus)
                    {
                        uint trialExpiryDate = LexActivator.GetTrialExpiryDate();
                        int  daysLeft        = (int)(trialExpiryDate - DateTimeOffset.Now.ToUnixTimeSeconds()) / 86400;
                        Console.WriteLine("Trial days left: " + daysLeft);
                    }
                    else if (LexStatusCodes.LA_TRIAL_EXPIRED == trialStatus)
                    {
                        Console.WriteLine("Trial has expired!");

                        // Time to buy the product key and activate the app
                        Activate();
                    }
                    else
                    {
                        Console.WriteLine("Either trial has not started or has been tampered!");
                        // Activating the trial
                        trialStatus = LexActivator.ActivateTrial(); // Ideally on a button click inside a dialog
                        if (LexStatusCodes.LA_OK == trialStatus)
                        {
                            uint trialExpiryDate = LexActivator.GetTrialExpiryDate();
                            int  daysLeft        = (int)(trialExpiryDate - DateTimeOffset.Now.ToUnixTimeSeconds()) / 86400;
                            Console.WriteLine("Trial days left: " + daysLeft);
                        }
                        else
                        {
                            // Trial was tampered or has expired
                            Console.WriteLine("Trial activation failed: " + trialStatus);
                        }
                    }
                }
            }
            catch (LexActivatorException ex)
            {
                Console.WriteLine("Error code: " + ex.Code.ToString() + " Error message: " + ex.Message);
            }
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }