Currently the component is called from
vb script,dot net and will be also in access
Im more interested in wether it should work
my assembly uses strong names like the following and ive
included some code from the main program. Hopefully you
may spot something
Regards
Stu
Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices
Imports System.EnterpriseServices
Imports System.Data
Imports System.Data.SqlClient
Imports CGCalc.Common
Imports CGCalc.CalcDataAccess
Namespace cgCalc
<Transaction(TransactionOption.Required)> _
Public Class CalcEngine
Inherits ServicedComponent
Private Shared s_count As Integer = 0
Private m_count As Integer
Private m_canBePooled As Boolean = True
Public Sub New()
MyBase.New()
m_count =
System.Threading.Interlocked.Increment(s_count)
End Sub
Protected Overrides Function canBePooled() As
Boolean
Return m_canBePooled
End Function
Protected Overrides Sub activate()
m_canBePooled = False
End Sub
Protected Overrides Sub deactivate()
m_canBePooled = True
End Sub
Public Sub reset()
End Sub
Public ReadOnly Property version() As String
Get
version = CgCalcConfiguration.CGTVersion
End Get
End Property
Public Property Calcmode() As Integer
Get
Calcmode = m_CalcMode
End Get
Set(ByVal Value As Integer)
If Value < 0 Or Value > 3 Then
Throw New Exception("Invalid Calc
mode: " & CStr(Value))
End If
m_CalcMode = Value
CgCalcConfiguration.glo.gCalcMode = Value
End Set
End Property
Public Property Client() As Integer
Get
Client = CInt(m_Client)
End Get
Set(ByVal Value As Integer)
If Not
CgCalcConfiguration.glo.gGlobalsLoaded Then
Throw New Exception("CGcalc has not
been initialised")
End If
objCalcDB.getClientType(m_CalcMode, _
Value)
m_Client = Value
End Set
End Property
Public Property asset(ByVal passet As Integer) As
Integer
Get
passet = CInt(m_Asset)
End Get
Set(ByVal Value As Integer)
Dim reccount As Long
If Not
CgCalcConfiguration.glo.gGlobalsLoaded Then
Throw New Exception("CGcalc has not
been initialised")
End If
'check asset exists
reccount = objCalcDB.AssetExistsCheck
(Value)
If reccount = 0 Then
Throw New Exception("Invalid Asset
Code: " & passet)
End If
m_Asset = Value
End Set
End Property
Public ReadOnly Property ErrorText() As String
Get
ErrorText = m_Error
End Get
End Property
Public ReadOnly Property MultPoss() As Boolean
Get
MultPoss = m_Multpos
End Get
End Property
Public Property MQuantity(ByVal Qty As Double) As
Double
Get
Dim TaxYear As Integer, LoadTable As
Boolean
Dim tcg() As CalcInfo
If Not
CgCalcConfiguration.glo.gGlobalsLoaded Then
Throw New Exception("CGcalc has not
been initialised")
End If
Call Check_Parms()
LoadTable = True
Call objModel.AcheiveRequiredTGainLoss
(m_Client, tcg, m_Asset, MDate, Price, _
m_Gain, m_ReturnGainLoss, GraphReqd, _
m_Qty, m_Multpos, m_ReturnCode,
AuditReqd, m_Error, LoadTable, TaxYear, m_CalcMode, 0)
MQuantity = m_Qty
If InStr(CgCalcConfiguration.glo.gErrText,
CgCalcConfiguration.gFAILEDUPDATETEXT) <> 0 Then
Throw New Exception
(CgCalcConfiguration.gFAILEDUPDATETEXT)
End If
End Get
Set(ByVal Value As Double)
m_Qty = CDec(Value)
End Set
End Property
Public Property MGain() As Decimal
Get
Dim TaxYear As Integer
Dim tcg() As CalcInfo
Dim LoadTable As Boolean, UpdateData As
Boolean, IncludeUnconfirmed As Boolean
If Not
CgCalcConfiguration.glo.gGlobalsLoaded Then
Throw New Exception("CGcalc has not
been initialised")
End If
Call Check_Parms()
LoadTable = True
UpdateData = True
IncludeUnconfirmed = False
Call objModel.ComputeGainLoss(m_Client,
tcg, m_Asset, Price, MDate, _
TaxYear, m_Qty, m_NetGL, m_LossApplied,
m_Taper, m_Gain, _
m_LossCF, m_Error, UpdateData,
LoadTable, IncludeUnconfirmed, _
AuditReqd, m_ReturnCode, m_CalcMode)
MGain = m_Gain
If InStr(CgCalcConfiguration.glo.gErrText,
CgCalcConfiguration.gFAILEDUPDATETEXT) <> 0 Then
Throw New Exception
(CgCalcConfiguration.gFAILEDUPDATETEXT)
End If
End Get
Set(ByVal Value As Decimal)
m_Gain = Value
End Set
End Property
Public ReadOnly Property ReturnGain() As Decimal
Get
ReturnGain = m_ReturnGainLoss
End Get
End Property
Private Sub Check_Parms()
Dim holdingsDR As SqlDataReader
Dim reccount As Long
Dim validated_asset() As Boolean
Dim MaxHldgs As Integer, AssetX As Integer,
maxtxns As Integer, X As Integer
Dim NullTxn As CGcalcTxnStructure
If m_Client = 0 Then
m_ReturnCode = 9
Throw New Exception("Client not
specified.")
End If
If m_CalcMode < 0 Or m_CalcMode > 3 Then
m_ReturnCode = 9
Throw New Exception("Calcmode incorrectly
specified: " & m_CalcMode)
End If
If m_CalcMode =
CgCalcConfiguration.WHAT_IF_CALC_MODE Then
If m_Asset = 0 Then
m_ReturnCode = 9
Throw New Exception("Asset not
specified.")
End If
'check client has a holding in the asset
to model
reccount = objCalcDB.clientAssetHldgExists
(m_Client, m_Asset)
If reccount = 0 Then
m_ReturnCode = 9
Throw New Exception("Client does not
have a holding in the asset.")
End If
End If
If m_CalcMode =
CgCalcConfiguration.WHAT_IF_CALC_MODE Then
'check date is >= current
If MDate < System.DateTime.Now Then
m_ReturnCode = 9
Throw New Exception("Modelling date
cannot be in the past.")
End If
End If
If m_CalcMode =
CgCalcConfiguration.MODEL_SLE_TXNS_MODE Or m_CalcMode =
CgCalcConfiguration.MODEL_PUR_TXNS_MODE Then
maxtxns = UBound(m_ModelTxns)
For X = 1 To maxtxns
If CInt(m_ModelTxns(X).InQty) = 0 Then
Exit For
End If
MaxHldgs = X
Next X
If MaxHldgs > 0 Then
ReDim validated_asset(MaxHldgs)
'validate all the holdings exist
holdingsDR =
objCalcDB.ClientHoldingList(m_Client)
Do While holdingsDR.Read
For AssetX = 1 To MaxHldgs
If CLng(holdingsDR.Item
("AssetID")) = m_ModelTxns(AssetX).AssetID Then
validated_asset(AssetX) =
True
End If
Next AssetX
Loop
End If
For AssetX = 1 To MaxHldgs
If Not validated_asset(AssetX) Then
m_ReturnCode = 9
Throw New Exception("Client does
not have a holding in the asset." & m_ModelTxns
(AssetX).AssetID)
End If
Next AssetX
End If
End Sub
<AutoComplete()> _
Public Function CalcCGT() As Integer
Dim reccount As Long
Dim tcg() As CalcInfo
m_ReturnCode = 0
If Not CgCalcConfiguration.glo.gGlobalsLoaded
Then
Throw New Exception("CGcalc has not been
initialised")
End If
Call Check_Parms()
objEvent.EventProcessor(m_Client, tcg,
m_CalcMode, m_Asset, 0, Price, _
True, True, False,
AuditReqd, m_ReturnCode)
CalcCGT = m_ReturnCode
If InStr(CgCalcConfiguration.glo.gErrText,
CgCalcConfiguration.gFAILEDUPDATETEXT) <> 0 Then
m_ReturnCode = 8
CalcCGT = 8
'Err.Raise 111 + gObjectError, ,
gFailedUpdateText
End If
Return CalcCGT
End Function
Public ReadOnly Property ReturnCode() As String
Get
ReturnCode = CStr(m_ReturnCode)
End Get
End Property
Public Sub InitialiseClass(ByVal PServer As
String, _
ByVal PDatabase As String, _
Optional ByVal PUser As String = "", _
Optional ByVal PPassword As String = "")
If Not CgCalcConfiguration.glo.gGlobalsLoaded
Then
ReDim CgCalcConfiguration.glo.gEELtxt(9)
Call load_globals(PServer, _
PDatabase, _
PUser, _
PPassword, _
m_Error)
End If
If m_Error <> "" Then
Throw New Exception(m_Error)
End If
End Sub
Public Function Execute(ByVal Action As String) As
String
'A generic function for future
methods/properties without
'inflicting painful version incompatability
issues.
'For use refer francesco balena's book
prog'ing vb6 pg850
Select Case Action
Case "CGCALC"
Execute = "test generic function"
Case "AutoGenerateAllDisposals"
'this function just sets the boolean
value to state that all
'modelled txns will be generated
automatically from the notionals.
'Ordinarily this would be a class
variable, but rolling out a new class is
'too painful...!
m_AutoGenerateAllDisposals = True
Execute = "Set
AutoGenerateAllDisposals to true."
End Select
Return Execute
End Function
Public Property ModelTxns() As CGcalcTxnType()
Get
ModelTxns = m_ModelTxns
End Get
Set(ByVal Value As CGcalcTxnType())
m_ModelTxns = Value
End Set
End Property
<AutoComplete()> _
Function ModelTxnSet() As Integer
Dim TaxYear As Integer
Dim tcg() As CalcInfo
If Not CgCalcConfiguration.glo.gGlobalsLoaded
Then
Throw New Exception("CGcalc has not been
initialised")
End If
Call Check_Parms()
Select Case m_CalcMode
Case
CgCalcConfiguration.MODEL_SLE_TXNS_MODE
Call objModel.ModelMultipleDisposals
(m_Client, tcg, m_ModelTxns, ModelTxnSortID, m_NetGL, _
m_LossApplied, m_Taper,
m_ReturnGainLoss, m_LossCF, m_Error, m_ReturnCode,
m_CalcMode, _
m_AutoGenerateAllDisposals)
Case
CgCalcConfiguration.MODEL_PUR_TXNS_MODE
Call objModel.ModelMultipleAcquisitions
(m_Client, tcg, m_ModelTxns, m_NetGL, _
m_LossApplied, m_Taper,
m_ReturnGainLoss, m_LossCF, m_Error, m_ReturnCode,
m_CalcMode)
End Select
ModelTxnSet = m_ReturnCode
MGain = m_Gain
If InStr(CgCalcConfiguration.glo.gErrText,
CgCalcConfiguration.gFAILEDUPDATETEXT) <> 0 Then
Throw New Exception
(CgCalcConfiguration.gFAILEDUPDATETEXT)
End If
Return ModelTxnSet
End Function
End Class
End Namespace
<Assembly: ApplicationActivation(ActivationOption.Server)>
<Assembly: AssemblyTitle("Calcxxxxx")>
<Assembly: ApplicationName("xxxxxx(Dot Net)")>
<Assembly: AssemblyDescription("Calculator Engine")>
<Assembly: AssemblyCompany("xxxxxx Financial Systems")>
<Assembly: AssemblyProduct("xxxx")>
<Assembly: AssemblyCopyright("2003")>
<Assembly: AssemblyTrademark("")>
<Assembly: CLSCompliant(True)>
<Assembly: AssemblyKeyFile("DotNetCalc.snk")>
'The following GUID is for the ID of the typelib if this
project is exposed to COM
<Assembly: Guid("84838924-1931-4C0A-BB23-D4E4BFABAD96")>
' Version information for an assembly consists of the
following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the
Build and Revision Numbers
' by using the '*' as shown below: