public MegaConfigureViewModel()
        {
            Task.Run(async() =>
            {
                try
                {
                    IsWorking = true;

                    if (AssistantOptions.BackupOptions.Provider is MegaBackupProvider provider &&
                        provider.Authentication != null)
                    {
                        OverwriteExisting = provider.OverwriteExisting;

                        _client.Login(new MegaApiClient.LogonSessionToken(provider.Authentication.SessionId,
                                                                          provider.Authentication.MasterKey));

                        IAccountInformation info = await _client.GetAccountInformationAsync();

                        IsLoggedIn = true;
                    }
                }
                catch (Exception)
                {
                    IsLoggedIn = false;
                }
                finally
                {
                    IsWorking = false;
                }
            });
        }
Esempio n. 2
0
        /// <inheritdoc cref="IFileUploader"/>
        /// <summary>
        /// Uploads the file to mega.nz.
        /// </summary>
        /// <returns>The result as <see cref="string"/>.</returns>
        /// <seealso cref="IFileUploader"/>
        public async Task <string> UploadToMega()
        {
            var client           = new MegaApiClient();
            var possibleAccounts = this.GetPossibleAccounts("mega");

            foreach (var account in possibleAccounts)
            {
                LoginMega(client, account);
                var info = await client.GetAccountInformationAsync();

                if (info.UsedQuota + GetFileSize(this.FileName) > info.TotalQuota)
                {
                    continue;
                }

                var root     = GetRootFolderMega(client);
                var progress = this.GetProgress();
                var node     = await client.UploadFileAsync(this.FileName, root, progress, null);

                var link = await client.GetDownloadLinkAsync(node);

                await client.LogoutAsync();

                return(link.AbsoluteUri);
            }

            return(string.Empty);
        }