Beispiel #1
0
        public void TestKeyBlock()
        {
            string token = "WyIxNzIiLCJhak9OT1g3NW90YlQyRFFVUzBWdnlGSHJYdUpMdDA0REMxNzNOa2duIl0=";
            string key   = "LEPWV-FOTPG-MWBEO-FBFPS";

            // this is a simple hack to retrieve license info (auto complete it).
            var license = new LicenseKey {
                ProductId = 3349, Key = key
            };

            license.Refresh(token);

            Key.BlockKey(token, new KeyLockModel {
                Key = key, ProductId = 3349
            });

            license.Refresh(token);

            Assert.IsTrue(license.IsBlocked().IsValid());

            Key.UnblockKey(token, new KeyLockModel {
                Key = key, ProductId = 3349
            });

            license.Refresh(token);

            Assert.IsTrue(license.IsNotBlocked().IsValid());
        }
Beispiel #2
0
        public void UsageCounter()
        {
            var token     = getKeys;
            var tokenDObj = "WyIxMSIsInRFLzRQSzJkT2V0Y1pyN3Y3a1I2Rm9YdmczNUw0SzJTRHJwUERhRFMiXQ==";

            // this is a simple hack to retrieve license info (auto complete it).
            var license = new LicenseKey {
                ProductId = 3349, Key = "GEBNC-WZZJD-VJIHG-GCMVD"
            };

            license.Refresh(token);

            if (license.DataObjects.Contains("usagecount"))
            {
                var dataObj = license.DataObjects.Get("usagecount");

                // attempt to increment. true means we succeed.
                if (dataObj.IncrementIntValue(token: tokenDObj,
                                              incrementValue: 1,
                                              enableBound: true,
                                              upperBound: 4,
                                              licenseKey: license))
                {
                    // success, we can keep using this feature
                }
                else
                {
                    dataObj.SetIntValue(tokenDObj, 0);
                    Assert.Fail();
                    // fail, the the user has already used it 10 times.
                }
            }
            else
            {
                // if it does not exist, add a new one.
                license.AddDataObject(tokenDObj, new DataObject {
                    Name = "usagecount", IntValue = 0
                });
            }
        }