Esempio n. 1
0
        private void ManageLicense_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var lic = DemoLicense.GetLicenseFromFile(DemoLicense.LicenseFilePath);
                if (lic == null)
                {
                    MessageBox.Show("Error! No license found. Please create a license first.");
                    return;
                }

                ChangeLicenseDialog diag = new ChangeLicenseDialog(lic);
                var host = new Window();
                host.Title   = "License Manager";
                host.Width   = 460;
                host.Height  = 600;
                host.Content = diag;
                host.ShowDialog();
                if (diag.License != null)
                {
                    _license = diag.License;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void Export_Click(object sender, RoutedEventArgs e)
        {
            if (License == null)
            {
                License = DemoLicense.GetLicenseFromFile(DemoLicense.LicenseFilePath);
            }

            if (License == null)
            {
                MessageBox.Show("Nothing to export!");
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName         = $"License{DemoLicense.LicenseFileExtention}r";
            dlg.Filter           = $"{DemoLicense.LicenseFileDescription} request files (*{DemoLicense.LicenseFileExtention}r)|*{DemoLicense.LicenseFileExtention}r|All files (*.*)|*.*";
            dlg.FilterIndex      = 2;
            dlg.RestoreDirectory = true;
            dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            var result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {                // Save document
                License.SaveLicense(dlg.FileName);
            }
        }
Esempio n. 3
0
        private void Btn_Manage_Click(object sender, EventArgs e)
        {
            try
            {
                var lic = DemoLicense.GetLicenseFromFile(DemoLicense.LicenseFilePath);
                if (lic == null)
                {
                    MessageBox.Show("Error! No license found. Please create a license first.");
                    return;
                }

                var  licenseManager = new LicenseManagerUserControl(lic);
                Form window         = new Form
                {
                    Text            = "License Manager",
                    TopLevel        = true,
                    FormBorderStyle = FormBorderStyle.Fixed3D, //Disables user resizing
                    MaximizeBox     = false,
                    MinimizeBox     = false,
                    ClientSize      = licenseManager.Size //size the form to fit the content
                };
                window.Controls.Add(licenseManager);
                licenseManager.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
                window.ShowDialog();

                if (licenseManager.License != null)
                {
                    _license = licenseManager.License;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 4
0
 private void GetTimeLeftTimer_Tick(object sender, EventArgs e)
 {
     _license = DemoLicense.GetLicenseFromFile(DemoLicense.LicenseFilePath);
     if (_license == null)
     {
         Lb_TimeLeft.Content = "PLEASE CREATE A LICENSE FILE";
     }
     else
     {
         Lb_TimeLeft.Content = $"Time left: {Validator.GetTimeLeftReadableString(_license)}";
     }
 }
Esempio n. 5
0
        private void CreateLicense_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var lic = DemoLicense.GetLicenseFromFile(DemoLicense.LicenseFilePath);
                if (lic == null)
                {
                    //Get timestamp from registry to avoid re-starting the trial
                    long unixTimeMillis = DemoLicense.GetUnixTimestampOfLicenseCreation();

                    lic = new DemoLicense()
                    {
                        //ORBNNET License SDK mandatory fields
                        ClientName   = "<Enter your company name here>",
                        DaysAllowed  = 30,
                        MachineId    = Validator.GetUniqueMachineId(),
                        ClientId     = Guid.NewGuid().ToString(),
                        ClientNumber = unixTimeMillis,
                        //DemoLicense custom fields
                        //Use these to limit features in your application.
                        DemoBoolValue     = true,
                        DemoIntValue      = 42,
                        DemoFloatValue    = 1.618034f,
                        DemoEnumChoice    = DemoLicense.DemoEnum.Three,
                        DemoListOfStrings = new List <string>()
                        {
                            "192.168.1.1",
                            "192.168.1.2",
                            "192.168.1.3",
                        },
                    };
                    lic.SaveLicense(DemoLicense.LicenseFilePath);
                    _license = lic;
                    MessageBox.Show($"A 30 day license has been activated! Please enter your company name into the license, export it and get it activated for permanent use. Note: If you are upgrading from an older version your trial will not be reset.");
                }
                else
                {
                    WriteLog($"License already exists in {DemoLicense.LicenseFilePath}. A new license will only be created if the existing license is deleted.");
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show($"Error generating license file!: " + ex.ToString());
            }
        }
        private void Button_Load_Click(object sender, EventArgs e)
        {
            string         path;
            OpenFileDialog file = new OpenFileDialog();

            if (file.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    path    = file.FileName;
                    License = DemoLicense.GetLicenseFromFile(path);
                    propertyGrid1.SelectedObject = License;

                    return;
                }
                catch { }
            }
        }
Esempio n. 7
0
        public MainWindow()
        {
            InitializeComponent();

            DemoLicense.LicenseTrialTerminated += DemoLicense_LicenseTrialTerminated;
            DemoLicense.LicenseLogEntry        += DemoLicense_LicenseLogEntry;

            DemoLicense.InitializeSDK();

            _getTimeleftTimer.Tick    += GetTimeLeftTimer_Tick;
            _getTimeleftTimer.Interval = new TimeSpan(0, 0, 1);
            _getTimeleftTimer.Start();

            try
            {
                WriteLog($"Attempting to load license from {DemoLicense.LicenseFilePath}");
                _license = DemoLicense.GetLicenseFromFile(DemoLicense.LicenseFilePath);

                if (_license != null)
                {
                    var licenseStatus = _license.CheckLicense();
                    if (licenseStatus == DemoLicense.LicenseStatus.ValidNoTimeRestriction)
                    {
                        Lb_TimeLeft.Content = $"LICENSE IS VALID WITH NO TIME RESTRICTIONS";
                        _getTimeleftTimer.Stop();
                    }
                    else if (licenseStatus == DemoLicense.LicenseStatus.TrialStillActive)
                    {
                        WriteLog($"Your license has not been validated, you are running a trial of {_license.DaysAllowed} days.");
                    }
                    else if (licenseStatus == DemoLicense.LicenseStatus.NotValid || licenseStatus == DemoLicense.LicenseStatus.TrialTerminated)
                    {
                        WriteLog($"License needs validation.");
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog($"{ex}");
            }
        }
        /// <summary>
        /// This could be used to create a test license. It would have to be run on the local host where the license would end up so that the Machine Id match.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_CreateTestLicense_Click(object sender, EventArgs e)
        {
            var License = new DemoLicense();

            License.ClientName  = _testLicenseClientName;
            License.ClientId    = Guid.NewGuid().ToString();
            License.DaysAllowed = 30;
            License.GenerateMachineId();
            License.Hash = string.Empty;

            SaveFileDialog savefile = new SaveFileDialog();

            // set a default file name
            savefile.FileName = $"License{DemoLicense.LicenseFileExtention}r";
            // set filters - this can be done in properties as well
            savefile.Filter = $"{DemoLicense.LicenseFileDescription} Request files (*{DemoLicense.LicenseFileExtention}r)|*{DemoLicense.LicenseFileExtention}r|All files (*.*)|*.*";

            if (savefile.ShowDialog() == DialogResult.OK)
            {
                License.SaveLicense(savefile.FileName);
            }
        }
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            string         pathToFile = "";
            OpenFileDialog dlg        = new OpenFileDialog();

            dlg.Filter           = $"{DemoLicense.LicenseFileDescription} files (*{DemoLicense.LicenseFileExtention})|*{DemoLicense.LicenseFileExtention}|All files (*.*)|*.*";
            dlg.FilterIndex      = 1;
            dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var result = dlg.ShowDialog();

            if (result == true)
            {
                pathToFile = dlg.FileName;
            }
            if (File.Exists(pathToFile))// only executes if the file at pathtofile exists//you need to add the using System.IO reference at the top of te code to use this
            {
                try
                {
                    License = DemoLicense.GetLicenseFromFile(pathToFile);

                    if (Validator.CheckLicense(License, Validator.GetUniqueMachineId()))
                    {
                        MessageBox.Show("License is valid.");
                        License.SaveLicense(DemoLicense.LicenseFilePath);
                        PropertyGrid.SelectedObject = License;
                        MessageBox.Show($"License Activated!\nSaved to: {DemoLicense.LicenseFilePath}");
                    }
                    else
                    {
                        throw new Exception("License not valid.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + " Something went wrong, sorry.");
                }
            }
        }
 public ChangeLicenseDialog(DemoLicense lic)
 {
     InitializeComponent();
     License = lic;
     PropertyGrid.SelectedObject = License;
 }
 public LicenseManagerUserControl(DemoLicense license)
 {
     InitializeComponent();
     License = license;
     PropertyGrid_License.SelectedObject = License;
 }