i am build application that open Wireshark services (Wireshark has several services) in order to to different things on Wireshark files like Edit, change format, statistics etc... each option usually use different service so i want to build my classes with inheritance i was wonder if what i want to do is appropriate way or proper way:
main class WiresharkServices with the following members and method:
public class WiresharkProcesses
{
protected string _filePath; //the file path who send to Wiresahrk process
protected string _capinfos;
protected string _dumpcap;
protected string _editcap;
protected string _mergecap;
protected string _rawshark;
protected string _text2pcap;
protected string _tshark;
protected string _wireshark;
public void initializeServices()
{
if (Directory.Exists(@"C:\Program Files (x86)\Wireshark"))
{
_capinfos = @"C:\Program Files (x86)\Wireshark\_capinfos.exe";
_dumpcap = @"C:\Program Files (x86)\Wireshark\_dumpcap.exe";
_editcap = @"C:\Program Files (x86)\Wireshark\editcap.exe";
_mergecap = @"C:\Program Files (x86)\Wireshark\_mergecap.exe";
_rawshark = @"C:\Program Files (x86)\Wireshark\_rawshark.exe";
_text2pcap = @"C:\Program Files (x86)\Wireshark\_text2pcap.exe";
_tshark = @"C:\Program Files (x86)\Wireshark\_tshark.exe";
_wireshark = @"C:\Program Files (x86)\Wireshark\_wireshark.exe";
}
else if (Directory.Exists(@"C:\Program Files\Wireshark"))
{
_capinfos = @"C:\Program File)\Wireshark\_capinfos.exe";
_dumpcap = @"C:\Program Files\Wireshark\_dumpcap.exe";
_editcap = @"C:\Program Files\Wireshark\editcap.exe";
_mergecap = @"C:\Program Files\Wireshark\_mergecap.exe";
_rawshark = @"C:\Program Files\Wireshark\_rawshark.exe";
_text2pcap = @"C:\Program Files\Wireshark\_text2pcap.exe";
_tshark = @"C:\Program Files\Wireshark\_tshark.exe";
_wireshark = @"C:\Program Files\Wireshark\_wireshark.exe";
}
}
}
when the application running i am check of course if Wireshark installed on the machine and if not throw exception and in Wireshark exist:
WiresharkServices wservices = new WiresharkServices();
wservices .initializeServices();
and in each class it's own methods.
child class example who receive file path to convert it to other Wireshark format:
public class Editcap : WiresharkProcesses
{
private string _newFileName;
public void startProcess(string filePath)
{
FileInfo file = new FileInfo(filePath);
_newFileName = file.FullName.Replace(file.Extension, "_new") + ".pcap";
ProcessStartInfo editcapProcess = new ProcessStartInfo(string.Format("\"{0}\"", _editcap))
{
Arguments = string.Format("{2}{0}{2} -F libpcap {2}{1}{2}", file.FullName, _newFileName, "\""),
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
UseShellExecute = false,
ErrorDialog = false
};
using (Process editcap = Process.Start(editcapProcess))
{
editcap.WaitForExit();
}
}
public string getNewFileName()
{
return _newFileName;
}
}