.NET linked files
, but linked files are still not a straight conversion: we would have to make some decisions and also deal with assigning and using namespaces. Code file linking has other disadvantages for builds and deployments so it has a higher cost of ownership. Consequently, there is some value in hosting each shared file in only one assembly and referencing it there. gmStudio can help implement this re-hosting process. hosting
rather than linking
, we begin with a guiding principle: each file should be referenced by at most one assembly (the host). Once in that host, the file will become a class in the namespace of the host. If a class is used by other assemblies, those others must reference the host assembly and use the shared class members through the host namespace. But, as always, the problems are in the details. "SharedFile
" statement described in this article.Shared Files Consolidation is a three step process:
1) Translate VBPs to produce desired VBI files
2) Prepare a ShareFile script and process it using the SharedFile utility: gmSharedFile \ABCTeam\csh\SharedFile.xml
3) Use ShareFiles commands in a second set of translation scripts to produces consolidated translations
Example:
In this example, the shared files are into ABCCommon.VBP. Note: ABCCommon.VBP does not need to actually exist on the legacy side. It may be a VBP developed by hand, adding references to COM and Code files as needed.
SharedFile.xml
Used in Step 2: gmSharedFile \ABCTeam\csh\SharedFile.xml
Notice that two outputs are specified:
<SharedFile ReportFile="\ABCTeam\csh\SharedFile.out" RegistryFile="\ABCTeam\proj\usr\Registry_SharedFile" >
<gmBasic> <Storage Action="Create" Identifier="SharedFile" /> <select Target="\ABCTeam\proj\usr" /> <Select Local="\ABCTeam\proj\idf\FromCode" /> <Select System="\ABCTeam\proj\idf\FromIdl" /> <Load project="\ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCCheck\ABCCheck.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCClock\ABCClock.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCEmailReport\ABCEmailReport.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCKey\ABCKey.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCManage\ABCManage.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCMonitor\ABCMonitor.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCRead\ABCRead.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCReport\ABCReport.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCUpdate\ABCUpdate.vbp" SourceCode="On" /> <Load project="\ABCTeam\src\ABC\Applications\ABCView\ABCView.vbp" SourceCode="On" /> <Output Status="New" Filename="\ABCTeam\csh\Registry_SharedFile.xml" /> <SharedFile ReportFile="\ABCTeam\csh\SharedFile.out" RegistryFile="\ABCTeam\proj\usr\Registry_SharedFile" > <Exclude identifier="\ABCTeam\src\ABC\Applications\glbl-modShift.bas" /> <Exclude identifier="\ABCTeam\src\ABC\Applications\glbl-modSaveSensorDB.bas" /> <VbiFile identifier="\ABCTeam\csh\ABCCommon.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCCheck.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCClock.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCEmailReport.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCKey.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCManage.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCMonitor.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCRead.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCReport.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCUpdate.vbi" /> <VbiFile identifier="\ABCTeam\csh\ABCView.vbi" /> </SharedFile> <Storage Action="Close" /> </gmBasic>
SharedFile.out
This is a log file generated by Step 2. It is information only. The location of this file is set by the SharedFile@ReportFile attribute.
There were 43 Shared Files in this group of projects: Modules = 29, Forms = 8 Classes = 6 The Module file [\ABCTeam\src\ABC\Applications\glbl-Monitor.bas] is shared by 11 projects (1) \ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp (2) \ABCTeam\src\ABC\Applications\ABCCheck\ABCCheck.vbp (3) \ABCTeam\src\ABC\Applications\ABCClock\ABCClock.vbp (4) \ABCTeam\src\ABC\Applications\ABCEmailReport\ABCEmailReport.vbp (5) \ABCTeam\src\ABC\Applications\ABCKey\ABCKey.vbp (6) \ABCTeam\src\ABC\Applications\ABCManage\ABCManage.vbp (7) \ABCTeam\src\ABC\Applications\ABCMonitor\ABCMonitor.vbp (8) \ABCTeam\src\ABC\Applications\ABCRead\ABCRead.vbp (9) \ABCTeam\src\ABC\Applications\ABCReport\ABCReport.vbp (10) \ABCTeam\src\ABC\Applications\ABCUpdate\ABCUpdate.vbp (11) \ABCTeam\src\ABC\Applications\ABCView\ABCView.vbp The Class file [\ABCTeam\src\ABC\Applications\glbl-Monitor.cls] is shared by 11 projects (1) \ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp (2) \ABCTeam\src\ABC\Applications\ABCCheck\ABCCheck.vbp (3) \ABCTeam\src\ABC\Applications\ABCClock\ABCClock.vbp (4) \ABCTeam\src\ABC\Applications\ABCEmailReport\ABCEmailReport.vbp (5) \ABCTeam\src\ABC\Applications\ABCKey\ABCKey.vbp (6) \ABCTeam\src\ABC\Applications\ABCManage\ABCManage.vbp (7) \ABCTeam\src\ABC\Applications\ABCMonitor\ABCMonitor.vbp (8) \ABCTeam\src\ABC\Applications\ABCRead\ABCRead.vbp (9) \ABCTeam\src\ABC\Applications\ABCReport\ABCReport.vbp (10) \ABCTeam\src\ABC\Applications\ABCUpdate\ABCUpdate.vbp (11) \ABCTeam\src\ABC\Applications\ABCView\ABCView.vbp The Class file [\ABCTeam\src\ABC\Applications\glbl-Monitors.cls] is shared by 11 projects (1) \ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp (2) \ABCTeam\src\ABC\Applications\ABCCheck\ABCCheck.vbp (3) \ABCTeam\src\ABC\Applications\ABCClock\ABCClock.vbp (4) \ABCTeam\src\ABC\Applications\ABCEmailReport\ABCEmailReport.vbp (5) \ABCTeam\src\ABC\Applications\ABCKey\ABCKey.vbp (6) \ABCTeam\src\ABC\Applications\ABCManage\ABCManage.vbp (7) \ABCTeam\src\ABC\Applications\ABCMonitor\ABCMonitor.vbp (8) \ABCTeam\src\ABC\Applications\ABCRead\ABCRead.vbp (9) \ABCTeam\src\ABC\Applications\ABCReport\ABCReport.vbp (10) \ABCTeam\src\ABC\Applications\ABCUpdate\ABCUpdate.vbp (11) \ABCTeam\src\ABC\Applications\ABCView\ABCView.vbp ... The Module file [\ABCTeam\src\ABC\Applications\glbl-modLocalPort.bas] is shared by 3 projects (1) \ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp (2) \ABCTeam\src\ABC\Applications\ABCCheck\ABCCheck.vbp (3) \ABCTeam\src\ABC\Applications\ABCClock\ABCClock.vbp This component has no host file <ABCCommon.AppObject.SSubTimer6_GSubclass> The subprogram <ABCCommon.Monitor.ControlMonitor> is being used as a Variant Function. The defined variant <ABCCommon.Monitor.ControlMonitor.lParam> is being used as a Integer The defined Collection <ABCCommon.modABCShared.GenerateCompleteSortLabel.cmbIN> is not being changed to the using type of Object The defined Collection <ABCCommon.modABCShared.InitSortCombos.cmbIN> is not being changed to the using type of Object ... The defined Collection <ABCCommon.modABCShared.GenerateCompleteSortLabel.cmbIN> is not being changed to the using type of Object The defined variant <ABCCommon.modABCDBFunctions.CheckCloseDB.dbIN> is being used as a ADODB.Connection The defined String <ABCCommon.modABCDBFunctions.ClearBPUDisplay.lblArrayIN> is being used as a Collection. It is refactored The User Type component<frmStartup> referenced by <ABCCheck.frmStartup> is not shared This component has no host file <ABCView.AppObject.SSubTimer6_GSubclass> There is no existing GlobalSetting File selected.
Registry_SharedFile.xml
This is a rules file generated by Step 2. It contains various commands to direct the shared files consolidation. The location of this file is set by the SharedFile@RegistryFile attribute.
<GlobalImports> <Storage Action="Create" Identifier="\ABCTeam\proj\usr\Registry_SharedFile"/> <Registry type="SharedFile" Source="\ABCTeam\src\ABC\Applications\glbl-Monitor.bas" Target="\ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp;ABCCommon.dll"/> <Registry type="SharedFile" Source="\ABCTeam\src\ABC\Applications\glbl-Monitor.cls" Target="\ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp;ABCCommon.dll"/> <Registry type="SharedFile" Source="\ABCTeam\src\ABC\Applications\glbl-Monitors.cls" Target="\ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp;ABCCommon.dll"/> <Registry type="SharedFile" Source="\ABCTeam\src\ABC\Applications\glbl-modPassword.bas" Target="\ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp;ABCCommon.dll"/> <Registry type="SharedFile" Source="\ABCTeam\src\ABC\Applications\glbl-frmPassword.frm" Target="\ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp;ABCCommon.dll"/> <Registry type="SharedFile" Source="\ABCTeam\src\ABC\Applications\glbl-modLocalPort.bas" Target="\ABCTeam\src\ABC\Applications\ABCCommon\ABCCommon.vbp;ABCCommon.dll"/> ... <Storage Action="Close"/> </GlobalImports>
The Registry-SharedFile commands generated by the SharedFiles utility should be added to a GlobalSettings script. Processing that GlobalSettings script stores the command in a GlobalSettings VBI file.
Finally, loading the GlobalSettings.VBI file during translation of your VBPs will result in translations that reference shared files in the desired host project(s) rather than locally.
The FMStocks sample demonstrates the ShareFiles migration.