コード例 #1
0
        public static Task SetLicense(WebProductLicense productLicense)
        {
            var     apiClient = DependencyResolver.Current.GetService <IAPIHttpClient>();
            dynamic param     = new ExpandoObject();

            param.productLicense = productLicense;
            return(apiClient.ServiceAsync(KL2_Server.API, "LicenseService", "SetLicense", param));
        }
コード例 #2
0
        public IHttpActionResult SetLicense([DynamicBody] dynamic param)
        {
            try
            {
                WebProductLicense productLicense = (WebProductLicense)param.productLicense;

                XmlDocument doc = new XmlDocument();
                doc.Load("Files/PublicKey.xml");
                ProductLicenseManager.Initialize(_traceManager, doc.OuterXml);
                ProductLicenseManager.Current.SaveWebLicense(ActivationConstants.WebProductName, productLicense);

                return(Ok());
            }
            catch (Exception ex)
            {
                _traceManager.TraceError(ex, ex.Message);
                return(InternalServerError(ex));
            }
        }
コード例 #3
0
        public async Task <ActionResult> SaveDefault()
        {
            if (Request.Cookies.AllKeys.Contains("token"))
            {
                _apiHttpClient.Token = Request.Cookies["token"].Value;
            }

            HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;
            var uploadedLicenseFile = System.Web.HttpContext.Current.Request.Files["uploadLicense"];

            var name    = System.Web.HttpContext.Current.Request.Headers["name"];
            var company = System.Web.HttpContext.Current.Request.Headers["company"];
            var email   = System.Web.HttpContext.Current.Request.Headers["email"];
            await LicenseMapper.SetUserInformation(name, company, email);

            ProductLicenseInfo licenseInfo = null;

            try
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(uploadedLicenseFile.InputStream))
                {
                    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(ProductLicenseInfo));
                    licenseInfo = (ProductLicenseInfo)serializer.Deserialize(reader);
                }
            }
            catch (Exception e)
            {
                _traceManager.TraceError(e, e.Message);
                HttpContext.Response.StatusDescription = $"{HttpStatusCode.BadRequest}";
                return(Content(LocalizedStrings.GetString("Web_Controller_License_CantCheckLicense")));
            }

            try
            {
                WebProductLicense license = await LicenseMapper.ActivateLicense(licenseInfo);

                if (license.Status == WebLicenseStatus.OverageOfUsers)
                {
                    HttpContext.Response.StatusDescription = $"{HttpStatusCode.ExpectationFailed}";
                    return(Content(LocalizedStrings.GetStringFormat(license.StatusReason, license.StatusReasonParams?.Select(_ => _.ToString()).ToArray())));
                }
                // Comment this part if you want to be able to save a expired license
                if (license.Status != WebLicenseStatus.Licensed && license.Status != WebLicenseStatus.TrialVersion)
                {
                    HttpContext.Response.StatusDescription = $"{HttpStatusCode.Forbidden}";
                    return(Content(LocalizedStrings.GetStringFormat(license.StatusReason, license.StatusReasonParams?.Select(_ => _.ToString()).ToArray())));
                }

                //First initialize of license, set UserPool to current Admin
                if (license.UsersPool.Count == 0)
                {
                    //Get current user id - Admin
                    var adminId = int.Parse(System.Web.HttpContext.Current.User.Identity.GetUserId());
                    license.UsersPool.Add(adminId);
                }
                await LicenseMapper.SetLicense(license);

                // TODO : Update license infos from the secured storage
            }
            catch (Exception e)
            {
                _traceManager.TraceError(e, e.Message);
                HttpContext.Response.StatusDescription = $"{HttpStatusCode.BadRequest}";
                return(Content(LocalizedStrings.GetString("Web_Controller_License_LicenseInvalid")));
            }

            HttpContext.Response.StatusDescription = $"{HttpStatusCode.OK}";
            return(Content($"{HttpStatusCode.OK}"));
        }