Ejemplo n.º 1
0
        private bool ExpireDemoLicence(PragmaLicense lic)
        {
            if (lic != null && lic.PurchaseType == PurchaseType.Demo)
            {
                DateTime now = DateTime.Now;
                if (now > lic.ValidTo || now < lic.ValidFrom)
                {
                    return(false);
                }
            }


            LayoutConfig dex = new LayoutConfig();

            dex.LoadFromFile();
            bool result = dex.ValidateLayout();

            dex.SaveToFile();

            return(true);
        }
Ejemplo n.º 2
0
        private bool ActivatePragmaSql()
        {
            string error = String.Empty;

            /*
             * if (String.IsNullOrEmpty(cmbCodeName.Text.Trim()))
             * {
             * error += "\r\n" + " - Product code name";
             * }
             */

            if (String.IsNullOrEmpty(cmbPurchaseType.Text.Trim()))
            {
                error += "\r\n" + " - Purchase type";
            }

            if (String.IsNullOrEmpty(txtActivationKey.Text.Trim()))
            {
                error += "\r\n" + " - Activation key";
            }

            if (String.IsNullOrEmpty(txtMachineKey.Text.Trim()))
            {
                error += "\r\n" + " - Machine key";
            }

            if (!IsDemo && String.IsNullOrEmpty(txtEMail.Text.Trim()))
            {
                error += "\r\n" + " - EMail";
            }

            if (!String.IsNullOrEmpty(error))
            {
                MessageService.ShowError("Required fields listed below are empty!\r\n" + error);
                return(false);
            }


            // Create request licence object
            LicUtils      licUtils = new LicUtils();
            PragmaLicense lic      = new PragmaLicense();

            lic.Product         = Product.PragmaSQL;
            lic.ProductCodeName = new ProductInfo().CurrentCodeName;

            //lic.ProductCodeName = (ProductCodeName)licUtils.ParseEnum(typeof(ProductCodeName), cmbCodeName.Text);
            lic.PurchaseType  = (PurchaseType)licUtils.ParseEnum(typeof(PurchaseType), cmbPurchaseType.Text);
            lic.ActivationKey = txtActivationKey.Text;
            lic.MachineKey    = new MachineID(txtMachineKey.Text);
            lic.MachineIdType = MachineIdType.Composite2;
            lic.LicType       = LicType.Machine;
            lic.EMail         = txtEMail.Text;


            if (lic.PurchaseType == PurchaseType.Demo)
            {
                lic.ValidFrom = DateTime.Now;
                lic.ValidTo   = DateTime.Now.AddDays(121);
            }

            // Sign the licence request via web service
            string         licXml = lic.ToXmlString();
            LicenceSignSvc svc    = new LicenceSignSvc();

            try
            {
                WebProxy prx = WebProxy.GetDefaultProxy();
                if (prx != null)
                {
                    prx.Credentials = CredentialCache.DefaultCredentials;
                    svc.Proxy       = prx;
                }
            }
            catch (Exception ex)
            {
                frmException.ShowAppError("Default static proxy settings can not be retreived!", ex);
            }

            string signedLicXml = svc.SignLicence(licXml);

            XmlDocument signedXml = new XmlDocument();

            signedXml.LoadXml(signedLicXml);

            // Check if resulting string is an error xml
            if (ErrorXml.IsError(signedLicXml))
            {
                ServiceCallError er  = ErrorXml.CreateServiceCallError(signedXml);
                string           msg = "Product can not be activated!\r\n";
                msg += "Error:" + er.ErrorMessage;
                msg += !String.IsNullOrEmpty(er.InnerErrorMessage) ? "Detail:" + er.InnerErrorMessage : String.Empty;
                MessageService.ShowError(msg);
                return(false);
            }

            if (lic.PurchaseType == PurchaseType.Demo)
            {
                LayoutConfig dex = new LayoutConfig();
                dex.Items.Add(licUtils.GetSimpleDate(DateTime.Now));
                dex.SaveToFile();
            }

            signedXml.Save(_licFile);
            return(true);
        }
Ejemplo n.º 3
0
        public bool VerifyLicence(out string message)
        {
            // 1- Try to load licence from licence file.
            LicUtils      utils = new LicUtils();
            PragmaLicense lic   = LoadLicence();

            message = String.Empty;


            // 2- No licence file.
            if (lic == null)
            {
                message = "No license found.\r\n";
                //message = _licFile;
                return(false);
            }

            // 2- Verify the licence.
            try
            {
                if (!utils.VerifyLicense(_licFile))
                {
                    message = "You are trying to use an invalid license.\r\nPlease visit www.PragmaSQL.com to purchase a valid license.";
                    return(false);
                }
            }
            catch (Exception ex)
            {
                message = "Error:" + ex.Message;
                return(false);
            }

            MachineID current = MachineIdProvider.Retrieve(lic.MachineIdType);

            if (current.Key != lic.MachineKey.Key)
            {
                message = "You are trying to use a license which was not issued to you.\r\nPlease visit www.PragmaSQL.com to purchase a valid license.";
                return(false);
            }

            if (new ProductInfo().CurrentCodeName != lic.ProductCodeName)
            {
                message = "You are trying to use a license which was not issued for this version.\r\nPlease visit www.PragmaSQL.com to purchase a valid license.";
                return(false);
            }

            // 3- If licence is a demo licence check existance of the expire file
            if (lic.PurchaseType == PurchaseType.Demo)
            {
                try
                {
                    if (!File.Exists(_demoExpireFile))
                    {
                        message = "Demo expire date can not be determined!\r\nPlease visit www.PragmaSQL.com to purchase a license.";
                        return(false);
                    }

                    if (!ExpireDemoLicence(lic))
                    {
                        message = "Your demo period expired!\r\nPlease visit www.PragmaSQL.com to purchase a license.";
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    return(false);
                }
            }

            return(true);
        }