I have a telephony application, there is a windows service(third party product) running on a remote server. The application runs against the server. To connect the server, we have the code.
public static TelephonyServer ts;
ts = new TelephonyServer(sIpaddress, "username", "password");
TelephonyServer is very complicated.
After getting TelephonyServer instance, now we can get the resource from it in the application. Say:
m_ChannelResource = m_TelephonyServer.GetChannel();
m_VoiceResource = m_ChannelResource.VoiceResource; // VoiceResource
Remember each telephone call will have its own VoiceResource. Then in the code, I used a thread to make a call. If there are N calls, it will have N threads.
Now in each thread, we dial a number by Dial
method then play a string by PlayTTS
code.
public DialResult Dial(string phonenumber)
{
int num = 1024;
num += phonenumber.Length * 2;
byte[] array = this.SerializePropertiesForInvocation();
num += array.Length;
VPacket vPacket = new VPacket(this.TelephonyLinkInfo.Guid, num, "ChannelResource.Dial.string.Invoke", 1);
vPacket.WriteNullableString(phonenumber);
vPacket.Serialize(array);
vPacket.DoneWriting();
byte[] buffer = base.TelephonyServer.ExecuteCommandHelperAsync(vPacket.Buffer, "ChannelResource::Dial()");
vPacket = VPacket.FromByteArray(buffer, "ChannelResource.Dial.string.Reply");
int version = vPacket.Version;
if (version == 1)
{
this.DeSerializePropertiesFromReply(VPacket.FromByteArray((byte[])vPacket.Deserialize()));
vPacket.DoneReading();
return this.m_DialResult;
}
vPacket.DoneReading();
throw new Exception("ChannelResource::Dial() Wrong Packet Version Received From Invocation.");
}
And.
public PlayTTS(string ttsString, string voice)
{
int num = 1024;
this.StopPlayAsync();
if (ttsString != null && ttsString.Length > 0)
{
num += ttsString.Length * 2;
}
if (voice != null && voice.Length > 0)
{
num += voice.Length * 2;
}
byte[] array = this.SerializePropertiesForInvocation();
num += array.Length;
VPacket vPacket = new VPacket(this.TelephonyLinkInfo.Guid, num, "VoiceResource.PlayTTS.string.string.Invoke", 1);
vPacket.WriteNullableString(ttsString);
vPacket.WriteNullableString(voice);
vPacket.Serialize(array);
vPacket.DoneWriting();
byte[] buffer = base.TelephonyServer.ExecuteCommandHelperAsync(vPacket.Buffer, "VoiceResource::PlayTTS()");
vPacket = VPacket.FromByteArray(buffer, "VoiceResource.PlayTTS.string.string.Reply");
int version = vPacket.Version;
if (version == 1)
{
this.DeSerializePropertiesFromReply(VPacket.FromByteArray((byte[])vPacket.Deserialize()));
vPacket.DoneReading();
}
vPacket.DoneReading();
throw new Exception("VoiceResource::PlayTTS() Wrong Packet Version Received From Invocation.");
}
Now I have to face a question that using C# Task
or async/await
choice in my application. From this article, I heard that using Task
or async/await
is depend on whether the application is I/O bound or CPU bound.
I am not quite sure the application is I/O bound or CPU bound or some kind of hybrid. Can you give me some advice based on my information?
EDIT: Remove TelephonyServer detail image based on comment. 10/10/2014 12:54pm