Webclient Resume download with Async - wpf

I am implementing multiple file download progress in my WPF application. I need to maintain the downloaded data and resume the download if the internet fails during download.
For example, during the download progress if the internet fails i need to wait for 5 mins for the internet to reconnect and resume the download, if it fails to reconnect after 5 mins then the request needs to be terminated. And also the process needs to be Async since i am downloading multiple files and the second file must not start downloading second before the first file is downloaded.
using (client = new WebClient())
{
try
{
client.DownloadProgressChanged += client_DownloadProgressChanged;
client.DownloadFileCompleted += client_DownloadFileCompleted(fileName);
await AsyncPlatformExtensions.DownloadFileTaskAsync(client, new Uri(sourceUri), outputDir);
}
catch(WebException exe)
{
}
catch(Exception e)
{
}
}
I have checked a few links like below but none seems to be working.
https://github.com/Avira/.NetFileDownloader
https://github.com/markodt/SGet
https://www.codeproject.com/Tips/307548/Resume-Suppoert-Downloading
Please share your thoughts on how to retain the download cache and resume the download if the internet reconnects within a specified time.
Regards,
Cheran

Related

How to keep browser open with Selenium WebDriver 4 and Groovy on Jmeter?

I am currently in the process, with a Jmeter script, of opening firefox browsers which are functional. However, I have a small problem which is to let the browsers turn on even after the script is finished.
Currently my browsers turn off once the script is finished.
Here is my code :
WDS.sampleResult.sampleStart()
    def display = WDS.vars.get("DISPLAY");
    WDS.browser.get('url'+ display +'set')
WDS.sampleResult.sampleEnd()
Is there a possibility to do it?
Are there additional parameters to set in the webdriver sampler, because I don't have an HTTP Sampler or even HTTP cookies.
Thank you for your time
I think if you tick Development Mode box the browser will remain open:
If it doesn't fit your needs, i.e. you're using headless or Remote WebDriver, looking in the source code
#Override
public void threadFinished() {
if (!isDevMode()) {
final T browser = removeThreadBrowser();
quitBrowser(browser);
}
}
so just comment out/remove this quitBrowser function, recompile the plugin and replace the version in the "lib/ext" folder with your own one.
and last but not the least the browser is being shut down when your test ends, if you want to keep the browser open it's sufficient to configure your test so it would never end by adding i.e. Flow Control Action sampler configured to sleep the required amount of time or just adding the next line as the last one in your WebDriver Sampler code:
Thread.sleep(3600000)
the line will pause the execution for 1 hour, hopefully this time will be sufficient for troubleshooting.
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

How implement deploy tracking on Next.js without a custom server?

I'm working on a Next.js project and we're running it WITHOUT the custom server, using the next build + next start.
On the backend, when a new version is deployed and starts to run, we send a log to a service warning the team of the success of the deploy, so we want to do the same for the Next.js frontend.
My question is: where can we add this log that will only be send when the build is already finished and the new version is running for the first time (with success)?
Would be nice if this log is only send a single time for each new build;
Also, this log need to be send only on runtime, and not on build time;
One more thing that would be nice for the deploy tracking is to send the log only when the frontend successfully load;
With the custom server, is enough for us if we log on the app.prepare, but we're really trying to skip the implementation of the custom server.
There's a central point/callback that is only called a single time after the yarn start?
One option is to create a custom next.config.js, and listen for the phase-production-server phase.
const { PHASE_PRODUCTION_SERVER } = require('next/constants');
module.exports = (phase, { defaultConfig }) => {
if (phase === PHASE_PRODUCTION_SERVER) {
// Post to an API
}
return defaultConfig;
};
It's not perfect but I'm not sure there's a handler for when the server is ready. I'm also curious about that and asked a similar-but-different question in their discussion section.
You can read more about phase here.

Android WCF client stop responding after 2 calls

I have a service that is is self hosted in a WPF application. Also I have a WPF client and a xamarin android client that use the WCF client to consume the service.
I have realize that I can call with no problems from the WPF client, but from android client I only can call 2 times, later the application stop responding and after a time, I get a timeout exception.
I have read threads that say that I have to close the client proxy to solve the problem, because the number of connections are limited in the server, but this doesn't solve the problem. In fact, I have tried to no close the proxy in the WPF application and I don't have problems and I have tried to close the proxy in the android application, in the finally try/catch and in a using block, in both cases the application stops responding.
I try the solutions in threads like this and this, but they doesn't solve my problem.
The code is the following:
WPF client:
int _numeroLlamadas = 0;
GestorAplicacionesServiceProxy _proxy = new GestorAplicacionesServiceProxy();
private void BtnTest_Click(object sender, RoutedEventArgs e)
{
txtResultado.Text = _proxy.GetData(2);
_numeroLlamadas = _numeroLlamadas + 1;
txtNumeroLlamadas.Text = _numeroLlamadas.ToString();
}
In this case I have a counter to know how many times I can call to the service, and I don't have problems to call 20, 30, 40... times.
In the android application I have this code in the click event of a button:
using (GestorAplicacionesServiceProxy miProxy = new GestorAplicacionesServiceProxy(_binding, _endPointAddress))
{
string miResultado = miProxy.GetData(2);
Toast.MakeText(this, "Hola", ToastLength.Short).Show();
}
In this case I use a using block to dispose the proxy when I finish to use it. But I only can call 2 times and in the next call, the application throw a timeout exception.
The service, the instance context mode is per call.
How the WPF client works fine and the android application isn't, I was thinking that perhaps it is because the android application has different considerations.
Thanks.

how to close application opened from Windows 10 c# wpf Launcher.LaunchUriAsync

I have created a demo which opens Windows 10 installed APP using Launcher.
private async void OpenApp()
{
var launchUri = new Uri("URL of Installed APP");
var success = await Launcher.LaunchUriAsync(launchUri);
b1 = success;
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
}
For Example I have opened the windows settings application from Launcher. I want to close the same application from my WPF application after some interval of time.
Is it possible? Please let me know some solutions.
Short answer: No.
The LaunchUriAsync API just starts the default app associated with the URI scheme name for the specified URI and returns a bool that specifies whether the operation was successful. It doesn't give you any kind of reference back to the default app that was (maybe) opened so you cannot really close the app. There is no API to do this.
In WPF, you might be able to close a specific app by terminating the process:
Kill some processes by .exe file name
In UWP you are not allowed to kill a process though so then there is no way to close the app opened by the LaunchUriAsync API.

Silverlight 4 OOB + Browser HTTP Stack + Client Certificates = FAIL?

I'm having an issue where IIS 7.5 (on Windows 7 64-bit) is failing when I call it from an out-of-browser Silverlight 4 app using SSL and a client certificate, with the message "The I/O operation has been aborted because of either a thread exit or an application request. (0x800703e3)". The request does make it to IIS. here is a sample from the failed request trace:
The I/O operation has been aborted because of either a thread exit or an application request. (0x800703e3) http://www.slipjig.org/IISError.gif
I am using the browser HTTP stack, because the client HTTP stack does not support client certificates. The client code attempting to hit the server is the Prism module loader. If I run the app out-of-browser but ignore client certs, or if I run the application in-browser but require client certs, it works fine. It seems to be the combination of the two that is causing the problem.
I tried the following to gather more info:
Used Fiddler to view the failing request. It works if Fiddler is running (presumably because Fiddler is handling the client certificate differently?);
Created an .aspx web form to serve up the module .xaps;
Created an HTTPModule to see if I could intercept the request before it failed;
Used a packet sniffer to see if I could tell if the client certificate was being sent correctly.
None of the above gave me much useful information beyond what I could see in the trace file, although the Fiddler thing is interesting.
Any ideas? Thanks in advance!
Mike
I beat my head against the wall for weeks on this problem. Here's what I learned and how I finally worked around it.
Prism's FileDownloader class uses System.Net.WebClient to load modules. In OOB mode, WebClient seems to use the same stack as IE, but it apparently either doesn't send the client certificate, or (more likely) doesn't correctly negotiate the SSL/client cert handshake with the server. I say this because:
I was able to successfully request .xap files using Firefox and Chrome;
I was not able to successfully request .xap files using IE;
IIS would fail with a 500, not a 403.
I couldn't get good visibility into what was actually happening over the wire; if I used Fiddler, it would work, because Fiddler intercepts communications with the server and handles the client certificate handshake itself. And trying to use a packet sniffer obviously wouldn't tell me anything because of SSL.
So - I first spent a lot of time on the server side trying to eliminate things (unneeded handlers, modules, features, etc.) that might be causing the problem.
When that didn't work, I tried modifying the Prism source code to use the browser's HTTP stack instead of WebClient. To do this, I created a new class similar in design to FileDownloader, implementing IFileDownloader, that used the browser stack. I then made some changes to XapModuleTypeLoader (which instantiates the downloader) to make it use the new class. This approach failed with the same error I was originally experiencing.
Then I started researching whether a commercial third-party HTTP stack might be available. I found one that supported the features I needed and that supported the Silverlight 4 runtime. I created another implementation of IFileDownloader that used that stack, and BOOM - it worked.
The good news with this approach is that not only can I use this to load modules, I can also use it to protect communications between the client and our REST API (a benefit we were going to give up, before).
I plan to submit a patch to Prism to allow the downloader to be registered or bound externally, as it's currently hard-coded to use its own FileDownloader. If anyone is interested in that or in the commercial HTTP stack I'm using, contact me (msimpson -at- abelsolutions -dot- com) for links and code samples.
And I must say this - I still don't know for sure whether the root problem is in the HTTP stack on the client side or the server side, but it's a FAIL on Microsoft's part nonetheless.
What we (Slipjig and I) found out this week is that there does appear to be a way around these issues, or at least, we're on the trail to determining whether there is a reliable, repeatable way. We're still not positive on that, but here's what we know so far:
At first pass, if you have code like this you can start making requests with either the Browser or Client stack:
First, place a "WebBrowser" control in your Silverlight XAML, and make it send a request to your HTTPS site.
This may pop up the certificate dialog box for the user. Big deal. Accept it. If you have only one cert, then you can turn an option in IE off to suppress that message.
private void Command_Click(object sender, RoutedEventArgs e) {
// This does not pop up the cert dialog if the option to take the first is turned on in IE settings:
BrowserInstance.Navigate(new Uri("https://www.SiteThatRequiresClientCertificates.com/"));
}
Then, in a separate handler invoke by the user, create an instance of your stack, either Client or Browser:
private void CallServer_Click(object sender, RoutedEventArgs e) {
// Works with BrowserHttp factory also:
var req = WebRequestCreator.ClientHttp.Create(new Uri("https://www.SiteThatRequiresClientCertificates.com/"));
req.Method = "GET";
req.BeginGetResponse(new AsyncCallback(Callback), req);
}
Finally, the Callback:
private void Callback(IAsyncResult result)
{
var req = result.AsyncState as System.Net.WebRequest;
var resp = req.EndGetResponse(result);
var content = string.Empty;
using (var reader = new StreamReader(resp.GetResponseStream())) {
content = reader.ReadToEnd();
}
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Results.Text = content;
});
}
I had the same issue and I fixed it by creating the certificate using makecert. Follow the steps from this article http://www.codeproject.com/Articles/24027/SSL-with-Self-hosted-WCF-Service and replace CN with your ip/domain. In my case I have tested the service on the local machine and run the commands as follows:
1) makecert -sv SignRoot.pvk -cy authority -r signroot.cer -a sha1 -n "CN=Dev Certification Authority" -ss my -sr localmachine
after running the first command drag the certificate from "Personal" directory to "Trusted Root Certification Authority"
2) makecert -iv SignRoot.pvk -ic signroot.cer -cy end -pe -n
CN="localhost" -eku 1.3.6.1.5.5.7.3.1 -ss my -sr
localmachine -sky exchange -sp
"Microsoft RSA SChannel Cryptographic Provider" -sy 12
In case you want to run the silverlight application on another machine, export the certificate created at step1 and then import it on any machine where you want your application to run.

Resources