Advertisement
Guest User

Untitled

a guest
May 19th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using MySql.Data.MySqlClient;
  4. using FreeSWITCH.Native;
  5.  
  6. namespace FreeSWITCH.Managed.DP_Fxmx
  7. {
  8.     public class DP_Fxmx : IAppPlugin
  9.     {
  10.         public void Run(AppContext context)
  11.         {
  12.             context.Session.HangupFunction = () => HandleHangup();
  13.             context.Session.Answer();
  14.            
  15.             IDbConnection dbcon = dbConnect(context.Session);
  16.             if( dbcon.State != ConnectionState.Open )
  17.                 return;
  18.            
  19.             int ret;
  20.             do {
  21.                 ret = processStep(dbcon, context.Session);
  22.             } while( ret == 1 );
  23.            
  24.             dbcon.Close();
  25.            
  26.             return;
  27.         }
  28.        
  29.         public int processStep(IDbConnection dbcon, ManagedSession session)
  30.         {
  31.             /* Simply read the 'command' from our DB table, and process it appropriately. */
  32.             session.PlayAndGetDigits(1, 4, 3, 20, "#", "ivr/ivr-welcome_to_freeswitch.wav", "", "", "test");
  33.             return -1;
  34.         }
  35.        
  36.         public void HandleHangup()
  37.         {
  38.             Log.WriteLine(LogLevel.Info, "Client hung up.");
  39.         }
  40.        
  41.         public IDbConnection dbConnect(ManagedSession session)
  42.         {
  43.             IDbConnection dbcon;
  44.  
  45.             string dbType = session.GetVariable("db_type");
  46.             string dbUser = session.GetVariable("db_username");
  47.             string dbPass = session.GetVariable("db_password");
  48.             string dbHost = session.GetVariable("db_hostname");
  49.             string dbBase = session.GetVariable("db_database");
  50.             string dbPort = session.GetVariable("db_port");
  51.            
  52.             if( dbType != "mysql" )
  53.             {
  54.                 Log.WriteLine(LogLevel.Error, "Currently, only MySQL is supported.");
  55.                 return null;
  56.             }
  57.            
  58.             string connectionString =
  59.                 "Server="+dbHost+";" +
  60.                 "Port="+dbPort+";" +
  61.                 "Database="+dbBase+";" +
  62.                 "User ID="+dbUser+";" +
  63.                 "Password="+dbPass+";" +
  64.                 "Pooling=true";
  65.            
  66.             dbcon = new MySqlConnection(connectionString);
  67.            
  68.             dbcon.Open();
  69.  
  70.             if( dbcon.State != ConnectionState.Open )
  71.             {
  72.                 Log.WriteLine(LogLevel.Error,"Failed to open database.");
  73.                 return dbcon;
  74.             }
  75.            
  76.             return dbcon;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement