public static int ActivateFromServer(string productId, string licenseKey, string publicKey, ActivationPayload activationPayload, List <ActivationMeterAttribute> meterAttributes, bool serverSync = false)
        {
            var    metadata    = new List <ActivationMetadata>();
            string jsonBody    = GetActivationRequest(licenseKey, productId, metadata, meterAttributes);
            var    httpService = new LexHttpService();
            HttpResponseMessage httpResponse;

            try
            {
                if (serverSync)
                {
                    httpResponse = httpService.UpdateActivation(activationPayload.Id, jsonBody);
                }
                else
                {
                    httpResponse = httpService.CreateActivation(jsonBody);
                }
            }
            catch (Exception exception)
            {
                System.Console.WriteLine(exception.Message);
                return(LexStatusCodes.LA_E_INET);
            }


            //             if (serverSync && LexThread.ActivationValidity.count(activationPayload.id) && LexThread.ActivationValidity[activationPayload.id] == false)
            //             {
            // # ifdef LEX_DEBUG

            //                 LexLogger.LogDebug("Ignore the response as user deactivated the key.");
            // #endif
            //                 return LexStatusCodes.LA_FAIL;
            //             }

            if (!httpResponse.IsSuccessStatusCode)
            {
                return(ActivationErrorHandler(productId, httpResponse));
            }
            var    json = httpResponse.Content.ReadAsStringAsync().Result;
            var    activationResponse = JsonConvert.DeserializeObject <ActivationResponse>(json);
            string jwt = activationResponse.ActivationToken;

            return(LexValidator.ValidateActivation(jwt, publicKey, licenseKey, productId, activationPayload));
        }
        public static int DeactivateFromServer(string productId, ActivationPayload activationPayload)
        {
            var httpService = new LexHttpService();
            HttpResponseMessage httpResponse;

            try
            {
                httpResponse = httpService.DeleteActivation(activationPayload.Id);
            }
            catch (Exception exception)
            {
                System.Console.WriteLine(exception.Message);
                return(LexStatusCodes.LA_E_INET);
            }
            if (!httpResponse.IsSuccessStatusCode)
            {
                return(DeactivationErrorHandler(productId, httpResponse));
            }
            activationPayload.IsValid = false;
            LexDataStore.Reset(productId);
            return(LexStatusCodes.LA_OK);
        }