public NippsLicenseResponse Get()
        {
            NippsLicenseResponse response = new NippsLicenseResponse();

            response.Result         = Result.OK;
            response.ResultMessages = new List <string>();

            try
            {
                if (!LicenseWrapper.Valid())
                {
                    response.Result = Result.FAIL;
                    response.ResultMessages.Add(string.Format("License is not VALID."));
                }

                response.License = LicenseWrapper.License;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                response.Result = Result.FAIL;
                response.ResultMessages.Add(ex.ToString());
            }
            return(response);
        }
        public BaseResponse Load(NippsLicenseRequest request)
        {
            NippsLicenseResponse response = new NippsLicenseResponse();

            response.Result         = Result.OK;
            response.ResultMessages = new List <string>();

            try
            {
                if (string.IsNullOrEmpty(request.Content))
                {
                    response.Result = Result.FAIL;
                    response.ResultMessages.Add("Request.Content");
                    Logger.Error(response.ResultMessages[0]);
                }
                else
                {
                    if (!LicenseWrapper.Valid(request.Content))
                    {
                        response.Result = Result.FAIL;
                        response.ResultMessages.Add(string.Format("License is not VALID."));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                response.Result = Result.FAIL;
                response.ResultMessages.Add(ex.ToString());
            }

            return(response);
        }
Esempio n. 3
0
        private LicenseInfo GetLocalLicense()
        {
            string licenseFile = LocalLicenseFilename();

            if (!File.Exists(licenseFile))
            {
                var info     = new LicenseInfo(TrialDays);
                var newTrial = LicenseWrapper.FromInfo(info);
                JsonFile.Save(licenseFile, newTrial);
            }

            var wrapper = JsonFile.Load <LicenseWrapper>(licenseFile);

            return(JsonConvert.DeserializeObject <LicenseInfo>(wrapper.Info));
        }
Esempio n. 4
0
        /// <summary>
        /// Called when user enters license key in UI to complete app purchase,
        /// removes expiration date from client-side registration info
        /// </summary>
        public async Task <ValidateResult> ActivateAsync(string email, string key)
        {
            var result = await _client.ValidateAsync(new LicenseKey()
            {
                Product = ProductId,
                Email   = email,
                Key     = key
            });

            if (result.Success)
            {
                var license = GetLocalLicense();
                license.Activate();
                JsonFile.Save(LocalLicenseFilename(), LicenseWrapper.FromInfo(license));
            }

            return(result);
        }
        public BaseResponse Ipps(NippsLicenseRequest ippsRequest)
        {
            NippsLicenseResponse response = new NippsLicenseResponse();

            response.Result         = Result.OK;
            response.ResultMessages = new List <string>();

            try
            {
                if (ippsRequest == null || string.IsNullOrEmpty(ippsRequest.Version))
                {
                    throw new ArgumentNullException("Request.Version.");
                }

                string[] psParts = ippsRequest.Version.Split(':');
                if (psParts == null || psParts.Length != 2)
                {
                    throw new ArgumentException("Request.Version");
                }

                if (!LicenseWrapper.Valid())
                {
                    response.Result = Result.FAIL;
                    response.ResultMessages.Add(string.Format("License is not VALID."));
                }

                LicenseWrapper.Valid(psParts[0], psParts[1]);
            }
            catch (Exception ex)
            {
                Logger.Error("{0}> {1}", ippsRequest.ToString(), ex.ToString());
                response.Result = Result.FAIL;
                response.ResultMessages.Add(ex.ToString());
            }
            return(response);
        }