Exemplo n.º 1
0
        private void ProcessDataPartMessage(DataPartMessage dataPartMessage)
        {
            if (!this._receivedPackageInfoMessages.ContainsKey(dataPartMessage.ObjectID))
            {
                return;
            }

            this.OnChunkReceived?.Invoke(dataPartMessage.ObjectID);

            var packageInfoMessage = this._receivedPackageInfoMessages[dataPartMessage.ObjectID];
            var dataParts          = this.GetOrAddCurrentlyReceivingDataParts(packageInfoMessage);

            if (!dataParts.ContainsKey(dataPartMessage.PartID) &&
                HashHelper.GetStringHash(dataPartMessage.Data) == dataPartMessage.DataHash)
            {
                dataParts.Add(dataPartMessage.PartID, dataPartMessage.Data);
            }

            int progress = 1 + 99 * dataParts.Count / packageInfoMessage.NumberOfParts;

            this.OnProgressChanged?.Invoke(progress);

            if (dataParts.Count == packageInfoMessage.NumberOfParts)
            {
                this.HandleDataReceived(packageInfoMessage, dataParts);
            }
        }
Exemplo n.º 2
0
        private static string[] CreateDataPartsMessages(string[] dataParts, string objectID)
        {
            var dataPartsMessages = new List <string>();

            for (int i = 0; i < dataParts.Length; i++)
            {
                var dataPartMessage = new DataPartMessage
                {
                    MsgIntegrity = Constants.DataPartMessageIntegrityCheckID,
                    PartID       = i,
                    Data         = dataParts[i],
                    DataHash     = HashHelper.GetStringHash(dataParts[i]),
                    ObjectID     = objectID,
                };

                var dataPartMessageStr = JsonSerializer.Serialize(dataPartMessage);
                dataPartsMessages.Add(dataPartMessageStr);
            }

            return(dataPartsMessages.ToArray());
        }