New examples posted

Posts   
 
    
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39771
Joined: 17-Aug-2003
# Posted on: 31-Aug-2007 18:36:36   

New examples have been posted: - Auditing (showing dependency injection, 3 different ways to audit, both adapter & selfservicing and ASP.NET and winforms). Written by David Elizondo of our support team. - Web databinding (showing all kinds of different ways how to databind data with the LLBLGen Pro datasource controls in both selfservicing and adapter and different type of controls, e.g. grids, formviews, comboboxes etc.). Written by Walaa Atef of our support team.

Please consult the customer area -> V2.5 -> Examples

or go to the general site -> Examples.

Frans Bouma | Lead developer LLBLGen Pro
Desa
User
Posts: 2
Joined: 02-Sep-2007
# Posted on: 02-Sep-2007 06:01:42   

Thanks Otis for the examples. But I was not able to download the Auditing example. I think there is a link error there.

Thanks a lot

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39771
Joined: 17-Aug-2003
# Posted on: 02-Sep-2007 12:23:31   

Indeed, I think I made a typo in the filename, the system then reverts to the default page. WIll fix it.

(edit) Fixed!

Frans Bouma | Lead developer LLBLGen Pro
Desa
User
Posts: 2
Joined: 02-Sep-2007
# Posted on: 21-Sep-2007 20:38:40   

Dear Frans,

Thanks for the Auditing example. I would love to see an example for authorization too. Thanks

Hugh
User
Posts: 13
Joined: 12-Mar-2009
# Posted on: 12-Mar-2009 13:14:09   

Hi Frans,

I downloaded the audit example and tried to open it in VS2005 (SP1) and the upgrade wizard recognised the GUI csproj was developed in an earlier version. Unfortunately I am getting the following error when the wizard tries to convert this Conversion Issues - SD.LLBLGen.Pro.Examples.Auditing.GUI.csproj: (Error List): ERROR: Unable to parse project file SD.LLBLGen.Pro.Examples.Auditing.GUI.csproj.

If you have any ideas that would be great.

Ideally I was looking for a vb.net example but if I could get this running I am sure I can figure out what is going on.

Thanks Hugh

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39771
Joined: 17-Aug-2003
# Posted on: 12-Mar-2009 14:10:49   

Odd that you see an upgrade wizard as the project file format is in vs.net 2005's ? Or did you try to open it in vs.net 2008?

Frans Bouma | Lead developer LLBLGen Pro
Hugh
User
Posts: 13
Joined: 12-Mar-2009
# Posted on: 12-Mar-2009 16:50:54   

It was definitely 2005 as I changed machines specifically to open it in 2005. Could it be that the VS.net is configured to mainly use vb? Its obviously opening for you in VS2005.disappointed

Hugh
User
Posts: 13
Joined: 12-Mar-2009
# Posted on: 12-Mar-2009 16:53:39   

Anyways what I want is to set up and use the auditing functionality provided by your cool DAL generator.

I have read the articles on Generated code – ‘Setting up and using Auditing’ and the article relating to Dependency Injection (our preferred method for setting the entity’s auditor).

The composition of my vs2008 solution is 2 auto generated llblgenpro projects providing an adapter dal in vb.net 1 application project with UI and business logic together.

It’s a windows application written in vb.net.

What I’ve done is • Added the sample GeneralAuditor class below to the application project – commenting out one or two of the methods not relevant for me. • Added the line <add key="autoDependencyInjectionDiscovery" value="true"/> to the appsettings section in the config file in the application project. • Created an AuditInfo table and generated the AuditInfoEntity using LLBLGenPro

I then used an adapter to do an insert of an entity (see code below) and the insert is working fine – see the AddTheTransaction function below (I commented out the transaction thinking it might be an issue here but no). What I thought would happen is that the override method for AuditInsertOfNewEntity in an instance of GeneralAuditor would be called each time I did an insert using oadapter.SaveEntity(oCDTran, True). I am obviously missing something. Any help you might be able to provide would be greatly appreciated?

Sample Code Imports SD.LLBLGen.Pro.ORMSupportClasses Imports FAS.EntityClasses Imports System.Collections.Generic

' VB.NET ' <summary>Example Auditor class which is usable on all entities in a project.</summary> <DependencyInjectionInfo(GetType(IEntity2), "AuditorToUse"), Serializable()> _ Public Class GeneralAuditor Inherits AuditorBase

Private Enum AuditType
    DeleteOfEntity = 1
    DirectDeleteOfEntities = 2
    DirectUpdateOfEntities = 3
    DereferenceOfRelatedEntity = 4
    ReferenceOfRelatedEntity = 5
    EntityFieldSet = 6
    InsertOfNewEntity = 7
    UpdateOfExistingEntity = 8
End Enum

Private _auditInfoEntities As List(Of AuditInfoEntity)

''' <summary>CTor </summary>
Public Sub New()
    _auditInfoEntities = New List(Of AuditInfoEntity)()
End Sub

''' <summary>Audits the successful delete of an entity from the database</summary>
''' <param name="entity">The entity which was deleted.</param>
''' <remarks>As the entity passed in was deleted succesfully, reading values from the 
''' passed in entity is only possible in this routine. After this call, the
''' state of the entity will be reset to Deleted again and reading the fields 
''' will result in an exception. It's also recommended not to reference
''' the passed in entity in any audit entity you might want to persist as the entity 
''' doesn't exist anymore in the database.</remarks>
Public Overrides Sub AuditDeleteOfEntity(ByVal entity As IEntityCore)
    Dim auditInfo As New AuditInfoEntity()
    auditInfo.AffectedEntityName = entity.LLBLGenProEntityName
    auditInfo.ActionDateTime = DateTime.Now
    auditInfo.ActionType = CInt(AuditType.DeleteOfEntity)
    _auditInfoEntities.Add(auditInfo)
End Sub

''' <summary>Audits the successful dereference of related entity from the entity passed in.</summary>
''' <param name="entity">The entity of which the related entity was dereferenced from.</param>
''' <param name="relatedEntity">The related entity which was dereferenced from entity</param>
''' <param name="mappedFieldName">Name of the mapped field onto the relation from entity to related 
''' entity for which the related entity was dereferenced.</param>
'Public Overrides Sub AuditDereferenceOfRelatedEntity(ByVal entity As IEntityCore, ByVal relatedEntity As IEntityCore, _
'   ByVal mappedFieldName As String)

'   Dim auditInfo As New AuditInfoEntity()
'   auditInfo.AffectedEntityName = entity.LLBLGenProEntityName
'   auditInfo.ActionDateTime = DateTime.Now
'   auditInfo.ActionType = CInt(AuditType.DereferenceOfRelatedEntity)
'   auditInfo.ActionData = String.Format("RelatedEntityName: {0}. MappedFieldName: {1}", _
'           relatedEntity.LLBLGenProEntityName, mappedFieldName)
'   _auditInfoEntities.Add(auditInfo)
'End Sub

''' <summary>Audits the successful insert of a new entity into the database.</summary>
''' <param name="entity">The entity saved successfully into the database.</param>
Public Overrides Sub AuditInsertOfNewEntity(ByVal entity As IEntityCore)
    Dim auditInfo As New AuditInfoEntity()
    auditInfo.AffectedEntityName = entity.LLBLGenProEntityName
    auditInfo.ActionDateTime = DateTime.Now
    auditInfo.ActionType = CInt(AuditType.InsertOfNewEntity)
    _auditInfoEntities.Add(auditInfo)
End Sub

''' <summary>
''' Audits the successful reference of related entity from the entity passed in.
''' </summary>
''' <param name="entity">The entity of which the related entity was dereferenced from.</param>
''' <param name="relatedEntity">The related entity which was dereferenced from entity</param>
''' <param name="mappedFieldName">Name of the mapped field onto the relation from entity to related 
''' entity for which the related entity was referenced.</param>
'Public Overrides Sub AuditReferenceOfRelatedEntity(entity As IEntityCore, relatedEntity As IEntityCore, 
'   mappedFieldName As String)

'   Dim auditInfo As New AuditInfoEntity()
'   auditInfo.AffectedEntityName = entity.LLBLGenProEntityName
'   auditInfo.ActionDateTime = DateTime.Now
'   auditInfo.ActionType = CInt(AuditType.ReferenceOfRelatedEntity)
'   auditInfo.ActionData = String.Format("RelatedEntityName: {0}. MappedFieldName: {1}", _
'       relatedEntity.LLBLGenProEntityName, mappedFieldName)
'   _auditInfoEntities.Add(auditInfo)
'End Sub

''' <summary>
''' Audits the successful update of an existing entity in the database
''' </summary>
''' <param name="entity">The entity updated successfully in the database.</param>
Public Overrides Sub AuditUpdateOfExistingEntity(ByVal entity As IEntityCore)
    Dim auditInfo As New AuditInfoEntity()
    auditInfo.AffectedEntityName = entity.LLBLGenProEntityName
    auditInfo.ActionDateTime = DateTime.Now
    auditInfo.ActionType = CInt(AuditType.UpdateOfExistingEntity)
    _auditInfoEntities.Add(auditInfo)
End Sub

''' <summary>
''' Gets the audit entities to save. Audit entities contain the audit information stored 
''' inside this auditor.
''' </summary>
''' <returns>The list of audit entities to save, or null if there are no audit entities to save</returns>
''' <remarks>Do not remove the audit entities and audit information from this auditor when this method is 
''' called, as the transaction in which the save takes place can fail and retried which will result in 
''' another call to this method</remarks>
Public Overrides Function GetAuditEntitiesToSave() As IList
    Return _auditInfoEntities
End Function

''' <summary>
''' The transaction with which the audit entities requested from GetAuditEntitiesToSave were saved.
''' Use this method to clear any audit data in this auditor as all audit information is persisted 
''' successfully.
''' </summary>
Public Overrides Sub TransactionCommitted()
    _auditInfoEntities.Clear()
End Sub

End Class

Function AddTheTransaction() As Boolean Dim oCDTran As New FAS.EntityClasses.CallDepositTransactionsEntity Dim oCDFundTran As New FAS.EntityClasses.CallDepositFundTransactionsEntity Dim ocolCDFundTran As New FAS.HelperClasses.EntityCollection(Of FAS.EntityClasses.CallDepositFundTransactionsEntity)

    AddTheTransaction = False

    With oCDTran
        .BankId = CInt(Me.LookUpEditBankAccounts.EditValue)
        .CdaccountId = CInt(Me.LookUpEditBankAccounts.EditValue)
        .TradeDate = CType(dtTransactionDate.Text, Date)
        .TransTypeId = CType(Me.LookUpEditTransactionType.EditValue, Integer)
        .CurrencyId = CType(Me.LookUpEditCurrency.EditValue, Integer)
        .Narrative = Me.LookUpEditNarrative.Text
        .Description = Me.txtDescription.Text & " - Manual CD"
        .ProcessedDate = Now
        .SourceId = enumPostingAreaID.ePostAreaCallDeposit
        .CurrentRec = -1
    End With

    For Each drowview As System.Data.DataRowView In _mbsCDJournals
        With oCDFundTran
            .IfundNo = CType(drowview("FundID"), Integer)
            .Amount = CType(drowview("Amount"), Decimal)
        End With
        ocolCDFundTran.Add(oCDFundTran)
    Next
    Dim oadapter As New DataAccessAdapter(FASDatabase.ClientDBConnectionString)
    Using oadapter
        'oadapter.StartTransaction(IsolationLevel.Serializable, "Add CD Transaction")
        oadapter.SaveEntity(oCDTran, True)
        'Dim GenAudit As New GeneralAuditor
        'oCDTran.AuditorToUse = GenAudit
        'oCDFundTran.AuditorToUse.AuditInsertOfNewEntity(oCDTran)


        For Each oCDFundTran In ocolCDFundTran
            oCDFundTran.TransId = oCDTran.RecordId
        Next
        Dim nNoSaved As Integer = oadapter.SaveEntityCollection(ocolCDFundTran)

        If _mbsCDJournals.Count <> nNoSaved Then
            MsgBox("There was a problem in saving the funds and we are rolling back.", MsgBoxStyle.Critical)
            'oadapter.Rollback()
        Else
            'oadapter.Commit()
            AddTheTransaction = True
        End If

    End Using

End Function
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Mar-2009 07:29:20   

I then used an adapter to do an insert of an entity (see code below) and the insert is working fine – see the AddTheTransaction function below (I commented out the transaction thinking it might be an issue here but no). What I thought would happen is that the override method for AuditInsertOfNewEntity in an instance of GeneralAuditor would be called each time I did an insert using oadapter.SaveEntity(oCDTran, True). I am obviously missing something. Any help you might be able to provide would be greatly appreciated?

Hi Hugh. the code looks ok. Nevertheless I don't clearly understand your problem. Please elaborate a bit more.

David Elizondo | LLBLGen Support Team
Hugh
User
Posts: 13
Joined: 12-Mar-2009
# Posted on: 13-Mar-2009 10:13:23   

David thanks for coming back to me on this...looks like you start early...

Ok so when I call the function AddTheTransaction from my windows form it goes and saves the two related entities

oCDTran and oCDFundTran using the lines of code oadapter.SaveEntity(oCDTran, True) oadapter.SaveEntityCollection(ocolCDFundTran)

What I thought would happen during the execution of the line

oadapter.SaveEntity(oCDTran, True)

is that the function AuditInsertOfNewEntity would be called (assuming I am adding/insert a new record).

This is not happening for me. Is this how it is designed to work? Or do I have to do something else to call the AuditInsertOfNewEntity or other methods for the auditing?

Hugh
User
Posts: 13
Joined: 12-Mar-2009
# Posted on: 13-Mar-2009 10:17:32   

Just copped you are in Guatemala....and like its 3am over there now....

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Mar-2009 17:27:11   

What I thought would happen during the execution of the line

oadapter.SaveEntity(oCDTran, True)

is that the function AuditInsertOfNewEntity would be called (assuming I am adding/insert a new record).

Yes. It Should be called. First of all please check (at debug time) if the Auditor is properly set (the AuditorToUse of the entity isn't null after you instantiate it) and that the method is called (put a breakpoint at the AuditInsertOfNewEntity method).

I see your code and it looks like the involved entity is new. Just please double check that the entity you are saving is new (.IsNew == true).

Just copped you are in Guatemala....and like its 3am over there now....

You're right simple_smile

David Elizondo | LLBLGen Support Team
Hugh
User
Posts: 13
Joined: 12-Mar-2009
# Posted on: 13-Mar-2009 19:03:59   

Thats the problem the auditor is not being properly set i.e. the AuditorToUse is nothing when the entity oCDTran is instantiated. All things working as expected I am guessing this should instantiate automatically if it recognises the Dependency Injection tags on the class?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Mar-2009 21:47:17   

Aha. If your GUI is a website you better do manual DI instead of automatically discovery. Please read this carefully. If you keep getting this behavior please attach your .config file.

David Elizondo | LLBLGen Support Team
Hugh
User
Posts: 13
Joined: 12-Mar-2009
# Posted on: 16-Mar-2009 11:29:44   

The auditing is working as documented...the reason it was not working is I stupidly updated the wrong config file with the autoDependencyInjectionDiscovery key. ...the reason we have two is that we are developing a dotnet dll that is called from a vb6 application and while developing it I run it as a standalone windows application (which calls the app.config) instead of the vb6.config file. I updated the vb6.config file.

Thanks for your help David. simple_smile