Interface with subProject - vb.net

Hy, Can I create an interface with a sub-project?
Public Interface IDraft
Property LienVue() As String
End Interface
Public Class C2018
Implements IDraft
Private m_LienVue As String
Sub New(Optional ByVal LienVue As String = "")
m_LienVue = LienVue
End Sub
Property LienVue() As String Implements IDraft.LienVue
Get
Return getlienvue()
End Get
Set(value As String)
m_LienVue = value
End Set
End Property
Private Function getlienvue() As String
Return "xxxxxxxx"
End Function
End Class
The c2018 class is in a sub-project of my main project. The goal is to add a reference to a different API from the main project

Related

How Do I Create an Extension of a Single Class Property

I have a primitive Class that looks like this:
Public Class BaseGeoData
Property GeoOrigin As String
Property GeoDestination As String
Property TravelDistance As Double?
Property TravelTime As Double?
Public Sub New()
End Sub
End Class
Public Class GeoData
Inherits BaseGeoData
Public Sub New(geoOrigStr As String, geoDestStr As String)
GeoOrigin = geoOrigStr
GeoDestination = geoDestStr
TravelDistance = 5000 'in meters
TravelTime = 360 'in minutes
End Sub
End Class
I want to be able to add 2 extensions that will return converted values like this:
TravelDistance.ToMiles()
TravelTime.ToHours()
When I add a Module to extend the class, it offers the extension to the entire class, most properties of which will never use the extension. How can I just offer the extensions to the properties that need them?
Introduce own type of "Unit" for measurement values
Public MustInherit Class Unit
Public ReadOnly Property Value As Double
Public MustOverride ReadOnly Property Name As String
Public Sub New(value As Double)
Me.Value = value
End Sub
Public Overrides Function ToString() As String
Return $"{Value} {Name}"
End Function
End Class
Public Class Meter
Inherits Unit
Public Sub New(value As Double)
MyBase.New(value)
End Sub
Public Overrides ReadOnly Property Name As String
Get
Return "m"
End Get
End Property
End Class
Public Class Mile
Inherits Unit
Public Sub New(value As Double)
MyBase.New(value)
End Sub
Public Overrides ReadOnly Property Name As String
Get
Return "mi"
End Get
End Property
End Class
And extension methods for creating unit and convertions
Public Module UnitConversions
<Extension>
Public Function Meters(value As Integer) As Meter
Return New Meter(value)
End Function
<Extension>
Public Function Miles(value As Integer) As Mile
Return New Mile(value)
End Function
<Extension>
Public Function ToMiles(meters As Meter) As Mile
Dim miles = meters.Value * 0.00062137
Return New Mile(miles)
End Function
<Extension>
Public Function ToMeters(miles As Mile) As Meter
Dim meters = miles.Value * 1609.344
Return New Meter(meters)
End Function
End Module
Then you can use value in more readable manner
TravelDistance = 5000.Meters() ' meters
' Conversion
geoData.TravelDistance.ToMiles() ' miles
Console.WriteLine(geoData.TravelDistance) ' print 3.10685 mi
You can only add extension methods into types (i.e. classes).
TravelDistance is of type Double? so you have to add an extention method into Double?.
Note that it would make the method available for every Double?, which may not be something you want.
I really like Plutonix's resolution and is the same one I would go for first.
Its simple and resolves your initial problem.
Public Class BaseGeoData
Property GeoOrigin As String
Property GeoDestination As String
Property TravelDistance As Double?
Property TravelTime As Double?
Public Sub New()
End Sub
End Class
Public Class GeoData
Inherits BaseGeoData
Public Sub New(geoOrigStr As String, geoDestStr As String)
GeoOrigin = geoOrigStr
GeoDestination = geoDestStr
TravelDistance = 5000 'in meters
TravelTime = 360 'in minutes
End Sub
Function DistanceMiles() As Double
DistanceMiles = (TravelDistance/1609.344)
End Function
Function TimeHours() As Double
DistanceMiles = (TravelTime /60)
End Function
End Class

Getting a property from the instantiator class

Not an experienced programmer, so probably not a hard question.
Developing a small application in VB.net in WPF.
I made 3 classes, EngineeringObject<==Inherits==PartOfInstallation<==Inherits==SensorActor
In the class SensorActor I'm trying to get a property of PartOfInstallation with the function MyBase.Name. But this goes directly to EngineeringObject. How do I solve this?
Public Class EngineeringObject
''Private declarations, alleen objecten die erven kunnen hieraan, of dmv van getters en setters
'Name of part
Private sName As String = "Naam"
'81346 Id's
Private sSystemId As String = "Functie" 'VentilationSystem, Pumpsystem
Private sLocationId As String = "Locatie" 'Room 0.0
Private sObjectId As String = "Object" 'Fan, Pump
'General
Private sPartNumber As String
Private sLinkToDatasheet As String
'Property's
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal value As String)
sName = value
End Set
End Property
Public Property SystemId() As String
Get
Return sSystemId
End Get
Set(ByVal value As String)
sSystemId = value
End Set
End Property
Public Property PartNumber() As String
Get
Return sPartNumber
End Get
Set(ByVal value As String)
sPartNumber = value
End Set
End Property
Public Property LinkToDatasheet() As String
Get
Return sLinkToDatasheet
End Get
Set(ByVal value As String)
sLinkToDatasheet = value
End Set
End Property
Public Sub New()
End Sub
End Class
Public Class PartOfInstallation
Inherits EngineeringObject
'src: https://stackoverflow.com/questions/21308881/parent-creating-child-object
'src: https://stackoverflow.com/questions/16244548/how-to-create-a-list-of-parent-objects-where-each-parent-can-have-a-list-of-chil
Private lSensorActor As New List(Of SensorActor)
Public Function GetSensorActor()
Return Me.lSensorActor
End Function
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor)
End Sub
End Class
Public Class SensorActor
Inherits PartOfInstallation
Dim sMyPartOfInstallation As String
Public Property MyPartOfInstallation As String
Get
Return sMyPartOfInstallation
End Get
Set(value As String)
sMyPartOfInstallation = MyBase.Name
End Set
End Property
End Class
If I understand it correctly, based on your comments, you want every SensorActor instantiated within a PartOfInstallation instance to get the same name as that instance.
If so, then just add a second constructor to your SensorActor class allowing you to pass a name for it as well:
Public Class SensorActor
Inherits PartOfInstallation
...your code...
Public Sub New() 'Empty constructor, for if/when you don't want to set the name immediately.
End Sub
Public Sub New(ByVal Name As String)
Me.Name = Name
End Sub
End Class
Now in your PartOfInstallation class you can do:
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me.Name)) 'Here, "Me" refers to the current PartOfInstallation instance.
End Sub
Alternatively you can make the SensorActor constructor take a PartOfInstallation instance instead, allowing you to copy any properties you like:
Public Class SensorActor
Inherits PartOfInstallation
...your code...
Public Sub New()
End Sub
Public Sub New(ByVal BasedOnPOI As PartOfInstallation)
Me.Name = BasedOnPOI.Name
End Sub
End Class
Thus making the code in the PartOfInstallation class:
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me))
End Sub
Read more about constructors: Object Lifetime: How Objects Are Created and Destroyed (Visual Basic) | Microsoft Docs
The result below, if there's room for improvement... always welcome.
SensorActor
Public Class SensorActor
Inherits PartOfInstallation
Dim sTemp As String
Public Overloads Property SystemId() As String
Get
Return Me.sSystemId
End Get
Set(ByVal value As String)
Me.sSystemId = sTemp + "." + value
End Set
End Property
Public Sub New(ByVal BasedOnPOI As PartOfInstallation)
sTemp = BasedOnPOI.SystemId
End Sub
End Class
PartOfInstallation
Public Class PartOfInstallation
Inherits EngineeringObject
'src: https://stackoverflow.com/questions/21308881/parent-creating-child-object
'src: https://stackoverflow.com/questions/16244548/how-to-create-a-list-of-parent-objects-where-each-parent-can-have-a-list-of-chil
Private lSensorActor As New List(Of SensorActor)
Public Function GetSensorActor()
Return Me.lSensorActor
End Function
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me))
End Sub
End Class
EngineeringObject
Public Class EngineeringObject
''Private declarations, alleen objecten die erven kunnen hieraan, of dmv van getters en setters
'Name of part
Private sName As String = "Naam"
'81346 Id's
Friend sSystemId As String = "Functie" 'VentilationSystem, Pumpsystem
Private sLocationId As String = "Locatie" 'Room 0.0
Private sObjectId As String = "Object" 'Fan, Pump
'General
Private sPartNumber As String
Private sLinkToDatasheet As String
'Property's
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal value As String)
sName = value
End Set
End Property
Public Property SystemId() As String
Get
Return sSystemId
End Get
Set(ByVal value As String)
sSystemId = "=" + value
End Set
End Property
Public Property PartNumber() As String
Get
Return sPartNumber
End Get
Set(ByVal value As String)
sPartNumber = value
End Set
End Property
Public Property LinkToDatasheet() As String
Get
Return sLinkToDatasheet
End Get
Set(ByVal value As String)
sLinkToDatasheet = value
End Set
End Property
Public Sub New()
End Sub
End Class

Implement same logic for diffrent objects as T

I suppose to use T but i am not sure how do it in proper way.
Let's consider following example.
Base class:
Public Class HtmlBase
Implements IGetInformation
Public Overridable Function IsExist() As Boolean Implements IGetInformation.IsExist
Throw New NotImplementedException()
End Function
Public Overridable Function GetIdByName(pName As String) As Integer Implements IGetInformation.GetIdByName
Throw New NotImplementedException()
End Function
End Class
Example classes which inherit from base class:
Public Class HtmlSubSection
Inherits HtmlBase
'--sometimes i have to overload to add additioinal parameter
Public Overloads Function isExist(subsection As String) As Boolean
Dim dlsubkategorie As New DataLayer.DALSubSection
Return dlsubkategorie.CheckIfSubSectionExist(subsection)
End Function
Public Overrides Function GetIdByName(subsectionName As String) As Integer
Dim dlget As New DataLayer.DALSubSection
Return dlget.GetSubSectionIdByName(subsectionName)
End Function
End Class
Public Class HtmlSection
Inherits HtmlBase
'sometime i have to overload to add additioinal parameter
Public Overloads Function IsExist(section As String) As Boolean
Dim dlsubkategorie As New DataLayer.DALSection
Return dlsubkategorie.CheckIfSectionExist(section)
End Function
Public Overrides Function GetIdByName(Name As String) As Integer
Dim dlsubkategorie As New DataLayer.DALSection
Return dlsubkategorie.GetSectionIdByName(Name)
End Function
End Class
As could be seen above two classes which inherits from base within their methods has same logic (sometimes i have to use additional parameter therefore overloads there, but are using diffrent DAL class to call. I would like to implement this logic in base class and for each just point to specific DAL. How to do that to not everytime in those classes write e.g:
Dim dlsubkategorie As New DataLayer.<DALSection>
Return dlsubkategorie.GetSectionIdByName(Name)
EDIT:
Htmlbase constructor's:
Sub New()
End Sub
Sub New(pId As Integer)
_Id = pId
End Sub
HtmlSubSection's constructors:
Sub New()
MyBase.New()
AvailableSentences = New List(Of HtmlSubSection_Sentence)
SelectedSentences = New List(Of HtmlSubSection_Sentence)
End Sub
Sub New(pId As Integer)
MyBase.New(pId)
End Sub
Sub New(pName As String)
_Name = pName
End Sub
Sub New(pId As Integer, pName As String)
MyBase.New(pId)
_Name = pName
End Sub
HtmlSection's constructors:
Sub New()
MyBase.New()
End Sub
Sub New(pId As Integer)
MyBase.New(pId)
End Sub
Sub New(pId As Integer, pName As String, pPosition As Integer)
MyBase.New(pId)
_Name = pName
_Position = pPosition
End Sub
Sub New(pName As String)
_Name = pName
End Sub
Sub New(pName As String, pPosition As Integer)
_Name = pName
_Position = pPosition
End Sub
You donĀ“t need generic types here. Just use Interfaces, Sub Classing and Polymorphism correctly.
New Interface IDAL which is implemented by DAL classes to get rid of different method names which take same parameters and do the same:
Public Interface IDAL
Function CheckIfSectionExist(section As string) As Boolean
Function GetSectionIdByName(section As string) As Integer
End Interface
Public Class DALSection
Implements IDAL
Public Function CheckIfSectionExist(section As string) As Boolean Implements IDAL.CheckIfSectionExist
...
End Function
Public Function GetSectionIdByName(section As String) As Integer Implements IDAL.GetSectionIdByName
...
End Function
End Class
Public Class DALSubSection
Implements IDAL
Public Function CheckIfSubSectionExist(subSection As string) As Boolean Implements IDAL.CheckIfSectionExist
...
End Function
Public Function GetSubSectionIdByName(subSection As String) As Integer Implements IDAL.GetSectionIdByName
...
End Function
End Class
Base class changed to abstract and the constructor now takes IDAL parameter. Function can now be executed polymorphic. Added a isExists(string) function to avoid overloading:
Public MustInherit Class HtmlBase
Implements IGetInformation
Public Property DAL as DataLayer.IDAL
Protected Sub New(dal as DataLayer.IDAL)
Me.DAL = dal
End Sub
Public Overridable Function isExist() As Boolean Implements IGetInformation.isExist
Return True
End Function
Public Overridable Function isExist(section As String) As Boolean
Return DAL.CheckIfSectionExist(Section)
End Function
Public Overridable Function GetIdByName(pName As String) As Integer Implements IGetInformation.GetIdByName
Return DAL.GetSectionIdByName(pName)
End Function
End Class
Client classes only need to give correct DAL to base class:
Public Class HtmlSubSection
Inherits HtmlBase
Public Sub New()
MyBase.New(New DataLayer.DALSubSection)
End Sub
End Class
Public Class HtmlSection
Inherits HtmlBase
Public Sub New()
MyBase.New(New DataLayer.DALSection)
End Sub
End Class
Basically it would be ideal if IGetInformation had a isExist method with an optional string parameter. This would save one unneccessary method in HtmlBase.

Class can't be used in WCF service, while derived class can

I have an abstract class FileFolderBase with 2 classes deriving from it File and Folder, the class ProjectFolder is again deriving from the Folder class.
I have a WCF service, called BrowseService with 2 functions: GetRoot, which returns a list of ProjectFolder instances, and OpenFolder, which returns one Folder instance.
Here's the service code
iBrowseService.vb:
Imports System.ServiceModel
<ServiceContract()>
Public Interface IBrowseService
<OperationContract()>
Function OpenFolder(ByVal path As String) As Domain.Folder
<OperationContract()>
Function GetRoot(ByVal projectCodes As String) As List(Of Domain.ProjectFolder)
End Interface
BrowseService.svc.vb:
Imports System.ServiceModel.Activation
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class BrowseService
Implements IBrowseService
Public Function OpenFolder(ByVal path As String) As Domain.Folder Implements IBrowseService.OpenFolder
Dim service As MyService = New MyService()
Dim folder As Domain.Folder = service.OpenFolder(path)
Return folder
End Function
Public Function GetRoot(ByVal projectCodes As String) As List(Of Domain.ProjectFolder) Implements IBrowseService.GetRoot
Dim service As MyService = New MyService()
Dim folders As List(Of Domain.ProjectFolder)
If Not String.IsNullOrEmpty(projectCodes) Then
Dim codes As List(Of String) = projectCodes.Split(",").ToList
folders = service.GetRoot(codes)
Else
folders = service.GetRoot(Nothing)
End If
Return folders
End Function
End Class
Nothing overly complicated there, now the odd thing is, the GetRoot function works perfectly and returns a set of ProjectFolder instances when I call it. The OpenFolder function however, won't work at all. The WCF test client gives a 'This operation is not supported in the WCF Test Client cause it uses the type Folder' message and when I use the service in an application, I get a CommunicationsException, most inner exception message 'An existing connection was forcibly closed by the remote host', when invoking it.
I can't find any cause why ProjectFolder can be used, while Folder can't, especially cause ProjectFolder derives from Folder.
Here are the sources for the 4 type classes:
FileFolderBase
Imports System.Runtime.Serialization
<Serializable()>
<DataContract(IsReference:=True)>
Public MustInherit Class FileFolderBase
Implements IComparable(Of FileFolderBase)
#Region "Attributes"
Protected varPkey As Long
Protected varName As String
Protected varFullName As String
Protected varProjectFolder As ProjectFolder
Protected varLastModified As Date
#End Region
#Region "Properties"
<DataMember>
Public Property Pkey() As Long
Get
Return varPkey
End Get
Set(value As Long)
varPkey = value
End Set
End Property
<DataMember>
Public Property Name() As String
Get
Return varName
End Get
Set(ByVal value As String)
varName = value
End Set
End Property
<DataMember>
Public Property FullName() As String
Get
Return varFullName
End Get
Set(ByVal value As String)
varFullName = value
End Set
End Property
<DataMember>
Public Property ProjectFolder() As ProjectFolder
Get
Return varProjectFolder
End Get
Set(value As ProjectFolder)
varProjectFolder = value
End Set
End Property
<DataMember>
Public Property LastModified() As Date
Get
Return Me.varLastModified
End Get
Set(ByVal value As Date)
Me.varLastModified = value
End Set
End Property
#End Region
#Region "Methods"
'Equals function and = and <> operators
#End Region
#Region "CompareMethods"
'Comparison functions, used for sorting and stuff
#End Region
End Class
File
Imports System.Runtime.Serialization
<Serializable()>
<DataContract(IsReference:=True)>
Public Class File
Inherits FileFolderBase
#Region "Attributes"
Private varSize As Long
Private varComment As String
#End Region
#Region "Constructors"
Public Sub New()
Me.varPkey = 0
End Sub
Public Sub New(ByVal pkey As Long, ByVal name As String, ByVal fullName As String, ByVal lastModified As Date, ByVal size As Long, ByVal comment As String, ByVal project As ProjectFolder)
Me.varPkey = pkey
Me.varName = name
Me.varFullName = fullName
Me.varLastModified = lastModified
Me.varSize = size
Me.varComment = comment
Me.varProjectFolder = project
End Sub
#End Region
#Region "Properties"
<DataMember>
Public Property Size() As Long
Get
Return Me.varSize
End Get
Set(ByVal value As Long)
Me.varSize = value
End Set
End Property
<DataMember>
Public Property Comment() As String
Get
Return Me.varComment
End Get
Set(ByVal value As String)
Me.varComment = value
End Set
End Property
#End Region
#Region "Methods"
'Equals function and = and <> operators
#End Region
#Region "CompareMethods"
'Comparison functions, used for sorting and stuff
#End Region
End Class
Folder
Imports System.Runtime.Serialization
<Serializable()>
<DataContract(IsReference:=True)>
Public Class Folder
Inherits FileFolderBase
#Region "Attributes"
Protected varItems As List(Of FileFolderBase)
Protected varParent As Folder
#End Region
#Region "Constructors"
Public Sub New()
Me.varPkey = 0
End Sub
Public Sub New(ByVal pkey As Long, ByVal name As String, ByVal fullName As String, ByVal lastModified As Date, ByVal parent As Folder, ByVal project As ProjectFolder)
Me.varPkey = pkey
Me.varName = name
Me.varFullName = fullName
Me.varLastModified = lastModified
Me.varParent = parent
Me.varProjectFolder = project
varItems = New List(Of FileFolderBase)()
End Sub
#End Region
#Region "Properties"
<DataMember>
Public Property Items() As List(Of FileFolderBase)
Get
Return Me.varItems
End Get
Set(ByVal value As List(Of FileFolderBase))
Me.varItems = value
End Set
End Property
<DataMember>
Public Property Parent() As Folder
Get
Return varParent
End Get
Set(ByVal value As Folder)
Me.varParent = value
End Set
End Property
#End Region
#Region "Methods"
'Equals function and = and <> operators
#End Region
End Class
ProjectFolder
Imports System.Runtime.Serialization
<Serializable()>
<DataContract(IsReference:=True)>
Public Class ProjectFolder
Inherits Folder
#Region "Attributes"
Private varProject As Project
#End Region
#Region "Constructors"
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal project As Project, ByVal parent As Folder)
MyBase.New(0, project.Name, project.Name, Date.Now, parent, Nothing)
Me.varProject = project
End Sub
#End Region
#Region "Properties"
<DataMember>
Public Property Project() As Project
Get
Return Me.varProject
End Get
Set(ByVal value As Project)
Me.varProject = value
End Set
End Property
<DataMember>
Public Overloads Property Items() As List(Of FileFolderBase)
Get
Return Me.varItems
End Get
Set(ByVal value As List(Of FileFolderBase))
Me.varItems = value
End Set
End Property
<DataMember>
Public Overloads Property ProjectFolder() As ProjectFolder
Get
Return Me
End Get
Set(value As ProjectFolder)
End Set
End Property
#End Region
#Region "Methods"
'Equals function and = and <> operators
#End Region
End Class
Please help, cause I have no clue how this can be possible.

ServiceStack cache in VB.net

How do I go about implementing ServiceStack cache in VB.net? I've seen many C# examples, but I am not able to transfer this onto vb.net.
The point I get stack in the 1st and 2nd argument of the ServiceStack.ServiceHost.RequestContextExtensions.ToOptimizedResultUsingCache
1st should be: ServiceStack.ServiceHost.IRequestContext - not sure
what IRequestContext is
2nd should be:
ServiceStack.CacheAccess.Providers.MemoryCacheClient - how do I set
this do cache default in config i.e. MemoryCacheClient
Code below, any suggestion much appreciated.
Global.asax.vb
Public Class Global_asax
Inherits System.Web.HttpApplication
Public Class HelloAppHost
Inherits AppHostBase
Public Sub New()
MyBase.New("Web Services", GetType(Wrapper).Assembly)
End Sub
Public Overrides Sub Configure(ByVal container As Container)
Routes.Add(Of GetProduct)("/GetProduct").Add(Of GetProduct)("/GetProduct/{*}")
Plugins.Add(New Cors.CorsFeature(allowedHeaders:="Content-Type, Authorization"))
container.Register(Of ICacheClient)(New MemoryCacheClient())
End Sub
End Class
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim apphost = New HelloAppHost()
apphost.Init()
End Sub
End Class
WS.vb
Public Class Wrapper
Public Class WrapperGetProduct
Implements IService(Of GetProduct)
Public Function Execute(ByVal request As GetProduct) As Object Implements ServiceStack.ServiceHost.IService(Of GetProduct).Execute
Dim cachekey As String = "some_key"
Dim expireInTimespan = New TimeSpan(1, 0, 0)
Return ServiceStack.ServiceHost.RequestContextExtensions.ToOptimizedResultUsingCache(
ServiceStack.ServiceHost.IRequestContext, // not sure what this should be
ServiceStack.CacheAccess.Providers.MemoryCacheClient, // not sure what this should be - how do I set this to cache setted in configuration (in memory cache)?
cachekey, expireInTimespan,
Function() request.HandleRequest()
)
End Function
End Class
End Class
Use the new API
ToOptimizedResultUsingCache is an extension method for RequestContext which services inherit/expose, same with Cache (resolved automatically via IOC).
Example below converted from C#, caching/wrapping an existing service (AppConfig and Repository are resolved via IOC, registered in AppHost configure method).
Imports System.Collections.Generic
Imports ServiceStack.Common
Imports ServiceStack.ServiceHost
Imports ServiceStack.ServiceInterface.ServiceModel
Imports ServiceStack.Common.Web
Public Class SearchTerm
Public Property Latitude() As Double
Get
Return m_Latitude
End Get
Set
m_Latitude = Value
End Set
End Property
Private m_Latitude As Double
Public Property Longitude() As Double
Get
Return m_Longitude
End Get
Set
m_Longitude = Value
End Set
End Property
Private m_Longitude As Double
Public Property Term() As String
Get
Return m_Term
End Get
Set
m_Term = Value
End Set
End Property
Private m_Term As String
End Class
<Route("/lookup/searchterm", "GET")> _
Public Class SearchTermRequest
Implements IReturn(Of SearchTermResponse)
Public Property Term() As String
Get
Return m_Term
End Get
Set
m_Term = Value
End Set
End Property
Private m_Term As String
End Class
Public Class SearchTermResponse
Implements IHasResponseStatus
Public Property ResponseStatus() As ResponseStatus
Get
Return m_ResponseStatus
End Get
Set
m_ResponseStatus = Value
End Set
End Property
Private m_ResponseStatus As ResponseStatus
Public Property Results() As List(Of SearchTerm)
Get
Return m_Results
End Get
Set
m_Results = Value
End Set
End Property
Private m_Results As List(Of SearchTerm)
End Class
<Route("/cached/lookup/searchterm")> _
Public Class CachedSearchTermRequest
Implements IReturn(Of CachedSearchTermResponse)
Public ReadOnly Property CacheKey() As String
Get
Return UrnId.Create(Of CachedSearchTermRequest)(String.Format("{0}", Me.Term))
End Get
End Property
Public Property Term() As String
Get
Return m_Term
End Get
Set
m_Term = Value
End Set
End Property
Private m_Term As String
End Class
Public Class CachedSearchTermResponse
Implements IHasResponseStatus
Public Property ResponseStatus() As ResponseStatus
Get
Return m_ResponseStatus
End Get
Set
m_ResponseStatus = Value
End Set
End Property
Private m_ResponseStatus As ResponseStatus
Public Property Results() As List(Of SearchTerm)
Get
Return m_Results
End Get
Set
m_Results = Value
End Set
End Property
Private m_Results As List(Of SearchTerm)
End Class
Public Class SearchTermService
Inherits Service
Public Property Repository() As IRepository
Get
Return m_Repository
End Get
Set
m_Repository = Value
End Set
End Property
Private m_Repository As IRepository
Public Function [Get](request As SearchTermRequest) As SearchTermResponse
Return New SearchTermResponse() With { _
Key .Results = Me.Repository.SearchTermGet(request) _
}
End Function
End Class
Public Class CachedSearchTermService
Inherits Service
Public Property AppConfig() As AppConfig
Get
Return m_AppConfig
End Get
Set
m_AppConfig = Value
End Set
End Property
Private m_AppConfig As AppConfig
Public Function [Get](request As CachedSearchTermRequest) As Object
Dim cacheKey As String = request.CacheKey
Return Me.RequestContext.ToOptimizedResultUsingCache(
MyBase.Cache, cacheKey, New TimeSpan(0, Me.AppConfig.CacheTimeMinutes, 0),
Function()
Using service = Me.ResolveService(Of SearchTermService)()
Return service.[Get](request.TranslateTo(Of SearchTermRequest)()).TranslateTo(Of CachedSearchTermResponse)()
End Using
End Function
)
End Function
End Class