The project is created with a single class in the Class1.vb file. You can either delete the class and create another, or you can alter the class by renaming the file and the class to suit the example.
Create a class with the name ISPFHostDefault1 and put it in the namespace.
SPF.Server.Schema.Interface.Default.
You should also turn on the options for Explicit and Strict.
Imports assist with any classes you want to use without typing in the full namespace
Imports SPF.Server.Schema.Collections
Imports SPF.Server.Schema.Model
Imports SPF.Server.Schema.Model.PropertyTypes
Imports SPF.Server.Schema.Errors
Add an inherits statement (from ISPFHostDefault).
Inherits ISPFHostDefault
The class must have a constructor common to all interface classes in SmartPlant Foundation.
Public Sub New(ByVal pblnInstantiateRequiredItems As Boolean)
MyBase.New(pblnInstantiateRequiredItems)
End Sub
When complete, your stub class should look similar to the following:
Option Explicit On
Option Strict On
Imports SPF.Server.Schema.Collections
Imports SPF.Server.Schema.Model
Imports SPF.Server.Schema.Model.PropertyTypes
Imports SPF.Server.Schema.Errors
Namespace SPF.Server.Schema.Interface.Default
Public Class ISPFHostDefault1
Inherits ISPFHostDefault
Public Sub New(ByVal pblnInstantiateRequiredItems As Boolean)
MyBase.New(pblnInstantiateRequiredItems)
End Sub
End Class
End Namespace
As an easy example, we want to verify that the host has a valid name when it is created. To do that, we are going to override a secondary MethodDef named 'OnCreatingValidation'. If you put the cursor within the class and type 'public overrides ', the Intellisense should kick in a give you a list of the base class methods that you can override.
Select the OnCreatingValidation method, and Visual Studio will stub out that method for you.
Public Overrides Sub OnCreatingValidation(ByVal e As Model.CancelCreateEventArgs)
MyBase.OnCreatingValidation(e)
End Sub
The only parameter to this method is an object of class CancelCreateEventArgs. The actual data regarding the object being questioned is going to be in the class that you're writing. Remember that you are inheriting from ISPFHostDefault. After the call to MyBase, add the following lines of code:
If Me.Name.Contains(" ") Then
e.Cancel = True
e.CancelMessage = "Host name cannot contain a space"
End If
The 'if' statements tests the object name to see if contains a space. In this example, we'll consider both those conditions a reason to fail validation. If one or both of those conditions is true, then the failure code kicks in. The first line just tells SPF to cancel the create, and the second line of code sets the error message that will be sent back to the user for the reason.
Compile the example, and work through any compile errors you find.