Exemplo n.º 1
0
        private string SerializeMetadata(TransferMetadata metadata)
        {
            var serializer  = new XmlSerializer(typeof(TransferMetadata));
            var xmlMetadata = new StringBuilder();
            var writer      = new StringWriter(xmlMetadata);

            serializer.Serialize(writer, metadata);
            return(xmlMetadata.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Records a file transfer for future resuming between core restarts.
        /// </summary>
        /// <param name="file">The file associated with the transfer.</param>
        /// <param name="friendNumber">The friend number of the transfer.</param>
        /// <param name="fileNumber">The file number of the transfer.</param>
        /// <param name="direction">The direction of the transfer.</param>
        public void RecordTransfer(StorageFile file, int friendNumber, int fileNumber, TransferDirection direction)
        {
            // TODO: Maybe we should try to make place for newer items?
            if (_futureAccesList.MaximumItemsAllowed == _futureAccesList.Entries.Count)
                return;

            var metadata = new TransferMetadata
            {
                FriendNumber = friendNumber,
                FileNumber = fileNumber,
                FileId = ToxModel.Instance.FileGetId(friendNumber, fileNumber),
                TransferredBytes = 0,
                Direction = direction
            };

            var xmlMetadata = SerializeMetadata(metadata);

            _futureAccesList.Add(file, xmlMetadata);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Records a file transfer for future resuming between core restarts.
        /// </summary>
        /// <param name="file">The file associated with the transfer.</param>
        /// <param name="friendNumber">The friend number of the transfer.</param>
        /// <param name="fileNumber">The file number of the transfer.</param>
        /// <param name="direction">The direction of the transfer.</param>
        public void RecordTransfer(StorageFile file, int friendNumber, int fileNumber, TransferDirection direction)
        {
            // TODO: Maybe we should try to make place for newer items?
            if (_futureAccesList.MaximumItemsAllowed == _futureAccesList.Entries.Count)
            {
                return;
            }

            var metadata = new TransferMetadata
            {
                FriendNumber     = friendNumber,
                FileNumber       = fileNumber,
                FileId           = _toxModel.FileGetId(friendNumber, fileNumber),
                TransferredBytes = 0,
                Direction        = direction
            };

            var xmlMetadata = SerializeMetadata(metadata);

            _futureAccesList.Add(file, xmlMetadata);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Constructs and returns resume data (based on metadata) necessary for a transfer to resume it.
        /// </summary>
        /// <param name="token">The token of the record in the future access list.</param>
        /// <param name="metadata">The metadata of the transfer to get the resume data for.</param>
        /// <returns>The resume data.</returns>
        private async Task <ResumeData> GetResumeData(string token, TransferMetadata metadata)
        {
            try
            {
                var file = await _futureAccesList.GetFileAsync(token);

                _futureAccesList.Remove(token);

                var resumeData = new ResumeData
                {
                    FriendNumber     = metadata.FriendNumber,
                    File             = file,
                    FileId           = metadata.FileId,
                    TransferredBytes = metadata.TransferredBytes
                };
                return(resumeData);
            }
            catch (FileNotFoundException)
            {
                // If we don't find the file anymore, we really don't need to keep record of it.
                _futureAccesList.Remove(token);
            }
            return(null);
        }
Exemplo n.º 5
0
 private string SerializeMetadata(TransferMetadata metadata)
 {
     var serializer = new XmlSerializer(typeof (TransferMetadata));
     var xmlMetadata = new StringBuilder();
     var writer = new StringWriter(xmlMetadata);
     serializer.Serialize(writer, metadata);
     return xmlMetadata.ToString();
 }
Exemplo n.º 6
0
        /// <summary>
        ///     Constructs and returns resume data (based on metadata) necessary for a transfer to resume it.
        /// </summary>
        /// <param name="token">The token of the record in the future access list.</param>
        /// <param name="metadata">The metadata of the transfer to get the resume data for.</param>
        /// <returns>The resume data.</returns>
        private async Task<ResumeData> GetResumeData(string token, TransferMetadata metadata)
        {
            try
            {
                var file = await _futureAccesList.GetFileAsync(token);
                _futureAccesList.Remove(token);

                var resumeData = new ResumeData
                {
                    FriendNumber = metadata.FriendNumber,
                    File = file,
                    FileId = metadata.FileId,
                    TransferredBytes = metadata.TransferredBytes
                };
                return resumeData;
            }
            catch (FileNotFoundException)
            {
                // If we don't find the file anymore, we really don't need to keep record of it.
                _futureAccesList.Remove(token);
            }
            return null;
        }