Example #1
0
        // ToDo: Insert the parameter for the respective function
        static async Task Main()
        {
            StartSampleAsync().GetAwaiter().GetResult();

            var slasconeProxy = new SampleProxy();



            //ToDo: Fill the variables
            var activateClientDto = new ActivateClientDto
            {
                ProductId         = Guid.Parse("47df1df5-bbc8-4b1b-a185-58ddfb1d3271"),
                LicenseKey        = "0efce21f-c6bb-4a68-b65e-c3cdfdded42c",
                ClientId          = slasconeProxy.GetWindowsUniqueDeviceId(),
                ClientDescription = "",
                ClientName        = "",
                SoftwareVersion   = "12.2.8"
            };

            var activatedLicense = await slasconeProxy.ActivateAsync(activateClientDto);

            // If the activation failed, the api server responses with a specific error message which describes the problem. Therefore the LicenseInfo object is declared with null.
            if (activatedLicense.WarningInfo != null)
            {
                Console.WriteLine(activatedLicense.WarningInfo.Message);

                /*Example for
                 * if (activatedLicense.WarningInfo.Id == 2006)
                 * {
                 * }
                 */
            }
            else
            {
                Console.WriteLine("Successfully activated license.");
            }

            // ToDo: Uncomment specific scenario
            //await HeartbeatSample(activatedLicense);
            //await FloatingLicensingSample(activatedLicense);
            //await LicenseFileSample("XX/LicenseSample.xml");
        }
Example #2
0
        /// <summary>
        /// Activates a License
        /// </summary>
        /// <returns>ProvisioningInfo where LicenseInfoDto or WarningInfoDto is set.</returns>
        public async Task <ProvisioningInfo> ActivateAsync(ActivateClientDto activateClientDto)
        {
            var uri = new UriBuilder(ApiBaseUrl)
            {
                Path = $"/api/v2/isv/{IsvId}/provisioning/activations"
            };

            var bodyJson = JsonConvert.SerializeObject(activateClientDto);
            var body     = new StringContent(bodyJson, Encoding.UTF8, "application/json");

            var response = await _httpClient.PostAsync(uri.Uri, body);

            var content = await response.Content.ReadAsStringAsync();

            if (!await IsSignatureValid(response))
            {
                throw new Exception("Signature is not valid!");
            }

            // If activation was successful, the api returns a status code Ok(200) with the information of the license.
            if (response.StatusCode == HttpStatusCode.OK)
            {
                var resultProvisioningInfo = new ProvisioningInfo();
                resultProvisioningInfo.WarningInfo = null;
                resultProvisioningInfo.LicenseInfo = JsonConvert.DeserializeObject <LicenseInfo>(content);
                return(resultProvisioningInfo);
            }

            // If activation was unsuccessful, the api returns a status code Conflict(409) with the information of a warning.
            if (response.StatusCode == HttpStatusCode.Conflict)
            {
                var resultProvisioningInfo = new ProvisioningInfo();
                resultProvisioningInfo.WarningInfo = JsonConvert.DeserializeObject <WarningInfo>(content);
                resultProvisioningInfo.LicenseInfo = null;
                return(resultProvisioningInfo);
            }

            throw new Exception(response.StatusCode.ToString());
        }