示例#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);
        }
示例#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);
        }