To select the startup object, right-click on the WaapiCS project in the Solution Explorer and click on Properties. Then select the Application tab and under the section labeled Startup object, select WaapiCS.CallWwise.
This file contains the following code, which allows you to connect to the Wwise Authoring API.
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using WampSharp.Core.Serialization;
using WampSharp.V2;
using WampSharp.V2.Client;
using WampSharp.V2.Core.Contracts;
using WampSharp.V2.Rpc;
namespace WaapiCS
{
class CallWwise
{
const string serverAddress = "ws://127.0.0.1:8080/waapi";
public static void Main(string[] args)
{
DefaultWampChannelFactory factory = new DefaultWampChannelFactory();
IWampChannel channel = factory.CreateJsonChannel(serverAddress, "realm1");
channel.Open().Wait();
IWampRealmProxy realmProxy = channel.RealmProxy;
CallGetInfo(realmProxy);
CallGetSelectedObjects(realmProxy);
Console.ReadLine();
}
public static void CallGetInfo(IWampRealmProxy realmProxy)
{
Console.WriteLine("Calling 'ak.wwise.core.getInfo'");
IDictionary<string, object> keywordArguments = new Dictionary<string, object>();
realmProxy.RpcCatalog.Invoke(
new AssertCallback(),
new CallOptions(),
"ak.wwise.core.getInfo",
new object[] { },
keywordArguments);
}
public static void CallGetSelectedObjects(IWampRealmProxy realmProxy)
{
Console.WriteLine("Calling 'ak.wwise.ui.getSelectedObjects'");
MyCallOptions options = new MyCallOptions();
options.@return = new string[] { "id", "name", "parent" };
realmProxy.RpcCatalog.Invoke(
new GetSelectedObjectsCallback(),
options,
"ak.wwise.ui.getSelectedObjects",
new object[] { },
new Dictionary<string, object>());
}
}
public class AssertCallback : IWampRawRpcOperationClientCallback
{
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details, TMessage[] arguments, IDictionary<string, TMessage> argumentsKeywords)
{
string name = argumentsKeywords["displayName"].ToString();
string copyright = formatter.Deserialize<JToken>(argumentsKeywords["version"])["displayName"].ToString();
Console.WriteLine("ak.wwise.core.getInfo: Hello {0} {1}", name, copyright);
}
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error, TMessage[] arguments, TMessage argumentsKeywords) {}
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error) {}
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error, TMessage[] arguments) {}
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details) {}
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details, TMessage[] arguments) {}
}
public class GetSelectedObjectsCallback : IWampRawRpcOperationClientCallback
{
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details, TMessage[] arguments, IDictionary<string, TMessage> argumentsKeywords)
{
string prefix = "ak.wwise.ui.getSelectedObjects: ";
Console.WriteLine(prefix + "Got selected object data!");
IEnumerable<JToken> objects = formatter.Deserialize<IEnumerable<JToken>>(argumentsKeywords["objects"]);
int selectedObjectsNum = objects.Count<JToken>();
Console.WriteLine(prefix + "Got {0} object(s)!", selectedObjectsNum);
if (selectedObjectsNum >= 1)
{
JToken firstObject = objects.First<JToken>();
Console.WriteLine(prefix + "The first selected object is '{0}' ({1})",
firstObject["name"].ToString(),
firstObject["id"].ToString());
JToken parent = firstObject["parent"];
if (parent == null)
{
Console.WriteLine(prefix + "It has no parent.");
}
else
{
Console.WriteLine(prefix + "Its parent is '{0}' ({1})",
parent["name"].ToString(),
parent["id"].ToString());
}
}
else
{
Console.WriteLine(prefix + "Select something and try again!");
}
}
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error, TMessage[] arguments, TMessage argumentsKeywords) { }
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error) { }
public void Error<TMessage>(IWampFormatter<TMessage> formatter, TMessage details, string error, TMessage[] arguments) { }
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details) { }
public void Result<TMessage>(IWampFormatter<TMessage> formatter, ResultDetails details, TMessage[] arguments) { }
}
public class MyCallOptions : CallOptions
{
[DataMember(Name = "return")]
public IEnumerable<string> @return { get; set; }
[DataMember(Name = "platform")]
public string platform { get; set; }
}
}
Build the solution (Ctrl+B) and run the sample using Visual Studio (F5).
The sample calls two methods: one to get general information from the Wwise Authoring Application and another to get the objects currently selected in the Application.
Observe messages printed in the output console. You should see something similar to: