Example #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);
        }
Example #2
0
        public void onTransferStart(MegaSDK api, MTransfer transfer)
        {
            TransferObjectModel megaTransfer = null;

            if (transfer.getType() == MTransferType.TYPE_DOWNLOAD)
            {
                // If is a public node
                MNode node = transfer.getPublicMegaNode();
                if (node == null) // If not
                {
                    node = api.getNodeByHandle(transfer.getNodeHandle());
                }

                if (node != null)
                {
                    megaTransfer = new TransferObjectModel(api,
                                                           NodeService.CreateNew(api, App.AppInformation, node, ContainerType.CloudDrive),
                                                           TransferType.Download, transfer.getPath());
                }
            }
            else
            {
                megaTransfer = new TransferObjectModel(api, App.MainPageViewModel.CloudDrive.FolderRootNode,
                                                       TransferType.Upload, transfer.getPath());
            }

            if (megaTransfer != null)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    TransfersService.GetTransferAppData(transfer, megaTransfer);

                    megaTransfer.Transfer                      = transfer;
                    megaTransfer.Status                        = TransferStatus.Queued;
                    megaTransfer.CancelButtonState             = true;
                    megaTransfer.TransferButtonIcon            = new Uri("/Assets/Images/cancel transfers.Screen-WXGA.png", UriKind.Relative);
                    megaTransfer.TransferButtonForegroundColor = new SolidColorBrush(Colors.White);
                    megaTransfer.IsBusy                        = true;
                    megaTransfer.TotalBytes                    = transfer.getTotalBytes();
                    megaTransfer.TransferedBytes               = transfer.getTransferredBytes();
                    megaTransfer.TransferSpeed                 = transfer.getSpeed().ToStringAndSuffixPerSecond();

                    App.MegaTransfers.Add(megaTransfer);
                    Transfers.Add(megaTransfer);
                });
            }
        }
Example #3
0
        /// <summary>
        /// Create a <see cref="TransferObjectModel"/> from a <see cref="MTransfer"/>.
        /// </summary>
        /// <param name="transfer"></param>
        /// <returns>The new <see cref="TransferObjectModel"/></returns>
        public static TransferObjectModel CreateTransferObjectModel(MTransfer transfer)
        {
            if (transfer == null)
            {
                return(null);
            }

            try
            {
                TransferObjectModel megaTransfer = null;

                switch (transfer.getType())
                {
                case MTransferType.TYPE_DOWNLOAD:
                    MNode node = transfer.getPublicMegaNode() ??                               // If is a public node
                                 SdkService.MegaSdk.getNodeByHandle(transfer.getNodeHandle()); // If not

                    if (node == null)
                    {
                        return(null);
                    }

                    megaTransfer = new TransferObjectModel(SdkService.MegaSdk,
                                                           NodeService.CreateNew(SdkService.MegaSdk, App.AppInformation, node, ContainerType.CloudDrive),
                                                           MTransferType.TYPE_DOWNLOAD, transfer.getPath());
                    break;

                case MTransferType.TYPE_UPLOAD:
                    var parentNode = SdkService.MegaSdk.getNodeByHandle(transfer.getParentHandle());

                    if (parentNode == null)
                    {
                        return(null);
                    }

                    megaTransfer = new TransferObjectModel(SdkService.MegaSdk,
                                                           NodeService.CreateNew(SdkService.MegaSdk, App.AppInformation, parentNode, ContainerType.CloudDrive),
                                                           MTransferType.TYPE_UPLOAD, transfer.getPath());
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (megaTransfer != null)
                {
                    GetTransferAppData(transfer, megaTransfer);

                    megaTransfer.Transfer          = transfer;
                    megaTransfer.TransferState     = transfer.getState();
                    megaTransfer.TransferPriority  = transfer.getPriority();
                    megaTransfer.IsBusy            = false;
                    megaTransfer.TotalBytes        = transfer.getTotalBytes();
                    megaTransfer.TransferedBytes   = transfer.getTransferredBytes();
                    megaTransfer.TransferSpeed     = string.Empty;
                    megaTransfer.TransferMeanSpeed = 0;

                    megaTransfer.TransferState = !SdkService.MegaSdk.areTransfersPaused((int)transfer.getType())
                        ? MTransferState.STATE_QUEUED : MTransferState.STATE_PAUSED;
                }

                return(megaTransfer);
            }
            catch (Exception) { return(null); }
        }