Пример #1
0
        public async Task <DateTime> IsValidUntil()
        {
            var licString = await licenseStorage.FetchAsync();

            if (!string.IsNullOrEmpty(licString))
            {
                var lic = Standard.Licensing.License.Load(licString);
                return(lic.Expiration.ToUniversalTime().Date);
            }

            return(DateTime.MinValue);
        }
Пример #2
0
        protected override async Task <int> ExecuteCommand(RequestTrialCommand arguments)
        {
            WriteLine("Fetching user information...");
            logger.LogInformation("Fetching user information...");

            var userInfo = await userInfoProvider.GetUserInfoAsync();

            if (userInfo == null)
            {
                WriteLine("ERROR: Cannot fetch user information");
                logger.LogError("ERROR: Cannot fetch user information");
                return(-1);
            }
            else
            {
                logger.LogInformation("Logged in with {User}", userInfo);
            }

            WriteLine($"Hello {userInfo.UserName}!");
            WriteLine($"Id:    {userInfo.UserId}");
            WriteLine($"Email: {userInfo.Email}");

            WriteLine("Fetching active licenses...");
            logger.LogInformation("Fetching active licenses...");

            var storedLicense = await licenseStorage.FetchAsync();

            WriteLine($"Has stored license...? {!string.IsNullOrEmpty(storedLicense)}");

            if (string.IsNullOrEmpty(storedLicense))
            {
                var askForKey = arguments.AskForKey("You don't have a license yet. Do you want to request a trial?");

                if (askForKey)
                {
                    try
                    {
                        var machineKey = await deviceIdProvider.GetDeviceIdAsync();

                        var trialResult = await licenseClient.LicensesRequestTrialAsync(new InRequestTrialModel(machineKey));

                        if (await licenseValidator.IsValid(trialResult.License, trialResult.PublicKey))
                        {
                            WriteLine($"License is valid until {await licenseInformationProvider.IsValidUntil()}");
                        }

                        if (!arguments.NoStore)
                        {
                            await licenseStorage.StoreAsync(trialResult.License);

                            await publicKeyStorage.StoreAsync(trialResult.PublicKeyName, trialResult.PublicKey);
                        }

                        return(0);
                    }
                    catch (LicenseApiException <IDictionary <string, object> > ex) when(ex.StatusCode == 400)
                    {
                        WriteLine($"ERROR");
                        foreach (var error in ex.Result)
                        {
                            WriteLine($"{error.Key}: {error.Value}");
                        }
                    }
                    catch (LicenseApiException ex) when(ex.StatusCode == 400 || ex.StatusCode == 500)
                    {
                        WriteLine($"ERROR {ex}");
                    }
                }
            }

            if (await licenseValidator.IsValid(storedLicense))
            {
                WriteLine($"License is valid until {await licenseInformationProvider.IsValidUntil()}");
            }

            return(0);
        }