예제 #1
0
        private static async Task DisplayPremiumPurchasePage(IAccountService accountService)
        {
            string tag  = New <KnownIdentities>().IsLoggedOn ? (await accountService.AccountAsync()).Tag ?? string.Empty : string.Empty;
            string link = Texts.LinkToAxCryptPremiumPurchasePage.QueryFormat(Resolve.UserSettings.AccountWebUrl, New <KnownIdentities>().DefaultEncryptionIdentity.UserEmail, tag);

            Process.Start(link);
        }
        public async Task BuyPremium(LogOnIdentity identity)
        {
            string tag = string.Empty;

            if (New <KnownIdentities>().IsLoggedOn)
            {
                IAccountService accountService = New <LogOnIdentity, IAccountService>(identity);
                tag = (await accountService.AccountAsync()).Tag ?? string.Empty;
            }

            string link = Texts.LinkToAxCryptPremiumPurchasePage.QueryFormat(Resolve.UserSettings.AccountWebUrl, identity.UserEmail, tag);

            New <IBrowser>().OpenUri(new Uri(link));
        }
예제 #3
0
        private static async Task <PlanInformation> NoPremiumOrCanTryAsync(IAccountService service)
        {
            if (New <AxCryptOnlineState>().IsOffline)
            {
                return(new PlanInformation(PlanState.OfflineNoPremium, 0));
            }

            if (!(await service.AccountAsync().Free()).Offers.HasFlag(Offers.AxCryptTrial))
            {
                return(new PlanInformation(PlanState.CanTryPremium, 0));
            }

            return(new PlanInformation(PlanState.NoPremium, 0));
        }
        public static async Task <bool> IsIdentityValidAsync(this IAccountService service)
        {
            if (service.Identity == LogOnIdentity.Empty)
            {
                return(false);
            }

            UserAccount account = await service.AccountAsync().Free();

            if (!account.AccountKeys.Select(k => k.ToUserKeyPair(service.Identity.Passphrase)).Any((ukp) => ukp != null))
            {
                return(false);
            }
            return(true);
        }
예제 #5
0
        private static async Task <int> GetDaysLeft(IAccountService service)
        {
            DateTime expiration = (await service.AccountAsync().Free()).LevelExpiration;

            if (expiration == DateTime.MaxValue || expiration == DateTime.MinValue)
            {
                return(int.MaxValue);
            }

            DateTime utcNow = New <INow>().Utc;

            if (expiration < utcNow)
            {
                return(0);
            }

            double totalDays = (expiration - utcNow).TotalDays;

            return(totalDays > int.MaxValue ? int.MaxValue : (int)totalDays);
        }
예제 #6
0
        /// <summary>
        /// Fetches the user user account.
        /// </summary>
        /// <returns>
        /// The complete user account information.
        /// </returns>
        public async Task <UserAccount> AccountAsync()
        {
            UserAccount localAccount = await _localService.AccountAsync().Free();

            if (New <AxCryptOnlineState>().IsOffline || Identity.Passphrase == Passphrase.Empty)
            {
                return(localAccount);
            }

            try
            {
                UserAccount remoteAccount;
                remoteAccount = await _remoteService.AccountAsync().Free();

                if (remoteAccount.AccountKeys.Count == 0)
                {
                    return(localAccount);
                }

                UserAccount mergedAccount = remoteAccount.MergeWith(localAccount);

                if (mergedAccount != remoteAccount)
                {
                    await _remoteService.SaveAsync(mergedAccount).Free();
                }
                if (mergedAccount != localAccount)
                {
                    await _localService.SaveAsync(mergedAccount).Free();
                }
                return(mergedAccount);
            }
            catch (ApiException aex)
            {
                await aex.HandleApiExceptionAsync();
            }
            return(localAccount);
        }
예제 #7
0
        private static async Task <PlanInformation> GetPlanInformationAsync(LogOnIdentity identity)
        {
            IAccountService service = New <LogOnIdentity, IAccountService>(identity);

            SubscriptionLevel level = await(await service.AccountAsync().Free()).ValidatedLevelAsync();

            switch (level)
            {
            case SubscriptionLevel.Unknown:
            case SubscriptionLevel.Free:
                return(await NoPremiumOrCanTryAsync(service));

            case SubscriptionLevel.Business:
                return(new PlanInformation(PlanState.HasBusiness, await GetDaysLeft(service)));

            case SubscriptionLevel.Premium:
                return(new PlanInformation(PlanState.HasPremium, await GetDaysLeft(service)));

            case SubscriptionLevel.DefinedByServer:
            case SubscriptionLevel.Undisclosed:
            default:
                return(new PlanInformation(PlanState.NoPremium, 0));
            }
        }
 /// <summary>
 /// Fetches the user user account.
 /// </summary>
 /// <returns>
 /// The complete user account information.
 /// </returns>
 public async Task <UserAccount> AccountAsync()
 {
     return(await New <ICache>().GetItemAsync(_key.Subkey(nameof(AccountAsync)), async() => await _service.AccountAsync()).Free());
 }
        public static async Task <bool> IsAccountSourceLocalAsync(this IAccountService service)
        {
            UserAccount userAccount = await service.AccountAsync();

            return(userAccount.AccountSource == AccountSource.Local);
        }