/// <summary> /// Creates a usage heartbeat /// </summary> /// <param name="usageHeartbeatDto">Is the object which contains all usage Heartbeat Information.</param> /// <returns>"Successfully created usage heartbeat." or a WarningInfoDto</returns> public async Task <string> AddUsageHeartbeat(UsageHeartbeatDto usageHeartbeatDto) { var uri = new UriBuilder(ApiBaseUrl) { Path = $"/api/v2/isv/{IsvId}/data_gathering/usage_heartbeats" }; var bodyJson = JsonConvert.SerializeObject(usageHeartbeatDto); 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 generating a usage heartbeat was successful, the api returns a status code Ok(200) with the message "Successfully created usage heartbeat.". if (response.StatusCode == HttpStatusCode.OK) { return(content); } // If generating a usage heartbeat was unsuccessful, the api returns a status code Conflict(409) with the information of a warning. if (response.StatusCode == HttpStatusCode.Conflict) { var errorInfo = JsonConvert.DeserializeObject <WarningInfo>(content); return(errorInfo.Message); } throw new Exception(response.StatusCode.ToString()); }
private static async Task HeartbeatSample(ProvisioningInfo activatedLicense) { var slasconeProxy = new SampleProxy(); // ToDo: Fill the variables var heartbeatDto = new AddHeartbeatDto { TokenKey = "", ProductId = Guid.Parse(""), ClientId = slasconeProxy.GetWindowsUniqueDeviceId(), SoftwareVersion = "", //GroupId = "", //HeartbeatTypeId = Guid.Parse(""), OperatingSystem = slasconeProxy.GetOperatingSystem() }; var heartbeatResult = await slasconeProxy.AddHeartbeatAsync(heartbeatDto); // If the heartbeat failed, the api server responses with a specific error message which describes the problem. Therefore the LicenseInfo object is declared with null. if (heartbeatResult.LicenseInfo == null) { Console.WriteLine(heartbeatResult.WarningInfo.Message); } else { Console.WriteLine("Successfully created heartbeat."); } // ToDo: Fill the variables var analyticalHb = new AnalyticalHeartbeat(); analyticalHb.Heartbeat = new List <AnalyticalFieldValue>(); analyticalHb.ClientId = slasconeProxy.GetWindowsUniqueDeviceId(); var analyticalHeartbeatResult = await slasconeProxy.AddAnalyticalHeartbeatAsync(analyticalHb); Console.WriteLine(analyticalHeartbeatResult); // ToDo: Fill the variables var usageHeartbeat = new UsageHeartbeatDto(); usageHeartbeat.UsageHeartbeat = new List <UsageHeartbeatValue>(); usageHeartbeat.ClientId = slasconeProxy.GetWindowsUniqueDeviceId(); var usageFeatureValue1 = new UsageHeartbeatValue(); usageFeatureValue1.UsageFeatureId = Guid.Parse(""); usageFeatureValue1.Value = slasconeProxy.GetWindowsUniqueDeviceId(); var usageFeatureValue2 = new UsageHeartbeatValue(); usageFeatureValue2.UsageFeatureId = Guid.Parse(""); usageFeatureValue2.Value = ""; usageHeartbeat.UsageHeartbeat.Add(usageFeatureValue1); usageHeartbeat.UsageHeartbeat.Add(usageFeatureValue2); var usageHeartbeatResult = await slasconeProxy.AddUsageHeartbeat(usageHeartbeat); Console.WriteLine(usageHeartbeatResult); if (activatedLicense.LicenseInfo != null) { // ToDo: Fill the variables var unassignDto = new UnassignDto { TokenKey = "" }; var unassignResult = await slasconeProxy.UnassignAsync(unassignDto); Console.WriteLine(unassignResult); } // ToDo: Fill the variables var consumptionHeartbeat = new ConsumptionHeartbeatDto(); consumptionHeartbeat.ClientId = slasconeProxy.GetWindowsUniqueDeviceId(); consumptionHeartbeat.ConsumptionHeartbeat = new List <ConsumptionHeartbeatValueDto>(); consumptionHeartbeat.TokenKey = Guid.Parse(""); var consumptionHeartbeatValue1 = new ConsumptionHeartbeatValueDto(); consumptionHeartbeatValue1.LimitationId = Guid.Parse(""); consumptionHeartbeatValue1.Value = 1; consumptionHeartbeatValue1.LimitationId = Guid.Parse(""); consumptionHeartbeat.ConsumptionHeartbeat.Add(consumptionHeartbeatValue1); var consumptionHeartbeatResult = await slasconeProxy.AddConsumptionHeartbeat(consumptionHeartbeat); Console.WriteLine(consumptionHeartbeatResult); var remainingConsumptions = await slasconeProxy.GetConsumptionStatus(new ValidateConsumptionStatusDto { LimitationId = Guid.Parse(""), ClientId = slasconeProxy.GetWindowsUniqueDeviceId() }); }