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.
Related
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
I want a class for a Customer, with a text property name.
Another property CustAddress will be a list of multiple addresses.
Each address will have two string properties.
Here is what I have.
I am not sure if I need something in the constructor of the class address.
And I'm even not sure what the code would look like to exploit this class.
Also, I can't get the F11 Step Into debug feature to step into the class code. If i put a break in the class code it does break and works fine. I have modified the option "Just My Code" to remove checkbox, but it does not help. I have a solution containing one class module and one Windows App together.
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)>
Public Class ComClass1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "c8e723b4-f229-4368-9737-97c4c71d490a"
Public Const InterfaceId As String = "16275ddb-5cfe-47c0-995f-84a5f868ad1b"
Public Const EventsId As String = "dad73a5c-8ac4-4384-a5f9-8e2c388b5514"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
'Fields
Private _name As String
Public _CustAddress As List(Of address)
'Constructor for class ComClass
Public Sub New()
_CustAddress = New List(Of address)
End Sub
Public Property CustName() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property CustAddress() As List(Of address)
Get
Return _CustAddress
End Get
Set(value As List(Of address))
_CustAddress = value
End Set
End Property
Public Class address
Private _address1 As String
Private _address2 As String
Public Sub New()
'??????
End Sub
Public Property Address1 As String
Get
Return _address1
End Get
Set(value As String)
_address1 = value
End Set
End Property
Public Property Address2 As String
Get
Return _address2
End Get
Set(value As String)
_address2 = value
End Set
End Property
End Class
End Class
I took out the com stuff just to shorten the answer. Since you had no extra code in the Property Procedures I shortened that to automatic Properties. I also moved the address Class out on its own. This class could be useful else where in the program so a nested class is not really necessary.
Public Class ComClass1
Public Property CustName As String
Public Property CustAddress As List(Of address)
Public Sub New(cName As String, cAddresses As List(Of address))
CustName = cName
CustAddress = cAddresses
End Sub
End Class
Public Class address
Public Property Address1 As String 'Street Address
Public Property Address2 As String 'City and State
Public Sub New(a1 As String, a2 As String)
Address1 = a1
Address2 = a2
End Sub
End Class
Private Sub DeclareAComClass1()
Dim addrList As New List(Of address) From {
New address("12 Main Street", "Los Angeles, CA"),
New address("13 Park Avenue", "New York, NY")
}
Dim cc As New ComClass1("Big Company, Inc.", addrList)
End Sub
Here is what I have ended up with. #Mary got me further ahead. But because I am using a COM class, I can't have any public constructors with parameters.
I added a method called AddAddress which gives me the functionality I need.
In my original post I somehow left out MyBase.New which is required for a COM class.
I encourage comments with insights on this approach.
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)>
Public Class ComClass1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "c8e723b4-f229-4368-9737-97c4c71d490a"
Public Const InterfaceId As String = "16275ddb-5cfe-47c0-995f-84a5f868ad1b"
Public Const EventsId As String = "dad73a5c-8ac4-4384-a5f9-8e2c388b5514"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
'Fields
Private _name As String
Private _CustAddress As List(Of address)
'Constructor for class ComClass
Public Sub New()
MyBase.New
_CustAddress = New List(Of address)
End Sub
Public Sub AddAddress(a1 As String, a2 As String)
Dim addr As New address(a1, a2)
_CustAddress.Add(addr)
End Sub
Public Property CustName() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property CustAddress() As List(Of address)
Get
Return _CustAddress
End Get
Set(value As List(Of address))
_CustAddress = value
End Set
End Property
Public Class address
Private _address1 As String
Private _address2 As String
Public Sub New(a1 As String, a2 As String)
_address1 = a1
_address2 = a2
End Sub
Public Property Address1 As String
Get
Return _address1
End Get
Set(value As String)
_address1 = value
End Set
End Property
Public Property Address2 As String
Get
Return _address2
End Get
Set(value As String)
_address2 = value
End Set
End Property
End Class
End Class
And the code to implement/test is as follows:
Dim TestClass As New ComClass1
Dim myint As Int32
TestClass.CustName = "John Smith"
TestClass.AddAddress("123 Main Street", "Los Angeles")
TestClass.AddAddress("13 Park Avenue", "New York")
Debug.Print(TestClass.CustAddress(0).Address1) '123 Main Stree'
Debug.Print(TestClass.CustAddress(1).Address1) '13 Park Avenue
TestClass.CustAddress.Remove(TestClass.CustAddress(0))
Debug.Print(TestClass.CustAddress(0).Address1) ' 13 Park Avenue
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
I am using the EntityFramework.SQLite library and for the life of me can not figure out how to combine two tables together into a temporary table for display purposes in xaml code.
Here's the code for my two tables I want to combine which is about all I am using right now besides a class for my temp table called CategoryList (this is part of the business/data logic dll library):
Partial Public Class CategoryList
Public Sub New()
Me.CategoryInfo = New CategoryReference
'Me.CategoryCode = New HashSet(Of CategoryCodes)
Me.CategoryCodes = New CategoryCodes
End Sub
Public Property MyId As Integer
<Key, ForeignKey("CodeID")>
<Required>
Public Property CodeID As Integer
<Key, ForeignKey("CategoryID")>
Public CategoryID As Integer
'Public Property CategoryCode As ICollection(Of CategoryCodes)
Public Property CategoryInfo As CategoryReference
' Public Property CategoryInfo As ICollection(Of CategoryReference)
Public Property CategoryCodes As CategoryCodes
End Class
<Table("CategoryCodes")>
Public Class CategoryCodes 'category shortnames/codes
<MaxLength(100)>
<Required>
Public Property CategoryCode As String
Get
Return _CategoryCode
End Get
Set(value As String)
_CategoryCode = value
End Set
End Property
Private _CategoryCode As String
'<NotNull>
' <PrimaryKey>
'<Unique(Name:="UQ__CategoryCodes__0000000000000081_CategoryCodes", Order:=0)>
<Key>
<Required>
Public Property CodeID As Integer
Get
Return CategoryCode
End Get
Set(value As Integer)
_CodeID = value
End Set
End Property
Private _CodeID As Integer
End Class
<Table("CategoryReference")>
Partial Public Class CategoryReference 'table design for category data
<MaxLength(100)>
Public Property CategoryName As String
Get
Return _CategoryName
End Get
Set(value As String)
_CategoryName = value
End Set
End Property
Private _CategoryName As String
<MaxLength(100)>
Public Property CategoryDescription As String
Get
Return _CategoryDescription
End Get
Set(value As String)
_CategoryDescription = value
End Set
End Property
Private _CategoryDescription As String
'<Unique(Name:="UQ__CatagoryReference__000000000000005F_CatagoryReference", Order:=0)>
<ForeignKey("CodeID")>
<Required>
Public Property CodeID As Integer
Get
Return _CodeID
End Get
Set(value As Integer)
_CodeID = value
End Set
End Property
Private _CodeID As Integer
'<Unique(Name:="UQ__CatagoryReference__000000000000005A_CatagoryReference", Order:=0)>
<Key>
<Required>
Public Property CategoryID As Integer
Get
Return _CategoryID
End Get
Set(value As Integer)
_CategoryID = value
End Set
End Property
Private _CategoryID As Integer
End Class
It may seem long but the tables are very simple and the get/set blocks make it look long (A vb.net editor can turn them into simple property's if she/he wishes). I may be using the CategoryList class wrong but here's where I use it in my xaml datasource in my main application code (I have business logic/data processing in a dll library):
Private Property ViewModel As List(Of UIELLUWP.DataAccess.CategoryList)
Dim categories As New UIELLUWP.DataAccess.SQLiteDb
ViewModel = categories.Categories.ToList
Errors received with current code:
I receive an error that Table "CategoryList" does not exist when I run the above code.
my solution I found out to this question was to add asnotracking because tracking was taking place.
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