~*McoreD*~
Dec 6th, 2005, 12:10 AM
Hey Guys,
The Project: TreeGUI, I am currently coding has a Windows Service and a GUI. Both do the same job so I have about 99% of the code shared. There is only one method I don't know how to share with both Windows.Service project and Windows.Form project.
Here is the code in the Windows.Form
Private Sub IndexNowTreeNetLib(ByVal myReader As cReader)
Dim where As String
Dim folderList As New ArrayList
folderList = myReader.GetConfig.FolderList
Dim treeNetLib As New cTreeNetLib(myReader)
Select Case mIndexMode
Case cReader.IndexingMode.INDEX_FILE_IN_EACH_DIR
For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 1
Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
where = strDirPath + "\" + myReader.GetConfig.GetIndexFileName
Try
Dim sw As New StreamWriter(where, False)
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
'MessageBox.Show(myReader.GetConfig.mCssFilePath)
treeNetLib.mBooFirstIndexFile = True
treeNetLib.IndexFolderToHtml(strDirPath, sw, True)
Case Else
treeNetLib.IndexFolderToTxt(strDirPath, sw, True)
End Select
sw.Close()
If myReader.GetConfig.ZipFilesInEachDir Then
myReader.ZipAdminFile(where)
End If
bwIndexer.ReportProgress(0.0, strDirPath)
Catch ex As System.UnauthorizedAccessException
End Try
Next
Case cReader.IndexingMode.INDEX_FILE_IN_ONE_FOLDER
If myReader.GetConfig.isMergeFiles Then
where = myReader.GetConfig.GetIndexFilePath
Dim sw As New StreamWriter(where, False)
If myReader.GetConfig.FolderList.Count > 1 Then
For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 2
Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
Dim dir As New cDir(strDirPath)
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
treeNetLib.mBooMoreFilesToCome = True
treeNetLib.IndexFolderToHtml(strDirPath, sw, False)
Case Else
treeNetLib.IndexFolderToTxt(strDirPath, sw, False)
End Select
bwIndexer.ReportProgress(0.0, strDirPath)
Next
End If
Dim lastDir As New cDir(myReader.GetConfig.FolderList.Item(myReader.GetConfig.FolderList.Count - 1))
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
treeNetLib.mBooFirstIndexFile = False
treeNetLib.IndexFolderToHtml(lastDir.GetDirPath, sw, True)
Case Else
treeNetLib.IndexFolderToTxt(lastDir.GetDirPath, sw, True)
End Select
sw.Close()
If myReader.GetConfig.ZipMergedFile Then
myReader.ZipAdminFile(where)
End If
bwIndexer.ReportProgress(0.0, lastDir.GetDirPath)
End If
End Select
End Sub
And here is the code for in the Windows.Service:
Private Sub IndexNowTreeNetLib(ByVal myReader As cReader)
Dim where As String
Dim folderList As New ArrayList
folderList = myReader.GetConfig.FolderList
Dim treeNetLib As New cTreeNetLib(myReader)
Select Case mIndexMode
Case cReader.IndexingMode.INDEX_FILE_IN_EACH_DIR
For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 1
Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
where = strDirPath + "\" + myReader.GetConfig.GetIndexFileName
Try
Dim sw As New StreamWriter(where, False)
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
'MessageBox.Show(myReader.GetConfig.mCssFilePath)
treeNetLib.mBooFirstIndexFile = True
treeNetLib.IndexFolderToHtml(strDirPath, sw, True)
Case Else
treeNetLib.IndexFolderToTxt(strDirPath, sw, True)
End Select
sw.Close()
If myReader.GetConfig.ZipFilesInEachDir Then
myReader.ZipAdminFile(where)
End If
Catch ex As System.UnauthorizedAccessException
End Try
Next
Case cReader.IndexingMode.INDEX_FILE_IN_ONE_FOLDER
If myReader.GetConfig.isMergeFiles Then
where = myReader.GetConfig.GetIndexFilePath
Dim sw As New StreamWriter(where, False)
If myReader.GetConfig.FolderList.Count > 1 Then
For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 2
Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
Dim dir As New cDir(strDirPath)
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
treeNetLib.mBooMoreFilesToCome = True
treeNetLib.IndexFolderToHtml(strDirPath, sw, False)
Case Else
treeNetLib.IndexFolderToTxt(strDirPath, sw, False)
End Select
Next
End If
Dim lastDir As New cDir(myReader.GetConfig.FolderList.Item(myReader.GetConfig.FolderList.Count - 1))
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
treeNetLib.mBooFirstIndexFile = False
treeNetLib.IndexFolderToHtml(lastDir.GetDirPath, sw, True)
Case Else
treeNetLib.IndexFolderToTxt(lastDir.GetDirPath, sw, True)
End Select
sw.Close()
If myReader.GetConfig.ZipMergedFile Then
myReader.ZipAdminFile(where)
End If
End If
End Select
End Sub
As you now see, both methods are indentical, but the only difference in Windows.Forms method is that it reports Progress to a ProgressBar.
I can't seperate the method from the Form because it won't then report the progress to the ProgressBar in the Windows.Form.
Well, this is what the project is all about: http://microsoftuse.temp.powweb.com/mcored/downloads/treegui/
I hope you understand my problem. Is there any workground for this?
Thanks in advance.
McoreD
The Project: TreeGUI, I am currently coding has a Windows Service and a GUI. Both do the same job so I have about 99% of the code shared. There is only one method I don't know how to share with both Windows.Service project and Windows.Form project.
Here is the code in the Windows.Form
Private Sub IndexNowTreeNetLib(ByVal myReader As cReader)
Dim where As String
Dim folderList As New ArrayList
folderList = myReader.GetConfig.FolderList
Dim treeNetLib As New cTreeNetLib(myReader)
Select Case mIndexMode
Case cReader.IndexingMode.INDEX_FILE_IN_EACH_DIR
For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 1
Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
where = strDirPath + "\" + myReader.GetConfig.GetIndexFileName
Try
Dim sw As New StreamWriter(where, False)
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
'MessageBox.Show(myReader.GetConfig.mCssFilePath)
treeNetLib.mBooFirstIndexFile = True
treeNetLib.IndexFolderToHtml(strDirPath, sw, True)
Case Else
treeNetLib.IndexFolderToTxt(strDirPath, sw, True)
End Select
sw.Close()
If myReader.GetConfig.ZipFilesInEachDir Then
myReader.ZipAdminFile(where)
End If
bwIndexer.ReportProgress(0.0, strDirPath)
Catch ex As System.UnauthorizedAccessException
End Try
Next
Case cReader.IndexingMode.INDEX_FILE_IN_ONE_FOLDER
If myReader.GetConfig.isMergeFiles Then
where = myReader.GetConfig.GetIndexFilePath
Dim sw As New StreamWriter(where, False)
If myReader.GetConfig.FolderList.Count > 1 Then
For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 2
Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
Dim dir As New cDir(strDirPath)
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
treeNetLib.mBooMoreFilesToCome = True
treeNetLib.IndexFolderToHtml(strDirPath, sw, False)
Case Else
treeNetLib.IndexFolderToTxt(strDirPath, sw, False)
End Select
bwIndexer.ReportProgress(0.0, strDirPath)
Next
End If
Dim lastDir As New cDir(myReader.GetConfig.FolderList.Item(myReader.GetConfig.FolderList.Count - 1))
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
treeNetLib.mBooFirstIndexFile = False
treeNetLib.IndexFolderToHtml(lastDir.GetDirPath, sw, True)
Case Else
treeNetLib.IndexFolderToTxt(lastDir.GetDirPath, sw, True)
End Select
sw.Close()
If myReader.GetConfig.ZipMergedFile Then
myReader.ZipAdminFile(where)
End If
bwIndexer.ReportProgress(0.0, lastDir.GetDirPath)
End If
End Select
End Sub
And here is the code for in the Windows.Service:
Private Sub IndexNowTreeNetLib(ByVal myReader As cReader)
Dim where As String
Dim folderList As New ArrayList
folderList = myReader.GetConfig.FolderList
Dim treeNetLib As New cTreeNetLib(myReader)
Select Case mIndexMode
Case cReader.IndexingMode.INDEX_FILE_IN_EACH_DIR
For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 1
Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
where = strDirPath + "\" + myReader.GetConfig.GetIndexFileName
Try
Dim sw As New StreamWriter(where, False)
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
'MessageBox.Show(myReader.GetConfig.mCssFilePath)
treeNetLib.mBooFirstIndexFile = True
treeNetLib.IndexFolderToHtml(strDirPath, sw, True)
Case Else
treeNetLib.IndexFolderToTxt(strDirPath, sw, True)
End Select
sw.Close()
If myReader.GetConfig.ZipFilesInEachDir Then
myReader.ZipAdminFile(where)
End If
Catch ex As System.UnauthorizedAccessException
End Try
Next
Case cReader.IndexingMode.INDEX_FILE_IN_ONE_FOLDER
If myReader.GetConfig.isMergeFiles Then
where = myReader.GetConfig.GetIndexFilePath
Dim sw As New StreamWriter(where, False)
If myReader.GetConfig.FolderList.Count > 1 Then
For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 2
Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
Dim dir As New cDir(strDirPath)
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
treeNetLib.mBooMoreFilesToCome = True
treeNetLib.IndexFolderToHtml(strDirPath, sw, False)
Case Else
treeNetLib.IndexFolderToTxt(strDirPath, sw, False)
End Select
Next
End If
Dim lastDir As New cDir(myReader.GetConfig.FolderList.Item(myReader.GetConfig.FolderList.Count - 1))
Select Case myReader.GetConfig.IndexFileExtension
Case Is = ".html"
treeNetLib.mBooFirstIndexFile = False
treeNetLib.IndexFolderToHtml(lastDir.GetDirPath, sw, True)
Case Else
treeNetLib.IndexFolderToTxt(lastDir.GetDirPath, sw, True)
End Select
sw.Close()
If myReader.GetConfig.ZipMergedFile Then
myReader.ZipAdminFile(where)
End If
End If
End Select
End Sub
As you now see, both methods are indentical, but the only difference in Windows.Forms method is that it reports Progress to a ProgressBar.
I can't seperate the method from the Form because it won't then report the progress to the ProgressBar in the Windows.Form.
Well, this is what the project is all about: http://microsoftuse.temp.powweb.com/mcored/downloads/treegui/
I hope you understand my problem. Is there any workground for this?
Thanks in advance.
McoreD