Пример #1
0
        public TransferListViewModel(MTransferType type) : base(SdkService.MegaSdk)
        {
            this.Type = type;
            switch (this.Type)
            {
            case MTransferType.TYPE_DOWNLOAD:
                this.Description = UiResources.Downloads;
                this.CancelTransfersTitleText       = UiResources.UI_CancelDownloads;
                this.CancelTransfersDescriptionText = AppMessages.AM_CancelDownloadsQuestion;
                this.Items = TransfersService.MegaTransfers.Downloads;
                break;

            case MTransferType.TYPE_UPLOAD:
                this.Description = UiResources.Uploads;
                this.CancelTransfersTitleText       = UiResources.UI_CancelUploads;
                this.CancelTransfersDescriptionText = AppMessages.AM_CancelUploadsQuestion;
                this.Items = TransfersService.MegaTransfers.Uploads;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            this.IsCompletedTransfersList = false;
            this.PauseOrResumeCommand     = new DelegateCommand(PauseOrResumeTransfers);
            this.CancelCommand            = new DelegateCommand(CancelTransfers);
            this.CleanCommand             = new DelegateCommand(CleanTransfers);

            this.Items.CollectionChanged += ItemsOnCollectionChanged;

            this.SetEmptyContentTemplate();
        }
Пример #2
0
        private void Initialize(IMegaNode selectedNode, MTransferType transferType,
                                string transferPath, string externalDownloadPath = null)
        {
            this.TypeAndState = new object[2];

            switch (transferType)
            {
            case MTransferType.TYPE_DOWNLOAD:
                this.DisplayName = selectedNode.Name;
                this.TotalBytes  = selectedNode.Size;
                break;

            case MTransferType.TYPE_UPLOAD:
                this.DisplayName = Path.GetFileName(transferPath);
                if (FileService.FileExists(transferPath))
                {
                    Task.Run(async() =>
                    {
                        try
                        {
                            var srcFile = await StorageFile.GetFileFromPathAsync(transferPath);
                            if (srcFile != null)
                            {
                                var fileProperties = await srcFile.GetBasicPropertiesAsync();
                                this.TotalBytes    = fileProperties.Size;
                            }
                        }
                        catch (Exception e)
                        {
                            var message = (this.DisplayName == null) ? "Error getting transfer size" :
                                          string.Format("Error getting transfer size. File: '{0}'", this.DisplayName);
                            LogService.Log(MLogLevel.LOG_LEVEL_WARNING, message, e);
                        }
                    });
                }
                break;
            }

            this.IsBusy                       = false;
            this.Type                         = transferType;
            this.TransferPath                 = transferPath;
            this.ExternalDownloadPath         = externalDownloadPath;
            this.TransferState                = MTransferState.STATE_NONE;
            this.TransferedBytes              = 0;
            this.TransferSpeed                = string.Empty;
            this.SelectedNode                 = selectedNode;
            this.AutoLoadImageOnFinish        = false;
            this.PauseOrResumeTransferCommand = new RelayCommand(PauseOrResumeTransfer);
            this.CancelTransferCommand        = new RelayCommand(CancelTransfer);
            this.RetryTransferCommand         = new RelayCommand(RetryTransfer);
            this.RemoveTransferCommand        = new RelayCommand(RemoveTransfer);
            SetThumbnail();
        }
Пример #3
0
        private void Initialize(IMegaNode selectedNode, MTransferType transferType,
                                string transferPath, string externalDownloadPath = null)
        {
            this.TypeAndState = new object[2];

            switch (transferType)
            {
            case MTransferType.TYPE_DOWNLOAD:
                DisplayName = selectedNode.Name;
                TotalBytes  = selectedNode.Size;
                break;

            case MTransferType.TYPE_UPLOAD:
                DisplayName = Path.GetFileName(transferPath);
                if (FileService.FileExists(transferPath))
                {
                    Task.Run(async() =>
                    {
                        try
                        {
                            var srcFile = await StorageFile.GetFileFromPathAsync(transferPath);
                            if (srcFile != null)
                            {
                                var fileProperties = await srcFile.GetBasicPropertiesAsync();
                                this.TotalBytes    = fileProperties.Size;
                            }
                        }
                        catch (Exception e)
                        {
                            var message = (this.DisplayName == null) ? "Error getting transfer size" :
                                          string.Format("Error getting transfer size. File: '{0}'", this.DisplayName);
                            LogService.Log(MLogLevel.LOG_LEVEL_WARNING, message, e);
                        }
                    });
                }
                break;
            }

            Type                  = transferType;
            TransferPath          = transferPath;
            ExternalDownloadPath  = externalDownloadPath;
            TransferState         = MTransferState.STATE_NONE;
            TransferedBytes       = 0;
            TransferSpeed         = string.Empty;
            SelectedNode          = selectedNode;
            TransferButtonIcon    = new Uri("/Assets/Images/cancel transfers.Screen-WXGA.png", UriKind.Relative);
            AutoLoadImageOnFinish = false;
            CancelTransferCommand = new DelegateCommand(CancelTransfer);
            SetThumbnail();
        }
Пример #4
0
        /// <summary>
        /// Update a transfers list.
        /// </summary>
        /// <param name="megaTransfers"><see cref="TransferQueue"/> which contains the transfers list(s).</param>
        /// <param name="type">Type of the transfers list to update (Download or Upload).</param>
        /// <param name="cleanTransfers">Boolean value which indicates if clean the transfers list before update or not.</param>
        public static void UpdateMegaTransferList(TransferQueue megaTransfers, MTransferType type, bool cleanTransfers = false)
        {
            var transferData = SdkService.MegaSdk.getTransferData();

            switch (type)
            {
            case MTransferType.TYPE_DOWNLOAD:
                if (cleanTransfers)
                {
                    megaTransfers.Downloads.Clear();
                }

                for (int i = 0; i < transferData.getNumDownloads(); i++)
                {
                    AddTransferToList(megaTransfers, SdkService.MegaSdk.getTransferByTag(transferData.getDownloadTag(i)));
                }
                break;

            case MTransferType.TYPE_UPLOAD:
                // List to store the uploads that are pending on preparation (copy file to the temporary upload folder),
                // because they have not already added to the SDK queue
                List <TransferObjectModel> uploadsInPreparation = new List <TransferObjectModel>();

                if (cleanTransfers)
                {
                    // Store the uploads pending on preparation and clear the list
                    uploadsInPreparation = megaTransfers.Uploads.Where(t => t.PreparingUploadCancelToken != null).ToList();
                    megaTransfers.Uploads.Clear();
                }

                for (int i = 0; i < transferData.getNumUploads(); i++)
                {
                    AddTransferToList(megaTransfers, SdkService.MegaSdk.getTransferByTag(transferData.getUploadTag(i)));
                }

                foreach (var upload in uploadsInPreparation)
                {
                    megaTransfers.Add(upload);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("type", type, null);
            }
        }
Пример #5
0
        public TransferListViewModel(MTransferType type) : base(SdkService.MegaSdk)
        {
            this.Type           = type;
            this.ItemCollection = new CollectionViewModel <TransferObjectModel>(this.MegaSdk);

            switch (this.Type)
            {
            case MTransferType.TYPE_DOWNLOAD:
                this.Description                    = ResourceService.UiResources.GetString("UI_Downloads");
                this.EmptyStateHeaderText           = ResourceService.EmptyStates.GetString("ES_DownloadsHeader");;
                this.EmptyStateSubHeaderText        = ResourceService.EmptyStates.GetString("ES_DownloadsSubHeader");
                this.CancelTransfersTitleText       = ResourceService.UiResources.GetString("UI_CancelDownloads");
                this.CancelTransfersDescriptionText = ResourceService.AppMessages.GetString("AM_CancelDownloadsQuestion");
                this.ItemCollection.Items           = TransferService.MegaTransfers.Downloads;
                break;

            case MTransferType.TYPE_UPLOAD:
                this.Description                    = ResourceService.UiResources.GetString("UI_Uploads");
                this.EmptyStateHeaderText           = ResourceService.EmptyStates.GetString("ES_UploadsHeader");;
                this.EmptyStateSubHeaderText        = ResourceService.EmptyStates.GetString("ES_UploadsSubHeader");
                this.CancelTransfersTitleText       = ResourceService.UiResources.GetString("UI_CancelUploads");
                this.CancelTransfersDescriptionText = ResourceService.AppMessages.GetString("AM_CancelUploadsQuestion");
                this.ItemCollection.Items           = TransferService.MegaTransfers.Uploads;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            this.IsCompletedTransfersList = false;
            this.PauseOrResumeCommand     = new RelayCommand(PauseOrResumeTransfers);
            this.CancelCommand            = new RelayCommand(CancelTransfers);
            this.CleanCommand             = new RelayCommand <bool>(UpdateTransfers);

            this.ItemCollection.Items.CollectionChanged += ItemsOnCollectionChanged;
        }
Пример #6
0
 public TransferObjectModel(MegaSDK megaSdk, IMegaNode selectedNode, MTransferType transferType,
                            string transferPath, string externalDownloadPath = null) : base(megaSdk)
 {
     Initialize(selectedNode, transferType, transferPath, externalDownloadPath);
 }