예제 #1
0
        private static async Task FloatingLicensingSample(ProvisioningInfo activatedLicense)
        {
            var slasconeProxy = new SampleProxy();

            // ToDo: Fill the variables
            var heartbeatDto = new AddHeartbeatDto
            {
                ProductId       = Guid.Parse(""),
                ClientId        = slasconeProxy.GetWindowsUniqueDeviceId(),
                SoftwareVersion = "",
                //GroupId = "",
                //HeartbeatTypeId = Guid.Parse(""),
                //TokenKey = "",
                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
            {
                // After successfully generating a heartbeat the client have to check provisioning mode of the license. Is it floating a session has to be opened.
                if (heartbeatResult.LicenseInfo.ProvisioningMode == ProvisioningMode.Floating)
                {
                    // ToDo: Fill the variables
                    var sessionDto = new SessionDto
                    {
                        ClientId  = slasconeProxy.GetWindowsUniqueDeviceId(),
                        LicenseId = Guid.Parse("")
                    };

                    var openSessionResult = await slasconeProxy.OpenSession(sessionDto);

                    // If the floating limit is reached the api server responses with an Error.
                    if (openSessionResult.SessionViolationInfo == null)
                    {
                        Console.WriteLine(openSessionResult.WarningInfo.Message);
                    }
                    else
                    {
                        Console.WriteLine("Session active until: " + openSessionResult.SessionViolationInfo.SessionValidUntil);
                    }

                    // If the client have finished his work, he has to close the session. Therefore other clients are not blocked anymore and have not to wait until another Client expired.
                    var closeSessionResult = await slasconeProxy.CloseSession(sessionDto);

                    Console.WriteLine(closeSessionResult);
                }
            }
        }
예제 #2
0
        // Creates a heartbeat
        // Response is either a LicenseInfoDto or a WarningInfoDto
        /// <summary>
        /// Creates a heartbeat
        /// </summary>
        /// <returns>ProvisioningInfo where LicenseInfoDto or WarningInfoDto is set.</returns>
        public async Task <ProvisioningInfo> AddHeartbeatAsync(AddHeartbeatDto heartbeatDto)
        {
            var uri = new UriBuilder(ApiBaseUrl)
            {
                Path =
                    $"/api/v2/isv/{IsvId}/provisioning/heartbeats"
            };

            var bodyJson = JsonConvert.SerializeObject(heartbeatDto);
            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 heartbeat 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 generating a heartbeat 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());
        }
예제 #3
0
파일: SystemInfo.cs 프로젝트: Azure/iotedge
 public SystemInfo(string operatingSystemType, string architecture, string version, ProvisioningInfo provisioning, string serverVersion, string kernelVersion, string operatingSystem, int numCpus, string virtualized)
 {
     this.OperatingSystemType = operatingSystemType;
     this.Architecture        = architecture;
     this.Version             = version;
     this.Provisioning        = provisioning;
     this.ServerVersion       = serverVersion;
     this.KernelVersion       = kernelVersion;
     this.OperatingSystem     = operatingSystem;
     this.NumCpus             = numCpus;
     this.Virtualized         = virtualized;
 }
예제 #4
0
        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() });
        }