Using Delegates To Follow Upload Progress Via WCF Method


P

pbd22

Hi.

I have successfully designed a large file upload method using WCF.
Now, I would like to report progress for each unique file being
loaded. In my upload method, i have the following code block:

Code:

while ((bytesRead = request.FileByteStream.Read(buffer, 0,
bufferSize)) > 0)
{
outfile.Write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;

if (this.ProgressChanged != null)
this.ProgressChanged(this, new ProgressArgs(totalBytesRead,
request.FileByteStream.Length));

}



Which uses the delegate ProgressEventHandler as declared below:

Code:

public delegate void ProgressEventHandler(object sender, ProgressArgs
e);
public event ProgressEventHandler ProgressChanged;

I do not use delegates all that much and got this far by following
examples online. The class ProgressArgs was missing from the example
but I am guessing that is where the calculation takes place and is
returned? Something like:

return Convert.ToInt32((totalBytesRead * 100) / fileSize) ?

So, my questions are thus:

1) Assming I have declared and called my ProgressChanged event
correctly, what is the role of ProgressArgs?

2) How do I report progress back to the client? My WCF method call
currently has a 'void' return type:

Code:

upload.UploadFile(fileinfo, m_objFile.InputStream);

Will I need to fire a simultaneous JavaScript method that calls a WCF
JSON method or something of that nature? If so, it is still unclear to
me how the delegate is used/accessed to report **which file** and
**what precent of it** is being uploaded.

Thanks!

PS - I am using ASP.NET 2.0 / Framework 3.5 / C# / and I am self-
hosting currently.
 
Ad

Advertisements

P

pbd22

Hi.

I have successfully designed a large file upload method using WCF.
Now, I would like to report progress for each unique file being
loaded. In my upload method, i have the following code block:

Code:

while ((bytesRead = request.FileByteStream.Read(buffer, 0,
bufferSize)) > 0)
{
    outfile.Write(buffer, 0, bytesRead);
    totalBytesRead += bytesRead;

    if (this.ProgressChanged != null)
        this.ProgressChanged(this, new ProgressArgs(totalBytesRead,
request.FileByteStream.Length));

}

Which uses the delegate ProgressEventHandler as declared below:

Code:

public delegate void ProgressEventHandler(object sender, ProgressArgs
e);
public event ProgressEventHandler ProgressChanged;

I do not use delegates all that much and got this far by following
examples online. The class ProgressArgs was missing from the example
but I am guessing that is where the calculation takes place and is
returned? Something like:

return Convert.ToInt32((totalBytesRead * 100) / fileSize) ?

So, my questions are thus:

1) Assming I have declared and called my ProgressChanged event
correctly, what is the role of ProgressArgs?

2) How do I report progress back to the client? My WCF method call
currently has a 'void' return type:

Code:

upload.UploadFile(fileinfo, m_objFile.InputStream);

Will I need to fire a simultaneous JavaScript method that calls a WCF
JSON method or something of that nature? If so, it is still unclear to
me how the delegate is used/accessed to report **which file** and
**what precent of it** is being uploaded.

Thanks!

PS - I am using ASP.NET 2.0 / Framework 3.5 / C# / and I am self-
hosting currently.

Anything else I can add to clarify?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top