Beispiel #1
0
        private void ThrowIfFullDataHashIsWrong(PackageInfoMessage packageInfoMessage, string fullDataStr)
        {
            var dataHash = HashHelper.GetStringHash(fullDataStr);

            if (dataHash != packageInfoMessage.DataHash)
            {
                throw new Exception($"Received data is incorrect. Hashes differ.");
            }
        }
Beispiel #2
0
        private Dictionary <int, string> GetOrAddCurrentlyReceivingDataParts(PackageInfoMessage packageInfoMessage)
        {
            if (!this._receivedItemsCache.ContainsKey(packageInfoMessage.DataHash))
            {
                this._receivedItemsCache.Add(packageInfoMessage.DataHash, new Dictionary <int, string>());
            }
            var dataParts = this._receivedItemsCache[packageInfoMessage.DataHash];

            return(dataParts);
        }
Beispiel #3
0
        private void ProcessPackageInfoMessage(PackageInfoMessage packageInfoMessage)
        {
            if (!this._receivedPackageInfoMessages.ContainsKey(packageInfoMessage.DataHash))
            {
                this._receivedPackageInfoMessages.Add(packageInfoMessage.ObjectID, packageInfoMessage);
            }

            this.OnProgressChanged?.Invoke(1);
            this.OnReceivingStarted?.Invoke(packageInfoMessage.ObjectID);
            this._currentlyReceivingObjectID = packageInfoMessage.ObjectID;
        }
Beispiel #4
0
        private void HandleDataReceived(PackageInfoMessage packageInfoMessage, Dictionary <int, string> dataParts)
        {
            var fullDataStr = string.Join("", dataParts.ToList().OrderBy(p => p.Key).Select(p => p.Value));

            this.ThrowIfFullDataHashIsWrong(packageInfoMessage, fullDataStr);

            var fullData = ConvertHelper.GetInitialDataFromZippedDataStr(fullDataStr, packageInfoMessage.DataType);

            this.NotifyDataReceived(fullData, packageInfoMessage.DataType);

            this.OnReceivingStopped?.Invoke(null);
            this._currentlyReceivingObjectID = null;
        }
Beispiel #5
0
        private static string CreatePackageInfoMessage(
            string[] dataParts, string dataType, string dataHash, string objectID)
        {
            var packageInfoMessage = new PackageInfoMessage
            {
                MsgIntegrity  = Constants.PackageInfoMessageIntegrityCheckID,
                NumberOfParts = dataParts.Length,
                DataType      = dataType,
                DataHash      = dataHash,
                ObjectID      = objectID,
            };

            var packageInfoMessageStr = JsonSerializer.Serialize(packageInfoMessage);

            return(packageInfoMessageStr);
        }
Beispiel #6
0
        private void NotifyIfNotAllDataPartsReceived(PackageInfoMessage packageInfoMessage, Dictionary <int, string> dataParts)
        {
            if (dataParts.Count != packageInfoMessage.NumberOfParts)
            {
                var idsNotReceived = new List <string>();
                for (int i = 0; i < packageInfoMessage.NumberOfParts; i++)
                {
                    if (!dataParts.ContainsKey(i))
                    {
                        idsNotReceived.Add(i.ToString());
                    }
                }

                var missingPartsCount = packageInfoMessage.NumberOfParts - dataParts.Count;
                this.OnNotification?.Invoke(
                    $"Data was not fully received.\n" +
                    $"{dataParts.Count} out of {packageInfoMessage.NumberOfParts} parts received.\n" +
                    $"{missingPartsCount} parts missing.\n" +
                    $"Missing IDs list:\n" +
                    string.Join(" ", idsNotReceived)
                    );
            }
        }