<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][16541] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=16541">16541</a></dd>
<dt>Author</dt> <dd>dftoro</dd>
<dt>Date</dt> <dd>2010-01-29 23:32:56 -0600 (Fri, 29 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add new examples about use ESL managed. Inbound and Outbound modes were documented.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunklibseslmanagedManagedEslTestProgramcs">freeswitch/trunk/libs/esl/managed/ManagedEslTest/Program.cs</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunklibseslmanagedManagedEslTestProgramcs"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/libs/esl/managed/ManagedEslTest/Program.cs (16540 => 16541)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/libs/esl/managed/ManagedEslTest/Program.cs        2010-01-30 02:55:49 UTC (rev 16540)
+++ freeswitch/trunk/libs/esl/managed/ManagedEslTest/Program.cs        2010-01-30 05:32:56 UTC (rev 16541)
</span><span class="lines">@@ -1,23 +1,201 @@
</span><del>-using System;
</del><ins>+/*
+ * C# ESL managed examples
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Contributor:
+ * Diego Toro <dftoro@yahoo.com>
+ */
</ins><span class="cx">
</span><ins>+using System;
+using System.Net;
+using System.Net.Sockets;
+using System.Threading;
+
</ins><span class="cx"> namespace ManagedEslTest
</span><span class="cx"> {
</span><ins>+ [Flags]
+ public enum enLogLevel
+ {
+ EMERG = 0,
+ ALERT,
+ CRIT,
+ ERROR,
+ WARNING,
+ NOTICE,
+ INFO,
+ DEBUG
+ }
+
+
</ins><span class="cx"> class Program
</span><span class="cx"> {
</span><ins>+ public static readonly int ESL_SUCCESS = 1;
+
</ins><span class="cx"> static void Main(string[] args)
</span><span class="cx"> {
</span><del>- // Connect to FreeSWITCH
</del><ins>+ /*
+ * The next lines are usefull to view simples C# examples about how ESL managed works.
+ * Active only a mode uncomment it: inbound, outbound sync or outbound async.
+ * If you active two o more on this application you may have problems.
+ * Remember modify your dialplan for testing outbound modes (see OutboundModeSync and OutboundModeAsync members)
+ */
+ ThreadPool.QueueUserWorkItem(new WaitCallback(InboundMode));
+ //ThreadPool.QueueUserWorkItem(new WaitCallback(OutboundModeSync));
+ //ThreadPool.QueueUserWorkItem(new WaitCallback(OutboundModeAsync));
+
+ Console.ReadLine();
+ }
+
+ /// <summary>
+ /// Example using event socket in "Inbound" mode
+ /// </summary>
+ /// <param name="stateInfo">Object state info</param>
+ static void InboundMode(Object stateInfo)
+ {
+ //Initializes a new instance of ESLconnection, and connects to the host $host on the port $port, and supplies $password to freeswitch
</ins><span class="cx"> ESLconnection eslConnection = new ESLconnection("localhost", "8021", "ClueCon");
</span><del>- // We want all Events (probably will want to change this depending on your needs)
- eslConnection.SendRecv("event plain ALL");
</del><span class="cx">
</span><ins>+ if (eslConnection.Connected() != ESL_SUCCESS)
+ {
+ Console.WriteLine("Error connecting to FreeSwitch");
+ return;
+ }
</ins><span class="cx">
</span><ins>+ //Set log level
+ //ESL.eslSetLogLevel((int)enLogLevel.DEBUG);
+
+ // Subscribe to all events
+ ESLevent eslEvent = eslConnection.SendRecv("event plain ALL");
+
+ if (eslEvent == null)
+ {
+ Console.WriteLine("Error subscribing to all events");
+ return;
+ }
+
+ //Turns an event into colon-separated 'name: value' pairs. The format parameter isn't used
+ Console.WriteLine(eslEvent.Serialize(String.Empty));
+
</ins><span class="cx"> // Grab Events until process is killed
</span><del>- while (eslConnection.Connected() == 1)
</del><ins>+ while (eslConnection.Connected() == ESL_SUCCESS)
</ins><span class="cx"> {
</span><del>- ESLevent eslEvent = eslConnection.RecvEvent();
</del><ins>+ eslEvent = eslConnection.RecvEvent();
</ins><span class="cx"> Console.WriteLine(eslEvent.Serialize(String.Empty));
</span><span class="cx"> }
</span><span class="cx"> }
</span><ins>+
+ /// <summary>
+ /// Example using event socket in "Outbound" mode synchronic
+ /// </summary>
+ /// <param name="stateInfo">Object state info</param>
+ static void OutboundModeSync(Object stateInfo)
+ {
+ /* add next line to a dialplan
+ <action application="socket" data="localhost:8022 sync full"/>
+ */
+ TcpListener tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8022);
+
+ try
+ {
+ tcpListener.Start();
+
+ Console.WriteLine("OutboundModeSync, waiting for a connection...");
+
+ while (true)
+ {
+ Socket sckClient = tcpListener.AcceptSocket();
+
+ //Initializes a new instance of ESLconnection, and connects to the host $host on the port $port, and supplies $password to freeswitch
+ ESLconnection eslConnection = new ESLconnection(sckClient.Handle.ToInt32());
+
+ Console.WriteLine("Execute(\"answer\")");
+ eslConnection.Execute("answer", String.Empty, String.Empty);
+ Console.WriteLine("Execute(\"playback\")");
+ eslConnection.Execute("playback", "music/8000/suite-espanola-op-47-leyenda.wav", String.Empty);
+ Console.WriteLine("Execute(\"hangup\")");
+ eslConnection.Execute("hangup", String.Empty, String.Empty);
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex);
+ }
+ finally
+ {
+ tcpListener.Stop();
+ }
+ }
+
+ /// <summary>
+ /// Example using event socket in "Outbound" mode asynchronic
+ /// </summary>
+ /// <param name="stateInfo">Object state info</param>
+ static void OutboundModeAsync(Object stateInfo)
+ {
+ /* add next line to a dialplan
+ <action application="socket" data="localhost:8022 async full" />
+ */
+ TcpListener tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8022);
+
+ try
+ {
+ tcpListener.Start();
+
+ Console.WriteLine("OutboundModeAsync, waiting for connections...");
+
+ while (true)
+ {
+ tcpListener.BeginAcceptSocket((asyncCallback) =>
+ {
+ TcpListener tcpListened = (TcpListener)asyncCallback.AsyncState;
+
+ Socket sckClient = tcpListened.EndAcceptSocket(asyncCallback);
+
+ //Initializes a new instance of ESLconnection, and connects to the host $host on the port $port, and supplies $password to freeswitch
+ ESLconnection eslConnection = new ESLconnection(sckClient.Handle.ToInt32());
+
+ ESLevent eslEvent = eslConnection.GetInfo();
+ string strUuid = eslEvent.GetHeader("UNIQUE-ID");
+
+ eslConnection.SendRecv("myevents");
+ eslConnection.SendRecv("divert_events on");
+
+ eslConnection.Execute("answer", String.Empty, String.Empty);
+ eslConnection.Execute("playback", "music/8000/suite-espanola-op-47-leyenda.wav", String.Empty);
+
+ while (eslConnection.Connected() == ESL_SUCCESS)
+ {
+ eslEvent = eslConnection.RecvEvent();
+ Console.WriteLine(eslEvent.Serialize(String.Empty));
+ }
+
+ sckClient.Close();
+ Console.WriteLine("Connection closed uuid:{0}", strUuid);
+
+ }, tcpListener);
+
+ Thread.Sleep(50);
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex);
+ }
+ finally
+ {
+ tcpListener.Stop();
+ }
+ }
</ins><span class="cx"> }
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>