Exemplo n.º 1
0
        public void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            if (e.getErrorCode() == MErrorType.API_OK)
            {
                switch (request.getType())
                {
                case MRequestType.TYPE_ACCOUNT_DETAILS:

                    ulong TotalSpace = request.getMAccountDetails().getStorageMax();
                    ulong UsedSpace  = request.getMAccountDetails().getStorageUsed();
                    int   usedSpacePercent;

                    if ((TotalSpace > 0) && (UsedSpace > 0))
                    {
                        usedSpacePercent = (int)(UsedSpace * 100 / TotalSpace);
                    }
                    else
                    {
                        usedSpacePercent = 0;
                    }

                    // If used space is less than 95% and is a free account, the 5% of the times show a message to upgrade the account
                    if (usedSpacePercent <= 95)
                    {
                        if (request.getMAccountDetails().getProLevel() == MAccountType.ACCOUNT_TYPE_FREE)
                        {
                            Task.Run(() =>
                            {
                                Visibility visibility = GetRandomVisibility(5);
                                Deployment.Current.Dispatcher.BeginInvoke(() => _mainPage.ChangeGetProAccountBorderVisibility(visibility));

                                if (visibility == Visibility.Visible)
                                {
                                    this.TimerGetProAccountVisibility(30000);
                                }
                            });
                        }
                    }
                    // Else show a warning message indicating the user is running out of space
                    else
                    {
                        Task.Run(() =>
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(() => _mainPage.ChangeWarningOutOfSpaceBorderVisibility(Visibility.Visible));
                            this.TimerWarningOutOfSpaceVisibility(15000);
                        });
                    }

                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_ACCOUNT_DETAILS)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull get account details process
                    Tcs?.TrySetResult(request.getMAccountDetails());
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(null);
                    break;
                }
            }
        }
Exemplo n.º 3
0
        protected override void OnSuccesAction(MegaSDK api, MRequest request)
        {
            switch (request.getType())
            {
            case MRequestType.TYPE_ACCOUNT_DETAILS:

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    accountDetails.TotalSpace      = request.getMAccountDetails().getStorageMax();
                    accountDetails.TotalSpaceSize  = accountDetails.TotalSpace.ToReadableSize();
                    accountDetails.TotalSpaceUnits = accountDetails.TotalSpace.ToReadableUnits();
                    accountDetails.UsedSpace       = request.getMAccountDetails().getStorageUsed();
                    accountDetails.CreateDataPoints();
                    accountDetails.AccountType = request.getMAccountDetails().getProLevel();

                    if (accountDetails.AccountType == MAccountType.ACCOUNT_TYPE_FREE)
                    {
                        accountDetails.IsFreeAccount   = true;
                        accountDetails.AccountTypeText = AppResources.AccountTypeFree;
                        accountDetails.AccountTypeUri  = new Uri("/Assets/Images/small_free" + ImageService.GetResolutionExtension() + ".png", UriKind.Relative);
                    }
                    else
                    {
                        switch (accountDetails.AccountType)
                        {
                        case MAccountType.ACCOUNT_TYPE_LITE:
                            accountDetails.AccountTypeText = AppResources.AccountTypeLite;
                            //accountDetails.AccountTypeUri = new Uri("/Assets/Images/small_free" + ImageService.GetResolutionExtension() + ".png", UriKind.Relative);
                            break;

                        case MAccountType.ACCOUNT_TYPE_PROI:
                            accountDetails.AccountTypeText = AppResources.AccountTypePro1;
                            accountDetails.AccountTypeUri  = new Uri("/Assets/Images/small_pro1" + ImageService.GetResolutionExtension() + ".png", UriKind.Relative);
                            break;

                        case MAccountType.ACCOUNT_TYPE_PROII:
                            accountDetails.AccountTypeText = AppResources.AccountTypePro2;
                            accountDetails.AccountTypeUri  = new Uri("/Assets/Images/small_pro2" + ImageService.GetResolutionExtension() + ".png", UriKind.Relative);
                            break;

                        case MAccountType.ACCOUNT_TYPE_PROIII:
                            accountDetails.AccountTypeText = AppResources.AccountTypePro3;
                            accountDetails.AccountTypeUri  = new Uri("/Assets/Images/small_pro3" + ImageService.GetResolutionExtension() + ".png", UriKind.Relative);
                            break;
                        }

                        accountDetails.IsFreeAccount = false;

                        DateTime date;
                        DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, 0);

                        // If there is a valid subscription get the renew time
                        if (request.getMAccountDetails().getSubscriptionStatus() == MSubscriptionStatus.SUBSCRIPTION_STATUS_VALID)
                        {
                            try
                            {
                                if (request.getMAccountDetails().getSubscriptionRenewTime() != 0)
                                {
                                    date = start.AddSeconds(Convert.ToDouble(request.getMAccountDetails().getSubscriptionRenewTime()));
                                }
                                else
                                {
                                    date = start.AddSeconds(Convert.ToDouble(request.getMAccountDetails().getProExpiration()));
                                }

                                accountDetails.SubscriptionRenewDate = date.ToString("dd-MM-yyyy");
                            }
                            catch (ArgumentOutOfRangeException) { /* Do nothing*/ }

                            accountDetails.SubscriptionCycle   = request.getMAccountDetails().getSubscriptionCycle();
                            accountDetails.IsValidSubscription = true;
                        }
                        // Else get the expiration time for the current PRO status
                        else
                        {
                            try
                            {
                                date = start.AddSeconds(Convert.ToDouble(request.getMAccountDetails().getProExpiration()));
                                accountDetails.ProExpirationDate = date.ToString("dd-MM-yyyy");
                            }
                            catch (ArgumentOutOfRangeException) { /* Do nothing*/ }

                            accountDetails.IsValidSubscription = false;
                        }
                    }

                    if (_getAccountDetailsFinish != null)
                    {
                        _getAccountDetailsFinish.Invoke(this, EventArgs.Empty);
                    }
                });

                break;

            case MRequestType.TYPE_CREDIT_CARD_QUERY_SUBSCRIPTIONS:
                accountDetails.CreditCardSubscriptions = request.getNumber();
                break;
            }
        }