Board index » delphi » Request progress

Request progress


2006-10-17 11:09:06 PM
delphi89
Hi all
This is actually a dotnet question, but those people in the MS newsgroups
are useless, despite the fact that there are 10 times more of them!
I was just wondering if there is a way to get the upload/download progress
of a request when that request sends/receives a large binary?
If you know how to do it in C# that would be great, if you know how to do it
in Win32 the info would still be appreciated!
Thanks
--
Pete
Blessed are the geek, for they shall public class GeekEarth : Earth {}
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
====
 
 

Re:Request progress

Hi Pete,
Quote
I was just wondering if there is a way to get the upload/download progress
of a request when that request sends/receives a large binary?
So you are writing a client, which makes a request, and you want the
client to show the progress, right?
Well, using a .NET client, you have the option of making the
asynchronous request, which means you have a callback function that is
called for every intermediate piece of result which is sent to you. It
would mean that the server sends you partial updates before everything
is done (so the client is notified of the next progress step), and it
might help if the client knows how much more work is expected...
Do you have any control over that kind of information (like the
filesize, which might be determined on beforehand), or do you want a
real generic solution?
Quote
If you know how to do it in C# that would be great, if you know how to do it
in Win32 the info would still be appreciated!
It's actually easier in Delphi for .NET ;-)
Groetjes,
Bob Swart
--
Bob Swart Training & Consultancy (eBob42.com) Forever Loyal to Delphi
Blog: www.drbob42.com/blog - RSS: drbob42.com/weblog.xml
New Delphi 2006 Courseware e-books at www.eBob42.com/courseware
 

Re:Request progress

Hi Bob
Quote
So you are writing a client, which makes a request, and you want the
client to show the progress, right?
Yes. Basically I am uploading a file and then downloading a file, at the
moment this is done via FTP but the customer wants to close down all ports
except 80 (strangely the only port which they have been successfully
attacked with). I will know the upload file size but not the download file
size. Something like this
[WebMethod]
public void PutFile(string fileName, byte[] data);
[WebMethod]
public byte[] GetFile(string fileName);
Any info greatly appreciated, thanks.
--
Pete
Blessed are the geek, for they shall public class GeekEarth : Earth {}
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
====
 

Re:Request progress

Hello Peter,
I don't know how relevant this article is anymore (and maybe you've seen it
already) but here's something that might be helpful:
msdn.microsoft.com/library/default.asp
"Adding a ProgressBar to your Web Service Client Application".
Cheers,
Bruneau.
 

Re:Request progress

Hi
I will read through that as soon as I get a chance, thankyou very much!
--
Pete
Blessed are the geek, for they shall public class GeekEarth : Earth {}
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
====
 

Re:Request progress

Jean-Marie Babet writes:
Quote
Hello Peter,

I don't know how relevant this article is anymore (and maybe you've
seen it already) but here's something that might be helpful:

msdn.microsoft.com/library/default.asp
vice/html/service11052002.asp

"Adding a ProgressBar to your Web Service Client Application".

[Long message]
Wow. That was cool. I managed to finally get it to twist and turn and
actually work with my Delphi (Win32) download progress bar code
(www.agnisoft.com/white_papers/dlprogress/dlprogress.asp)
(Note: that project has one file referenced wrong in the server DPR
file, which btw is a Web App De{*word*81} app. You can correct it by
editing the dpr - I no longer work there and have no access)
The Microsoft article expects you to already know the transfer size,
which honestly is silly. But then you don't get any knowledge of the
transfer size in your SoapExtension (which gets you a non-seekable
stream meaning you can not get Stream.Length() from it)
So how do you get to the length then? Response.ContentLength is your
answer, except where can you see Response? Answer: NOWHERE. I had to
use Reflector to back up the call stack a little bit and find a
reasonable place, and that is another overridden method. Heck, let me
not bore you with all of this. Here's the Extension code:
namespace DotNetProgress
{
internal class ProgressClient :
DotNetProgress.localhost.IIDownloaderservice
{
public ProgressBar Progress;
public int TransferSize;
public Form1.UpdateDelegate ProgressDelegate;
public WebResponse _Response = null;
protected override WebResponse GetWebResponse(WebRequest
request)
{
_Response = base.GetWebResponse(request);
return _Response;
}
}
public class ProgressExtension : SoapExtension
{
// Holds the original stream
private Stream m_oldStream;
// The new stream
private Stream m_newStream;
// The buffer for reading from the old stream
// and writing to the new stream
private byte[] m_bufferIn;
// The progress bar we will be incrementing
private ProgressBar m_Progress;
// The size of each read
private int m_readSize;
private int m_totalSize;
// The delegate we will invoke for updating the
// progress bar.
private Form1.UpdateDelegate m_progressDelegate;
// Used to keep track of which stream we are trying
// to chain into
private bool m_isAfterSerialization;
public override void ProcessMessage(SoapMessage message)
{
switch (message.Stage)
{
case SoapMessageStage.AfterSerialize:
// To let us know that the next ChainStream call
// will let us hook in where we want.
m_isAfterSerialization = true;
break;
case SoapMessageStage.BeforeDeserialize:
// This is where we stream through the data
SoapClientMessage clientMessage
= (SoapClientMessage)message;
if (clientMessage.Client is ProgressClient)
{
ProgressClient proxy
= (ProgressClient)clientMessage.Client;
m_Progress = proxy.Progress;
// Read 1/100th of the request at a time.
// This will give the progress bar 100
// notifications.
//m_readSize = proxy.TransferSize / 100;
m_readSize = 8192;
m_totalSize = ((int)
proxy._Response.ContentLength) / 100;
m_progressDelegate = proxy.ProgressDelegate;
}
int CurRead = 0;
while (true)
{
try
{
int bytesRead
= m_oldStream.Read(m_bufferIn,
0,
m_readSize);
if (bytesRead == 0)
{
// end of message...rewind the
// memory stream so it is ready
// to be read during deserial.
m_newStream.Seek(0,
System.IO.SeekOrigin.Begin);
return;
}
m_newStream.Write(m_bufferIn,
0,
bytesRead);
// Update the progress bar
CurRead += bytesRead;
m_Progress.Invoke(m_progressDelegate, new
object[] { CurRead, m_totalSize });
}
catch
{
// rewind the memory stream
m_newStream.Seek(0,
System.IO.SeekOrigin.Begin);
return;
}
}
}
}
public override Stream ChainStream(Stream stream)
{
if (m_isAfterSerialization)
{
m_oldStream = stream;
m_newStream = new MemoryStream();
m_bufferIn = new Byte[8192];
return m_newStream;
}
return stream;
}
// We don't have an initializer to be shared across streams
public override object GetInitializer(Type serviceType)
{
return null;
}
public override object GetInitializer(
LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
return null;
}
public override void Initialize(object initializer)
{ m_isAfterSerialization = false; }
}
}
and in the Main Form:
private void btnDownload_Click(object sender, EventArgs e)
{
ProgressClient srv = new ProgressClient();
srv.Progress = this.progressBar1;
srv.TransferSize = 8192 * 100;
srv.ProgressDelegate = new
UpdateDelegate(ProgressBarUpdate);
srv.DownloadFile(edtFileName.Text);
}
public delegate void UpdateDelegate( int CurRead, int
TotalSize);
private void ProgressBarUpdate( int CurRead, int TotalSize)
{
progressBar1.Value = CurRead / TotalSize;
Application.DoEvents();
}
If this is still confusing, let me know and I will bundle it all up and
email. it is a wonder you're still reading this, really.
--
Deepak Shenoy (TeamB)
shenoyatwork.blogspot.com
 

Re:Request progress

Hi Deepak,
Quote
So how do you get to the length then? Response.ContentLength is your
answer, except where can you see Response? Answer: NOWHERE. I had to
use Reflector to back up the call stack a little bit and find a
reasonable place, and that is another overridden method. Heck, let me
not bore you with all of this. Here's the Extension code:
Thanks for sharing. One little comment:
Quote
while (true)
I would probably code this as a "repeat ... until butesRead = 0" in
Delphi ;-)
Quote
If this is still confusing, let me know and I will bundle it all up and
email. it is a wonder you're still reading this, really.
I read all the way until the end ;-)
Groetjes,
Bob Swart
--
Bob Swart Training & Consultancy (eBob42.com) Forever Loyal to Delphi
Blog: www.drbob42.com/blog - RSS: drbob42.com/weblog.xml
New Delphi 2006 Courseware e-books at www.eBob42.com/courseware
 

Re:Request progress

Bob Swart writes:
Quote
I would probably code this as a "repeat ... until butesRead = 0" in
Delphi ;-)
That's probably a better solution, honestly. I don't like While(true)
at at all, it is a kind of C legacy that refuses to go away. That code
though was not mine - it was the MSDN article code that I tweaked...
Quote
>If this is still confusing, let me know and I will bundle it all up
>and email. it is a wonder you're still reading this, really.

I read all the way until the end ;-)
Pretty cool :) Hope the code works at your end though!
--
Deepak Shenoy (TeamB)
shenoyatwork.blogspot.com
 

Re:Request progress

Quote
That's probably a better solution, honestly. I don't like While(true)
at at all, it is a kind of C legacy that refuses to go away
You could use
do
{
}
while (bytesRead != 0);
--
Pete
Blessed are the geek, for they shall public class GeekEarth : Earth {}
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
====
 

Re:Request progress

Peter Morris [Droopy eyes software] writes:
Quote
>That's probably a better solution, honestly. I don't like
>While(true) at at all, it is a kind of C legacy that refuses to go
>away

You could use

do
{
}
while (bytesRead != 0);
Ah yes. Good idea. Have mailed the original author of the article as
well.
--
Deepak Shenoy (TeamB)
shenoyatwork.blogspot.com
 

Re:Request progress

Quote
Hi all

This is actually a dotnet question, but those people in the MS newsgroups
are useless, despite the fact that there are 10 times more of them!

I was just wondering if there is a way to get the upload/download progress
of a request when that request sends/receives a large binary?

If you know how to do it in C# that would be great, if you know how to do it
in Win32 the info would still be appreciated!

Thanks


--
Pete

Blessed are the geek, for they shall public class GeekEarth : Earth {}
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
====

Nice design, good graphical content. I think I will come back later again;) phentermines.forum-on.de
BizTalk Utilities - Frustration free BizTalk Adapters
www.topxml.com/biztalkutilities
 

Re:Request progress

Quote
Hi all

This is actually a dotnet question, but those people in the MS newsgroups
are useless, despite the fact that there are 10 times more of them!

I was just wondering if there is a way to get the upload/download progress
of a request when that request sends/receives a large binary?

If you know how to do it in C# that would be great, if you know how to do it
in Win32 the info would still be appreciated!

Thanks


--
Pete

Blessed are the geek, for they shall public class GeekEarth : Earth {}
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
====

mmm.. nice design, I must say.. www.paradistc.org/italia
BizTalk Utilities - Frustration free BizTalk Adapters
www.topxml.com/biztalkutilities
 

Re:Request progress

Quote
Hi all

This is actually a dotnet question, but those people in the MS newsgroups
are useless, despite the fact that there are 10 times more of them!

I was just wondering if there is a way to get the upload/download progress
of a request when that request sends/receives a large binary?

If you know how to do it in C# that would be great, if you know how to do it
in Win32 the info would still be appreciated!

Thanks


--
Pete

Blessed are the geek, for they shall public class GeekEarth : Earth {}
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
====

Du musst ein Fachmann sein - wirklich guter Aufstellungsort, den du hast! www.paradistc.org/liberi
BizTalk Utilities - Frustration free BizTalk Adapters
www.topxml.com/biztalkutilities
 

Re:Request progress

Quote
Hi all

This is actually a dotnet question, but those people in the MS newsgroups
are useless, despite the fact that there are 10 times more of them!

I was just wondering if there is a way to get the upload/download progress
of a request when that request sends/receives a large binary?

If you know how to do it in C# that would be great, if you know how to do it
in Win32 the info would still be appreciated!

Thanks


--
Pete

Blessed are the geek, for they shall public class GeekEarth : Earth {}
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
====

i'am really impressed!! www.sanzkdni59.org/libera
BizTalk Utilities - Frustration free BizTalk Adapters
www.topxml.com/biztalkutilities
 

Re:Request progress

Quote
Hi all

This is actually a dotnet question, but those people in the MS newsgroups
are useless, despite the fact that there are 10 times more of them!

I was just wondering if there is a way to get the upload/download progress
of a request when that request sends/receives a large binary?

If you know how to do it in C# that would be great, if you know how to do it
in Win32 the info would still be appreciated!

Thanks


--
Pete

Blessed are the geek, for they shall public class GeekEarth : Earth {}
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
====

luogo grande:) nessun osservazioni! www.paradistc.org/sardinia
BizTalk Utilities - Frustration free BizTalk Adapters
www.topxml.com/biztalkutilities