At first, I thought that this is for just studying C#. So I was coding without design.
At the end, GFtp's source code is getting more dirty. And I decided to refactoring.
1. UML
- I made some classces for modulize and small cs files.
Almost source codes was included in Form1.cs file. But Form1.cs file is worng name and become very big. So I designed FileGridViewHelper and FtpController.
FileGridViewHelper has 2 extend method of DataGridView control.
FtpController has some method and property for Ftp.
Form1 is renamed to MainForm. Form1 was made by Visual Studio wizard.
Following is UML for that.
2. Code snippet
- The extend method for getting selected files in the DataGridView
- define
// Helper class for FileGridView
static class FileGridViewHelper
{
// Get file names selected in the grid view
static public string[] GetSelectedFiles(this DataGridView gridView)
{
string[] files = new string[gridView.SelectedRows.Count];
int idx = 0;
foreach (DataGridViewRow row in gridView.SelectedRows)
{
files[idx++] = row.Cells[0].Value.ToString();
}
return files;
}
}
- call
string[] files = fileGridView.GetSelectedFiles();
- FtpController's properties
- I defined properties instead of field that I need.
Property allows source code is cleaned and developer can make easy coding for simple method like get, set.
So I think that property is better than field in case not need to performance and special case.
class FtpController
{
// _ftpAddress = @"ftp://ftp.novell.com";
public string FtpAddress { get; set; }
public string ID { get; private set; }
public string Password { get; private set; }
public System.Windows.Forms.ProgressBar _progressBar = null;
...
}
3. Git
- GFtp version is v1.3.
Now I am feeling that version management is difficult without any version management tool.
So I added GFtp source code to Git.
Here is Git link.
댓글 없음:
댓글 쓰기