/*  public dynamic GetDialPlanXml(){
         * string dialplanxml = string.Empty;
         *
         *       try{
         *
         *           UDC.DialPlan dialPlanVariables = new UDC.DialPlan();
         *
         *           //outboundtypes
         *           //1-internal
         *           //2-national
         *           //3-international
         *           //4-no outbound
         *
         *           //internal
         *           if(this.AgentOutBoundType==1 && this.DialNumberType ==1){
         *               //agent able to make internal calls only no national and international
         *               dialPlanVariables.Mode = 1;
         *               dialPlanVariables.DestinationNumber = DialPlanParameters.DestinationNumber;
         *               dialPlanVariables.ExtensionName = "Extension_internal_" + DialPlanParameters.CallerIdNumber;
         *               dialPlanVariables.GatewayName = "user";
         *               dialPlanVariables.UserContext = "public";
         *               dialplanxml = GetDialplanXml(dialPlanVariables);
         *               //dialplanxml = bridgeXml(DialPlanParameters.DestinationNumber,"Extension_internal_"+DialPlanParameters.CallerIdNumber,"user","public");
         *           }
         *           else if (this.AgentOutBoundType == 2 &&(this.DialNumberType ==1 || this.DialNumberType==2))
         *           {
         *               //agent have national access so he can call to internal as wel national calls
         *               dialPlanVariables.Mode = 1;
         *               dialPlanVariables.DestinationNumber = DialPlanParameters.DestinationNumber;
         *               dialPlanVariables.ExtensionName = "Extension_national_internal" + DialPlanParameters.CallerIdNumber;
         *               dialPlanVariables.GatewayName = "user";
         *               dialPlanVariables.UserContext = "public";
         *               dialplanxml = GetDialplanXml(dialPlanVariables);
         *               //dialplanxml = bridgeXml(DialPlanParameters.DestinationNumber, "Extension_national_internal" + DialPlanParameters.CallerIdNumber, "user", "public");
         *
         *           }else if (this.AgentOutBoundType ==3 && (this.DialNumberType==1 || this.DialNumberType==2 || this.DialNumberType ==3)){
         *               //agent have international access so he can call to internal and national and international numbers
         *               dialPlanVariables.Mode = 1;
         *               dialPlanVariables.DestinationNumber = DialPlanParameters.DestinationNumber;
         *               dialPlanVariables.ExtensionName = "Extension_international" + DialPlanParameters.CallerIdNumber;
         *               dialPlanVariables.GatewayName = "user";
         *               dialPlanVariables.UserContext = "public";
         *               dialplanxml = GetDialplanXml(dialPlanVariables);
         *               //dialplanxml = bridgeXml(DialPlanParameters.DestinationNumber, "Extension_international" + DialPlanParameters.CallerIdNumber, "user", "public");
         *
         *           }
         *           else{
         *
         *               if(this.AgentOutBoundType ==1 &&(this.DialNumberType == 2 || this.DialNumberType == 3)){
         *                   //agent have internal acces but he made national or international calls play that clip
         *                   dialPlanVariables.Mode = 2;
         *                   dialPlanVariables.DestinationNumber = DialPlanParameters.DestinationNumber;
         *                   dialPlanVariables.ExtensionName = "Extension_" + DialPlanParameters.DestinationNumber;
         *                   dialPlanVariables.UserContext = "public";
         *                   dialPlanVariables.PlayFile = "http://agent have internal acces but he made national or international calls play that clip.mp3";
         *                   dialplanxml = GetDialplanXml(dialPlanVariables);
         *                   //dialplanxml = noOutBOundXml("http://agent have internal acces but he made national or international calls play that clip.mp3", "public", "Extension_" + DialPlanParameters.DestinationNumber, DialPlanParameters.DestinationNumber);
         *
         *
         *               }else if(this.AgentOutBoundType ==2 &&(this.DialNumberType == 3)){
         *                   //agent have national acces but he made an international call
         *                   dialPlanVariables.Mode = 2;
         *                   dialPlanVariables.DestinationNumber = DialPlanParameters.DestinationNumber;
         *                   dialPlanVariables.ExtensionName = "Extension_" + DialPlanParameters.DestinationNumber;
         *                   dialPlanVariables.UserContext = "public";
         *                   dialPlanVariables.PlayFile = "http://agent have national acces but he made an international call.mp3";
         *                   dialplanxml = GetDialplanXml(dialPlanVariables);
         *                   //dialplanxml = noOutBOundXml("http://agent have national acces but he made an international call.mp3", "public", "Extension_" + DialPlanParameters.DestinationNumber, DialPlanParameters.DestinationNumber);
         *               }
         *
         *
         *            //agent does not have any acces so we are playing a file
         *               //String playFile,string userContext,string extensionName,string application,string destinationNumber
         *              // dialplanxml = noOutBOundXml("play file",DialPlanParameters.VarUserContext,"Extension_"+DialPlanParameters.CallerIdNumber,"playback",DialPlanParameters.DestinationNumber);
         *           }
         *
         *         }catch(Exception e){
         *             Logger.Error("Exception while getting DialPlan Xml:"+e.ToString());
         *         }
         *
         *       return dialplanxml;
         *   }*/

        public string GetDialplanXml(UDC.DialPlan dialPlanVariableObj)
        {
            string responseXml = "";

            try
            {
                Press3.DataAccessLayer.SipPhoneRegistration sipObj = new Press3.DataAccessLayer.SipPhoneRegistration(AppConfig.ConnectionString);
                DataSet ds = new DataSet();
                ds = sipObj.GetDialplanXml(dialPlanVariableObj);
                if (ds != null)
                {
                    if (ds.Tables.Count > 0)
                    {
                        if (Convert.ToBoolean(ds.Tables[0].Rows[0]["Success"]))
                        {
                            responseXml = ds.Tables[0].Rows[0]["DialPlanXML"].ToString();
                        }
                    }
                }
                Logger.Info("Response xml in GetDialplanxml:" + responseXml);
            }catch (Exception e) {
                Logger.Error("Exception in GetDialPlanXml:" + e.ToString());
            }

            return(responseXml);
        }
Exemple #2
0
 public DataSet GetDialplanXml(UDC.DialPlan dialPlanVarObj)
 {
     _cmd = new SqlCommand();
     _ds  = new DataSet();
     _da  = new SqlDataAdapter();
     try
     {
         _cmd.CommandText = "GetDialplanXml";
         _cmd.CommandType = CommandType.StoredProcedure;
         _cmd.Connection  = Connection;
         _cmd.Parameters.Add("@Mode", SqlDbType.Int).Value = dialPlanVarObj.Mode;
         _cmd.Parameters.Add("@DestinationNumber", SqlDbType.VarChar, 20).Value = dialPlanVarObj.DestinationNumber;
         _cmd.Parameters.Add("@ExtensionName", SqlDbType.VarChar, 100).Value    = dialPlanVarObj.ExtensionName;
         _cmd.Parameters.Add("@GatewayName", SqlDbType.VarChar, 100).Value      = dialPlanVarObj.GatewayName;
         _cmd.Parameters.Add("@UserContext", SqlDbType.VarChar, 100).Value      = dialPlanVarObj.UserContext;
         _cmd.Parameters.Add("@PlayFile", SqlDbType.VarChar, 500).Value         = dialPlanVarObj.PlayFile;
         _cmd.Parameters.Add("@IsInBound", SqlDbType.Bit).Value               = dialPlanVarObj.IsInBound;
         _cmd.Parameters.Add("@TransFrom", SqlDbType.VarChar, 500).Value      = dialPlanVarObj.TransferFromNumber;
         _cmd.Parameters.Add("@TransTo", SqlDbType.VarChar, 500).Value        = dialPlanVarObj.TransferToNumber;
         _cmd.Parameters.Add("@DialPlanXML", SqlDbType.VarChar, -1).Direction = ParameterDirection.Output;
         _cmd.Parameters.Add("@Message", SqlDbType.VarChar, 500).Direction    = ParameterDirection.Output;
         _cmd.Parameters.Add("@Success", SqlDbType.Bit).Direction             = ParameterDirection.Output;
         Connection.Open();
         _cmd.ExecuteNonQuery();
         Connection.Close();
         _ds.Tables.Add(_helper.ConvertOutputParametersToDataTable(_cmd.Parameters));
     }
     catch (Exception ex)
     {
         Logger.Error("Exception in DAl GetDialPlanXml:" + ex.ToString());
     }
     finally
     {
         _cmd = null;
         _da  = null;
         Connection.Close();
     }
     return(_ds);
 }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string isSave = AppConfig.GetApplicationKey("SaveFreeSwitchRequest");

                if (isSave == "1")
                {
                    if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/FreeSwitchRequest/")))
                    {
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/FreeSwitchRequest/"));
                        Logger.Info("Freeswitch requsts directory created in dial plan section.");
                    }


                    string path = HttpContext.Current.Server.MapPath("~/FreeSwitchRequest/") + System.DateTime.Now.ToString("yyyyMMddHHmmss");
                    HttpContext.Current.Request.SaveAs(path + ".txt", true);
                    Logger.Debug("Freeswitch dialplan  Request is saved in " + path);
                }

                Press3.BusinessRulesLayer.CurlDialPlan DialPlanObject = new Press3.BusinessRulesLayer.CurlDialPlan(context);
                UDC.DialPlan dialPlanVariables = new UDC.DialPlan();

                if (DialPlanObject.CallerId == 1)
                {
                    dialPlanVariables.Mode = 3;
                    dialPlanVariables.DestinationNumber = DialPlanObject.DestinationNumber;
                    dialPlanVariables.ExtensionName     = "Extension_All_inbound";
                    dialPlanVariables.IsInBound         = true;
                    dialplanxml = DialPlanObject.GetDialplanXml(dialPlanVariables);
                    //dialplanxml=  DialPlanObject.SocketXml("Extension_All_inbound",true);
                    Logger.Debug("Incoming call to Press3 Studio so socket Xml:" + dialplanxml);
                }
                else if (!DialPlanObject.IsAgentDial && !String.IsNullOrEmpty(DialPlanObject.TransferFrom) && !String.IsNullOrEmpty(DialPlanObject.TransferTo))
                {
                    dialPlanVariables.Mode               = 5;
                    dialPlanVariables.ExtensionName      = "Extension_Agent_Transfer";
                    dialPlanVariables.DestinationNumber  = DialPlanObject.DestinationNumber;
                    dialPlanVariables.TransferFromNumber = DialPlanObject.TransferFrom;
                    dialPlanVariables.TransferToNumber   = DialPlanObject.TransferTo;
                    dialPlanVariables.UserContext        = DialPlanObject.UserContext;
                    dialPlanVariables.IsInBound          = false;
                    dialplanxml = DialPlanObject.GetDialplanXml(dialPlanVariables);
                    Logger.Debug("Reached to Transfer functionality" + dialplanxml);
                }

                else if (!DialPlanObject.IsAgentDial)
                {
                    dialPlanVariables.Mode              = 3;
                    dialPlanVariables.ExtensionName     = "Extension_Agent_dial";
                    dialPlanVariables.DestinationNumber = DialPlanObject.DestinationNumber;
                    dialPlanVariables.IsInBound         = false;
                    dialplanxml = DialPlanObject.GetDialplanXml(dialPlanVariables);

                    //dialplanxml = DialPlanObject.SocketXml("Extension_Agent_dial",false);
                    Logger.Debug("It is not press3 studio call so that we are navigating to socket with agent dial page:" + dialplanxml);
                }


                else if (DialPlanObject.IsAgentDial && DialPlanObject.CurlCallEvent.Equals("newcall"))
                {
                    dialplanxml = DialPlanObject.ResponseXml();
                    Logger.Debug("Reached to AgentDial bridging xml:" + dialplanxml);
                }
                //else if(DialPlanObject.IsAgentDial && DialPlanObject.CurlCallEvent.Equals("dial")){
                //    // we are updating event dial parameters all event params willpost to this url
                //   responseJobj= DialPlanObject.UpdateDial();
                //   if (responseJobj.SelectToken("Success").ToString() == "True")
                //   {

                //       dialplanxml = "<Response><Hangup reason='Dial Details Updated Successfully'/></Response>";
                //     //  context.Response.Write("<Response>Dial Details Updated Successfully</Response>");
                //   }
                //   else
                //   {
                //       dialplanxml = "<Response><Hangup reason='Dail Details Updation Failed'/></Response>";
                //     //  context.Response.Write("<Response>Dail Details Updation Failed</Response>");

                //   }
                //}
                else
                {
                    dialPlanVariables.Mode              = 4;
                    dialPlanVariables.ExtensionName     = "Extension_All_inbound_xml";
                    dialPlanVariables.DestinationNumber = DialPlanObject.DestinationNumber;
                    dialPlanVariables.IsInBound         = false;
                    dialplanxml = DialPlanObject.GetDialplanXml(dialPlanVariables);
                    Logger.Info("Send default Socket Xml for if serveris in smscountry production.");
                }

                if (String.IsNullOrEmpty(dialplanxml))
                {
                    dialplanxml = "<Response><Hangup reason='No Xml Action Found'/></Response>";
                }
                //else if (DialPlanObject.IsAgentDial && DialPlanObject.CurlCallEvent.Equals("newcall") && !String.IsNullOrEmpty(DialPlanObject.TransferFrom) && !String.IsNullOrEmpty(DialPlanObject.TransferTo))
                //{
                //    SendXmlResponse(context, dialplanxml, true);
                //}
                else if (DialPlanObject.CurlCallEvent != null && DialPlanObject.CurlCallEvent.Equals("newcall") && DialPlanObject.IsAgentDial)
                {
                    SendXmlResponse(context, dialplanxml, false);
                }
                else
                {
                    SendXmlResponse(context, dialplanxml, true);
                }

                Logger.Info("Curl Dial plan details updated ---" + dialplanxml);
            }
            catch (Exception e)
            {
                Logger.Error("Exception in dialplan Handler:" + e.ToString());
            }
        }