Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Jon Tackabury (BFS)'s profile on WallpaperFusion.com
This is an example of how to use an external .NET assembly from a VoiceBot script. This example references the Newtonsoft Json library, so you'll need to download that before you use this example.

Code

using System;
using System.Drawing;
using Newtonsoft.Json;
// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
    //to get this script to work, you need the Newtonsoft Json library downloaded to your computer,
    //then add the path to the Newtonsoft.Json.dll in the references of this script
    //http://www.newtonsoft.com/json
    
    public static void Run(IntPtr windowHandle)
    {
        //create a new test object
        TestObject test = new TestObject(1, "testing");
        
        //convert the object into json and display it to the user
        string json = JsonConvert.SerializeObject(test);
        BFS.Dialog.ShowMessageInfo(json);
        
        //take the json and make a new test object with the newtonsoft deserializer
        TestObject test2 = JsonConvert.DeserializeObject<TestObject>(json);
        BFS.Dialog.ShowMessageInfo("Number: " + test2.Number + "\nText: " + test2.Text);
    }
    
    //this object will be used to test the functionality of the newtonsoft json library
    private class TestObject
    {
        public int Number;
        public string Text;
        
        public TestObject(int number, string text)
        {
            this.Number = number;
            this.Text = text;
        }
    }
}
May 14, 2016  • #1
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)