Author Topic: My own vaProxy for debugging  (Read 2932 times)

janjan

  • Newbie
  • *
  • Posts: 42
My own vaProxy for debugging
« on: May 20, 2020, 12:52:00 AM »
Hi,
Creating my first plugin I was looking for an easy way to debug it.
I created a console application and I can debug in VA by attaching to process or as suggested by @Gary here:
"Next, open the plugin's project settings, go down to the Debug tab and set the, 'Start external program' value to the path of VA (usually C:\Program Files (x86)\VoiceAttack\VoiceAttack.exe)."

However, for quicker debugging I generated a test project, which calls my plugin and performs various actions.
The main problem was the missing vaProxy object.

For this I create my own dummy global vaProxy which I attached here.

It is only for testing of course and mostly prints messages to the console but you can use Set/Get/WriteToLog and other functions and you do not need to comment anything.

If this is helpful you can add your own missing objects/methods and update it - mine only has what i needed so far.

To use it just define it and pass to your plugin:

Code: [Select]
            vaProxy myVaProxy = new vaProxy();
            VoiceAttackPlugin.VA_Invoke1(myVaProxy);
            myVaProxy.SetText("someVar1", "someText1");
            myVaProxy.SetText("someVar2", "sometext2");
            myVaProxy.Context = "InitProfile";
.
.
.
            VoiceAttackPlugin.VA_Init1(myVaProxy);
            VoiceAttackPlugin.VA_Invoke1(myVaProxy);

 

Code: [Select]
///////////// my vaProxy    /////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace Tester
{
    public class vaProxy
    {

        public string Context;

        static Dictionary<string, bool> _vaProxyBooleanDict = new Dictionary<string, bool>
        {
            {"name", false}
        };

        static Dictionary<string, string> _vaProxyStringDict = new Dictionary<string, string>
        {
            {"name", "value"}
        };

        static Dictionary<string, int> _vaProxyIntDict = new Dictionary<string, int>
        {
            {"name", 0}
        };

        static Dictionary<string, decimal> _vaProxyDecDict = new Dictionary<string, decimal>
        {
            {"name", 0}
        };

        public void InitvaProxy()
        {
            var vaProxyDict = new Dictionary<string, string>();
        }
        public void WriteToLog(string message, string color)
        {
            Console.WriteLine(message);
        }

        public void SetContext(string value)
        {
            Context = value;
        }

        public string GetText(string varName)
        {
            // Try to get the result in the static Dictionary
            string result;
            if (_vaProxyStringDict.TryGetValue(varName, out result))
            {
                return result;
            }
            else
            {
                return null;
            }
        }

        public void SetText(string varName, string value)
        {
            if (_vaProxyStringDict.ContainsKey(varName))
            {
                _vaProxyStringDict[varName] = value;
            }
            else
            {
                _vaProxyStringDict.Add(varName, value);
            }
        }

        public int GetInt(string varName)
        {
            // Try to get the result in the static Dictionary
            int result;
            if (_vaProxyIntDict.TryGetValue(varName, out result))
            {
                return result;
            }
            else
            {
                return 0;
            }
        }
        public void SetInt(string varName, int value)
        {
            if (_vaProxyIntDict.ContainsKey(varName))
            {
                _vaProxyIntDict[varName] = value;
            }
            else
            {
                _vaProxyIntDict.Add(varName, value);
            }
        }

        public decimal GetDecimal(string varName)
        {
            // Try to get the result in the static Dictionary
            decimal result;
            if (_vaProxyDecDict.TryGetValue(varName, out result))
            {
                return result;
            }
            else
            {
                return 0;
            }
        }

        public void SetDecimal(string varName, decimal value)
        {
            if (_vaProxyDecDict.ContainsKey(varName))
            {
                _vaProxyDecDict[varName] = value;
            }
            else
            {
                _vaProxyDecDict.Add(varName, value);
            }
        }

        public bool GetBoolean(string varName)
        {
            // Try to get the result in the static Dictionary
            bool result;
            if (_vaProxyBooleanDict.TryGetValue(varName, out result))
            {
                return result;
            }
            else
            {
                return false;
            }
        }

        public void SetBoolean(string varName, bool value)
        {
            if (_vaProxyBooleanDict.ContainsKey(varName))
            {
                _vaProxyBooleanDict[varName] = value;
            }
            else
            {
                _vaProxyBooleanDict.Add(varName, value);
            }
        }
        public Command Command = new Command();
        public Profile Profile = new Profile();
    }

    public class Command
    {
        //vaProxy.Command.Execute("saySomthing", true, false, null, somethingToSay)
        public void Execute(string command, bool one, bool two, string otherCmd, string txt1)
        {
            Console.WriteLine(command + ":" + txt1, "Blue");//Do something
        }
    }

    public class Profile
    {
        //vaProxy.Command.Execute("saySomthing", true, false, null, somethingToSay)
        public void Reset()
        {
            Console.WriteLine("Resetting the profile", "Blue");//Do something
        }
    }
   
}