TPL Dataflow Blocks: Transformblock<Tuple<byte[],int>,long> does not return a value, I...

  • Thread starter Thread starter Nic Scheepers
  • Start date Start date
N

Nic Scheepers

Guest
Hi There

I am new to TPL dataflow blocks and are still learning. If someone can help me with this problem or redirect me to an article specifically about the problem below it would be appreciated, all the articles on the web I found never spoke of this problem or admitted there can be a problem.

I am using TransFormBlock to send chunks of data up to a web service to upload big files to the server. That part is working fine.


_currentGuid = Guid.NewGuid();

service.InitialiseFileUpload(0, 0, _currentGuid, System.IO.Path.GetFileName(FileTextBox.Text), 0, null);

var fileId = _currentGuid;

var edb = new ExecutionDataflowBlockOptions { BoundedCapacity = 5, CancellationToken = m_cancelSource.Token, MaxDegreeOfParallelism = 5 };

var ab = new TransformBlock<Tuple<byte[], int>, long>(x => service.UploadFile(x.Item2, chunkSize, fileId, fileInfo.Name, x.Item1.Length, x.Item1), edb);

foreach (var item in stream.GetByteChunks(chunkSize).Select((x, i) => Tuple.Create(x, i)))
{
if (m_cancelSource.IsCancellationRequested)
{
progressBar1.Value = 0;
LogText("FileUpLoad Canceled");
return;
}

chunkList.Add(item.Item2);

ab.SendAsync(item, m_cancelSource.Token);
}

Where my problem is, is that I do get feedback from the service in this part, but it is all zeros. I am trying to return the long chunk number that was received at the server, to the client, so that I can show a progress bar of the actual data received on the server. So somewhere in the following code I must be doing something wrong on the client:


long chunkListCount = chunkList.Count;

Action<Task<long>> whenReady = task => {
var n = task.Result;
};

for (int i = 0; i < chunkList.Count; i++)
{
long result = await ab.ReceiveAsync(m_cancelSource.Token);

Task<long> resultTask = ab.ReceiveAsync();

resultTask.ContinueWith(whenReady);

//LogText(resultTask.Id.ToString());

//int perc = 0;
//if (resultTask.Id*100/chunkList.Count > 100)
// perc = 100;
//else
//{
// perc = resultTask.Id*100/chunkList.Count;
//}

//progressBar1.Value = perc;

}

ab.Complete();

await ab.Completion;





I left my commented lines in the code because that is where my problem lies. Just for completeness I am also giving the code running on the web service. Just a note, I have tried the normal receive, the


ReceiveAsync and with ContinueWith and without. All of those methods I used to receive the return value send 0s back. It seems like it does receive something in the receive buffer but the data is not what I am returning from the web service.



public DownloadedChunk UploadFile(RemoteFileInfo request)
{
try
{
if (!(fileGuids.BinarySearch(request.FileId) < 0))
{
if (!string.IsNullOrEmpty(System.IO.Path.GetFileName(request.FileName)))
{
var buffer = new byte[request.ChunkSize];

var file = new FileHandling();

string uploadDirectory = ConfigurationManager.AppSettings["UpLoadDirectory"];

string filePath = System.IO.Path.Combine(uploadDirectory,
path2: System.IO.Path.GetFileName(request.FileName ?? ""));

file.CreateNode(request.FileId, request.ChunkNo, request.FileByteStream, request.FileName,
request.ChunkSize, filePath);

var returnChunkNo = new DownloadedChunk()
{
ChunkNo = request.ChunkNo
};

return returnChunkNo;
}
var faultContract = new ExceptionFaultContract
{
StatusCode = "INVALID OPERATION",
Message = "file name is empty"
};
throw (new FaultException<ExceptionFaultContract>(faultContract,
new FaultReason("file name is empty")));
}
}
catch (Exception ex)
{
var faultContract = new ExceptionFaultContract
{
StatusCode = "INVALID OPERATION",
Message = ex.Message
};
if (ex.InnerException != null)
{
faultContract.Description = "Inner Exception : " + ex.InnerException.Message;
}
throw (new FaultException<ExceptionFaultContract>(faultContract, new FaultReason(ex.Message)));
}

var returnChunk = new DownloadedChunk()
{
ChunkNo = -1
};

return returnChunk;
}

Your help would be greatly appreciated.

Regards

Nic

Continue reading...
 
Back
Top