Class Wrapper for Cartes in C #

Hello everyone

I do not have a C# class to manage Cartes. Can someone post the code in C#?

thx

Hi Xavier,

yes, I have implemented a c# class that allow you to use Cartes in c#.

Here you have!

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Diagnostics;

namespace Robot_Cartes
{
public class RobotCartes
{
public enum CompareMode { EQUAL, INCLUDED, NOT_EQUAL, NOT_INCLUDED };

    private Boolean robot_on = false;

    private object FRigel;
    private Type tRigel;

    public RobotCartes()
    {
        if (!robot_on)
        {
            RunCartes();
            try
            {
                Thread.Sleep(2000);
            }
            catch (ThreadInterruptedException e)
            {
                e.ToString();
            }
            robot_on = true;
        }

        this.FRigel = Activator.CreateInstance(Type.GetTypeFromProgID("Cartes.CartesObj"));
        this.tRigel = FRigel.GetType();
    }

    public string LastError()
    {
        String res = (String)tRigel.InvokeMember("LastError", BindingFlags.InvokeMethod, null, FRigel, new object[] { });
        //Debug.Write("\n\nLASTERROR --->"+res+"<-----\n\n");
        if (res == null)
            res = "";
        return res;
    }

    public string ExecuteWithoutError(string msg)
    {
        String answer = (String)tRigel.InvokeMember("Execute", BindingFlags.InvokeMethod, null, FRigel, new object[] { msg });
        if (answer == null)
            answer = "";
        //Debug.Write(answer);
        return answer;
    }

    public string Execute(string script)
    {
        String ret = ExecuteWithoutError(script);
        String last;
        last = (String) LastError();
        if (last.Length > 0)
        {
            throw new Exception(last);
        }
        return ret;
    }

    public void Balloon(string message)
    {
        Execute("balloon(\"" + message.Replace("\"", "\"\"") + "\");");
    }

    private void RunCartes()
    {
        string res32;
        string res64;
        string ruta32 = "HKLM\\SOFTWARE\\Cartes\\Cartes Client";
        string ruta64 = "HKLM\\SOFTWARE\\Wow6432Node\\Cartes\\Cartes Client";

        object shell = Activator.CreateInstance(Type.GetTypeFromProgID("WSCript.Shell"));
        var tShell = shell.GetType();

        try
        {
            res32 = tShell.InvokeMember("RegRead", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { ruta32 }).ToString();
        }
        catch (Exception e)
        {
            res32 = "";
        }
        if (res32.EndsWith("artes.exe"))
        {
            System.Diagnostics.Process.Start(res32);
        }
        else
        {
            res64 = tShell.InvokeMember("RegRead", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { ruta64 }).ToString();
            if (res64.EndsWith("artes.exe"))
            {
                System.Diagnostics.Process.Start(res64);
            }
            else
            {
                System.Console.WriteLine("Cartes no está instalado");
                Environment.Exit(1);
            }
        }
    }
    public void WaitSleep(int seconds, string msg)
    {
        int remain = seconds;
        while (remain > 0)
        {
            CheckAbort();
            Balloon(msg + " " + remain);
            Thread.Sleep(1000);
            remain--;
        }
    }

    public void CheckAbort()
    {
        String res = (String) Execute("$ABORT.value;");
        if (res.Equals("1"))
        {
            throw new Exception("Proceso abortado por el usuario");
        }
    }

    public void OpenProject(string filename)
    {
        if (!Execute("open(\"" + filename + "\");").Equals("1"))
            throw new Exception("No puedo cargar el proyecto " + filename);
        else Balloon("Cargando proyecto \"" + Execute("Name;") + "\"\r\n" +
                    Execute("Description;"));
    }


    public void Merge(string filename)
    {
        if (!Execute("merge(\"" + filename + "\");").Equals("1"))
            throw new Exception("No puedo cargar la librería " + filename);
    }
    public void ShowAbortDialog(string text, string byeMessage, string buttonText)
    {
        Execute("$ABORT.ShowDialog(\"Abort\",\"" + text + "\",\"" + byeMessage + "\",\"" + buttonText + "\");");
    }

    public void Reset(String api)
    {
        Execute("reset(\"" + api + "\");");
    }

    public void Forensic(string msg)
    {
        Execute("Forensic(\"" + msg.Replace("\"", "\"\"") + "\");");
    }

    public void Close()
    {
        Execute("close;");
    }
}

}

Thank you for your response.

Hello @xavier & @amartinez , It is not necessary that you use a C# class to handle Cartes. Cartes offers dozens of classes that you can use directly from C#.

“RPA Suite for Visual Studio” is an extension for Visual Studio. It is available from the Microsoft Visual Studio Market Place. I leave the link

https://marketplace.visualstudio.com/items?itemName=Rigel-Technoligies.RPAVS

and this video of how to use it.

https://www.youtube.com/watch?v=-tDwGBoqopw&feature=youtu.be

Now you can implement with Cartes in C# or Vb Net entirely from Visual Studio. It is the best there is currently.

Regards

1 Like