I am a new developer therefore I have many questions:
In this class I get file path on the disk (wireshark file that needs to be converted to pcap format extension) and convert it with the method convertFileToPcap()
, in the constructor I am calling convertFileToPcap()
and from the main after create the Editcap object I am receiving the new file path (pcap format) with the property getNewFileName()
who return _newFileName
(class member) and I want to know if there is a better way or appropriate way to do it.
public class Editcap
{
#region members
private string _editpcap;
private ProcessStartInfo _editpcapProcess;
private FileInfo _fileInfo;
private string _newFileName;
#endregion
#region c'tor
public Editcap(FileInfo fileinfo)
{
_fileInfo = fileinfo;
_newFileName = "";
convertFileToPcap();
}
#endregion
public void convertFileToPcap()
{
string oldFileExtension = _fileInfo.Extension;
_newFileName = _fileInfo.FullName.Replace(oldFileExtension, "_new") + ".pcap";
_editpcapProcess = new ProcessStartInfo(string.Format("\"{0}\"", _editpcap));
_editpcapProcess.Arguments = (string.Format("{2}{0}{2} -F libpcap {2}{1}{2}", _fileInfo.FullName, _newFileName, "\""));
_editpcapProcess.WindowStyle = ProcessWindowStyle.Hidden;
_editpcapProcess.RedirectStandardOutput = true;
_editpcapProcess.RedirectStandardError = true;
_editpcapProcess.CreateNoWindow = true;
_editpcapProcess.UseShellExecute = false;
_editpcapProcess.ErrorDialog = false;
Process capinfosProcess = Process.Start(_editpcapProcess);
capinfosProcess.WaitForExit();
}
public string getNewFileName()
{
return _newFileName;
}
}