<commit_before>﻿Imports Csla.Reflection

Namespace Server

  Friend Module DataPortalMethodCache

    Private _cache As Dictionary(Of MethodCacheKey, DataPortalMethodInfo) = New Dictionary(Of MethodCacheKey, DataPortalMethodInfo)()

    Public Function GetMethodInfo(ByVal objectType As Type, ByVal methodName As String, ByVal ParamArray parameters() As Object) As DataPortalMethodInfo

      Dim key = New MethodCacheKey(objectType.Name, methodName, MethodCaller.GetParameterTypes(parameters))
      Dim result As DataPortalMethodInfo = Nothing
      If (Not _cache.TryGetValue(key, result)) Then
        result = New DataPortalMethodInfo(MethodCaller.GetMethod(objectType, methodName, parameters))
        _cache.Add(key, result)
      End If
      Return result

    End Function

#Region "Data Portal Methods"

    ''' <summary>
    ''' Gets a reference to the DataPortal_Create method for
    ''' the specified business object type.
    ''' </summary>
    ''' <param name="objectType">Type of the business object.</param>
    ''' <param name="criteria">Criteria parameter value.</param>
    ''' <remarks>
    ''' If the criteria parameter value is an integer, that is a special
    ''' flag indicating that the parameter should be considered missing
    ''' (not Nothing/null - just not there).
    ''' </remarks>
    Friend Function GetCreateMethod(ByVal objectType As Type, ByVal criteria As Object) As DataPortalMethodInfo

      Dim method As DataPortalMethodInfo = Nothing
      If TypeOf criteria Is Integer Then
        ' an "Integer" criteria is a special flag indicating
        ' that criteria is empty and should not be used
        method = GetMethodInfo(objectType, "DataPortal_Create")

      Else
        method = GetMethodInfo(objectType, "DataPortal_Create", criteria)<commit_msg>Fix threading issue by adding locking code.<commit_after>﻿Imports Csla.Reflection

Namespace Server

  Friend Module DataPortalMethodCache

    Private _cache As Dictionary(Of MethodCacheKey, DataPortalMethodInfo) = New Dictionary(Of MethodCacheKey, DataPortalMethodInfo)()

    Public Function GetMethodInfo(ByVal objectType As Type, ByVal methodName As String, ByVal ParamArray parameters() As Object) As DataPortalMethodInfo

      Dim key = New MethodCacheKey(objectType.Name, methodName, MethodCaller.GetParameterTypes(parameters))
      Dim result As DataPortalMethodInfo = Nothing
      If (Not _cache.TryGetValue(key, result)) Then
        SyncLock _cache
          If (Not _cache.TryGetValue(key, result)) Then
            result = New DataPortalMethodInfo(MethodCaller.GetMethod(objectType, methodName, parameters))
            _cache.Add(key, result)
          End If
        End SyncLock
      End If
      Return result

    End Function

#Region "Data Portal Methods"

    ''' <summary>
    ''' Gets a reference to the DataPortal_Create method for
    ''' the specified business object type.
    ''' </summary>
    ''' <param name="objectType">Type of the business object.</param>
    ''' <param name="criteria">Criteria parameter value.</param>
    ''' <remarks>
    ''' If the criteria parameter value is an integer, that is a special
    ''' flag indicating that the parameter should be considered missing
    ''' (not Nothing/null - just not there).
    ''' </remarks>
    Friend Function GetCreateMethod(ByVal objectType As Type, ByVal criteria As Object) As DataPortalMethodInfo

      Dim method As DataPortalMethodInfo = Nothing
      If TypeOf criteria Is Integer Then
        ' an "Integer" criteria is a special flag indicating
        ' that criteria is empty and should not be used
        method = GetMethodInfo(objectType, "DataPortal_Create")

      Else
        method = GetMethodInfo(objectType, "DataPortal_Create", criteria)
{'fraction_non_alphanumeric': 0.07632978723404256, 'fraction_numerical': 0.0, 'mean_word_length': 3.6547029702970297, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6431562', 'n_tokens_mistral': 969, 'n_tokens_neox': 951, 'n_words': 352}