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

VB Code:
  1. Private Sub IndexNowTreeNetLib(ByVal myReader As cReader)
  2.  
  3.         Dim where As String
  4.  
  5.         Dim folderList As New ArrayList
  6.         folderList = myReader.GetConfig.FolderList
  7.         Dim treeNetLib As New cTreeNetLib(myReader)
  8.  
  9.         Select Case mIndexMode
  10.  
  11.             Case cReader.IndexingMode.INDEX_FILE_IN_EACH_DIR
  12.  
  13.                 For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 1
  14.                     Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
  15.                     where = strDirPath + "\" + myReader.GetConfig.GetIndexFileName
  16.                     Try
  17.                         Dim sw As New StreamWriter(where, False)
  18.                         Select Case myReader.GetConfig.IndexFileExtension
  19.                             Case Is = ".html"
  20.                                 'MessageBox.Show(myReader.GetConfig.mCssFilePath)
  21.                                 treeNetLib.mBooFirstIndexFile = True
  22.                                 treeNetLib.IndexFolderToHtml(strDirPath, sw, True)
  23.                             Case Else
  24.                                 treeNetLib.IndexFolderToTxt(strDirPath, sw, True)
  25.                         End Select
  26.                         sw.Close()
  27.                         If myReader.GetConfig.ZipFilesInEachDir Then
  28.                             myReader.ZipAdminFile(where)
  29.                         End If
  30.                         [COLOR=Red]bwIndexer.ReportProgress(0.0, strDirPath)[/COLOR]
  31.                     Catch ex As System.UnauthorizedAccessException
  32.                     End Try
  33.                 Next
  34.  
  35.             Case cReader.IndexingMode.INDEX_FILE_IN_ONE_FOLDER
  36.  
  37.                 If myReader.GetConfig.isMergeFiles Then
  38.  
  39.                     where = myReader.GetConfig.GetIndexFilePath
  40.  
  41.                     Dim sw As New StreamWriter(where, False)
  42.  
  43.                     If myReader.GetConfig.FolderList.Count > 1 Then
  44.                         For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 2
  45.                             Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
  46.                             Dim dir As New cDir(strDirPath)
  47.                             Select Case myReader.GetConfig.IndexFileExtension
  48.                                 Case Is = ".html"
  49.                                     treeNetLib.mBooMoreFilesToCome = True
  50.                                     treeNetLib.IndexFolderToHtml(strDirPath, sw, False)
  51.                                 Case Else
  52.                                     treeNetLib.IndexFolderToTxt(strDirPath, sw, False)
  53.                             End Select
  54.                             [COLOR=Red]bwIndexer.ReportProgress(0.0, strDirPath)[/COLOR]
  55.                         Next
  56.                     End If
  57.  
  58.                     Dim lastDir As New cDir(myReader.GetConfig.FolderList.Item(myReader.GetConfig.FolderList.Count - 1))
  59.                     Select Case myReader.GetConfig.IndexFileExtension
  60.                         Case Is = ".html"
  61.                             treeNetLib.mBooFirstIndexFile = False
  62.                             treeNetLib.IndexFolderToHtml(lastDir.GetDirPath, sw, True)
  63.                         Case Else
  64.                             treeNetLib.IndexFolderToTxt(lastDir.GetDirPath, sw, True)
  65.                     End Select
  66.                     sw.Close()
  67.                     If myReader.GetConfig.ZipMergedFile Then
  68.                         myReader.ZipAdminFile(where)
  69.                     End If
  70.  
  71.                     [COLOR=Red]bwIndexer.ReportProgress(0.0, lastDir.GetDirPath)[/COLOR]
  72.                 End If
  73.  
  74.         End Select
  75.  
  76.     End Sub

And here is the code for in the Windows.Service:

VB Code:
  1. Private Sub IndexNowTreeNetLib(ByVal myReader As cReader)
  2.  
  3.         Dim where As String
  4.  
  5.         Dim folderList As New ArrayList
  6.         folderList = myReader.GetConfig.FolderList
  7.         Dim treeNetLib As New cTreeNetLib(myReader)
  8.  
  9.         Select Case mIndexMode
  10.  
  11.             Case cReader.IndexingMode.INDEX_FILE_IN_EACH_DIR
  12.  
  13.                 For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 1
  14.                     Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
  15.                     where = strDirPath + "\" + myReader.GetConfig.GetIndexFileName
  16.                     Try
  17.                         Dim sw As New StreamWriter(where, False)
  18.                         Select Case myReader.GetConfig.IndexFileExtension
  19.                             Case Is = ".html"
  20.                                 'MessageBox.Show(myReader.GetConfig.mCssFilePath)
  21.                                 treeNetLib.mBooFirstIndexFile = True
  22.                                 treeNetLib.IndexFolderToHtml(strDirPath, sw, True)
  23.                             Case Else
  24.                                 treeNetLib.IndexFolderToTxt(strDirPath, sw, True)
  25.                         End Select
  26.                         sw.Close()
  27.                         If myReader.GetConfig.ZipFilesInEachDir Then
  28.                             myReader.ZipAdminFile(where)
  29.                         End If                        
  30.                     Catch ex As System.UnauthorizedAccessException
  31.                     End Try
  32.                 Next
  33.  
  34.             Case cReader.IndexingMode.INDEX_FILE_IN_ONE_FOLDER
  35.  
  36.                 If myReader.GetConfig.isMergeFiles Then
  37.  
  38.                     where = myReader.GetConfig.GetIndexFilePath
  39.  
  40.                     Dim sw As New StreamWriter(where, False)
  41.  
  42.                     If myReader.GetConfig.FolderList.Count > 1 Then
  43.                         For i As Integer = 0 To myReader.GetConfig.FolderList.Count - 2
  44.                             Dim strDirPath As String = myReader.GetConfig.FolderList.Item(i)
  45.                             Dim dir As New cDir(strDirPath)
  46.                             Select Case myReader.GetConfig.IndexFileExtension
  47.                                 Case Is = ".html"
  48.                                     treeNetLib.mBooMoreFilesToCome = True
  49.                                     treeNetLib.IndexFolderToHtml(strDirPath, sw, False)
  50.                                 Case Else
  51.                                     treeNetLib.IndexFolderToTxt(strDirPath, sw, False)
  52.                             End Select
  53.                         Next
  54.                     End If
  55.  
  56.                     Dim lastDir As New cDir(myReader.GetConfig.FolderList.Item(myReader.GetConfig.FolderList.Count - 1))
  57.                     Select Case myReader.GetConfig.IndexFileExtension
  58.                         Case Is = ".html"
  59.                             treeNetLib.mBooFirstIndexFile = False
  60.                             treeNetLib.IndexFolderToHtml(lastDir.GetDirPath, sw, True)
  61.                         Case Else
  62.                             treeNetLib.IndexFolderToTxt(lastDir.GetDirPath, sw, True)
  63.                     End Select
  64.                     sw.Close()
  65.                     If myReader.GetConfig.ZipMergedFile Then
  66.                         myReader.ZipAdminFile(where)
  67.                     End If
  68.  
  69.                 End If
  70.  
  71.         End Select
  72.  
  73.     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/...loads/treegui/

I hope you understand my problem. Is there any workground for this?

Thanks in advance.
McoreD