Пример #1
0
        private void AddMessageToDictionary(FileBatchMessage message)
        {
            if (!_filesPatches.ContainsKey(message.FileDataHash))
            {
                _filesPatches.Add(message.FileDataHash, new List <FileBatchMessage>());
            }

            _filesPatches[message.FileDataHash].Add(message);
        }
Пример #2
0
        private byte[] GetReceivedBytes(FileBatchMessage message)
        {
            var bytesEnumerable = _filesPatches[message.FileDataHash].OrderBy(patch => patch.CurrentFilePatchNumber)
                                  .Select(patch => patch.FilePatchData)
                                  .ToList();

            var bytes = new List <byte>();

            bytesEnumerable.ForEach(item => bytes.AddRange(item));

            return(bytes.ToArray());
        }
Пример #3
0
        private void ProcessReceivedFileBatchMessage(FileBatchMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            _safeExecuteManager.ExecuteWithExceptionLogging(() =>
            {
                AddMessageToDictionary(message);

                if (HasAllAllPatchesBeenReceived(message))
                {
                    var fileBytes = GetReceivedBytes(message);
                    ProceedReceivedBytes(message, fileBytes);
                }
            });
        }
Пример #4
0
        private void ProceedReceivedBytes(FileBatchMessage message, byte[] fileBytes)
        {
            _fileSystemHelper.FileHelper.WriteBytesToFile(Path.Combine(ReceivedFilesDirectory, message.FileName), fileBytes.ToArray());

            _filesPatches.Remove(message.FileDataHash);
        }
Пример #5
0
 private bool HasAllAllPatchesBeenReceived(FileBatchMessage message)
 {
     return(_filesPatches[message.FileDataHash].Count == message.TotalFilePatchNumber);
 }