Here are some code samples that demonstrate working DLLs that Yui can run. Keep in mind these are extremely rough and may still undergo change.
The programs I am providing are written in Visual Basic .NET and provide simple memory functions for Yui. These include writing, recalling, and forgetting information, and demonstrate the PROCESS and FUNCTION types of programs. They are all Class projects, built to DLL.
All three programs have been tested to work with the latest version of Yui. Example programs for Async programs are still to come.
Imports System.Xml
Imports System.IO
Imports System.Collections.Specialized
Imports System.Runtime.Serialization.Formatters.Binary
Public Class MEMORIZE
Public Shared log As New Specialized.StringCollection
Shared Function INSTRUCTIONS() As Specialized.OrderedDictionary
Dim dictionary As New Specialized.OrderedDictionary
dictionary.Add("NAME", "MEMORIZE")
dictionary.Add("TYPE", "PROCESS")
dictionary.Add("FOLDERNEEDED", "TRUE")
dictionary.Add("TOTALREQUIREMENTS", 3) 'Requirements as arguments for the main Sub - in this case, MEMORIZE() has 3 arguments.
dictionary.Add("the nickname for the phrase", "STRING")
dictionary.Add("the phrase to memorize", "LONGSTRING")
dictionary.Add("aliasUsed", "OPTIONALSTRING") 'MUST be the last entry in the arguments, as in MEMORIZE()
Return dictionary
End Function
Shared Function ALIASES() As Array
Dim alias1 As Array = {"REMEMBER"}
Return alias1
End Function
Shared Function MEMORIZE(nickname As String, Optional phrase As String = "", Optional usedAlias As String = "") As Specialized.StringCollection
'The StringCollection to return will include the following:
'- Success/Failure as Boolean
'- LOG information
log.Clear()
Dim success As Boolean
Select Case usedAlias.ToLower
Case ""
success = memorize1(phrase, nickname)
Case "remember"
success = memorize1(phrase, nickname)
End Select
log.Insert(0, success.ToString)
Return log
End Function
Shared Function memorize1(phrase As String, nickname As String) As Boolean
Try
log.Add("start working")
Dim file As Specialized.StringDictionary
log.Add("opening previous if any")
file = deserialize()
log.Add("memorizing")
Try
file.Add(nickname, phrase)
Catch ex As Exception
log.Add("previous entry exists!")
Return False
End Try
log.Add("committing to memory")
serialize(file)
log.Add("done")
Return True
Catch ex As Exception
log.Add("error:" & ex.Message)
Return False
End Try
End Function
Shared Sub serialize(file As Object)
Dim binformatter As New BinaryFormatter
Dim mstream As New MemoryStream
Dim stream As New FileStream((CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui"), FileMode.OpenOrCreate)
binformatter.Serialize(stream, file)
stream.Close()
End Sub
Shared Function deserialize()
Dim binformatter As New BinaryFormatter
Dim mstream As New MemoryStream
If IO.File.Exists(CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui") Then
Dim stream As New FileStream((CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui"), FileMode.OpenOrCreate)
Try
Dim obj = binformatter.Deserialize(stream)
stream.Close()
Return obj
Catch ex As Exception
stream.Close()
Return New Specialized.StringDictionary
End Try
Else
IO.File.Create(CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui")
Return New Specialized.StringDictionary
End If
End Function
End Class
Imports System.Xml
Imports System.IO
Imports System.Collections.Specialized
Imports System.Runtime.Serialization.Formatters.Binary
Public Class RECALL 'meant to be paired with 'MEMORIZE'
Public Shared log As New Specialized.StringCollection
Shared Function INSTRUCTIONS() As Specialized.OrderedDictionary
Dim dictionary As New Specialized.OrderedDictionary
dictionary.Add("NAME", "RECALL")
dictionary.Add("TYPE", "FUNCTION")
dictionary.Add("FOLDERNEEDED", "FALSE")
'dictionary.Add("DEPENDENCIES", {"MEMORIZE"})
dictionary.Add("TOTALREQUIREMENTS", 2) 'Requirements as arguments for the main Sub - in this case, RECALL() has 3 arguments.
dictionary.Add("the nickname you assigned", "STRING")
dictionary.Add("aliasUsed", "OPTIONALSTRING") 'MUST be the last entry in the arguments, as in MEMORIZE()
Return dictionary
End Function
Shared Function ALIASES() As Array
Dim alias1 As Array = {"REMIND"}
Return alias1
End Function
Shared Function RECALL(nickname As String, Optional usedAlias As String = "") As Specialized.StringCollection
'The StringCollection to return will include the following:
'- Success/Failure as Boolean
'- Function returned VALUE information
'- LOG data
log.Clear()
Dim value As String = recalling(nickname)
Dim success As Boolean
If value.StartsWith("true") Then
success = True
Else
success = False
End If
Dim val As String = value.Substring(7)
log.Insert(0, success.ToString)
log.Insert(1, val)
Return log
End Function
Shared Function recalling(nickname As String) As String
Try
log.Add("start working")
Dim file As Specialized.StringDictionary
log.Add("searching for obj")
file = deserialize()
If file.ContainsKey(nickname) Then
log.Add(nickname & " found")
Return ("true[&]" + file.Item(nickname))
Else
Return "fals[&]"
End If
Catch ex As Exception
log.Add("error:" & ex.Message)
Return "fals[&]"
End Try
End Function
Shared Function deserialize()
Dim binformatter As New BinaryFormatter
Dim mstream As New MemoryStream
If IO.File.Exists(CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui") Then
Dim stream As New FileStream((CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui"), FileMode.OpenOrCreate)
Try
Dim obj = binformatter.Deserialize(stream)
stream.Close()
Return obj
Catch ex As Exception
stream.Close()
Return New Specialized.StringDictionary
End Try
Else
IO.File.Create(CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui")
Return New Specialized.StringDictionary
End If
End Function
Shared Sub serialize(file As Object)
Dim binformatter As New BinaryFormatter
Dim mstream As New MemoryStream
Dim stream As New FileStream((CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui"), FileMode.OpenOrCreate)
binformatter.Serialize(stream, file)
stream.Close()
End Sub
End Class
Imports System.Xml
Imports System.IO
Imports System.Collections.Specialized
Imports System.Runtime.Serialization.Formatters.Binary
Public Class FORGET
Public Shared log As New Specialized.StringCollection
Shared Function INSTRUCTIONS() As Specialized.OrderedDictionary
Dim dictionary As New Specialized.OrderedDictionary
dictionary.Add("NAME", "MEMORIZE")
dictionary.Add("TYPE", "PROCESS")
dictionary.Add("FOLDERNEEDED", "FALSE")
'dictionary.Add("DEPENDENCIES", {"MEMORIZE"})
dictionary.Add("TOTALREQUIREMENTS", 2) 'Requirements as arguments for the main Sub - in this case, MEMORIZE() has 3 arguments.
dictionary.Add("the nickname for the phrase", "STRING")
dictionary.Add("aliasUsed", "OPTIONALSTRING") 'MUST be the last entry in the arguments, as in MEMORIZE()
Return dictionary
End Function
Shared Function ALIASES() As Array
Dim alias1 As Array = {""}
Return alias1
End Function
Shared Function FORGET(nickname As String, Optional usedAlias As String = "") As Specialized.StringCollection
'The StringCollection to return will include the following:
'- Success/Failure as Boolean
'- LOG information
log.Clear()
Dim success As Boolean
success = forgetting(nickname)
log.Insert(0, success.ToString)
Return log
End Function
Shared Function forgetting(nickname As String) As Boolean
Try
log.Add("start working")
Dim file As Specialized.StringDictionary
log.Add("opening previous if any")
file = deserialize()
log.Add("forgetting")
Try
file.Remove(nickname)
Catch ex As Exception
log.Add("previous entry doesn't exist!")
Return False
End Try
log.Add("committing to memory")
serialize(file)
log.Add("done")
Return True
Catch ex As Exception
log.Add("error:" & ex.Message)
Return False
End Try
End Function
Shared Sub serialize(file As Object)
Dim binformatter As New BinaryFormatter
Dim mstream As New MemoryStream
Dim stream As New FileStream((CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui"), FileMode.OpenOrCreate)
binformatter.Serialize(stream, file)
stream.Close()
End Sub
Shared Function deserialize()
Dim binformatter As New BinaryFormatter
Dim mstream As New MemoryStream
If IO.File.Exists(CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui") Then
Dim stream As New FileStream((CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui"), FileMode.OpenOrCreate)
Try
Dim obj = binformatter.Deserialize(stream)
stream.Close()
Return obj
Catch ex As Exception
stream.Close()
Return New Specialized.StringDictionary
End Try
Else
IO.File.Create(CurDir() + "\PROGRAMS\MEMORIZE\MemorizedTopics.yui")
Return New Specialized.StringDictionary
End If
End Function
End Class