sipsorcery-mono /sipsorcery-core/SIPSorcery.Web.Services/CallManager/CallManagerPassThruService.cs

Language C# Lines 135
MD5 Hash 16d1185de2b5709fbff0e63002224964
Repository https://github.com/thecc4re/sipsorcery-mono.git View Raw File
  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
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading;
using SIPSorcery.SIP.App;
using SIPSorcery.Sys;
using log4net;

namespace SIPSorcery.Web.Services
{

    public class CallManagerPassThruService : ICallManagerServices
    {
        private const int OPERATION_TIMEOUT = 5000;

        private static ILog logger = AppState.logger;

        private CallManagerProxy m_callManagerClient;
        private ISIPCallDispatcher m_sipCallDispatcher;

        public CallManagerPassThruService()
        {
            m_callManagerClient = new CallManagerProxy();
        }

        public CallManagerPassThruService(ISIPCallDispatcher sipCallDispatcher)
        {
            m_sipCallDispatcher = sipCallDispatcher;
        }

        public bool IsAlive()
        {
            try
            {
                logger.Debug("CallManagerPassThruService IsAlive.");

                CallManagerProxy client = (m_sipCallDispatcher != null) ? m_sipCallDispatcher.GetCallManagerClient() : m_callManagerClient;

                if (client != null)
                {
                    logger.Debug("Sending isalive request to client endpoint at " + client.Endpoint.Address.ToString() + ".");
                    return client.IsAlive();
                }
                else
                {
                    throw new ApplicationException("Call Manager Pass Thru service could not create a client.");
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception CallManagerPassThruService IsAlive. " + excp.Message);
                return false;
            }
        }

        public string WebCallback(string username, string number)
        {
            try
            {
                logger.Debug("CallManagerPassThruService WebCallback, username=" + username + ", number=" + number + ".");

                CallManagerProxy client = (m_sipCallDispatcher != null) ? m_sipCallDispatcher.GetCallManagerClient() : m_callManagerClient;

                if (client != null)
                {
                    logger.Debug("Sending WebCallback request to client endpoint at " + client.Endpoint.Address.ToString() + ".");
                    return client.WebCallback(username, number);
                }
                else
                {
                    throw new ApplicationException("Call Manager Pass Thru service could not create a client.");
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception CallManagerPassThruService WebCallback. " + excp.Message);
                return "Sorry there was an unexpected error, the web callback was not initiated.";
            }
        }

        public string BlindTransfer(string username, string destination, string replacesCallID)
        {
            try
            {
                logger.Debug("CallManagerPassThruService BlindTransfer, username=" + username + ", destination=" + destination + ".");

                CallManagerProxy client = (m_sipCallDispatcher != null) ? m_sipCallDispatcher.GetCallManagerClient() : m_callManagerClient;

                if (client != null)
                {
                    logger.Debug("Sending BlindTransfer request to client endpoint at " + client.Endpoint.Address.ToString() + ".");
                    return client.BlindTransfer(username, destination, replacesCallID);
                }
                else
                {
                    throw new ApplicationException("Call Manager Pass Thru service could not create a client.");
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception CallManagerPassThruService BlindTransfer. " + excp.Message);
                return "Sorry there was an unexpected error, the blind transfer was not initiated.";
            }
        }

        public string DualTransfer(string username, string callID1, string callID2)
        {
            try
            {
                logger.Debug("CallManagerPassThruService DualTransfer, callID1=" + callID1 + ", callID2=" + callID2 + ".");

                CallManagerProxy client = (m_sipCallDispatcher != null) ? m_sipCallDispatcher.GetCallManagerClient() : m_callManagerClient;

                if (client != null)
                {
                    logger.Debug("Sending DualTransfer request to client endpoint at " + client.Endpoint.Address.ToString() + ".");
                    return client.DualTransfer(username, callID1, callID2);
                }
                else
                {
                    throw new ApplicationException("Call Manager Pass Thru service could not create a client.");
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception CallManagerPassThruService DualTransfer. " + excp.Message);
                return "Sorry there was an unexpected error, the dual transfer was not initiated.";
            }
        }
    }
}
Back to Top