Advertisement
Advertisement
| 05.22.2008 at 12:02PM PDT, ID: 23425561 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: |
namespace ParkedCalls
{
public partial class FrmParkedCalls : Form
{
const string DEV_HOST = "10.0.0.3";
const int ASTERISK_PORT = 5038;
const string ASTERISK_HOST = "10.0.0.12";
const string ASTERISK_LOGINNAME = "hiep";
const string ASTERISK_LOGINPWD = "matkhau";
const string ORIGINATE_CONTEXT = "local";
const string ORIGINATE_CHANNEL = "SIP/401";
const string ORIGINATE_EXTRA_CHANNEL = "SIP/402";
const string ORIGINATE_EXTRA_EXTEN = "101";
const string ORIGINATE_EXTEN = "101";
const string ORIGINATE_CALLERID = "Test Asterisk";
const string TRANSFER_CHANNEL = "SIP/402";
public static AsteriskManager manager;
private static string monitorChannel = null;
private static string transferChannel = null;
string ChannelConnect = "New channel Event";
string ChannelDisConnect = "Hangup Event";
public FrmParkedCalls()
{
InitializeComponent();
manager = new AsteriskManager(ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);
string strErrorConnection = "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond";
// Add or Remove events
manager.NewChannel += new NewChannelEventHandler(dam_NewChannel);
manager.Hangup += new HangupEventHandler(dam_Hangup);
manager.PeerStatus += new PeerStatusEventHandler(dam_PeerStatus);
manager.Dial += new DialEventHandler(dam_Dial);
manager.OriginateFailure += new OriginateFailureEventHandler(dam_OriginateFailure);
manager.OriginateSuccess += new OriginateSuccessEventHandler(dam_OriginateSuccess);
try
{
manager.Connection.DefaultTimeout = 0;
manager.Connection.DefaultEventTimeout = 0;
manager.Initialize(); // Login and initialize queue and channels (slow)
}
catch (Exception ex)
{
if (ex.Message.Equals("Authentication failed"))
{
Console.WriteLine("Authentication failed!");
}
if (String.Compare(strErrorConnection, 0, ex.Message, 0, 20) == 0)
{
Console.WriteLine("Please check the connection again!");
}
manager.Logoff();
return;
}
// Monitor call.
LinkEventHandler le = new LinkEventHandler(dam_Link);
manager.Link += le;
while (monitorChannel == null)
{
System.Threading.Thread.Sleep(100);
}
manager.Link -= le;
// Now send Monitor action
MonitorAction ma = new MonitorAction();
ma.Channel = monitorChannel;
ma.File = "voicefile";
ma.Format = "gsm";
ma.Mix = true;
try
{
ManagerResponse mr = manager.Connection.SendAction(ma, 10000);
//Console.WriteLine("Monitor Call" + "\n\tResponse:" + mr.Response);
if (String.Compare(ChannelConnect, 0, mr.Response, 0, 17) == 0)
{
lvParkedCalls.Items.Add(ExtractInformation("Channel", mr.Response), 0);
lvParkedCalls.Items.Add(ExtractInformation("UniqueId", mr.Response), 1);
lvParkedCalls.Items.Add(ExtractInformation("CallerId", mr.Response), 2);
lvParkedCalls.Items.Add(ExtractInformation("CallerIdName", mr.Response), 3);
lvParkedCalls.Items.Add(ExtractInformation("State", mr.Response), 4);
lvParkedCalls.Items.Add(ExtractInformation("DateReceived", mr.Response), 5);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private string ExtractInformation(string regExPattern, string searchString)
{
string returnValue = string.Empty;
Regex searchRegEx = new Regex(@"(" + regExPattern + @").*");
Regex replaceRegEx = new Regex(@"(" + regExPattern + @")(:)*\s*");
MatchCollection matches = searchRegEx.Matches(searchString);
foreach (Match m in matches)
{
returnValue = replaceRegEx.Replace(m.Value, "");
break;
}
return returnValue;
}
#region Event handlers
static void dam_Events(object sender, ManagerEvent e)
{
Console.WriteLine("+++ Event : " + e.GetType().FullName);
}
static void dam_Reload(object sender, ReloadEvent e)
{
Console.WriteLine("Reload Event"
+ "\n\tMessage\t\t" + e.Message
);
}
static void dam_ExtensionStatus(object sender, ExtensionStatusEvent e)
{
Console.WriteLine("ExtensionStatus Event"
+ "\n\tContext\t\t" + e.Context
+ "\n\tExten\t\t" + e.Exten
+ "\n\tStatus\t\t" + e.Status
);
}
static void dam_Dial(object sender, DialEvent e)
{
Console.WriteLine("Dial Event"
+ "\n\tCallerId\t" + e.CallerId
+ "\n\tCallerIdName\t" + e.CallerIdName
+ "\n\tDestination\t" + e.Destination
+ "\n\tDestUniqueId\t" + e.DestUniqueId
+ "\n\tSrc\t\t" + e.Src
+ "\n\tSrcUniqueId\t" + e.SrcUniqueId
);
if (e != null && e.Destination != null && e.Destination.StartsWith(ORIGINATE_CHANNEL))
transferChannel = e.Src;
}
static void dam_OriginateFailure(object sender, OriginateFailureEvent e)
{
Console.WriteLine("Originate Failure Event"
+ "\n\tChannel\t\t" + e.Channel
+ "\n\tUniqueId\t" + e.UniqueId
+ "\n\tContext\t\t" + e.Context
);
}
static void dam_OriginateSuccess(object sender, OriginateSuccessEvent e)
{
Console.WriteLine("Originate Success Event"
+ "\n\tChannel\t\t" + e.Channel
+ "\n\tUniqueId\t" + e.UniqueId
+ "\n\tContext\t\t" + e.Context
);
}
static void dam_Hangup(object sender, HangupEvent e)
{
Console.WriteLine("Hangup Event"
+ "\n\tChannel\t\t" + e.Channel
+ "\n\tUniqueId\t" + e.UniqueId
);
}
static void dam_NewExten(object sender, NewExtenEvent e)
{
Console.WriteLine("New Extension Event"
+ "\n\tChannel\t\t" + e.Channel
+ "\n\tExtension\t" + e.Extension
+ "\n\tContext\t\t" + e.Context
+ "\n\tDateReceived\t" + e.DateReceived.ToString()
+ "\n\tPriority\t" + e.Priority.ToString()
+ "\n\tPrivilege\t" + e.Privilege
+ "\n\tUniqueId\t" + e.UniqueId
+ "\n\tAppData\t\t" + e.AppData
+ "\n\tApplication\t" + e.Application
);
}
static void dam_NewChannel(object sender, NewChannelEvent e)
{
Console.WriteLine("New channel Event"
+ "\n\tChannel\t\t" + e.Channel
+ "\n\tUniqueId\t" + e.UniqueId
+ "\n\tCallerId\t" + e.CallerId
+ "\n\tCallerIdName\t" + e.CallerIdName
+ "\n\tState\t\t" + e.State
+ "\n\tDateReceived\t" + e.DateReceived.ToString()
);
}
static void dam_PeerStatus(object sender, PeerStatusEvent e)
{
Console.WriteLine("Peer Status Event"
+ "\n\tPeer\t\t" + e.Peer
+ "\n\tStatus\t\t" + e.PeerStatus
+ "\n\tDateReceived\t" + e.DateReceived.ToString()
);
}
static void dam_Link(object sender, LinkEvent e)
{
Console.WriteLine("Link Event"
+ "\n\tChannel1:\t" + e.Channel1
+ "\n\tChannel2:\t" + e.Channel2
);
if (e.Channel1.StartsWith(ORIGINATE_CHANNEL) || e.Channel2.StartsWith(ORIGINATE_CHANNEL))
monitorChannel = e.Channel1;
}
#endregion
}
}
|