예제 #1
0
        void telecomProvider_IncomingCall(object sender, CallEventArgs e)
        {
            UpdatePerformanceCounters();

            // Add a log entry
            LoggingService.AddLogEntry(LogLevel.Basic, "(Line " + e.LineNumber + ") Incoming call from " + e.CallerDisplayName + " " + e.CallerPhoneNumber + " to " + e.CallingToNumber + " " + e.CallingToMiscInfo, false);

            // Check to see if the service is supposed to be running and that we have a valid license.
            if (/*(LicenseService.IsLicensed() || LicenseService.IsTrialLicense() || Properties.Settings.Default.IsFreeVersion) &&*/ Properties.Settings.Default.ServiceEnabled)
            {
                TelecomScriptInterface tsInterface = tsInterfaces[e.LineNumber];

                // Populate our caller variables into the IML Interpreter so they can be used in our script
                tsInterface.IMLInterpreter.CallerDisplayName = e.CallerDisplayName;
                tsInterface.IMLInterpreter.CallerHost        = e.CallerMiscInfo;
                tsInterface.IMLInterpreter.CallerUsername    = e.CallerPhoneNumber;
                tsInterface.IMLInterpreter.DialedUsername    = e.CallingToNumber;
                tsInterface.IMLInterpreter.DialedHost        = e.CallingToMiscInfo;

                // Set the profile parameter of our tsInterface. This is usually the profile for the incoming call.
                //tsInterface.Profile = e.Tag;

                // Check to see if this caller is asking for a direct extension number
                WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow extension = null;
                tsInterface.Extension = null;
                int internalCallerExtension = 0;

                // Check to see if this is an internal caller
                if (registrarService != null)
                {
                    try
                    {
                        WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow internalExtensionRow = dataProvider.GetExtensionNumber(Properties.Settings.Default.CustomerID, Convert.ToInt32(e.CallerPhoneNumber));

                        if (internalExtensionRow != null)
                        {
                            tsInterface.Extension   = internalExtensionRow;
                            internalCallerExtension = internalExtensionRow.ExtensionNumber;

                            // Update our extension status

                            /*if (Properties.Settings.Default.EnableKinesisServer)
                             * {
                             *  tsInterface.UpdateExtensionCallStatus(CallStatus.Dialing);
                             * }*/
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                try
                {
                    int extensionNumber = Convert.ToInt32(e.CallingToNumber);
                    extension = dataProvider.GetExtensionNumber(Properties.Settings.Default.CustomerID, extensionNumber);
                }
                catch
                {
                }

                if (extension != null)
                {
                    // If this extension is calling itself, send it to the voicemail management script, otherwise send it to the extension.
                    if (e.CallerPhoneNumber == e.CallingToNumber)
                    {
                        // Start the voicemail processing script
                        tsInterface.ScriptProcessor = new VoicemailManagementScriptProcessor(extension, registrarService);

                        if (telecomProvider.IsLineInUse(e.LineNumber))
                        {
                            telecomProvider.AnswerCall(e.LineNumber, tsInterface.Extension == null ? false : true);
                        }
                    }
                    else
                    {
                        // Send the caller to the requested extension
                        if (telecomProvider.IsLineInUse(e.LineNumber))
                        {
                            telecomProvider.AnswerCall(e.LineNumber, tsInterface.Extension == null ? false : true);
                        }

                        TransferToExtension(extension.ExtensionNumber.ToString(), tsInterface, true);
                    }

                    return;
                }

                if (tsInterface.Extension != null)
                {
                    // If dialing "*", send the internal caller to the main menu
                    if (e.CallingToNumber == "*" || e.CallingToNumber.Trim() == "")
                    {
                    }
                    // This is an internal caller trying to make an outbound call
                    else if (Properties.Settings.Default.AllowOutboundDialing && e.CallingToNumber.StartsWith(Properties.Settings.Default.OutboundDialingPrefix))
                    {
                        if (MakeOutboundCall(tsInterface, e.CallingToNumber, e.CallerDisplayName, internalCallerExtension, true, false))
                        {
                            telecomProvider.AnswerCall(e.LineNumber, tsInterface.Extension == null ? false : true);

                            return;
                        }
                    }
                }

                // Should we be trying the receptionist first?
                if (Properties.Settings.Default.TryReceptionistFirst)
                {
                    WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow recepExtension = dataProvider.GetExtension(Properties.Settings.Default.CustomerID, Properties.Settings.Default.ReceptionistExtensionID);

                    if (recepExtension != null)
                    {
                        ReceptionistFinderScriptProcessor recepSp = new ReceptionistFinderScriptProcessor(recepExtension, this);
                        TransferToExtension(recepExtension.ExtensionNumber.ToString(), recepSp, tsInterface, true);
                        return;
                    }
                }

                ProcessAutoAttendantAnswer(e.LineNumber, tsInterface, true);
            }
        }