jlucben
Pro
Posts: 27
Joined: Wed Oct 12, 2016 1:54 pm

Trying to have an SIML adapters in a DLL not working

Tue Mar 20, 2018 4:50 pm

Hi

I want to have SIML adapters code in a Dll

Here is the Dll

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 TextopAdapter : IAdapter
// SIML Adaptator - Do some operations on a text string
// Return value depending on the operation
//
{
public bool IsRecursive => true;
public XName TagName => SimlSpecification.Namespace.X + "Textop";
// Syntax SIML
// <x:Textop Function = "function" Delimitor = "Delimitor" At = "position" Length = "length" Value = "Value" >text string</x:Syntax>
// Return value depending on function
// Function = "Substring" implicit value - At and Length parameter Mandatory - Return Substring of input text at Position with Length Length
// Function = "Split" - Delimitor parameter Mandatory - Character delimtor - Return Number of spliited element
// Splitted text can be retrieved in SIML variables ressplit_n
// Function = "Replace" - Parameter value is mandatory for replacing text and At for position - Length is optionnal(Implicoted length of replacing text)
// Return Text modified with replacing text at position At on length characters
//
public string Evaluate(Context parameter)
{
EZ_Builder.EZBManager.Log("Textop0 {0}:{1}", "split", "");
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;
EZ_Builder.EZBManager.Log("Textop {0}:{1}", "split", inputtext);
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;
}
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;
}
EZ_Builder.EZBManager.Log("Textopres {0}:{1}", "split", ressplit.Length.ToString());
return ressplit.Length.ToString();
}
default:
{
return string.Empty;
}
}
}
}
}

In the main program

I am using
IAdapter newone = new UserSIMLadaptators.TextopAdapter();
EZ_Builder.EZBManager.Log("internal {0}:{1}", newone.TagName, newone.ToString());
simlBot.Adapters.Add(newone);

The code is not activated
When I put the same code in class included in my Project , it is working

I have reference the DLL in my project with Local Copy True

Thanks for your Help

User avatar
Leslie
Lead Software Architect
Posts: 377
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Trying to have an SIML adapters in a DLL not working

Wed Mar 21, 2018 1:15 pm

Which platform are you using the framework in? Also could you shed some light on which version of .NET framework are you targeting in your project or application. This is really hard to produce on our end as the code wouldn't compile however I am certain its probably DLL file version conflict that might be causing the error.

Please note, if you aren't importing NuGet packages and trying to reference files directly then you should also ensure that the framework's dependencies are loaded as well.

Return to “Report Bugs and Issues”

Who is online

Users browsing this forum: No registered users and 1 guest