Example #1
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 #2
0
 private void lblCompany_Click(object sender, EventArgs e)
 {
     if (new Form2().CryptoLicensing())
     {
         if (MessageBox.Show("آیا مایلید این لایسنس حذف گردد؟"
                             , "Delete License"
                             , MessageBoxButtons.YesNo
                             , MessageBoxIcon.Stop
                             , MessageBoxDefaultButton.Button2
                             , MessageBoxOptions.RightAlign) == DialogResult.Yes)
         {
             license.Remove();
             Application.Exit();
         }
     }
 }
Example #3
0
        private void textBoxLic_KeyDown(object sender, KeyEventArgs e)
        {
            const string strLic = "SPACECODE@123456";

            if (e.KeyCode == Keys.L && e.Modifiers == Keys.Control)
            {
                if (textBoxLic.Text != strLic)
                {
                    return;
                }
                lic.Remove();
                lic.ResetCustomInfo();
                lic.ResetEvaluationInfo();
                MessageBox.Show(ResStrings.str_License_removed, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #4
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();
                }
            }
        }