Example #1
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);
        }