Example #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!File.Exists(txtProductLicense.Text))
            {
                MessageBox.Show("Please select an existing file.", msgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //
            // Validate the product license
            //
            CryptoLicense license = ProductLicense.Methods.CreateLicense();

            license.StorageMode     = LicenseStorageMode.ToFile;
            license.FileStoragePath = txtProductLicense.Text;

            // Load the license from file
            if (license.Load())
            {
                if (license.Status != LicenseStatus.Valid)
                {
                    MessageBox.Show("ConfigOS Foundry license validation failed.\nThe application will be closed.\n" + license.GetAllStatusExceptionsAsString() + "\nPlease select a correct license file and restart the application.", msgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    license.Dispose();
                    Process.GetCurrentProcess().Kill();
                }
                else
                {
                }
            }
            else
            {
                MessageBox.Show("ConfigOS Foundry license not found.\nThe application will be closed.", msgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                license.Dispose();
                Process.GetCurrentProcess().Kill();
            }
            //
            //
            // Copy the existing Foundrykey to the application folder
            try
            {
                File.Copy(txtProductLicense.Text, prouctLicensePath, true);
            }
            catch (Exception err)
            {
                MessageBox.Show("The ConfigOS Foundry license was not successfully copied to the ConfigOS Foundry application folder.\nThe application will be closed." + err.Message, msgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                Process.GetCurrentProcess().Kill();
            }
            this.Close();
        }
Example #2
0
        private void btnValidate_Click(object sender, EventArgs e)
        {
            if (DateTime.Now.ToShortDateString() == GetNistTime().ToShortDateString())
            {
                license.LicenseCode = txtValidation.Text.Trim();

                if (license.HasHostAssemblyName)
                {
                    if (license.HostAssemblyName.ToString() != "Manifest")
                    {
                        MessageBox.Show("هویت فعالساز مورد نظر با برنامه مغایرت دارد");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("هویت فعالساز مورد نظر تایید نشد");
                    return;
                }

                if (license.Status == LicenseStatus.InstancesExceeded)
                {
                    MessageBox.Show("تعداد دفعات نصب تمام شده است");
                    return;
                }


                if (license.Status == LicenseStatus.Valid)
                {
                    license.StorageMode = LicenseStorageMode.ToRegistry;
                    license.Save();
                    MessageBox.Show("برنامه با موفقیت فعال شد");
                    Hide();
                    Application.Restart();
                }
                else
                {
                    license.Remove();
                    MessageBox.Show("کد فعال سازی معتبر نمی باشد");
                    txtValidation.Text = string.Empty;
                }
                license.Dispose();
            }
            else  //Date is not OK
            {
                MessageBox.Show("امکان فعال سازی برنامه بدون اتصال به اینترنت میسر نیست");
                return;
            }
        }
Example #3
0
        private void A()
        {
            var A = new CryptoLicense
            {
                StorageMode = LicenseStorageMode.ToRegistry
            };

            A.ValidationKey = "AAAGgAGk/ESIIO4iJmXxVD/yH4xiLHGJIczm6SCvCAW157h/ew7tiYv/WJW0ug9nic4mf6y5GRywt0rBrFBL80Rb5otI+3AM79U669OUUIcdgP0tqaNSMUbAbLqXn6E/jispyo+R1LyUeKhNgk30iNJnto3C9LP6ASrQNA7jDWSQLWyrw94ztXc2vXSzzzpaRD0Jb3zWEqI9YY7QapnHMa/v0XI7pvK6aq46zgeZUP90yDbiHZjL7GU7R0qJOz8p3zI+6XPPKBohdfin9DcZ6QPJr9utB39wIJU6Mdx4i0acabWCGo1QeAmdUJ8Hvsc2EZ5Dpw0fFt2VfET4upf48aVpsx810oFJb4W70Y7+li5IO8Th9vcREF7OGaB1UasOppI5LCSEdgkv48r9PGldmkE58nAKjEBSp3MNVvhONMZrMPmozU/8YXttYEfmOxA7+5AaDLzJyJV5S38XC+4/0r7jOnezUggFGqjJ4gJIRXFHVMCcc8cRDQojYWzmKYloNF+2FlUDAAEAAQ==";
            if (!A.Load())
            {
                A.LicenseCode = "FgIkgTXjr2eZvNMBHgABbu29HnCHi267VJes6C+npz2IlKXxf3y6jv5STVfbfl6rU0s5pSByRT4ZclC9HYDwFg9TkLeIbowTpMNu+EFBVTILkovs7LfCIizYUZsfriR0sArMQCPzk5gP2dOdCK3Z+AyuovflkfissyJ+KAjDBYshohQ4yZdHIjPUhxA+TLc6mXv+GQTyrfFK/M1AFbJzj1km0UoeMhjRZ9SI2kh3bv5/QI8o18h9Fysa3aFRcVlGIi1ADHZGbcQK8XFzbicIyh1IVPoSRNtMzE3GeOQdzPL6YybM4+YQNIC+/yodUXbGUr9ldkMqTK7UoYtgTrTOgqJTOD/rPQrRQe4q5A40ZMSXtGu06tiZl+rfGzwlt9Aaalx8DGkV7Aixy2MGDNIxkVxIsVdmSP/BXLs9Qp8lPWpAGHG0nYZZr8iGNa9tpZ27lypQFrJdyrlYhL72vhcNlDSleR7Zn3AvyGJIvkKmzXwu/0f5bW/DAnhY7N49TmsR8LEjl7VHUallQ5ONI7iZ";
                A.Save();
            }

            if (!A.ShowEvaluationInfoDialog("Satış", "https://www.facebook.com/profile.php?id=100002547964778"))
            {
                Shutdown();
            }
            A.Dispose();
        }
Example #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            bool bLicOk = false;

            if (string.IsNullOrEmpty(textBoxLic.Text))
            {
                MessageBox.Show(ResStrings.str_Enter_a_License, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            CryptoLicense testLic = new CryptoLicense();

            testLic.ValidationKey = _validationKey;
            testLic.StorageMode   = LicenseStorageMode.ToRegistry;
            testLic.LicenseCode   = textBoxLic.Text;

            if (testLic.HasUserData)
            {
                Hashtable dataFields       = testLic.ParseUserData("#");
                string    licenseMachineId = dataFields["MachineID"] as string;
                string    machineId        = labelMachineID.Text;
                bLicOk = machineId.Equals(licenseMachineId);
            }

            if (bLicOk)
            {
                testLic.Save();
                lic.Load();
                UpdateLicence();
                MessageBox.Show(ResStrings.str_License_Info_Saved, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                textBoxLic.Text = string.Empty;
                MessageBox.Show(ResStrings.str_Not_a_valid_license_for_this_machine, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            testLic.Dispose();
        }
Example #5
0
        public bool EvaluateLicense()
        {
            /*
             * This code demonstrates typically evaluation license scenario. The idea is as follows....
             * First you check if a full license is present (using CryptoLicense.Load method).
             * If .Load returns false, you switch to a hardcoded evaluation license code (using .LicenseCode property).
             * Then, you validate using .Status property.
             *
             * Even if user uninstalls, all the usage data associated which each license code remains in the
             * registry and if user reinstalls, the evaluation continues from where it left off.
             */
            var licenseValid = false;

            CryptoLicense license = CreateLicense();

            // The license will be loaded from/saved to the registry
            license.StorageMode = LicenseStorageMode.ToRegistry;

            // To avoid conflicts with other scenarios from this sample, the default load/save registry key is changed
            license.RegistryStoragePath = license.RegistryStoragePath + "EvalLicense";

            // The remove method can be useful during development and testing - it deletes a previously saved license.
            //license.Remove();

            // Another useful method during development and testing is .ResetEvaluationInfo()



            // Load the license from the registry
            bool loadDialog = !license.Load() || license.Status != LicenseStatus.Valid;

            if (loadDialog)
            {
                string dialogMessage = !license.Load()?"Licensing missing, enter the license key": license.Status != LicenseStatus.Valid?"Licensing expired, enter a new license key": "Licensing missing, enter the license key";
                // When app runs for first time, the load will fail, so specify an evaluation code....
                // This license code was generated from the Generator UI with a "Limit Usage Days To" setting of 30 days.
                LicenseForm licenseForm = new LicenseForm();
                licenseForm.labelMessage.Text = dialogMessage;
                if (licenseForm.ShowDialog() == DialogResult.OK)
                {
                    string licenseKey = licenseForm.textBoxLicense.Text;
                    license.LicenseCode = licenseKey;
                    // Save it so that it will get loaded the next time app runs


                    if (license.Status != LicenseStatus.Valid)
                    {
                        licenseValid = false;
                    }
                    else
                    {
                        license.Save();
                        licenseValid = true;
                    }
                }
                else
                {
                    Environment.Exit(0);
                }
            }

            if (license.Status != LicenseStatus.Valid)
            {
                licenseValid = false;
            }
            else
            {
                licenseValid = true;
            }



            return(licenseValid);

            // ShowEvaluationInfoDialog shows the dialog only if the license specifies evaluation limits
            if (license.ShowEvaluationInfoDialog("GrabCaster", "http://www.grabcaster.io") == false)
            {
                // license has expired, new license entered is also expired
                // or user choose the 'Exit Program' option
                licenseValid = false;

                // In your app, you may wish to exit app when eval license has expired
                Application.Exit();
            }
            else
            {
                // The current license is valid or the new license entered is valid
                // or the user choose the 'Continue Evaluation' option

                // If the user enters a new valid license code, it replaces the existing code
                // and is automatically saved to the currently specified
                // storage medium (registry in this sample) using the CryptoLicense.Save method.
                // The new license code is thus available the next time your software runs.

                // We still need to check whether the license is an evaluation license
                if (license.IsEvaluationLicense() == true)
                {
                    // reduce functionality in evaluation version if so desired
                    licenseValid = true;
                }
            }

            license.Dispose(); // Be sure to call Dispose during app exit or when done using the CryptoLicense object
            return(licenseValid);
        }
Example #6
0
        public bool CryptoLicensing(bool IsNewLic = false)
        {
            if (IsNewLic)
            {
                try
                {
                    int days = manifestWS.ValidateDays(Properties.Settings.Default.LineCode);
                    //Console.WriteLine("Days:"+days.ToString());
                    if (days > 0)
                    {
                        if (Properties.Settings.Default.OfflineCount != 0)
                        {
                            Properties.Settings.Default.OfflineCount = 0;
                            Properties.Settings.Default.Save();
                        }
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch
                {
                    Properties.Settings.Default.OfflineCount += 1;
                    Properties.Settings.Default.Save();

                    if (Properties.Settings.Default.OfflineCount < 5)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                try
                {
                    license = new CryptoLicense
                    {
                        ValidationKey = ValidationKey,
                        StorageMode   = LicenseStorageMode.ToRegistry
                    };

                    if (!license.Load())
                    {
                        return(false);
                    }

                    if (license.Status == LicenseStatus.Valid)
                    {
                        //if (license.HasUserData)
                        //{
                        //    string aaa = license.ParseUserData("#")["linecode"].ToString();
                        //    MessageBox.Show(aaa);
                        //}
                        //Read information from lock every time execute program
                        Properties.Settings.Default.LineCode = license.UserData.Split('#')[0].Split('=')[1].ToString();
                        Properties.Settings.Default.Company  = license.UserData.Split('#')[1].Split('=')[1].ToString();
                        //Properties.Settings.Default.Save();
                        return(true);
                    }
                    else
                    {
                        license.Remove();
                        return(false);
                    }
                }
                catch (Exception)
                {
                    return(false);

                    throw;
                }
                finally
                {
                    license.Dispose();
                }
            }
        }
Example #7
0
 private bool DumpFloatingLicense(CryptoLicense license)
 {
     license.Dispose();
     license = null;
     return(true);
 }
        private void OnCheckKey()
        {
            try
            {
                //Show wait screen
                ServiceLocator.Current.GetInstance <RIS.Views.WaitSplashScreen>().Show();

                // Create temp cryptoLicense object
                CryptoLicense _temp = Activator.CreateInstance(cryptoLicense.GetType()) as CryptoLicense;
                _temp.StorageMode       = cryptoLicense.StorageMode;
                _temp.ValidationKey     = cryptoLicense.ValidationKey;
                _temp.LicenseServiceURL = cryptoLicense.LicenseServiceURL;
                _temp.HostAssembly      = cryptoLicense.HostAssembly;
                _temp.LicenseServiceSettingsFilePath = cryptoLicense.LicenseServiceSettingsFilePath;
                _temp.RegistryStoragePath            = cryptoLicense.RegistryStoragePath;
                _temp.FileStoragePath = cryptoLicense.FileStoragePath;

                //Check if internet connection to cryptoLicenseService is working
                if (_temp.PingLicenseService() != null)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show("Leider ist der Lizenzserver nicht erreichbar.\nUm Ihre Lizenz zu aktivieren, wird eine funktionierende Internetverbindung benötigt.", "RescueInformationSystem - ERROR", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    return;
                }

                // See if its a serial
                SerialValidationResult result = _temp.GetLicenseFromSerial(this.LicenseInput_Key, string.Empty);
                if (result == SerialValidationResult.Failed)
                {
                    // Its a serial, but is invalid
                    string    str = "Serial Überprüfung fehlgeschlagen: ";
                    Exception ex  = _temp.GetStatusException(LicenseStatus.SerialCodeInvalid);
                    if (ex != null) // Additional info available for the status
                    {
                        str += ex.Message;
                    }
                    else
                    {
                        str += "<no additional information>";
                    }

                    Xceed.Wpf.Toolkit.MessageBox.Show("Es ist ein Fehler aufgetreten: " + str, "RescueInformationSystem - ERROR", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    return;
                }

                // Not a serial, set .LicenseCode property
                if (result == SerialValidationResult.NotASerial)
                {
                    _temp.LicenseCode = this.LicenseInput_Key;
                }

                // Validate cryptoLicense
                if (_temp.Status == LicenseStatus.Valid)
                {
                    // Valid , dispose old cryptoLicense, replace with 'temp' cryptoLicense
                    cryptoLicense.Dispose();
                }

                //Close wait screen
                ServiceLocator.Current.GetInstance <RIS.Views.WaitSplashScreen>().Close();

                //Show result
                if (_temp.Status != LicenseStatus.Valid)
                {
                    string    additional = "Error code: " + _temp.Status.ToString();
                    Exception ex         = _temp.GetStatusException(_temp.Status);
                    if (ex != null)
                    {
                        additional += ". Error message: " + ex.Message;
                    }

                    Xceed.Wpf.Toolkit.MessageBox.Show("Die eingegebene Lizenz war leider ungültig. Bitte geben Sie einen gültigen Lizenzkey ein und versuchen es erneut.\n" + additional, "RescueInformationSystem - ERROR", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    return;
                }
                else
                {
                    cryptoLicense.Save();
                    this.IsLicenseValid = true;
                    this.ParseLicenseInfosForThanks();
                    this.CurrentUserControl = new Views.LicenseThanksUserControl();
                }
            }
            catch (Exception ex)
            {
                SRS.Utilities.Logger.Instance.WriteError(System.Reflection.MethodBase.GetCurrentMethod(), ex);
            }
            finally
            {
                ServiceLocator.Current.GetInstance <RIS.Views.WaitSplashScreen>().Close();
            }
        }