Posted on 20/02/2019 21:53:46
You can use a codeprovider, see dump.
Here is our code:
Imports Dynamicweb.Extensibility.AddIns
Imports Dynamicweb.Extensibility.Editors
Imports Dynamicweb.SystemTools
Imports Dynamicweb.Extensibility.Providers
Namespace Extensibility.CodeProviders
<AddInName("Dynamicweb.ICodeProvider"), AddInLabel("DateTime Provider"), AddInActive(True), AddInGroup("System.DateTime")>
Public Class DateTimeCodeProvider
Inherits CodeProviderBase
Implements ICodeProvider, IDropDownOptions
<AddInParameter("Number"), AddInParameterEditor(GetType(IntegerNumberParameterEditor), "inputClass=inputControl"), AddInParameterGroup("Source")>
Public Property Number As Integer
<AddInParameter("Interval"), AddInParameterEditor(GetType(DropDownParameterEditor), "inputClass=inputControl"), AddInParameterGroup("Source")>
Public Property Interval As String
Public Overrides Function BuildCodeString() As String
'Basically not used anymore because Execute is now being overriden
Return String.Format("@Code(DateTime.Now.Add{0}({1}))", Interval, Number)
End Function
Public Overrides Function BuildDisplayValue() As String
Return String.Format("Today {0} {1} {2}", If(Number >= 0, "+", "-"), Math.Abs(Number), Interval)
End Function
Public Overrides Function Execute() As Object
Select Case Interval
Case "Minutes"
Return DateTime.Now.AddMinutes(Number)
Case "Hours"
Return DateTime.Now.AddHours(Number)
Case "Days"
Return DateTime.Now.AddDays(Number)
Case "Months"
Return DateTime.Now.AddMonths(Number)
Case "Years"
Return DateTime.Now.AddYears(Number)
End Select
Return DateTime.Now
End Function
Public Function GetOptions(dropdownName As String) As Hashtable Implements IDropDownOptions.GetOptions
' Get Hashtable
Dim options As New Hashtable
options.Add("Minutes", Translate.Translate("Minutes"))
options.Add("Hours", Translate.Translate("Hours"))
options.Add("Days", Translate.Translate("Days"))
options.Add("Months", Translate.Translate("Months"))
options.Add("Years", Translate.Translate("Years"))
' Return the hashtable
Return options
End Function
End Class
End Namespace