Esempio n. 1
0
        /// <summary>
        /// Search into a transfers list the <see cref="TransferObjectModel"/> corresponding to a <see cref="MTransfer"/>.
        /// </summary>
        /// <param name="transfersList">Transfers list where search the transfer.</param>
        /// <param name="transfer">Transfer to search.</param>
        /// <returns>The transfer object if exists or NULL in other case.</returns>
        public static TransferObjectModel SearchTransfer(IList <TransferObjectModel> transfersList, MTransfer transfer)
        {
            // Folder transfers are not included into the transfers list.
            if (transfersList == null || transfer == null || transfer.isFolderTransfer())
            {
                return(null);
            }

            TransferObjectModel megaTransfer = null;

            try
            {
                megaTransfer = transfersList.FirstOrDefault(
                    t => (t.Transfer != null && t.Transfer.getTag() == transfer.getTag()) ||
                    (t.TransferPath != null && t.TransferPath.Equals(transfer.getPath())));
            }
            catch (Exception e)
            {
                var fileName = transfer.getFileName();
                var message  = (fileName == null) ? "Error searching transfer" :
                               string.Format("Error searching transfer. File: '{0}'", fileName);
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, message, e);
                return(null);
            }

            return(megaTransfer);
        }
Esempio n. 2
0
        /// <summary>
        /// Add a <see cref="MTransfer"/> to the corresponding transfers list if it is not already included.
        /// </summary>
        /// <param name="megaTransfers"><see cref="TransferQueue"/> which contains the transfers list(s).</param>
        /// <param name="transfer"><see cref="MTransfer"/> to be added to the corresponding transfer list.</param>
        /// <returns>The <see cref="TransferObjectModel"/> corresponding to the <see cref="MTransfer"/>.</returns>
        public static TransferObjectModel AddTransferToList(TransferQueue megaTransfers, MTransfer transfer)
        {
            // Folder transfers are not included into the transfers list.
            if (transfer == null || transfer.isFolderTransfer())
            {
                return(null);
            }

            // Search if the transfer already exists into the transfers list.
            var megaTransfer = SearchTransfer(megaTransfers.SelectAll(), transfer);

            if (megaTransfer != null)
            {
                return(megaTransfer);
            }

            // If doesn't exist create a new one and add it to the transfers list
            megaTransfer = CreateTransferObjectModel(transfer);
            if (megaTransfer != null)
            {
                megaTransfers.Add(megaTransfer);
            }

            return(megaTransfer);
        }
Esempio n. 3
0
        /// <summary>
        /// This function is called when a transfer fails by a default error.
        /// It does the needed actions to process this kind of error.
        /// </summary>
        /// <param name="transfer"></param>
        private void ProcessDefaultError(MTransfer transfer)
        {
            string message, title = string.Empty;

            switch (transfer.getType())
            {
            case MTransferType.TYPE_DOWNLOAD:
                title = ResourceService.AppMessages.GetString("AM_DownloadFailed_Title");
                if (transfer.isFolderTransfer())
                {
                    message = ResourceService.AppMessages.GetString("AM_DownloadFolderFailed");
                }
                else
                {
                    message = ResourceService.AppMessages.GetString("AM_DownloadFileFailed");
                }
                break;

            case MTransferType.TYPE_UPLOAD:
                title = ResourceService.AppMessages.GetString("AM_UploadFailed_Title");
                if (transfer.isFolderTransfer())
                {
                    message = ResourceService.AppMessages.GetString("AM_UploadFolderFailed");
                }
                else
                {
                    message = ResourceService.AppMessages.GetString("AM_UploadFileFailed");
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            UiService.OnUiThread(async() =>
            {
                await DialogService.ShowAlertAsync(title,
                                                   string.Format(message, transfer.getFileName()));
            });
        }
Esempio n. 4
0
        public void onTransferFinish(MegaSDK api, MTransfer transfer, MError e)
        {
            // Extra checking to avoid NullReferenceException
            if (transfer == null)
            {
                return;
            }

            if (transfer.isFolderTransfer())
            {
                FolderTransferFinish(api, transfer, e);
            }
            else
            {
                FileTransferFinish(api, transfer, e);
            }
        }