I'm using Visual Studio 2017 C#. I'm trying to create a simple Winform application for our remote small site employees that will help them assist IT remote support diagnose latency issues between their client computer and some enterprise application (exchange servers, webapps, databases, etc. on the network) from a netsh trace capture file.
IT remote small site support is expected to open the trace file and isolate the cause of packet latency between the two end points.
The goal here is for remote small site employees to launch a Winform App, click a button that launches netsh, capture a trace to a file, and to close netsh after a period of minutes. I haven't written the code for the timer yet. The initial code below is supposed to launch netsh which it does without arguments. It displays a window and the netsh> prompt appears. When I try to run netsh with arguments the Winform netsh command window flashes and then immediately closes. I've searched numerous articles and tried many of the suggested code segments but none seem to work. Any help would be appreciated.
****************** Code**********************
private void DegradationCaptureStartButton_Click(object sender, EventArgs e)
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.FileName = "netsh.exe";
startInfo.Arguments = "trace start persistent=yes capture=yes tracefile=c://temp//billstrace.etl";
startInfo.RedirectStandardOutput = false;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
Process.Start(startInfo);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Related
Please bear with, I have a little experience in SQL but otherwise I am a complete newbie when it comes to programming/coding.
I have a database with Microsoft SQL server and I have downloaded Android studios.
In short I want to create a basic app that can have the ability to show data as well as update tables from my database. (app won't be a problem)
The question is, what would be the 'best' way to do to link database to my app? Bearing in mind I am not at a great technical level at the moment
I have been informed that linking to the database to the app directly may pose security risks but other than that I am a bit lost at how to get the information I need to get started...
Any information you can chuck my way will be greatly appreciated!!
First, you need to download JTDS drivers https://sourceforge.net/projects/jtds/
If you are not sure about how to set up watch this video as a reference https://youtu.be/UXy_phw5Psg.
To add jar files to your android studio:
Right-click on app > New > Module.
A window will open where you can find jar files when you scroll down.
Select the widget another window will open, find the location of your jar and select.
Finish. That is it you can start creating projects with SQL server after the build is finished.
Now after adding JTDS, you have to Add This Line In Your App Gradle File, x.x.x is the version of JTDS that you downloaded
dependencies{
implementation project(':jtds-x.x.x')
}
Now we are going to make a java class to connect SQL server and android studio. Remember this class is the heart of your every android project with SQL server.
Use Imports Correctly.
import android.annotation.SuppressLint;
import android.os.StrictMode;
import android.util.Log;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionClass {
// Your IP address must be static otherwise this will not work. You //can get your Ip address
//From Network and security in Windows.
String ip = "000.000.000.00";
// This is default if you are using JTDS driver.
String classs = "net.sourceforge.jtds.jdbc.Driver";
// Name Of your database.
String db = "MyDB";
// Userame and password are required for security.
so Go to sql server and add username and password for your database.
String un = "username";
String password = "passw0rd";
#SuppressLint("NewApi")
public Connection CONN() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL;
try {
Class.forName(classs);
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";";
conn = DriverManager.getConnection(ConnURL);
}
catch (SQLException se)
{
Log.e("safiya", se.getMessage());
}
catch (ClassNotFoundException e) {
}
catch (Exception e) {
Log.e("error", e.getMessage());
}
return conn;
}
}
Strict Mode:
StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them.
StrictMode is most commonly used to catch accidental disk or network access on the application’s main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications.
Orignal link to this is guide is https://life-news.blog/2018/09/24/connect-sql-server-with-android-application-jdbc-driver-integration/
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.
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
There is a WPF application written in Visual Studio.
Can I add Application Insights to this WPF app?
I would like to know how many times a button/tile is clicked. Since there are multiple installations
of the same application, I would like to know which button was clicked how many times from which user/installation. Can this be done with Application Insights?
Thanks
Avanti
While not listed as a supported app type this means there isn't default telemetry data collected/sent to application insights nor is there support for adding AI/creating an application insights resource. That being said it is possible to add to your WPF with a few manual steps so that you can track the specific scenarios you mention (like a button/tile click).
-From Visual studio add the "Application Insights API" NuGet to the project (.11 is the latest today).
This will add the Application Insights API reference and create an application insights configuration file to your project.
The applicationinsights.config file needs to be updated with your instrumentation key as follows:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">
<TelemetryChannel>
<DeveloperMode>false</DeveloperMode>
</TelemetryChannel>
<TelemetryModules>
<Add Type="Microsoft.ApplicationInsights.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights"/>
</TelemetryModules>
<InstrumentationKey>**your-instrumentation-key-guid**</InstrumentationKey>
</ApplicationInsights>
To create an application insights instrumentation key login to your azure subscription.
https://portal.azure.com
Click + to create an Application Insights resource.
Then choose the properties tile on the application insights blade and copy the Instrumentation key and add it to your applicationinsights.config file.
Now in your WPF app you can use the Application Insights sdk as described here: http://blogs.msdn.com/b/visualstudioalm/archive/2014/10/21/application-insights-sdk-0-11-0-prerelease.aspx
your events will be visible in the diagnostic search blade which can be selected on the application insights blade.
Note: telemetry is batched locally for 1 min before being sent to the service unless > 500 telemetry events are queued at which point they are sent.
https://azure.microsoft.com/en-us/documentation/articles/app-insights-windows-desktop/
An official link from Microsoft on how to add Application Insights to a Windows Forms application. From the link:
In Azure - portal.azure.com
Create an Application Resource. ::New / Developer Services / Application Insights.
Notice the instrumentation key generated, grab a copy and set it aside, we'll need it when we configure your application.
In Your Application
NuGet - Add 'Application Insights API'
Configure your TelemetryClient.
I'm using MvvmCross in a WPF application, on startup I create a single TelemetryClient that I re-use throughout the application.
var telemetryClient = new TelemetryClient();
telemetryClient.InstrumentationKey = "your key here from Azure";
telemetryClient.Context.Session.Id = Guid.NewGuid().ToString();
telemetryClient.Context.User.AccountId = Username;
telemetryClient.Context.Component.Version = Settings.Default.Version;
telemetryClient.TrackEvent("Application Start");
Mvx.RegisterSingleton<TelemetryClient>(telemetryClient);
Record an event/screen/exception, etc
Any time 'something happens' I'll resolve the TelemetryClient and record the event. This is just like any other Application Insights implementation with regards to tracking and recording.
As an example -
//Resolve the telemetry client
readonly TelemetryClient telemetryClient = Mvx.Resolve<TelemetryClient>();
//Record a page View with some extra information
var pageviewTelemetry = new PageViewTelemetry("Observations");
pageviewTelemetry.Properties.Add("Breadcrumb", breadcrumb);
telemetryClient.TrackPageView(pageviewTelemetry);
//Track an event
var eventTelemetry = new EventTelemetry("Observation Saved");
eventTelemetry.Properties.Add("Saved Observation", observation);
telemetryClient.TrackEvent(eventTelemetry);
//Track an exception
try
{
// do work here
}
catch (Exception ex)
{
telemeteryClient.TrackException(ex);
}
Flush on Application Exit
Application Insights for Windows Desktop applications does not automatically gather/send anything. As a developer one needs to force a flush at application exit.
private void PowerButton_OnClick(object sender, RoutedEventArgs e)
{
var tc = Mvx.Resolve<TelemetryClient>();
if (null != tc)
{
tc.Flush(); // only for desktop apps
}
Application.Current.Shutdown();
}
Or setup an RxTimer to flush on a schedule...I decided to flush every 30 minutes:
var observable = Observable.Interval(new TimeSpan(0, 0, 30, 0));
observable.Subscribe(_ => Application.Current.Dispatcher.Invoke(new Action(() =>
{
var tc = Mvx.Resolve<TelemetryClient>();
if (null != tc)
{
tc.Flush(); // only for desktop apps
Console.WriteLine("Flush TC");
}
})));
FYI - As of 0.17.0 of the Application Insights API NuGet Package if you are offline the flush call doesn't hang, but appears to. Online, the call completes immediately, offline there is a solid 5 second pause before the call completes.
Application Insights (AI) for desktop applications is being deprecated in favor of HockeyApp. It's not overly mature yet, but it works (events essentially reach the same place AI events go).
For example, here's how it looks in RoslynPad (a WPF C# Editor):
using Microsoft.HockeyApp;
//In your initialization method:
var hockeyClient = (HockeyClient)HockeyClient.Current;
hockeyClient.Configure(HockeyAppId)
.RegisterCustomDispatcherUnhandledExceptionLogic(OnUnhandledDispatcherException)
.UnregisterDefaultUnobservedTaskExceptionHandler();
var platformHelper = (HockeyPlatformHelperWPF)hockeyClient.PlatformHelper;
platformHelper.AppVersion = _currentVersion.ToString();
hockeyClient.TrackEvent("App Start");
//sometime later:
hockeyClient.TrackEvent("Something happened");
EDIT Looks like the following NuGet package is required in order for this to work properly: https://www.nuget.org/packages/HockeySDK.WPF.TelemetryWorkaround (see https://github.com/bitstadium/HockeySDK-Windows/pull/88).
I'm building a wp7 app. I'm using WebClient to grab data from a server. In the past, it's been working, although all of a sudden it's failing.
static void downloadData(string uri, Action<object, DownloadStringCompletedEventArgs> onComplete)
{
Debug.WriteLine("Downloading: " + uri);
WebClient data = new WebClient();
data.DownloadStringCompleted += new DownloadStringCompletedEventHandler(onComplete);
data.DownloadStringAsync(new Uri(uri));
}
static void data_SectionDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
// throws NotFound
throw e.Error;
}
// ...
}
When I go to the URI in question in my browser, it works fine.
The exception:
"The remote server returned an error: NotFound." {System.Net.WebException}
What am I doing wrong here?
Update: I restarted the emulator, and now it works fine. Weird. Maybe it's an issue in the emulator? Hopefully I won't be able to reproduce it on the actual device.
NotFound is a generic error that basically means 'Error'. There is a real exception behind it that you need to dig to find. The easiest method I have found is Intellitrace which allows you to view every exception that ever happened on your web server. If you look just before your NotFound, you will find the real exception that backs it.
If Intellitrace is not an option, add more/better logging on your server and client. Google has many tips, a good example of deeper debugging:
http://www.mostlydevelopers.com/blog/post/2009/01/14/debugging-tips-ndash3b-the-remote-server-returned-an-error-notfound.aspx
I had similar experience with the emulator. I often open Internet Explorer and browse a site before I test any application that uses the network. Also, it is best not to change the IP address of the machine running the emulator, DHCP or manually. Lastly, I would suggest you handle any error scenarios with an error message displayed in a MessageBox.
HTH, indyfromoz
I get this occassionaly too. Even on real devices. A retry usually fixes it though.
Unfortunately this is one of the issues you need to be aware of and write code to cater for when working in an occassionally connected environment.