예제 #1
0
        public bool ValidateLayout()
        {
            LicUtils utils = new LicUtils();

            if (this.Items.Count != this.ItemCntInt)
            {
                throw new Exception("File was corrupted!");
            }

            string toDay = utils.GetSimpleDate(DateTime.Now);

            if (!Items.Contains(toDay))
            {
                Items.Add(toDay);
            }

            if (this.Items.Count >= 121)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #2
0
        private void DeserializeFromString(string values)
        {
            LicUtils utils = new LicUtils();
            string   deserializedValues = utils.Decrypt(values);

            string[] parts = deserializedValues.Split(new char[1] {
                ';'
            }, StringSplitOptions.RemoveEmptyEntries);
            bool isItemCntPart = true;

            ItemCount = "0";
            Items.Clear();
            foreach (string part in parts)
            {
                if (isItemCntPart)
                {
                    ItemCount     = part;
                    isItemCntPart = false;
                }
                else
                {
                    Items.Add(part);
                }
            }
        }
예제 #3
0
        private void QuerySpecificLicense()
        {
            try
            {
                var lics = mListLicenses;
                if (lics.Count <= 0)
                {
                    OnDebug(LogMode.Error, string.Format("No license to get."));
                    return;
                }
                JsonObject json = new JsonObject();
                json[LicDefines.KEYWORD_MSG_COMMON_CLASSID] =
                    new JsonProperty(LicDefines.LICENSE_MSG_CLASS_REQRES);
                json[LicDefines.KEYWORD_MSG_COMMON_CLASSDESC] =
                    new JsonProperty(LicUtils.GetClassDesc(LicDefines.LICENSE_MSG_CLASS_REQRES));
                json[LicDefines.KEYWORD_MSG_COMMON_MESSAGEID] =
                    new JsonProperty(LicDefines.LICENSE_MSG_REQUEST_QUERY_SPECIFIC_LICENSE);
                json[LicDefines.KEYWORD_MSG_COMMON_MESSAGEDESC] =
                    new JsonProperty(string.Format("\"Query special license\""));
                json[LicDefines.KEYWORD_MSG_COMMON_CURRENTTIME] =
                    new JsonProperty(DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss"));
                json[LicDefines.KEYWORD_MSG_REQRES_REQUESTID] =
                    new JsonProperty(LicDefines.LICENSE_MSG_NOTIFY_LICESNE_POOL);
                json[LicDefines.KEYWORD_MSG_COMMON_DATA] = new JsonProperty(new JsonObject());
                json[LicDefines.KEYWORD_MSG_COMMON_DATA][LicDefines.KEYWORD_MSG_APPINFO_LICENSES] = new JsonProperty();
                for (int i = 0; i < lics.Count; i++)
                {
                    var lic = lics[i];
                    lic.ResetValue();

                    JsonObject jsonLic = new JsonObject();
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_DISPLAY]   = new JsonProperty(lic.Name);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_LICENSEID] = new JsonProperty(lic.SerialNo);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_VALUETYPE] = new JsonProperty((int)lic.DataType);
                    if (lic.DataType == LicDataType.Number)
                    {
                        jsonLic[LicDefines.KEYWORD_MSG_LICENSE_VALUE] = new JsonProperty(lic.RequestValue);
                    }
                    else
                    {
                        jsonLic[LicDefines.KEYWORD_MSG_LICENSE_VALUE] = new JsonProperty(string.Format("\"{0}\"", lic.RequestValue));
                    }
                    json[LicDefines.KEYWORD_MSG_COMMON_DATA][LicDefines.KEYWORD_MSG_APPINFO_LICENSES].Add(jsonLic);
                }
                string strMsg = json.ToString();
                if (mLicConnector != null)
                {
                    mLicConnector.SendMessage(strMsg);
                    OnDebug(LogMode.Info,
                            string.Format("Send:\tClass: {0};\tMsg: {1}",
                                          LicUtils.GetClassDesc(LicDefines.LICENSE_MSG_CLASS_REQRES),
                                          LicUtils.GetMessageDesc(LicDefines.LICENSE_MSG_CLASS_REQRES,
                                                                  LicDefines.LICENSE_MSG_REQUEST_GET_LICENSE)));
                }
            }
            catch (Exception ex)
            {
                CurrentApp.WriteLog(string.Format("QuerySpecificLicense fail.\t{0}", ex.Message));
            }
        }
예제 #4
0
        internal PragmaLicense LoadLicence()
        {
            if (!File.Exists(_licFile))
            {
                return(null);
            }

            LicUtils utils = new LicUtils();

            return(utils.FromXmlFile(_licFile));
        }
예제 #5
0
        void LicConnector_MessageReceivedEvent(object sender, MessageReceivedEventArgs e)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                try
                {
                    string strInfo  = e.StringData;
                    JsonObject json = new JsonObject(strInfo);
                    if (mIsLogDetail)
                    {
                        //WriteLog(json.ToString("F"));
                        WriteLog(json.ToString());
                    }
                    int classid   = (int)json[LicDefines.KEYWORD_MSG_COMMON_CLASSID].Number;
                    int messageid = (int)json[LicDefines.KEYWORD_MSG_COMMON_MESSAGEID].Number;
                    WriteLog(string.Format("Recv\tClass: {0};\tMsg: {1}", LicUtils.GetClassDesc(classid), LicUtils.GetMessageDesc(classid, messageid)));
                    if (classid == LicDefines.LICENSE_MSG_CLASS_NOTIFY)
                    {
                        //通知消息
                        switch (messageid)
                        {
                        case LicDefines.LICENSE_MSG_NOTIFY_NEW_CLIENT:          //新的客户端连接
                            ProcessMessageNewClient(json);
                            break;

                        case LicDefines.LICENSE_MSG_NOTIFY_DEL_CLIENT:          //客户端断开连接
                            ProcessMessageDelClient(json);
                            break;

                        case LicDefines.LICENSE_MSG_NOTIFY_APPLICATION_LICENSE:         //当前Application的License信息
                            ProcessMessageAppLicense(json);
                            break;

                        case LicDefines.LICENSE_MSG_NOTIFY_LICESNE_POOL:                //当前LicensePool信息
                            ProcessMessageLicensePool(json);
                            break;

                        case LicDefines.LICENSE_MSG_NOTIFY_LICENSE_SERVERS:     //LicenseServer信息
                            ProcessMessageLicenseServer(json);
                            break;

                        case LicDefines.LICENSE_MSG_NOTIFY_SOFTDOGS_INFO:       //软件狗信息
                            ProcessMessageSoftdog(json);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage(ex.Message);
                }
            }));
        }
예제 #6
0
        private string SerializeToString()
        {
            string seralizedValues = String.Empty;
            int    itemCnt         = 0;
            string sep             = String.Empty;

            foreach (string value in Items)
            {
                seralizedValues += sep + value;
                sep              = ";";
                itemCnt++;
            }
            seralizedValues = itemCnt.ToString() + ";" + seralizedValues;
            LicUtils utils = new LicUtils();

            return(utils.Encrypt(seralizedValues));
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
0
        private void GetLicenses()
        {
            try
            {
                var lics = _mListLicenses;
                if (lics.Count <= 0)
                {
                    OnDebug(LogMode.Error, string.Format("No license to get."));
                    return;
                }
                JsonObject json = new JsonObject();
                json[LicDefines.KEYWORD_MSG_COMMON_CLASSID] =
                    new JsonProperty(LicDefines.LICENSE_MSG_CLASS_REQRES);
                json[LicDefines.KEYWORD_MSG_COMMON_CLASSDESC] =
                    new JsonProperty(LicUtils.GetClassDesc(LicDefines.LICENSE_MSG_CLASS_REQRES));
                json[LicDefines.KEYWORD_MSG_COMMON_MESSAGEID] =
                    new JsonProperty(LicDefines.LICENSE_MSG_REQUEST_GET_LICENSE);
                json[LicDefines.KEYWORD_MSG_COMMON_MESSAGEDESC] =
                    new JsonProperty(LicUtils.GetMessageDesc(LicDefines.LICENSE_MSG_CLASS_REQRES,
                                                             LicDefines.LICENSE_MSG_REQUEST_GET_LICENSE));
                json[LicDefines.KEYWORD_MSG_COMMON_CURRENTTIME] =
                    new JsonProperty(DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss"));
                json[LicDefines.KEYWORD_MSG_COMMON_DATA] = new JsonProperty(new JsonObject());
                json[LicDefines.KEYWORD_MSG_COMMON_DATA][LicDefines.KEYWORD_MSG_APPINFO_LICENSES] = new JsonProperty();
                for (int i = 0; i < lics.Count; i++)
                {
                    var lic = lics[i];
                    lic.ResetValue();

                    JsonObject jsonLic = new JsonObject();
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_DISPLAY]            = new JsonProperty(lic.Name);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_EXPIRATION]         = new JsonProperty(lic.Expiration);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_LICENSEID]          = new JsonProperty(lic.SerialNo);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_MODULEMARJORTYPEID] = new JsonProperty(lic.MajorID);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_MODULEMINJORTYPEID] = new JsonProperty(lic.MinorID);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_OWNERTYPE]          = new JsonProperty((int)lic.Type);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_VALUETYPE]          = new JsonProperty((int)lic.DataType);
                    if (lic.DataType == LicDataType.Number)
                    {
                        jsonLic[LicDefines.KEYWORD_MSG_LICENSE_VALUE] = new JsonProperty(lic.RequestValue);
                    }
                    else
                    {
                        jsonLic[LicDefines.KEYWORD_MSG_LICENSE_VALUE] = new JsonProperty(string.Format("\"{0}\"", lic.RequestValue));
                    }
                    json[LicDefines.KEYWORD_MSG_COMMON_DATA][LicDefines.KEYWORD_MSG_APPINFO_LICENSES].Add(jsonLic);
                }
                string strMsg = json.ToString();
                if (_mLicConnector != null)
                {
                    _mLicConnector.SendMessage(strMsg);

                    OnDebug(LogMode.Info,
                            string.Format("Send:\tClass: {0};\tMsg: {1}",
                                          LicUtils.GetClassDesc(LicDefines.LICENSE_MSG_CLASS_REQRES),
                                          LicUtils.GetMessageDesc(LicDefines.LICENSE_MSG_CLASS_REQRES,
                                                                  LicDefines.LICENSE_MSG_REQUEST_GET_LICENSE)));
                }
            }
            catch (Exception ex)
            {
                OnDebug(LogMode.Error, string.Format("GetLicenses fail.\t{0}", ex.Message));
            }
        }
예제 #10
0
        private void QueryLicInfos()
        {
            try
            {
                List <License> listLics = new List <License>();
                License        lic      = new License();
                lic.SerialNo = mLicID;
                lic.DataType = LicDataType.Number;
                listLics.Add(lic);

                JsonObject json = new JsonObject();
                json[LicDefines.KEYWORD_MSG_COMMON_CLASSID] =
                    new JsonProperty(LicDefines.LICENSE_MSG_CLASS_REQRES);
                json[LicDefines.KEYWORD_MSG_COMMON_CLASSDESC] =
                    new JsonProperty(LicUtils.GetClassDesc(LicDefines.LICENSE_MSG_CLASS_REQRES));
                json[LicDefines.KEYWORD_MSG_COMMON_MESSAGEID] =
                    new JsonProperty(LicDefines.LICENSE_MSG_REQUEST_QUERY_SPECIFIC_LICENSE);
                json[LicDefines.KEYWORD_MSG_COMMON_MESSAGEDESC] =
                    new JsonProperty(LicUtils.GetMessageDesc(LicDefines.LICENSE_MSG_CLASS_REQRES,
                                                             LicDefines.LICENSE_MSG_REQUEST_QUERY_SPECIFIC_LICENSE));
                json[LicDefines.KEYWORD_MSG_COMMON_CURRENTTIME] =
                    new JsonProperty(DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss"));
                json[LicDefines.KEYWORD_MSG_COMMON_DATA] = new JsonProperty(new JsonObject());
                json[LicDefines.KEYWORD_MSG_COMMON_DATA][LicDefines.KEYWORD_MSG_APPINFO_LICENSES] = new JsonProperty();
                for (int i = 0; i < listLics.Count; i++)
                {
                    lic = listLics[i];
                    lic.ResetValue();

                    JsonObject jsonLic = new JsonObject();
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_DISPLAY]            = new JsonProperty(lic.Name);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_EXPIRATION]         = new JsonProperty(lic.Expiration);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_LICENSEID]          = new JsonProperty(lic.SerialNo);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_MODULEMARJORTYPEID] = new JsonProperty(lic.MajorID);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_MODULEMINJORTYPEID] = new JsonProperty(lic.MinorID);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_OWNERTYPE]          = new JsonProperty((int)lic.Type);
                    jsonLic[LicDefines.KEYWORD_MSG_LICENSE_VALUETYPE]          = new JsonProperty((int)lic.DataType);
                    if (lic.DataType == LicDataType.Number)
                    {
                        jsonLic[LicDefines.KEYWORD_MSG_LICENSE_VALUE] = new JsonProperty(lic.RequestValue);
                    }
                    else
                    {
                        jsonLic[LicDefines.KEYWORD_MSG_LICENSE_VALUE] = new JsonProperty(string.Format("\"{0}\"", lic.RequestValue));
                    }
                    json[LicDefines.KEYWORD_MSG_COMMON_DATA][LicDefines.KEYWORD_MSG_APPINFO_LICENSES].Add(jsonLic);
                }
                string strMsg = json.ToString();
                if (mLicChecker != null)
                {
                    mLicChecker.SendMessage(strMsg);

                    AppendMessage(string.Format("Send:\tClass: {0};\tMsg: {1}",
                                                LicUtils.GetClassDesc(LicDefines.LICENSE_MSG_CLASS_REQRES),
                                                LicUtils.GetMessageDesc(LicDefines.LICENSE_MSG_CLASS_REQRES,
                                                                        LicDefines.LICENSE_MSG_REQUEST_QUERY_SPECIFIC_LICENSE)));
                }
            }
            catch (Exception ex)
            {
                AppendMessage(string.Format("QueryLicInfos fail.\t{0}", ex.Message));
            }
        }