All Tutorials / Jlucben / Synbot Plugin Tutorial - interface to Syn Bot Software

Synbot Plugin Tutorial - interface to Syn Bot Software

Step 9 : Adding new SIML Tags to the language

One of the main strength of Syn Bot Framework is the ability to code in C # custom adapters to handle new SIML Tags.

In SIML files you need to precise in the SIML tag that external adapters will be used

Code:

[Siml xmlns:x="http://syn.co.in/2014/siml#external" xmlns:Think="http://syn.co.in/2014/siml#think"]


In SIML , if we define an adapters with name newtag - tag Syntax will be [x:newtag][/x:newtag>]

Synbot plugin include reference to a UserSIMLadaptator.dll than you can code to create classes for handling custom new tags

You need just to download and unzip the Visual studio Solution here : UserSIMLadaptators.zip

Then to mofify in Visual Studio adding your code and generate
then to go to the BIN\DEBUG folder of the project
and to copy the files UserSIMLadaptators.dll , UserSIMLadaptators.dll.config and UserSIMLadaptators.pdb in the synbot plugin directory C:\Users\Public\Documents\EZ-Builder\Plugins\(GUID of Synbot plugin)

Here example of coding for the TextopAdapter adaptator processing SIML tag [x:Textop][/x:Textop>]

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Syn.Bot.Siml;
using Syn.Bot.Siml.Interfaces;
using Syn.Bot.Siml.Events;
using System.Diagnostics;
using System.Collections;

namespace UserSIMLadaptators
{
public class Simladaptators
{
public static bool traceEZlog = false;
private static Simladaptators instance;
static Simladaptators()
{
instance = new Simladaptators();

}
public static Simladaptators adaptators
{
get { return instance; }
}
private Simladaptators() { }
public void Add(string x, ref List listadapters)
{
// Add here to the list all new adapters you want to integrate method name as string
listadapters.Add("Textop");
return;
}
public static string Textop(Context parameter)
{
string function = string.Empty; string result = false.ToString(); string inputtext = string.Empty; string delimitor = string.Empty;
string charat = string.Empty; string length = string.Empty; string value = string.Empty; int textlength = 0;
int numat = 0; int numlength = 0;
if (parameter.Element.Value != null) inputtext = parameter.Element.Value;
if (parameter.Element.Value == null || parameter.Element.Value == string.Empty) return string.Empty;
textlength = inputtext.Length;
if (parameter.Element.Attribute("Function") != null) function = parameter.Element.Attribute("Function").Value.ToLower();
if (parameter.Element.Attribute("Delimitor") != null) delimitor = parameter.Element.Attribute("Delimitor").Value.ToLower();
if (function == string.Empty) function = "substring";
if (function == "split" && delimitor == string.Empty) return string.Empty;
if (parameter.Element.Attribute("At") != null)
{
charat = parameter.Element.Attribute("At").Value.ToLower();
if (!Int32.TryParse(charat, out numat)) numat = 0;
else
{
if (numat > textlength) numat = 0;
}
}
if (parameter.Element.Attribute("Length") != null)
{
length = parameter.Element.Attribute("Length").Value.ToLower();
if (!Int32.TryParse(charat, out numlength)) numlength = 0;
}
if (parameter.Element.Attribute("Value") != null) value = parameter.Element.Attribute("Value").Value;
if (function == "replace" && value == string.Empty) return inputtext;
if (function == "replace" || function == "substring")
{
if (numat == 0) return string.Empty;
}
var paruser = parameter.User;
EZ_Builder.EZBManager.Log("USER {0}:{1}", "split", paruser);
switch (function)
{
case "substring":
{
if (numlength == 0) return inputtext.Substring(numat - 1);
if (numat + numlength > textlength + 1) return inputtext.Substring(numat - 1);
return inputtext.Substring(numat - 1, numlength);
}
case "replace":
{
if (numlength == 0) numlength = value.Length;
StringBuilder sb = new StringBuilder(inputtext);
StringBuilder sbvalue = new StringBuilder(value);
int j = 0;
for (int i = 1; i < numlength + 1; i++)
{
sb[numat + i - 2] = sbvalue[j];
j++;
}
return sb.ToString();
}
case "split":
{
string[] ressplit = null;
ressplit = inputtext.Split(delimitor.ToCharArray());
for (int i = 1; i < ressplit.Length + 1; i++)
{
// Store results in SIML Var
parameter.User.Vars["ressplit_" + i.ToString()].Value = ressplit[i - 1];
}
return ressplit.Length.ToString();
}
default:
{
return string.Empty;
}
}
}
}
}



You can easily in the adapter code get or set Synbot variables

for Var variables - parameter.User.Vars["variable name"].Value
For User variables - parameter.User.Settings["variable name"].Value
For Bot variables - parameter.Bot.Settings["variable name"].Value

Steps