Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add downloader example #1689

Closed
wants to merge 2 commits into from
Closed

Add downloader example #1689

wants to merge 2 commits into from

Conversation

tal66
Copy link
Contributor

@tal66 tal66 commented Apr 15, 2022

Hi,
finished this example,
let me know if there's something to improve here :)

( Closes #1680 )

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Apr 15, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Minor various formatting fixes in feedback

if (message.Metadata != null)
{
Console.WriteLine("Saving metadata to file");
string metadata = message.Metadata.ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string metadata = message.Metadata.ToString();
var metadata = message.Metadata.ToString();

Comment on lines +47 to +49
while (await call.ResponseStream.MoveNext())
{
var message = call.ResponseStream.Current;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while (await call.ResponseStream.MoveNext())
{
var message = call.ResponseStream.Current;
await foreach (var message in call.ResponseStream.ReadAllAsync())
{

Comment on lines +64 to +65
Console.WriteLine("\nFiles were saved in: " + downloadIdPath);
Console.WriteLine("\nPress any key to exit...");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of \n here? IMO use Console.WriteLine() to add additional line breaks if desired.

Comment on lines +18 to +19


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +23 to +24


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

}
});

var buffer = new byte[ChunkSize];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var buffer = new byte[ChunkSize];
var buffer = new byte[ChunkSize];

Comment on lines +44 to +49
await responseStream.WriteAsync(new DownloadFileResponse {
Metadata = new FileMetadata
{
FileName = filename
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await responseStream.WriteAsync(new DownloadFileResponse {
Metadata = new FileMetadata
{
FileName = filename
}
});
await responseStream.WriteAsync(new DownloadFileResponse
{
Metadata = new FileMetadata { FileName = filename }
});

_logger.LogInformation("Sending data chunk of {numBytesRead} bytes", numBytesRead);
await responseStream.WriteAsync(new DownloadFileResponse
{
Data = UnsafeByteOperations.UnsafeWrap(buffer.AsMemory(0, numBytesRead))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Data = UnsafeByteOperations.UnsafeWrap(buffer.AsMemory(0, numBytesRead))
Data = UnsafeByteOperations.UnsafeWrap(buffer.AsMemory(0, numBytesRead))


while (true)
{
int numBytesRead = await fileStream.ReadAsync(buffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int numBytesRead = await fileStream.ReadAsync(buffer);
var numBytesRead = await fileStream.ReadAsync(buffer);

Comment on lines +292 to +293


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@tal66
Copy link
Contributor Author

tal66 commented Apr 18, 2022

i'm not sure how to edit this pull request without tons of commits.
i'll re-clone and do another pull request, this time on a separate branch

@JamesNK
Copy link
Member

JamesNK commented Apr 18, 2022

Lots of commits are fine. Squash merging is simple.

@tal66 tal66 mentioned this pull request Apr 18, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request downloader sample
2 participants