private void AddMessageToDictionary(FileBatchMessage message) { if (!_filesPatches.ContainsKey(message.FileDataHash)) { _filesPatches.Add(message.FileDataHash, new List <FileBatchMessage>()); } _filesPatches[message.FileDataHash].Add(message); }
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()); }
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); } }); }
private void ProceedReceivedBytes(FileBatchMessage message, byte[] fileBytes) { _fileSystemHelper.FileHelper.WriteBytesToFile(Path.Combine(ReceivedFilesDirectory, message.FileName), fileBytes.ToArray()); _filesPatches.Remove(message.FileDataHash); }
private bool HasAllAllPatchesBeenReceived(FileBatchMessage message) { return(_filesPatches[message.FileDataHash].Count == message.TotalFilePatchNumber); }