I need to have a dynamic URL preferably from a Test Class. Can any one help me in formatting this design pattern to handle dynamic links from tests. instead of a constant HomePageURL.
Namespace TestDesign
Public Class HomePage
Inherits IE
Public Const HomePageURL As String = "testlink"
Public Sub New()
MyBase.New(HomePageURL)
End Sub
Public Sub New(ByVal instance As IE)
MyBase.New(instance.InternetExplorer)
End Sub
Public ReadOnly Property UserIDField() As TextField
Get
Return TextField(Find.ById(New Regex("txtuserName")))
End Get
End Property
Public ReadOnly Property PasswordField() As TextField
Get
Return TextField(Find.ById(New Regex("txtPassword")))
End Get
End Property
Public ReadOnly Property ContinueButton() As Button
Get
Return Button(Find.ById(New Regex("Submit")))
End Get
End Property
Public ReadOnly Property LogoutLink() As Link
Get
Return Link(Find.ById(New Regex("lnkLogout")))
End Get
End Property
Friend Sub Login(ByVal username As String, ByVal password As String)
UserIDField.TypeText(username)
PasswordField.TypeText(password)
ContinueButton.Click()
End Sub
Friend Sub Logout()
LogoutLink.Click()
End Sub
End Class
End Namespace
How I would approach this is to put the base url into the applicaiton config and then build a URLs class to construct them here is an example:
In app config
<appSettings>
<add key="TestServerUri" value="http://www.apple.com"/>
</appSettings>
in class file
public static Uri AppleHome
{
get
{
return new Uri(ConfigurationManager.AppSettings["TestServerUri"]);
}
}
public static Uri Iphone = new Uri(AppleHome, #"/iphone/");
Related
I want to map a given XML in object form. The XML includes e.g. values like a file path. A typical path consists of an xml-attribute for the folder-path and a file-name. The pattern should give me the opportunity to load and save object at any time. I don't want to put the file path always manually together or separate them. (I don't want to change the original serialized-object (like "katalog","kovkatalog",) because it is automatically generated.)
I think inheritance could solve my problem and improve the overviewability of my code (or should I use an other wrapper?). Is something against the approach? Are there any better approaches?
When deserializing, the following error is always returned:
"InvalidOperationException: http://example.net/V3.0/Schema'> is not expected."
Does anyone have a solution for how I can extend inheritance with additional methods?
VB.NET-CODE:
Namespace abc
Public Class Main
Public Sub New()
Dim des As New unifa_katalog
des = Deserialisieren(Of unifa_katalog)("<PATH_TO_FILE>\katalog.xml")
End Sub
Private Function Deserialisieren(Of T)(strSpeicherOrt As String) As T
Dim serializer As New XmlSerializer(GetType(T))
Dim deserialized As T = Nothing
Using file = System.IO.File.OpenRead(strSpeicherOrt)
deserialized = DirectCast(serializer.Deserialize(file), T)
End Using
Return deserialized
End Function
End Class
<XmlRoot("katalog", [Namespace]:="urn:kosxmlns")>
Partial Public Class unifa_katalog
Inherits katalog
Public Sub furtherMethod()
End Sub
End Class
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432"),
System.SerializableAttribute(),
System.Diagnostics.DebuggerStepThroughAttribute(),
System.ComponentModel.DesignerCategoryAttribute("code"),
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="http://example.net/V3.0/Schema"),
System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://example.net/V3.0/Schema", IsNullable:=False)>
Partial Public Class katalog
Inherits kovkatalog
End Class
Partial Public Class kovkatalog
Private verfahrenField As String
Private verfahrensversionField As String
Private katalogversionField As Integer
Private myversionField As String
Public Sub New()
MyBase.New
Me.katalogversionField = 1
End Sub
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()>
Public Property verfahren() As String
Get
Return Me.verfahrenField
End Get
Set
Me.verfahrenField = Value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute("verfahrens-version")>
Public Property verfahrensversion() As String
Get
Return Me.verfahrensversionField
End Get
Set
Me.verfahrensversionField = Value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute("katalog-version"),
System.ComponentModel.DefaultValueAttribute(1)>
Public Property katalogversion() As Integer
Get
Return Me.katalogversionField
End Get
Set
Me.katalogversionField = Value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute("my-version")>
Public Property myversion() As String
Get
Return Me.myversionField
End Get
Set
Me.myversionField = Value
End Set
End Property
End Class
End Namespace
XMLFILE:
<?xml version="1.0" encoding="UTF-8"?>
<kov:katalog verfahren="kov" my-version="03000200" katalog-version="1" verfahrens-version="06090000" xmlns:kov="http://example.net/V3.0/Schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</kov:katalog>
It's not really an inheritance issue, rather a namespace issue. If you use the same namespace, it will deserialize
<XmlRoot("katalog", [Namespace]:="http://example.net/V3.0/Schema")>
Partial Public Class unifa_katalog
Inherits katalog
Public Sub furtherMethod()
End Sub
End Class
I created a class that inherits button in win forms
How can i create a Browsable property with type dictionary ?
here is my code
but i didn't find it in properties menu
vb.net
<Browsable(True)>
Property Set_ddn() As Dictionary(Of TextBox, String)
Get
Return ddn
End Get
Set(ByVal value As Dictionary(Of TextBox, String))
ddn = value
End Set
End Property
how can i make it browsable ?
or what should i use instead of dictionary?
or another solution
i found the answer here (C#)
https://stackoverflow.com/a/42829336/1543991
rewrite code for vb.net
You should write your own type descriptor by deriving from CustomTypeDescriptor or implementing ICustomTypeDescriptor. Here is an example:
MyPropertyDescriptor
Provide a custom description for a property. Here I override Attributes property to provide a new list of attributes for property. For example I check if the property has [Category("Extra")], I also added a [Browsable(false)] to its attribute collection.
Imports System
Imports System.ComponentModel
Imports System.Linq
Public Class MyPropertyDescriptor
Inherits PropertyDescriptor
Private o As PropertyDescriptor
Public Sub New(ByVal originalProperty As PropertyDescriptor)
MyBase.New(originalProperty)
o = originalProperty
End Sub
Public Overrides Function CanResetValue(ByVal component As Object) As Boolean
Return o.CanResetValue(component)
End Function
Public Overrides Function GetValue(ByVal component As Object) As Object
Return o.GetValue(component)
End Function
Public Overrides Sub ResetValue(ByVal component As Object)
o.ResetValue(component)
End Sub
Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
o.SetValue(component, value)
End Sub
Public Overrides Function ShouldSerializeValue(ByVal component As Object) As Boolean
Return o.ShouldSerializeValue(component)
End Function
Public Overrides ReadOnly Property Attributes As AttributeCollection
Get
Dim attributes = MyBase.Attributes.Cast(Of Attribute)().ToList()
Dim category = attributes.OfType(Of CategoryAttribute)().FirstOrDefault()
If category IsNot Nothing AndAlso category.Category = "Extra" Then attributes.Add(New BrowsableAttribute(False))
Return New AttributeCollection(attributes.ToArray())
End Get
End Property
Public Overrides ReadOnly Property ComponentType As Type
Get
Return o.ComponentType
End Get
End Property
Public Overrides ReadOnly Property IsReadOnly As Boolean
Get
Return o.IsReadOnly
End Get
End Property
Public Overrides ReadOnly Property PropertyType As Type
Get
Return o.PropertyType
End Get
End Property
End Class
MyTypeDescriptor
Used to provide a list of custom property descriptors for a type.
Imports System
Imports System.ComponentModel
Imports System.Linq
Public Class MyTypeDescriptor
Inherits CustomTypeDescriptor
Private original As ICustomTypeDescriptor
Public Sub New(ByVal originalDescriptor As ICustomTypeDescriptor)
MyBase.New(originalDescriptor)
original = originalDescriptor
End Sub
Public Overrides Function GetProperties() As PropertyDescriptorCollection
Return Me.GetProperties(New Attribute() {})
End Function
Public Overrides Function GetProperties(ByVal attributes As Attribute()) As PropertyDescriptorCollection
Dim properties = MyBase.GetProperties(attributes).Cast(Of PropertyDescriptor)().[Select](Function(p) New MyPropertyDescriptor(p)).ToArray()
Return New PropertyDescriptorCollection(properties)
End Function
End Class
MyTypeDescriptionProvider
Used to connect MyTypeDescriptor to a class using TypeDescriptionProvider attribute.
Imports System
Imports System.ComponentModel
Public Class MyTypeDescriptionProvider
Inherits TypeDescriptionProvider
Public Sub New()
MyBase.New(TypeDescriptor.GetProvider(GetType(Object)))
End Sub
Public Overrides Function GetTypeDescriptor(ByVal type As Type, ByVal o As Object) As ICustomTypeDescriptor
Dim baseDescriptor As ICustomTypeDescriptor = MyBase.GetTypeDescriptor(type, o)
Return New MyTypeDescriptor(baseDescriptor)
End Function
End Class
MySampleClass
Contains a property decorated with [Category("Extra")]. So Property2 will not be visible in property grid. (In visual studio or collection editor or even run-time property grid)
<TypeDescriptionProvider(GetType(MyTypeDescriptionProvider))>
Public Class MySampleClass
Public Property Property1 As Integer
<Category("Extra")>
Public Property Property2 As String
End Class
MyComplexComponent
Contains a collection of MySampleClass. So you can see behavior of MySampleClass in collection editor.
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Public Class MyComplexComponent
Inherits Component
Public Sub New()
MySampleClasses = New Collection(Of MySampleClass)()
End Sub
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public Property MySampleClasses As Collection(Of MySampleClass)
End Class
As the title says, I've run into a problem where I have to call certain private functions in a class.
Public Class Class1
private Type
Private Name
private Function()
I have tried doing the following:
Public Class Class1
Dim copyClass As Class1
Public Shared Instance As Class1
Public Sub New()
MyBase.New()
copyClass = Me
End Function
Public Function createInstance() As Class1
Instance = copyClass
Return Instance
End Function
Then in my other class, Class2, I have added:
Public Property callingObject As wdCopyPatch
Get
Return copyObject
End Get
Set(value As wdCopyPatch)
copyObject = value
End Set
End Property
now, I can just do the following from within a function in Class1
Dim Ob as Class2
Ob.callingObject = createInstance()
This allows me to use copyObject from Class2 but only gives me access to Class1's Public Functions and variables. What can I do to be able to access Class1's Private functions and variables without making everything public?
Any advice or comments are appreciated :)
As per my comments, here's some code:
Sandbox is my class with a private function, and a public property getting info from that private function.
otherclass, calls this property of sandbox.
Public Class sandbox
Public ReadOnly Property myHiddenValue() As String
Get
Return get_that_sucker()
End Get
End Property
Private Function get_that_sucker()
Return "boo!"
End Function
End Class
Public Class otherClass
Public Sub mySub()
Dim mysandbox As New sandbox
MsgBox(mysandbox.myHiddenValue)
End Sub
End Class
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
well hello everybody
i have one project with multiples web services so i created various singleton class thinking in performance. now i think create one singleton class and that have the instances of my webservices
example
public static WebServiceMaster
{
internal ServiceX WebX;
internal ServiceY WebY;
......
public static WEbServiceMaster GetInstance()
.....
}
what think about that?
is that bad?
Well, finally that is done. I know that is not perfect
Public NotInheritable Class ServiceProxySingleton
Private _services As IDictionary(Of ProxyServicesEnum, IServiceDispatcher) = New Dictionary(Of ProxyServicesEnum, IServiceDispatcher)
Private _dbRepository As IDACommon
Private Sub New()
_dbRepository = New DACommon()
LoadServices()
End Sub
Private Sub LoadServices()
_services.Add(ProxyServicesEnum.eActivity, New ActivityServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eAvailability, New AvailabilityServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eBrochure, New BrochureServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eInformation, New InformationServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eMeetingRoom, New MeetingRoomServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eMembership, New MembershipServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eName, New NameServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eReservation, New ReservationServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eResvAdvanced, New ResvAdvancedServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eSecurity, New SecurityServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eStayHistory, New StayHistoryServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.ePostXml, New PostXmlServiceImp(_dbRepository, ConfigurationServiceSingleton.GetInstance.GetPostXmlConfig))
_services.Add(ProxyServicesEnum.eOxiHttp, New OxiServiceImp(_dbRepository))
End Sub
Public ReadOnly Property Service(ByVal serviceEnum As ProxyServicesEnum) As Object
Get
If _services.ContainsKey(serviceEnum) Then
Return _services.Item(serviceEnum)
End If
Return Nothing
End Get
End Property
Public ReadOnly Property GetMeta(ByVal serviceEnum As ProxyServicesEnum) As IDictionary(Of String, MethodIdentityAttribute)
Get
If _services.ContainsKey(serviceEnum) Then
Return _services.Item(serviceEnum).MetaInfo
End If
Return Nothing
End Get
End Property
Public Shared Function GetInstance() As ServiceProxySingleton
Return NestedPrWireService._instance
End Function
Class NestedPrWireService
Friend Shared ReadOnly _instance As ServiceProxySingleton = New ServiceProxySingleton()
Shared Sub New()
End Sub
End Class
End Class
comments and criticisms are welcome
Very good approach is to use Dependency Injection. For example Unity.