示例#1
0
        public async Task <bool> LoginAsync(UserModel userModel)
        {
            bool tokenExist = await new LocalLicenseValidator().ValidateAsync();

            try
            {
                HttpResponseMessage userAccoutHttpRestul = await GetUserAccountHttpRestulAsync(userModel);

                if (userAccoutHttpRestul.IsSuccessStatusCode)
                {
                    TokenModel tokenModel = await userAccoutHttpRestul.Content.ReadAsAsync <TokenModel>();

                    if (string.IsNullOrWhiteSpace(tokenModel.jwt))
                    {
                        return(false);
                    }

                    SaveToken(tokenModel.jwt);
                    OnLicenseStatusChanced.Invoke(this, new LicenseEventArgs(true, tokenExist));
                    return(true);
                }
                else
                {
                    OnLicenseStatusChanced.Invoke(this, new LicenseEventArgs(false, tokenExist));
                    return(false);
                }
            }
            catch (Exception)
            {
                OnLicenseStatusChanced.Invoke(this, new LicenseEventArgs(false, tokenExist));
                return(false);
            }
        }
        public async Task <bool> CheckLicenseAsync()
        {
            bool networkConnection = await NetworkUtility.CheckInternetConnectionAsync();

            bool tokenExists   = await new LocalLicenseValidator().ValidateAsync();
            bool licenseStatus = networkConnection ? await new PersonalLicenseValidator().ValidateAsync() : tokenExists;

            OnLicenseStatusChanced.Invoke(this, new LicenseEventArgs(licenseStatus, tokenExists));
            return(licenseStatus);
        }
        public async Task <bool> CheckLicenseAsync(TokenModel tokenModel = null)
        {
            var networkAvailable = await NetworkUtility.CheckInternetConnectionAsync();

            if (tokenModel == null)
            {
                tokenModel = new TokenModel();
            }
            bool licenceStatus = networkAvailable ? await CheckOnlineLicenseAsync(tokenModel) : CheckLocalLicense();

            OnLicenseStatusChanced.Invoke(this, new LicenseEventArgs(licenceStatus));
            return(licenceStatus);
        }
        public async Task <bool> LoginAsync(UserModel userModel)
        {
            StringContent content = new StringContent(SeralizeUserModel(userModel), Encoding.UTF8, "application/json");

            try
            {
                using (HttpResponseMessage result = await ApiUtility.ApiClient.PostAsync(WebApiUrl.loginUrl, content))
                {
                    content.Dispose();
                    if (result.IsSuccessStatusCode)
                    {
                        TokenModel tokenModel = await result.Content.ReadAsAsync <TokenModel>();

                        LicenseController licenseController = new LicenseController();
                        bool licenseStatus = await licenseController.CheckLicenseAsync(tokenModel);

                        if (licenseStatus == false)
                        {
                            return(false);
                        }

                        SaveToken(tokenModel.jwt);
                        OnLicenseStatusChanced.Invoke(this, new LicenseEventArgs(true));
                        return(true);
                    }
                    else
                    {
                        OnLicenseStatusChanced.Invoke(this, new LicenseEventArgs(false));
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                OnLicenseStatusChanced.Invoke(this, new LicenseEventArgs(false));
                return(false);
            }
        }