Advertisement
Guest User

Untitled

a guest
Oct 30th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 117.80 KB | None | 0 0
  1. using Asterisk.NET.FastAGI;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Goldnet.IVR.ResellerPanelService;
  8. using Goldnet.IVR.ServiceReference1;
  9.  
  10. using Goldnet.Crm.Data;
  11. using System.Configuration;
  12. using Asterisk.NET.Manager;
  13. using Asterisk.NET.Manager.Action;
  14. using Asterisk.NET.Manager.Response;
  15. using System.Xml.Linq;
  16. using System.Timers;
  17. using System.Threading;
  18. using System.Data.Entity.Validation;
  19. using System.Diagnostics;
  20. using Asterisk.NET.Manager.Event;
  21. using System.Net;
  22. using System.IO;
  23. using System.Data.Entity.SqlServer;
  24.  
  25. namespace Goldnet.IVR
  26. {
  27.     public class GoldnetDemo : AGIScript
  28.     {
  29.         public static string ResellerId = "";
  30.         public static string callerId = "1";
  31.         public override void Service(AGIRequest request, AGIChannel channel)
  32.         {
  33.             Console.WriteLine("test : " + request);
  34.             #region Variables
  35.             var db = new GoldnetEntities();
  36.             int maxLine = 0;
  37.             Boolean QueueIsFull = false;
  38.             int priority = 0;
  39.             string QuOption = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSayAgentName"]) ? ",,,,queue.py" : "";
  40.             char key = ' ';
  41.             int counterPlaySound = 0;
  42.             bool rpeatSound = true;
  43.             bool MainIvr = false;
  44.             string SipName = "";
  45.             string TariffName = "";
  46.             double timeout = Convert.ToDouble(ConfigurationManager.AppSettings["ResellerService.TimeOut"]);
  47.             string CardNumber = ConfigurationManager.AppSettings["CardNumber"];
  48.             var identifier = request.UniqueId;
  49.             var data = "";
  50.             string ChargResult = "0";
  51.             int InsertId = 0;
  52.             int smsresult = -1;
  53.             var ivrc = new IVRServices.ServiceClient();
  54.             string ServiceId = "", mobileNumber = "";
  55.             string serviceName = "3 گیگ ترافیک مازاد";
  56.             long PriceLong = 0;
  57.             bool RepeatMainMenu = false;
  58.             var Payic = new SimulateParsianPaymentService.PaymentServiceSoapClient();
  59.  
  60.  
  61.             if (!string.IsNullOrEmpty(request.CallerId))
  62.                 callerId = request.CallerId;
  63.             Console.WriteLine("callerId : " + callerId);
  64.             //PriceLong = 120000;
  65.             //if (callerId == "09360769982")
  66.             //{
  67.             //    callerId = "5136634861";
  68.             //    PriceLong = 10000;
  69.             //}
  70.             #endregion
  71.  
  72.  
  73.             if (callerId.StartsWith("0"))
  74.                 callerId = callerId.TrimStart("0".ToCharArray());
  75.             if (callerId.Length > 10)
  76.                 callerId = callerId.Substring(callerId.Length - 10, 10);
  77.             IvrCallState callState = null;
  78.             try
  79.             {
  80.                 callState = db.IvrCallStates.FirstOrDefault(p => p.callId == request.UniqueId);
  81.             }
  82.             catch (Exception ex)
  83.             {
  84.                 this.log(identifier, IvrLogTypes.Error, ex.Message);
  85.             }
  86.  
  87.             //مدیریت تماس خروجی
  88.             var Sipresult = db.IvrSipFriends.Where(o => o.name == request.CallerId || o.name == request.Extension).FirstOrDefault();
  89.  
  90.             if (Sipresult != null)
  91.             {
  92.                 //در صورتی که تماس از داخل باشد. مثلا 300 به *01 زنگ بزند
  93.                 if (request.Extension.Substring(0, 1) == "*")
  94.                 {
  95.                     IvrDialPlan ivrDialPlan1 = null;
  96.                     string DialNumber = "";
  97.                     ivrDialPlan1 = db.IvrDialPlans.FirstOrDefault(p => p.Title == "StarIVR" && p.ParentId == 0 && p.KeyOfDialPlan == request.Extension);
  98.                     if (ivrDialPlan1 != null)
  99.                     {
  100.                         DialNumber = ivrDialPlan1.ValueOfKey;
  101.                         //ترانک خروجی که از جدول میخونه مثلا
  102.                         //cisco/#8809155019953
  103.                         Exec("Dial", "SIP/" + DialNumber + ",45,tr");
  104.                         var dialstatus = GetVariable("DIALSTATUS");
  105.                         Console.WriteLine("DialStatus : " + dialstatus);
  106.                     }
  107.                 }
  108.                 //در صورتی که تماس از داخل باشد. به بیرون از شرکت ، با داخلی 9 برای تماس بیرون
  109.                 if (request.Extension.Substring(0, 1) == "9" && request.Extension.Length > 3)
  110.                 {
  111.                     //تیم شبکه باید درست کنه این رو. ترانک خروجی
  112.                     //cisco/#8809155019953
  113.                     Exec("Dial", "SIP/cisco/#88" + request.Extension.Substring(1, request.Extension.Length - 1) + ",45,tr");
  114.                     var dialstatus = GetVariable("DIALSTATUS");
  115.                     Console.WriteLine("DialStatus : " + dialstatus);
  116.                 }
  117.                 else
  118.                 {
  119.                     //برای تماسی که از بیرون می آید و صف هم دارد ، مثلا 14 صف دارد
  120.                     //صف برای بعضی از شماره ها ، نیستانی ، سعادتمند
  121.                     callState.AgentId = request.Extension; // just for GoldnetIvr because there is no queue
  122.                     db.SaveChanges();
  123.                     var QueueOfSip = db.IvrQueueMembers.Where(o => o.membername == request.Extension).Select(o => o.queue_name).FirstOrDefault();
  124.                     if (QueueOfSip != null)
  125.                     {
  126.                         maxLine = db.IvrQueues.Where(o => o.name == QueueOfSip).Select(o => o.queue_member_count).FirstOrDefault();
  127.                         var InQueueCount = db.IvrCallStates.Where(p => (new string[] { "RINGNOANSWER", "ENTERQUEUE" }).Contains(p.status) && p.cdrid == null && p.queue == QueueOfSip && SqlFunctions.DateDiff("mi", p.timestamp, DateTime.Now) < 60).Count();
  128.                         if (maxLine <= InQueueCount)
  129.                         {
  130.                             callState.status = "QueueIsFull";
  131.                             QueueIsFull = true;
  132.                             StreamFile("fa_BusySip");
  133.                             StreamFile("fa_PleaseCallAgain");
  134.                         }
  135.                         else
  136.                         {
  137.                             bool q = this.queue(QueueOfSip, identifier, priority, false, QuOption);
  138.                         }
  139.                     }
  140.                     else
  141.                     {
  142.                         //برای تماسی که از بیرون می آید و صف هم نداریم ، مثلا 300 صف ندارد
  143.                         string dialledNum = "";
  144.                         dialledNum = request.Extension;
  145.  
  146.                         Console.Write("Dial + SIP/" + dialledNum + ",45,tr");
  147.                         Exec("Dial", "SIP/" + dialledNum + ",45,tr");
  148.                         var dialstatus = GetVariable("DIALSTATUS");
  149.                         Console.WriteLine("DialStatus : " + dialstatus);
  150.                         if (dialstatus == "CHANUNAVAIL" && dialstatus == "BUSY")
  151.                         {
  152.                             StreamFile("fa_BusySip");
  153.                             StreamFile("fa_PleaseCallAgain");
  154.                             //go to 14 !
  155.                             //Exec("Dial", "SIP/14,45,tr");
  156.                         }
  157.                         if (dialstatus == "NOANSWER")
  158.                         {
  159.                             StreamFile("fa_NoAnswerSip");
  160.                             StreamFile("fa_PleaseCallAgain");
  161.                         }
  162.  
  163.                     }
  164.                 }
  165.             }
  166.             else
  167.             {
  168.                 //اگر تماس از بیرون داشتیم ، توی این قسمت می رود
  169.                 //LoadConfigConnection();
  170.                 #region Answer
  171.                 try
  172.                 {
  173.                     Answer();
  174.  
  175.                     this.log(identifier, IvrLogTypes.Answer, request.CallerId);
  176.                 }
  177.                 catch (Exception ex)
  178.                 {
  179.                     this.log(identifier, IvrLogTypes.Error, ex.ToString());
  180.                     if (ex.ToString().Contains("Channel was hung up"))
  181.                     {
  182.                         callState.Comment = "Channel was hung up";
  183.                         callState.status = "HangUp";
  184.                         db.SaveChanges();
  185.                         return;
  186.                     }
  187.                 }
  188.  
  189.                 #endregion
  190.                 #region comment1
  191.                 //try
  192.                 //{
  193.  
  194.                 //    Thread t = new Thread(DoSomething);
  195.                 //    t.Start();
  196.                 //    if (!t.Join(TimeSpan.FromSeconds(timeout)))
  197.                 //    {
  198.                 //        t.Abort();
  199.                 //        Console.WriteLine("CallerId For Test :" + callerId + " ResellerId : " + ResellerId);
  200.                 //    }
  201.                 //}
  202.                 //catch (Exception ex)
  203.                 //{
  204.                 //    this.log(identifier, IvrLogTypes.Developer, ex.Message);
  205.                 //}
  206.                 //// ResellerId = "99999";
  207.                 //Console.WriteLine("RessellerId : " + ResellerId);
  208.                 //if (ResellerId != "" && ResellerId != null)
  209.                 //{
  210.                 //    #region Reseller
  211.                 //    try
  212.                 //    {
  213.                 //        data = GetData("fa_welcomes", 500, 3);
  214.                 //        while (counterPlaySound < 3 && rpeatSound)
  215.                 //        {
  216.                 //            data = GetData("fa_EnterTel", 5000, 10);
  217.                 //            Console.WriteLine("CustomerTelNumber :::: " + data);
  218.                 //            counterPlaySound++;
  219.  
  220.                 //            if (data.Length == 10)
  221.                 //            {
  222.                 //                string CustomerTelNumber = "";
  223.                 //                CustomerTelNumber = data;
  224.                 //                data = GetData("fa_TelNumberIs", 5000, 1);
  225.                 //                for (int i = 0; i < CustomerTelNumber.Length; i = i + 2)
  226.                 //                {
  227.                 //                    string number = CustomerTelNumber.Substring(i, 2);
  228.                 //                    key = CommonScript.SayTwoDigitNumber(this, number, true);
  229.                 //                }
  230.                 //                data = GetData("fa_IsAcceptTelNumber", 5000, 10);
  231.                 //                if (data == "1")
  232.                 //                {
  233.                 //                    rpeatSound = false;
  234.                 //                    Console.WriteLine("CustomerTelNumber :" + CustomerTelNumber);
  235.  
  236.                 //                    ServiceWrappers.ServiceResponse UserInfo = partner.GetUserInfoViaCustomer(CustomerTelNumber);
  237.                 //                    ServiceWrappers.UserInfo returnObject = (ServiceWrappers.UserInfo)UserInfo.ReturnedObject;
  238.                 //                    if (returnObject != null && returnObject.RemainingTraffic > 0)
  239.                 //                    {
  240.                 //                        data = GetData("fa_Volume", 1000, 1);
  241.  
  242.                 //                        int reservedTraffic = Convert.ToInt32(returnObject.ReservedTraffic * 1024);
  243.                 //                        Console.WriteLine("reservedTraffic :" + reservedTraffic);
  244.                 //                        int MegTraffic = Convert.ToInt32(returnObject.RemainingTraffic * 1024) + reservedTraffic;
  245.                 //                        string remainingTraffic = MegTraffic.ToString();
  246.                 //                        Console.WriteLine("remainingTraffic :" + remainingTraffic);
  247.                 //                        switch (remainingTraffic.Length)
  248.                 //                        {
  249.                 //                            case 1:
  250.                 //                                key = CommonScript.SayOneDigitNumber(this, remainingTraffic, false);
  251.                 //                                break;
  252.                 //                            case 2:
  253.                 //                                key = CommonScript.SayTwoDigitNumber(this, remainingTraffic, false);
  254.                 //                                break;
  255.                 //                            case 3:
  256.                 //                                key = CommonScript.SayThreeDigitNumber(this, remainingTraffic, false);
  257.                 //                                break;
  258.                 //                            case 4:
  259.                 //                                key = CommonScript.SayFourDigitNumber(this, remainingTraffic, false);
  260.                 //                                break;
  261.                 //                            case 5:
  262.                 //                                key = CommonScript.SayFiveDigitNumber(this, remainingTraffic, false);
  263.                 //                                break;
  264.                 //                            case 6:
  265.                 //                                key = CommonScript.SaySixDigitNumber(this, remainingTraffic, false);
  266.                 //                                break;
  267.                 //                            default:
  268.                 //                                break;
  269.                 //                        }
  270.  
  271.                 //                        data = GetData("fa_Meg", 1000, 1);
  272.                 //                    }
  273.  
  274.  
  275.                 //                    data = GetData("fa_WantToCharge_Reseller", 5000, 1);
  276.                 //                    if (data == "1") // Customer Want To Charge
  277.                 //                    {
  278.                 //                        data = GetData("fa_Gig", 5000, 1);
  279.                 //                        switch (data)
  280.                 //                        {
  281.                 //                            case "1":
  282.                 //                                TariffName = "1 گیگ ترافیک مازاد";
  283.                 //                                break;
  284.                 //                            case "2":
  285.                 //                                TariffName = "2 گیگ ترافیک مازاد";
  286.                 //                                break;
  287.                 //                            case "3":
  288.                 //                                TariffName = "5 گیگ ترافیک مازاد";
  289.                 //                                break;
  290.                 //                            case "4":
  291.                 //                                TariffName = "10 گیگ ترافیک مازاد";
  292.                 //                                break;
  293.                 //                            default:
  294.                 //                                break;
  295.                 //                        }
  296.  
  297.                 //                        var chargeResult = partner.ChargeCustomer(CustomerTelNumber, ResellerId, TariffName);
  298.                 //                        IvrResellerCharge qm = new IvrResellerCharge
  299.                 //                        {
  300.                 //                            CustomerTel = CustomerTelNumber,
  301.                 //                            ResellerId = Convert.ToInt32(ResellerId),
  302.                 //                            TrafficName = TariffName,
  303.                 //                            Chargeresult = Convert.ToInt32(chargeResult.Code.ToString()),
  304.                 //                            chargeDate = DateTime.Now
  305.                 //                        };
  306.  
  307.                 //                        db.IvrResellerCharges.Add(qm);
  308.                 //                        db.SaveChanges();
  309.  
  310.                 //                        if (chargeResult.Code.ToString() == "1")
  311.                 //                        {
  312.                 //                            Console.WriteLine("Successful Charge" + chargeResult.Code);
  313.                 //                            data = GetData("digits/Successful", 500, 1);
  314.                 //                            Console.WriteLine("Successs in Reseller");
  315.                 //                            //SendSMS();
  316.                 //                        }
  317.                 //                        else
  318.                 //                        {
  319.                 //                            Console.WriteLine("UnSuccessful Charge" + chargeResult.Code);
  320.                 //                            data = GetData("fa_unsuccess", 500, 1);
  321.                 //                        }
  322.  
  323.                 //                    }
  324.  
  325.                 //                }
  326.                 //            }
  327.                 //            else if (data == "9")
  328.                 //            {
  329.                 //                MainIvr = true;
  330.                 //                counterPlaySound = 3;
  331.                 //            }
  332.                 //            else
  333.                 //                data = GetData("fa_IncorrectTelNum", 1000, 1);
  334.                 //        }
  335.                 //    }
  336.                 //    catch (Exception ex)
  337.                 //    {
  338.                 //        this.log(identifier, IvrLogTypes.Developer, ex.Message);
  339.                 //    }
  340.                 //    #endregion
  341.                 //}
  342.                 //else
  343.                 //    MainIvr = true;
  344.                 #endregion
  345.  
  346.                 MainIvr = true;
  347.                 RepeatMainMenu = true;
  348.                 int counterCall = 1;
  349.                 while (MainIvr && RepeatMainMenu)
  350.                 {
  351.                     #region Custommer
  352.                     try
  353.                     {
  354.                         bool CustomerCharge = false;
  355.                         Console.WriteLine("In Main Ivr");
  356.                         data = GetData("fa_MainIVR", 3000, 4);
  357.                         string EnteredKey = data;
  358.                         IvrDialPlan ivrDialPlan = null;
  359.                         RepeatMainMenu = false;
  360.                         if (EnteredKey != "")
  361.                         {
  362.                             ivrDialPlan = db.IvrDialPlans.FirstOrDefault(p => p.Title == "MainIVR" && p.ParentId == 0 && p.KeyOfDialPlan == EnteredKey);
  363.                             if (ivrDialPlan != null)
  364.                                 SipName = ivrDialPlan.ValueOfKey;
  365.                             else
  366.                                 SipName = data;
  367.                             string PressKey = "";
  368.                             if (SipName == "Commerce")
  369.                             {
  370.                                 data = GetData("fa_CommerceMenu", 3000, 1);
  371.                                 PressKey = data;
  372.                             }
  373.                             if (SipName == "Support")
  374.                             {
  375.                                 data = GetData("fa_SupportMenu", 3000, 1);
  376.                                 PressKey = data;
  377.                             }
  378.                             if (PressKey != "")
  379.                             {
  380.                                 var dialdata = db.IvrDialPlans.FirstOrDefault(p => p.Title == "MainIVR" && p.ParentId == ivrDialPlan.Id && p.KeyOfDialPlan == PressKey);
  381.                                 if (dialdata != null)
  382.                                     SipName = dialdata.ValueOfKey;
  383.                             }
  384.                             if (SipName == "Fax")
  385.                             {
  386.                                 Exec("Dial", "IAX2/1001,,tr");
  387.                                 var dialstatus = GetVariable("DIALSTATUS");
  388.                                 Console.WriteLine("DialStatus : " + dialstatus);
  389.                                 var channelstatus = GetChannelStatus();
  390.                                 Console.WriteLine("Channelstatus : " + channelstatus);
  391.  
  392.                             }
  393.                             else if (SipName == "CustomerCharge")
  394.                             {
  395.                                 CustomerCharge = true;
  396.                                 Console.WriteLine("CustomerCharge is true");
  397.                             }
  398.                             else if (SipName.Substring(0, 2) != "99")
  399.                             {
  400.                                 Console.WriteLine("Dial To " + SipName);
  401.                                 callState.AgentId = SipName; // just for GoldnetIvr because the is no queue
  402.                                 db.SaveChanges();
  403.                                 var QueueOfSip = db.IvrQueueMembers.Where(o => o.membername == SipName).Select(o => o.queue_name).FirstOrDefault();
  404.                                 maxLine = db.IvrQueues.Where(o => o.name == QueueOfSip).Select(o => o.queue_member_count).FirstOrDefault();
  405.                                 Console.WriteLine("Name Of Queue :" + QueueOfSip + " &MaxLine : " + maxLine);
  406.                                 var InQueueCount = db.IvrCallStates.Where(p => (new string[] { "RINGNOANSWER", "ENTERQUEUE" }).Contains(p.status) && p.cdrid == null && p.queue == QueueOfSip && SqlFunctions.DateDiff("mi", p.timestamp, DateTime.Now) < 60).Count();
  407.                                 if (QueueOfSip != null)
  408.                                 {
  409.                                     if (maxLine <= InQueueCount)
  410.                                     {
  411.                                         callState.status = "QueueIsFull";
  412.                                         QueueIsFull = true;
  413.                                         StreamFile("fa_BusySip");
  414.                                         StreamFile("fa_PleaseCallAgain");
  415.                                     }
  416.                                     else
  417.                                     {
  418.                                         bool q = this.queue(QueueOfSip, identifier, priority, false, QuOption);
  419.                                     }
  420.                                 }
  421.                                 else
  422.                                 {
  423.  
  424.                                     Exec("Dial", "SIP/" + SipName + ",30,tr");
  425.                                     var dialstatus = GetVariable("DIALSTATUS");
  426.                                     Console.WriteLine("DialStatus : " + dialstatus);
  427.                                     if (dialstatus == "CHANUNAVAIL" && dialstatus == "BUSY")
  428.                                     {
  429.                                         StreamFile("fa_BusySip");
  430.                                         if (counterCall < 2)
  431.                                         {
  432.                                             RepeatMainMenu = true;
  433.                                             counterCall++;
  434.                                         }
  435.                                         StreamFile("fa_PleaseCallAgain");
  436.                                     }
  437.                                     if (dialstatus == "NOANSWER")
  438.                                     {
  439.                                         StreamFile("fa_NoAnswerSip");
  440.                                         if (counterCall < 2)
  441.                                         {
  442.                                             RepeatMainMenu = true;
  443.                                             counterCall++;
  444.                                         }
  445.                                         Console.WriteLine("In no answer mode : " + RepeatMainMenu);
  446.                                     }
  447.  
  448.                                 }
  449.                             }
  450.                             else
  451.                             {
  452.                                 var data1 = GetData("beep", 5000, 11);
  453.                                 string dialnum = data1;
  454.  
  455.                                 Console.WriteLine("Rabeteh DialedNumber:::: " + dialnum);
  456.                                 Exec("Dial", "SIP/cisco/#88" + dialnum + ",45,tr");
  457.                                 var dialstatus = GetVariable("DIALSTATUS");
  458.                                 Console.WriteLine("DialStatus : " + dialstatus);
  459.                                 var channelstatus = GetChannelStatus();
  460.                                 Console.WriteLine("Channelstatus : " + channelstatus);
  461.                             }
  462.                         }
  463.                         #region old DialPlan
  464.                         //bool CustomerCharge = false;
  465.                         //Console.WriteLine("In Main Ivr");
  466.                         //data = GetData("fa_MainIVR", 5000, 4);
  467.                         //string EnteredKey = data;
  468.                         //IvrDialPlan ivrDialPlan = null;
  469.                         //if (EnteredKey != "")
  470.                         //{
  471.                         //    ivrDialPlan = db.IvrDialPlans.FirstOrDefault(p => p.Title == "MainIVR" && p.ParentId == 0 && p.KeyOfDialPlan == EnteredKey);
  472.                         //    if (ivrDialPlan != null)
  473.                         //        SipName = ivrDialPlan.ValueOfKey;
  474.                         //    else
  475.                         //        SipName = data;
  476.                         //    Console.WriteLine("SipName ::: " + SipName);
  477.                         //    if (SipName != "Fax" && SipName != "CustomerCharge")
  478.                         //    {
  479.                         //        if (SipName == "Support")
  480.                         //        {
  481.                         //            data = GetData("fa_SupportMenu", 4000, 1);
  482.                         //            string PressKey = data;
  483.                         //            var Support = db.IvrDialPlans.FirstOrDefault(p => p.Title == "MainIVR" && p.ParentId == ivrDialPlan.Id && p.KeyOfDialPlan == PressKey);
  484.                         //            if (Support != null)
  485.                         //                SipName = Support.ValueOfKey;
  486.                         //        }
  487.  
  488.                         //        if (SipName == "GPSMenu")
  489.                         //        {
  490.                         //            data = GetData("fa_GpsMenu", 4000, 1);
  491.                         //            string PressKey = data;
  492.                         //            var Support = db.IvrDialPlans.FirstOrDefault(p => p.Title == "MainIVR" && p.ParentId == ivrDialPlan.Id && p.KeyOfDialPlan == PressKey);
  493.                         //            if (Support != null)
  494.                         //                SipName = Support.ValueOfKey;
  495.                         //        }
  496.  
  497.                         //        if (SipName == "nejati")
  498.                         //        {
  499.                         //            Exec("Dial", "SIP/cisco/#8838473980,45,tr");
  500.                         //            var dialstatus = GetVariable("DIALSTATUS");
  501.                         //            Console.WriteLine("DialStatus : " + dialstatus);
  502.                         //            var channelstatus = GetChannelStatus();
  503.                         //            Console.WriteLine("Channelstatus : " + channelstatus);
  504.  
  505.                         //        }
  506.                         //        else if (SipName.Substring(0, 2) != "99")
  507.                         //        {
  508.                         //            Console.WriteLine("Dial To " + SipName);
  509.                         //            callState.AgentId = SipName; // just for GoldnetIvr because the is no queue
  510.                         //            db.SaveChanges();
  511.                         //            var QueueOfSip = db.IvrQueueMembers.Where(o => o.membername == SipName).Select(o => o.queue_name).FirstOrDefault();
  512.                         //            maxLine = db.IvrQueues.Where(o => o.name == QueueOfSip).Select(o => o.queue_member_count).FirstOrDefault();
  513.                         //            Console.WriteLine("Name Of Queue :" + QueueOfSip + " &MaxLine : " + maxLine);
  514.                         //            var InQueueCount = db.IvrCallStates.Where(p => (new string[] { "RINGNOANSWER", "ENTERQUEUE" }).Contains(p.status) && p.cdrid == null && p.queue == QueueOfSip && SqlFunctions.DateDiff("mi", p.timestamp, DateTime.Now) < 60).Count();
  515.                         //            if (QueueOfSip != null)
  516.                         //            {
  517.                         //                if (maxLine <= InQueueCount)
  518.                         //                {
  519.                         //                    callState.status = "QueueIsFull";
  520.                         //                    QueueIsFull = true;
  521.                         //                    StreamFile("fa_BusySip");
  522.                         //                    StreamFile("fa_PleaseCallAgain");
  523.                         //                }
  524.                         //                else
  525.                         //                {
  526.                         //                    bool q = this.queue(QueueOfSip, identifier, priority, false, QuOption);
  527.                         //                }
  528.                         //            }
  529.                         //            else
  530.                         //            {
  531.  
  532.                         //                Exec("Dial", "SIP/" + SipName + ",30,tr");
  533.                         //                var dialstatus = GetVariable("DIALSTATUS");
  534.                         //                Console.WriteLine("DialStatus : " + dialstatus);
  535.                         //                if (dialstatus == "CHANUNAVAIL" && dialstatus == "BUSY")
  536.                         //                {
  537.                         //                    StreamFile("fa_BusySip");
  538.                         //                    StreamFile("fa_PleaseCallAgain");
  539.                         //                }
  540.  
  541.                         //            }
  542.                         //        }
  543.                         //        else // for software Rabeteh
  544.                         //        {
  545.                         //            var data1 = GetData("beep", 5000, 11);
  546.                         //            string dialnum = data1;
  547.  
  548.                         //            Console.WriteLine("Rabeteh DialedNumber:::: " + dialnum);
  549.                         //            Exec("Dial", "SIP/cisco/#88" + dialnum + ",45,tr");
  550.                         //            var dialstatus = GetVariable("DIALSTATUS");
  551.                         //            Console.WriteLine("DialStatus : " + dialstatus);
  552.                         //            var channelstatus = GetChannelStatus();
  553.                         //            Console.WriteLine("Channelstatus : " + channelstatus);
  554.                         //        }
  555.                         //    }
  556.                         //    else if (SipName == "Fax")
  557.                         //    {
  558.                         //        Exec("Dial", "IAX2/1001,,tr");
  559.                         //        var dialstatus = GetVariable("DIALSTATUS");
  560.                         //        Console.WriteLine("DialStatus : " + dialstatus);
  561.                         //        var channelstatus = GetChannelStatus();
  562.                         //        Console.WriteLine("Channelstatus : " + channelstatus);
  563.                         //    }
  564.                         //    else if (SipName == "CustomerCharge")
  565.                         //    {
  566.                         //        CustomerCharge = true;
  567.                         //        Console.WriteLine("CustomerCharge is true");
  568.                         //    }
  569.  
  570.                         //    //if (ra != null && !CustomerCharge)
  571.                         //    //{
  572.                         //    //    ManagerResponse rr = manager.SendAction(ra);
  573.  
  574.                         //    //    Console.WriteLine("rr.Message   " + rr.Message);
  575.                         //    //}
  576.                         //    //manager.Logoff();
  577.  
  578.                         //}
  579.                         #endregion old DialPlan
  580.                         #region CustomerCharge
  581.                         if (CustomerCharge)
  582.                         {
  583.                             RepeatMainMenu = false;
  584.                             Console.WriteLine("in CustomerCharge");
  585.                             string telNumber = "";
  586.                             string chargeType = "";
  587.                             try
  588.                             {
  589.                                 IVRServices.Tariffs tariffInfo = ivrc.GetUserTariffsFull(callerId);
  590.                                 IVRServices.StatusOfTariffGroups statusoftariff = ivrc.GetStatusOfTariffGroups(callerId);
  591.                                 int count = 0;
  592.                                 bool AcceptTel = false;
  593.  
  594.                                 if (!statusoftariff.IsGigCharge && !statusoftariff.IsMonthCharge)
  595.                                 {
  596.                                     while (count < 3)
  597.                                     {
  598.                                         if (count == 0)
  599.                                             data = GetData("fa_InActiveService", 500, 1);
  600.                                         else
  601.                                             data = GetData("fa_TelInActiveService", 500, 1);
  602.                                         data = GetData("fa_EnterTel2", 7000, 11);
  603.                                         if (data.StartsWith("0"))
  604.                                             data = data.Substring(1);
  605.                                         telNumber = data;
  606.                                         Console.WriteLine("tellll: " + telNumber);
  607.                                         tariffInfo = ivrc.GetUserTariffsFull(telNumber);
  608.                                         statusoftariff = ivrc.GetStatusOfTariffGroups(telNumber);
  609.                                         if (statusoftariff.IsGigCharge || statusoftariff.IsMonthCharge)
  610.                                         {
  611.                                             data = GetData("fa_TelNumberIs", 500, 1);
  612.                                             for (int i = 0; i < telNumber.Length; i = i + 2)
  613.                                             {
  614.                                                 string number = telNumber.Substring(i, 2);
  615.                                                 key = CommonScript.SayTwoDigitNumber(this, number, true);
  616.                                             }
  617.                                             data = GetData("fa_AcceptTel", 5000, 1);
  618.                                             if (data == "1")
  619.                                             {
  620.                                                 count = 4;
  621.                                                 AcceptTel = true;
  622.                                             }
  623.                                             else if (data == "3")
  624.                                                 count = 4;
  625.                                             else if (data == "2")
  626.                                                 count++;
  627.                                         }
  628.                                         else
  629.                                             count++;
  630.                                         Console.WriteLine("counter of Tel : " + count);
  631.                                     }
  632.                                 }
  633.  
  634.                                 if (count >= 3 && !AcceptTel)
  635.                                 {
  636.                                     data = GetData("fa_InActiveService", 500, 1);
  637.                                     StreamFile("fa_Final");
  638.                                     Hangup();
  639.                                     return;
  640.                                 }
  641.                                 if (statusoftariff.IsGigCharge && statusoftariff.IsMonthCharge)
  642.                                 {
  643.                                     data = GetData("fa_ChargeMenu", 1000, 1);
  644.                                     if (data == "1")
  645.                                         chargeType = "GigCharge";
  646.                                     else
  647.                                         chargeType = "MonthCharge";
  648.                                 }
  649.  
  650.                                 if ((statusoftariff.IsGigCharge && !statusoftariff.IsMonthCharge) || chargeType == "GigCharge")
  651.                                 {
  652.                                     data = GetData("fa_GetGig", 2000, 2);
  653.                                     Console.WriteLine("gig: " + data);
  654.                                     int Gig = Convert.ToInt32(data);
  655.                                     string TariffId = "";
  656.                                     switch (Gig)
  657.                                     {
  658.                                         case 1:
  659.                                             TariffId = "1025";
  660.                                             break;
  661.                                         case 2:
  662.                                             TariffId = "1026";
  663.                                             break;
  664.                                         case 3:
  665.                                             TariffId = "1027";
  666.                                             break;
  667.                                         case 4:
  668.                                             TariffId = "1028";
  669.                                             break;
  670.                                         case 5:
  671.                                             TariffId = "1029";
  672.                                             break;
  673.                                         case 6:
  674.                                             TariffId = "1030";
  675.                                             break;
  676.                                         case 7:
  677.                                             TariffId = "1031";
  678.                                             break;
  679.                                         case 8:
  680.                                             TariffId = "1032";
  681.                                             break;
  682.                                         case 9:
  683.                                             TariffId = "1033";
  684.                                             break;
  685.                                         case 10:
  686.                                             TariffId = "1034";
  687.                                             break;
  688.                                         default:
  689.                                             break;
  690.                                     }
  691.                                     Console.WriteLine("TariffId = " + TariffId);
  692.                                     var tariff = tariffInfo.GigCharge.FirstOrDefault(o => o.Id == TariffId);
  693.                                     if (tariff != null)
  694.                                     {
  695.                                         PriceLong = tariff.TotalPrice;
  696.                                         if (callerId == "05138408626")
  697.                                             PriceLong = 10000;
  698.                                         serviceName = tariff.Name;
  699.                                     }
  700.                                     string Price = PriceLong.ToString();
  701.                                     Console.WriteLine("Price: " + Price);
  702.                                     data = GetData("fa_WantToCharge1", 500, 1);
  703.                                     switch (Gig.ToString().Length)
  704.                                     {
  705.                                         case 1:
  706.                                             key = CommonScript.SayOneDigitNumber(this, Gig.ToString(), false);
  707.                                             break;
  708.                                         case 2:
  709.                                             key = CommonScript.SayTwoDigitNumber(this, Gig.ToString(), false);
  710.                                             break;
  711.                                     }
  712.                                     data = GetData("fa_WantToCharge2", 500, 1);
  713.                                     switch (Price.Length)
  714.                                     {
  715.                                         case 1:
  716.                                             key = CommonScript.SayOneDigitNumber(this, Price, false);
  717.                                             break;
  718.                                         case 2:
  719.                                             key = CommonScript.SayTwoDigitNumber(this, Price, false);
  720.                                             break;
  721.                                         case 3:
  722.                                             key = CommonScript.SayThreeDigitNumber(this, Price, false);
  723.                                             break;
  724.                                         case 4:
  725.                                             key = CommonScript.SayFourDigitNumber(this, Price, false);
  726.                                             break;
  727.                                         case 5:
  728.                                             key = CommonScript.SayFiveDigitNumber(this, Price, false);
  729.                                             break;
  730.                                         case 6:
  731.                                             key = CommonScript.SaySixDigitNumber(this, Price, false);
  732.                                             break;
  733.                                         case 7:
  734.                                             key = CommonScript.SaySevenDigitNumber(this, Price, false);
  735.                                             break;
  736.                                         default:
  737.                                             break;
  738.                                     }
  739.                                     data = GetData("fa_WantToCharge_Continue", 8000, 1);
  740.                                     if (data == "1") // Customer Want To Charge
  741.                                     {
  742.                                         counterPlaySound = 0;
  743.                                         rpeatSound = true;
  744.                                         while (counterPlaySound < 2 && rpeatSound)
  745.                                         {
  746.                                             Console.WriteLine("counter : " + counterPlaySound);
  747.                                             if (counterPlaySound == 0)
  748.                                                 data = GetData("fa_GetMobileNumber1", 4000, 11);
  749.                                             else
  750.                                                 data = GetData("fa_GetCorrectMobileNumber", 4000, 11);
  751.                                             counterPlaySound++;
  752.  
  753.                                             if (!string.IsNullOrEmpty(data) && data.StartsWith("0"))
  754.                                                 data = data.TrimStart("0".ToCharArray());
  755.                                             if (!string.IsNullOrEmpty(data) && data.Length > 10)
  756.                                                 data = data.Substring(0, 10);
  757.  
  758.                                             if (data.Length == 10)
  759.                                             {
  760.                                                 rpeatSound = false;
  761.                                                 mobileNumber = data;
  762.                                                 string customertel = telNumber == "" ? callerId : telNumber;
  763.                                                 try
  764.                                                 {
  765.                                                     long pricelong = Convert.ToInt64(Price);
  766.  
  767.                                                     IvrCharge qm = new IvrCharge
  768.                                                     {
  769.                                                         CustomerTel = customertel,
  770.                                                         Amount = pricelong,
  771.                                                         TariffCode = TariffId,
  772.                                                         TariffName = serviceName,
  773.                                                         MobileNumber = mobileNumber,
  774.                                                         ChargeType = 0 // charge Gig
  775.                                                     };
  776.  
  777.                                                     db.IvrCharges.Add(qm);
  778.                                                     db.SaveChanges();
  779.                                                     InsertId = qm.Id;
  780.  
  781.                                                 }
  782.                                                 catch (Exception ex)
  783.                                                 {
  784.                                                     Console.WriteLine("Erorr : " + ex.Message);
  785.                                                 }
  786.  
  787.                                                 string pricelength = "";
  788.                                                 int IdLength = InsertId.ToString().Length;
  789.                                                 string StoreCode = ConfigurationManager.AppSettings["StoreCode"];
  790.                                                 string pin = ConfigurationManager.AppSettings["Pin"];
  791.                                                 string storcodeLen = "";
  792.                                                 if (StoreCode.Length < 10)
  793.                                                     storcodeLen = "0" + StoreCode.Length.ToString();
  794.                                                 else
  795.                                                     storcodeLen = StoreCode.Length.ToString();
  796.  
  797.                                                 if (Price.Length < 10)
  798.                                                     pricelength = "0" + Price.Length.ToString();
  799.                                                 else
  800.                                                     pricelength = Price.Length.ToString();
  801.  
  802.  
  803.                                                 Random rnd = new Random();
  804.                                                 int OrderId = Convert.ToInt32(rnd.Next(10, 99).ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString());
  805.  
  806.                                                 Int16 @operator = 0; // for charge has value
  807.                                                 Int16 chType = 0; // for charge has value
  808.                                                 int amount = Convert.ToInt32(Price);
  809.                                                 string PaymentCode = "";
  810.                                                 try
  811.                                                 {
  812.                                                     PaymentCode = Payic.PaymentRequest(OrderId, 1, amount, @operator, chType, InsertId.ToString(), "", mobileNumber, pin, customertel, "");
  813.                                                     Console.WriteLine("PayCode::" + PaymentCode);
  814.                                                 }
  815.                                                 catch (Exception ex)
  816.                                                 {
  817.                                                     Console.WriteLine("error for paycode :::" + ex.Message);
  818.                                                 }
  819.                                                 try
  820.                                                 {
  821.                                                     if (PaymentCode != "")
  822.                                                     {
  823.                                                         IvrCharge ivrch = db.IvrCharges.FirstOrDefault(o => o.Id == InsertId);
  824.                                                         ivrch.PaymentCode = PaymentCode;
  825.                                                         db.SaveChanges();
  826.                                                         ManagerConnection manager = new ManagerConnection(
  827.                                                         ConfigurationManager.AppSettings["Asterisk.Manager.Ip"],
  828.                                                         int.Parse(ConfigurationManager.AppSettings["Asterisk.Manager.Port"]),
  829.                                                         ConfigurationManager.AppSettings["Asterisk.Manager.User"],
  830.                                                         ConfigurationManager.AppSettings["Asterisk.Manager.Secret"]);
  831.                                                         manager.Login();
  832.                                                         //RedirectAction ra = new RedirectAction(request.Channel.ToString(), "Pecopayment", "2020" + storcodeLen + StoreCode + pricelength + Price + InsertId.ToString(), 1);
  833.                                                         RedirectAction ra = new RedirectAction(request.Channel.ToString(), "Pecopayment", "2020" + PaymentCode, 1);
  834.                                                         GetData("fa_ConnectToBank", 1000);
  835.                                                         ManagerResponse rr = manager.SendAction(ra);
  836.                                                         manager.Logoff();
  837.                                                     }
  838.                                                 }
  839.                                                 catch (Exception ex)
  840.                                                 {
  841.                                                     Console.WriteLine("errrrrorrrr: " + ex.Message);
  842.                                                 }
  843.                                             }
  844.                                         }
  845.                                     }
  846.  
  847.  
  848.                                 }
  849.                                 else if ((statusoftariff.IsMonthCharge && !statusoftariff.IsGigCharge) || chargeType == "MonthCharge")
  850.                                 {
  851.                                     data = GetData("fa_GetMonth", 500, 2);
  852.                                     int month = Convert.ToInt32(data);
  853.                                     string TariffId = "";
  854.                                     switch (month)
  855.                                     {
  856.                                         case 1:
  857.                                             TariffId = "1044";
  858.                                             break;
  859.                                         case 2:
  860.                                             TariffId = "1049";
  861.                                             break;
  862.                                         default:
  863.                                             break;
  864.                                     }
  865.                                     var tariff = tariffInfo.MonthCharge.FirstOrDefault(o => o.Id == TariffId);
  866.                                     if (tariff != null)
  867.                                     {
  868.                                         PriceLong = tariff.TotalPrice;
  869.                                         Console.WriteLine("Caaaa: " + callerId);
  870.                                         if (callerId == "05138408626")
  871.                                             PriceLong = 10000;
  872.                                         serviceName = tariff.Name;
  873.                                     }
  874.                                     string Price = PriceLong.ToString();
  875.                                     Console.WriteLine("Price: " + Price);
  876.                                     data = GetData("fa_WantToCharge1", 500, 1);
  877.                                     key = CommonScript.SayOneDigitNumber(this, month.ToString(), false);
  878.                                     data = GetData("fa_WantToCharge3", 500, 1);
  879.                                     switch (Price.Length)
  880.                                     {
  881.                                         case 1:
  882.                                             key = CommonScript.SayOneDigitNumber(this, Price, false);
  883.                                             break;
  884.                                         case 2:
  885.                                             key = CommonScript.SayTwoDigitNumber(this, Price, false);
  886.                                             break;
  887.                                         case 3:
  888.                                             key = CommonScript.SayThreeDigitNumber(this, Price, false);
  889.                                             break;
  890.                                         case 4:
  891.                                             key = CommonScript.SayFourDigitNumber(this, Price, false);
  892.                                             break;
  893.                                         case 5:
  894.                                             key = CommonScript.SayFiveDigitNumber(this, Price, false);
  895.                                             break;
  896.                                         case 6:
  897.                                             key = CommonScript.SaySixDigitNumber(this, Price, false);
  898.                                             break;
  899.                                         case 7:
  900.                                             key = CommonScript.SaySevenDigitNumber(this, Price, false);
  901.                                             break;
  902.                                         default:
  903.                                             break;
  904.                                     }
  905.                                     data = GetData("fa_WantToCharge_Continue", 8000, 1);
  906.                                     if (data == "1") // Customer Want To Charge
  907.                                     {
  908.                                         counterPlaySound = 0;
  909.                                         rpeatSound = true;
  910.                                         while (counterPlaySound < 2 && rpeatSound)
  911.                                         {
  912.                                             Console.WriteLine("counter : " + counterPlaySound);
  913.                                             if (counterPlaySound == 0)
  914.                                                 data = GetData("fa_GetMobileNumber1", 4000, 11);
  915.                                             else
  916.                                                 data = GetData("fa_GetCorrectMobileNumber", 4000, 11);
  917.                                             counterPlaySound++;
  918.                                             if (!string.IsNullOrEmpty(data) && data.StartsWith("0"))
  919.                                                 data = data.TrimStart("0".ToCharArray());
  920.                                             if (!string.IsNullOrEmpty(data) && data.Length > 10)
  921.                                                 data = data.Substring(0, 10);
  922.  
  923.                                             if (data.Length == 10)
  924.                                             {
  925.                                                 rpeatSound = false;
  926.                                                 mobileNumber = data;
  927.                                                 try
  928.                                                 {
  929.                                                     long pricelong = Convert.ToInt64(Price);
  930.                                                     string customertel = telNumber == "" ? callerId : telNumber;
  931.                                                     IvrCharge qm = new IvrCharge
  932.                                                     {
  933.                                                         CustomerTel = customertel,
  934.                                                         Amount = pricelong,
  935.                                                         TariffCode = TariffId,
  936.                                                         TariffName = serviceName,
  937.                                                         MobileNumber = mobileNumber,
  938.                                                         ChargeType = 1 // charge Month
  939.                                                     };
  940.  
  941.                                                     db.IvrCharges.Add(qm);
  942.                                                     db.SaveChanges();
  943.                                                     InsertId = qm.Id;
  944.  
  945.                                                 }
  946.                                                 catch (Exception ex)
  947.                                                 {
  948.                                                     Console.WriteLine("Erorr : " + ex.Message);
  949.                                                 }
  950.  
  951.                                                 string pricelength = "";
  952.                                                 // int IdLength = InsertId.ToString().Length;
  953.                                                 string StoreCode = ConfigurationManager.AppSettings["StoreCode"];
  954.                                                 string storcodeLen = "";
  955.                                                 if (StoreCode.Length < 10)
  956.                                                     storcodeLen = "0" + StoreCode.Length.ToString();
  957.                                                 else
  958.                                                     storcodeLen = StoreCode.Length.ToString();
  959.  
  960.                                                 if (Price.Length < 10)
  961.                                                     pricelength = "0" + Price.Length.ToString();
  962.                                                 else
  963.                                                     pricelength = Price.Length.ToString();
  964.  
  965.                                                 try
  966.                                                 {
  967.                                                     ManagerConnection manager = new ManagerConnection(
  968.                                                     ConfigurationManager.AppSettings["Asterisk.Manager.Ip"],
  969.                                                     int.Parse(ConfigurationManager.AppSettings["Asterisk.Manager.Port"]),
  970.                                                     ConfigurationManager.AppSettings["Asterisk.Manager.User"],
  971.                                                     ConfigurationManager.AppSettings["Asterisk.Manager.Secret"]);
  972.                                                     manager.Login();
  973.                                                     RedirectAction ra = new RedirectAction(request.Channel.ToString(), "Pecopayment", "2020" + storcodeLen + StoreCode + pricelength + Price + InsertId.ToString(), 1);
  974.                                                     GetData("fa_ConnectToBank", 1000);
  975.                                                     ManagerResponse rr = manager.SendAction(ra);
  976.                                                     manager.Logoff();
  977.                                                 }
  978.                                                 catch (Exception ex)
  979.                                                 {
  980.                                                     Console.WriteLine("errrrrorrrr: " + ex.Message);
  981.                                                 }
  982.  
  983.                                             }
  984.                                         }
  985.                                     }
  986.  
  987.                                 }
  988.                                 else
  989.                                     data = GetData("fa_InActiveService", 500, 1);
  990.                                 //#endregion
  991.  
  992.                                 //IVRServices.TariffInfoResult[] tariffInfo = ivrc.GetUserTariffs(callerId);
  993.  
  994.  
  995.                                 //if (tariffInfo != null && tariffInfo.Length > 0)
  996.                                 //{
  997.                                 //    var tariff = tariffInfo.FirstOrDefault(o => o.Name == serviceName);
  998.                                 //    if (tariff != null)
  999.                                 //    {
  1000.                                 //        ServiceId = tariff.Id;
  1001.                                 //        PriceLong = tariff.TotalPrice;
  1002.                                 //    }
  1003.  
  1004.                                 //    string Price = PriceLong.ToString();
  1005.                                 //    Console.WriteLine("Price: " + Price);
  1006.                                 //    data = GetData("fa_WantToCharge", 500, 1);
  1007.                                 //    switch (Price.Length)
  1008.                                 //    {
  1009.                                 //        case 1:
  1010.                                 //            key = CommonScript.SayOneDigitNumber(this, Price, false);
  1011.                                 //            break;
  1012.                                 //        case 2:
  1013.                                 //            key = CommonScript.SayTwoDigitNumber(this, Price, false);
  1014.                                 //            break;
  1015.                                 //        case 3:
  1016.                                 //            key = CommonScript.SayThreeDigitNumber(this, Price, false);
  1017.                                 //            break;
  1018.                                 //        case 4:
  1019.                                 //            key = CommonScript.SayFourDigitNumber(this, Price, false);
  1020.                                 //            break;
  1021.                                 //        case 5:
  1022.                                 //            key = CommonScript.SayFiveDigitNumber(this, Price, false);
  1023.                                 //            break;
  1024.                                 //        case 6:
  1025.                                 //            key = CommonScript.SaySixDigitNumber(this, Price, false);
  1026.                                 //            break;
  1027.                                 //        case 7:
  1028.                                 //            key = CommonScript.SaySevenDigitNumber(this, Price, false);
  1029.                                 //            break;
  1030.                                 //        default:
  1031.                                 //            break;
  1032.                                 //    }
  1033.                                 //    data = GetData("fa_WantToCharge_Continue", 8000, 1);
  1034.                                 //    if (data == "1") // Customer Want To Charge
  1035.                                 //    {
  1036.                                 //        counterPlaySound = 0;
  1037.                                 //        rpeatSound = true;
  1038.                                 //        while (counterPlaySound < 2 && rpeatSound)
  1039.                                 //        {
  1040.                                 //            Console.WriteLine("counter : " + counterPlaySound);
  1041.                                 //            if (counterPlaySound == 0)
  1042.                                 //                data = GetData("fa_GetMobileNumber1", 4000, 11);
  1043.                                 //            else
  1044.                                 //                data = GetData("fa_GetCorrectMobileNumber", 4000, 11);
  1045.                                 //            counterPlaySound++;
  1046.                                 //            if (!string.IsNullOrEmpty(data) && data.StartsWith("0"))
  1047.                                 //                data = data.TrimStart("0".ToCharArray());
  1048.                                 //            if (!string.IsNullOrEmpty(data) && data.Length > 10)
  1049.                                 //                data = data.Substring(0, 10);
  1050.  
  1051.                                 //            if (data.Length == 10)
  1052.                                 //            {
  1053.                                 //                rpeatSound = false;
  1054.                                 //                mobileNumber = data;
  1055.                                 //                try
  1056.                                 //                {
  1057.                                 //                    long pricelong = Convert.ToInt64(Price);
  1058.                                 //                    IvrCharge qm = new IvrCharge
  1059.                                 //                    {
  1060.                                 //                        CustomerTel = callerId,
  1061.                                 //                        Amount = pricelong,
  1062.                                 //                        TariffCode = ServiceId,
  1063.                                 //                        TariffName = serviceName,
  1064.                                 //                        MobileNumber = mobileNumber
  1065.                                 //                    };
  1066.  
  1067.                                 //                    db.IvrCharges.Add(qm);
  1068.                                 //                    db.SaveChanges();
  1069.                                 //                    InsertId = qm.Id;
  1070.  
  1071.                                 //                }
  1072.                                 //                catch (Exception ex)
  1073.                                 //                {
  1074.                                 //                    Console.WriteLine("Erorr : " + ex.Message);
  1075.                                 //                }
  1076.  
  1077.                                 //                string pricelength = "";
  1078.                                 //                // int IdLength = InsertId.ToString().Length;
  1079.                                 //                string StoreCode = ConfigurationManager.AppSettings["StoreCode"];
  1080.                                 //                string storcodeLen = "";
  1081.                                 //                if (StoreCode.Length < 10)
  1082.                                 //                    storcodeLen = "0" + StoreCode.Length.ToString();
  1083.                                 //                else
  1084.                                 //                    storcodeLen = StoreCode.Length.ToString();
  1085.  
  1086.                                 //                if (Price.Length < 10)
  1087.                                 //                    pricelength = "0" + Price.Length.ToString();
  1088.                                 //                else
  1089.                                 //                    pricelength = Price.Length.ToString();
  1090.  
  1091.                                 //                try
  1092.                                 //                {
  1093.                                 //                    ManagerConnection manager = new ManagerConnection(
  1094.                                 //                    ConfigurationManager.AppSettings["Asterisk.Manager.Ip"],
  1095.                                 //                    int.Parse(ConfigurationManager.AppSettings["Asterisk.Manager.Port"]),
  1096.                                 //                    ConfigurationManager.AppSettings["Asterisk.Manager.User"],
  1097.                                 //                    ConfigurationManager.AppSettings["Asterisk.Manager.Secret"]);
  1098.                                 //                    manager.Login();
  1099.                                 //                    RedirectAction ra = new RedirectAction(request.Channel.ToString(), "Pecopayment", "2020" + storcodeLen + StoreCode + pricelength + Price + InsertId.ToString(), 1);
  1100.                                 //                    GetData("fa_ConnectToBank", 1000);
  1101.                                 //                    ManagerResponse rr = manager.SendAction(ra);
  1102.                                 //                    manager.Logoff();
  1103.                                 //                }
  1104.                                 //                catch (Exception ex)
  1105.                                 //                {
  1106.                                 //                    Console.WriteLine("errrrrorrrr: " + ex.Message);
  1107.                                 //                }
  1108.  
  1109.                                 //            }
  1110.                                 //        }
  1111.                                 //    }
  1112.                                 //}
  1113.                                 //else
  1114.                                 //{
  1115.                                 //    data = GetData("fa_InActiveService", 500, 1);
  1116.                                 //    StreamFile("fa_Final");
  1117.                                 //    Hangup();
  1118.                                 //    return;
  1119.                                 //}
  1120.                             }
  1121.                             catch (Exception ex)
  1122.                             {
  1123.                                 this.log(identifier, IvrLogTypes.Error, ex.Message);
  1124.                                 GetData("fa_ErrorInConnection", 1000);
  1125.                             }
  1126.  
  1127.                         }
  1128.                         #endregion
  1129.  
  1130.                     }
  1131.                     #region comment
  1132.                     //int CustomerStatus = partner.StatusOfCustomerCharge(callerId);
  1133.                     // Console.WriteLine("CustomerStatus ::: " + CustomerStatus);
  1134.                     // switch (CustomerStatus)
  1135.                     //  {
  1136.  
  1137.                     //case 0:
  1138.                     //    data = GetData("fa_InActiveService", 500, 1);
  1139.                     //    break;
  1140.                     //  case 1:
  1141.                     //string InfoStr = GetInfoOfSpecialService(ic.Get_Trafik_List_For_Sales("hkhosravi", "GoldNetQAZ*!@123", callerId));
  1142.                     //if (InfoStr != null && InfoStr != "")
  1143.                     //{
  1144.                     //    ServiceId = InfoStr.Split('*')[0];
  1145.                     //    Price = InfoStr.Split('*')[1];
  1146.                     //    serviceName = InfoStr.Split('*')[2];
  1147.                     //}
  1148.                     // Price = ConfigurationManager.AppSettings["Price"];
  1149.                     //ServiceWrappers.ServiceResponse UserInfo = partner.GetUserInfoViaCustomer(callerId);
  1150.                     //ServiceWrappers.UserInfo returnObject = (ServiceWrappers.UserInfo)UserInfo.ReturnedObject;
  1151.                     //if (returnObject != null && returnObject.RemainingTraffic > 0)
  1152.                     //{
  1153.                     //    data = GetData("fa_Volume", 1000, 1);
  1154.                     //    int reservedTraffic = Convert.ToInt32(returnObject.ReservedTraffic * 1024);
  1155.                     //    Console.WriteLine("reservedTraffic :" + reservedTraffic);
  1156.                     //    int MegTraffic = Convert.ToInt32(returnObject.RemainingTraffic * 1024) + reservedTraffic;
  1157.                     //    string remainingTraffic = MegTraffic.ToString();
  1158.                     //    Console.WriteLine("remainingTraffic :" + remainingTraffic);
  1159.                     //    switch (remainingTraffic.Length)
  1160.                     //    {
  1161.                     //        case 1:
  1162.                     //            key = CommonScript.SayOneDigitNumber(this, remainingTraffic, false);
  1163.                     //            break;
  1164.                     //        case 2:
  1165.                     //            key = CommonScript.SayTwoDigitNumber(this, remainingTraffic, false);
  1166.                     //            break;
  1167.                     //        case 3:
  1168.                     //            key = CommonScript.SayThreeDigitNumber(this, remainingTraffic, false);
  1169.                     //            break;
  1170.                     //        case 4:
  1171.                     //            key = CommonScript.SayFourDigitNumber(this, remainingTraffic, false);
  1172.                     //            break;
  1173.                     //        case 5:
  1174.                     //            key = CommonScript.SayFiveDigitNumber(this, remainingTraffic, false);
  1175.                     //            break;
  1176.                     //        case 6:
  1177.                     //            key = CommonScript.SaySixDigitNumber(this, remainingTraffic, false);
  1178.                     //            break;
  1179.                     //        default:
  1180.                     //            break;
  1181.                     //    }
  1182.                     //    data = GetData("fa_Meg", 1000, 1);
  1183.                     //}
  1184.                     //data = GetData("fa_WantToCharge", 500, 1);
  1185.                     //switch (Price.Length)
  1186.                     //{
  1187.                     //    case 1:
  1188.                     //        key = CommonScript.SayOneDigitNumber(this, Price, false);
  1189.                     //        break;
  1190.                     //    case 2:
  1191.                     //        key = CommonScript.SayTwoDigitNumber(this, Price, false);
  1192.                     //        break;
  1193.                     //    case 3:
  1194.                     //        key = CommonScript.SayThreeDigitNumber(this, Price, false);
  1195.                     //        break;
  1196.                     //    case 4:
  1197.                     //        key = CommonScript.SayFourDigitNumber(this, Price, false);
  1198.                     //        break;
  1199.                     //    case 5:
  1200.                     //        key = CommonScript.SayFiveDigitNumber(this, Price, false);
  1201.                     //        break;
  1202.                     //    case 6:
  1203.                     //        key = CommonScript.SaySixDigitNumber(this, Price, false);
  1204.                     //        break;
  1205.                     //    case 7:
  1206.                     //        key = CommonScript.SaySevenDigitNumber(this, Price, false);
  1207.                     //        break;
  1208.                     //    default:
  1209.                     //        break;
  1210.                     //}
  1211.                     //data = GetData("fa_WantToCharge_Continue", 8000, 1);
  1212.  
  1213.                     //if (data == "1") // Customer Want To Charge
  1214.                     //{
  1215.                     //    counterPlaySound = 0;
  1216.                     //    rpeatSound = true;
  1217.                     //    while (counterPlaySound < 2 && rpeatSound)
  1218.                     //    {
  1219.                     //        Console.WriteLine("counter : " + counterPlaySound);
  1220.                     //        if (counterPlaySound == 0)
  1221.                     //            data = GetData("fa_GetMobileNumber", 5000, 11);
  1222.                     //        else
  1223.                     //            data = GetData("fa_GetCorrectMobileNumber", 4000, 11);
  1224.                     //        counterPlaySound++;
  1225.                     //        if (!string.IsNullOrEmpty(data) && data.StartsWith("0"))
  1226.                     //            data = data.TrimStart("0".ToCharArray());
  1227.                     //        if (!string.IsNullOrEmpty(data) && data.Length > 10)
  1228.                     //            data = data.Substring(0, 10);
  1229.  
  1230.                     //        if (data.Length == 10)
  1231.                     //        {
  1232.                     //            rpeatSound = false;
  1233.                     //            mobileNumber = data;
  1234.                     //            try
  1235.                     //            {
  1236.                     //                long pricelong = Convert.ToInt64(Price);
  1237.                     //                IvrCharge qm = new IvrCharge
  1238.                     //                {
  1239.                     //                    CustomerTel = callerId,
  1240.                     //                    Amount = pricelong,
  1241.                     //                    TariffCode = ServiceId,
  1242.                     //                    TariffName = serviceName,
  1243.                     //                    MobileNumber = mobileNumber
  1244.                     //                };
  1245.  
  1246.                     //                db.IvrCharges.Add(qm);
  1247.                     //                db.SaveChanges();
  1248.                     //                InsertId = qm.Id;
  1249.  
  1250.                     //            }
  1251.                     //            catch (Exception ex)
  1252.                     //            {
  1253.                     //                Console.WriteLine("Erorr : " + ex.Message);
  1254.                     //            }
  1255.  
  1256.                     //            int pricelength = Price.Length;
  1257.                     //            int IdLength = InsertId.ToString().Length;
  1258.                     //            try
  1259.                     //            {
  1260.                     //               ManagerConnection manager = new ManagerConnection(
  1261.                     //               ConfigurationManager.AppSettings["Asterisk.Manager.Ip"],
  1262.                     //               int.Parse(ConfigurationManager.AppSettings["Asterisk.Manager.Port"]),
  1263.                     //               ConfigurationManager.AppSettings["Asterisk.Manager.User"],
  1264.                     //               ConfigurationManager.AppSettings["Asterisk.Manager.Secret"]);
  1265.                     //               manager.Login();
  1266.                     //               Console.WriteLine("before redirect : " + request.Channel.ToString());
  1267.  
  1268.                     //               RedirectAction ra = new RedirectAction(request.Channel.ToString(), "Pecopayment", "2020" + pricelength.ToString() + Price + IdLength.ToString() + InsertId.ToString(), 1);
  1269.                     //               ManagerResponse rr = manager.SendAction(ra);
  1270.                     //            }
  1271.                     //            catch (Exception ex)
  1272.                     //            {
  1273.                     //                Console.WriteLine("errrrrorrrr: " + ex.Message);
  1274.                     //            }
  1275.                     //   try
  1276.                     //                        {
  1277.                     //                            // ChargResult = GetEstelamService(ic.Sales_Trafik_To_Customer("hkhosravi", "hossein4111", callerId, ServiceId));//do charge from Partneri
  1278.                     //                            string resellerId = "1940";
  1279.                     //                            string tariffName = "3 گیگ ترافیک مازاد";
  1280.                     //                            ChargResult = partner.ChargeCustomer(callerId, resellerId, tariffName).Code.ToString();
  1281.                     //                            Console.WriteLine("Charge result:::: " + ChargResult);
  1282.                     //                            //ChargResult = "1";
  1283.                     //                        }
  1284.                     //                        catch
  1285.                     //                        {
  1286.                     //                            ChargResult = "0";
  1287.                     //                        }
  1288.  
  1289.                     //                        IvrCharge charge = null;
  1290.                     //                        charge = db.IvrCharges.FirstOrDefault(p => p.Id == InsertId);
  1291.                     //                        if (ChargResult == "1") //SuccessfulCharge
  1292.                     //                        {
  1293.                     //                            Console.WriteLine("Successs charge Customer");
  1294.                     //                            charge.ChargeResult = Convert.ToInt32(ChargResult);
  1295.                     //                            charge.ChargeDate = DateTime.Now;
  1296.                     //                            db.SaveChanges();
  1297.                     //                            data = GetData("digits/Successful", 500, 1);
  1298.                     //                            data = GetData("fa_AccountNumber", 500, 1);
  1299.                     //                            for (int i = 0; i < CardNumber.Length; i = i + 2)
  1300.                     //                            {
  1301.                     //                                string number = CardNumber.Substring(i, 2);
  1302.                     //                                key = CommonScript.SayTwoDigitNumber(this, number, true);
  1303.                     //                            }
  1304.                     //                            data = GetData("fa_CallAgainAfterPay", 500, 1);
  1305.                     //                            smsresult = SendSMS("شارژ با موفقیت انجام شد", mobileNumber);
  1306.  
  1307.                     //                        }
  1308.                     //                        else //UnSuccessfulCharge
  1309.                     //                        {
  1310.                     //                            charge.ChargeResult = Convert.ToInt32(ChargResult);
  1311.                     //                            charge.ChargeDate = DateTime.Now;
  1312.                     //                            db.SaveChanges();
  1313.                     //                            data = GetData("fa_unsuccess", 500, 1);
  1314.                     //                            smsresult = SendSMS("عملیات شارژ ناموفق بود", mobileNumber);
  1315.                     //                        }
  1316.                     //                        Console.WriteLine("smsResult ::: " + smsresult);
  1317.                     //                    }
  1318.                     //                    else
  1319.                     //                    {
  1320.                     //                        data = GetData("fa_InvalidMobileNumber", 500, 1);
  1321.                     //                    }
  1322.                     //                }
  1323.                     //            }
  1324.  
  1325.                     //            break;
  1326.                     //        case 2:
  1327.                     //            data = GetData("fa_LessThan3Days", 500, 1);
  1328.                     //            data = GetData("fa_AccountNumber", 500, 1);
  1329.                     //            for (int i = 0; i < CardNumber.Length; i = i + 2)
  1330.                     //            {
  1331.                     //                string number = CardNumber.Substring(i, 2);
  1332.                     //                key = CommonScript.SayTwoDigitNumber(this, number, true);
  1333.                     //            }
  1334.                     //            data = GetData("fa_CallAgainAfterPay", 500, 1);
  1335.                     //            break;
  1336.                     //        case 3:
  1337.                     //            data = GetData("fa_MoreThan3Days", 500, 1);
  1338.                     //            data = GetData("fa_AccountNumber", 500, 1);
  1339.                     //            for (int i = 0; i < CardNumber.Length; i = i + 2)
  1340.                     //            {
  1341.                     //                string number = CardNumber.Substring(i, 2);
  1342.                     //                key = CommonScript.SayTwoDigitNumber(this, number, true);
  1343.                     //            }
  1344.                     //            data = GetData("fa_CallAgainAfterPay", 500, 1);
  1345.                     //            break;
  1346.                     //        case 4:
  1347.                     //            data = GetData("fa_WaitForAcceptPaymentCode", 500, 1);
  1348.                     //            break;
  1349.                     //        default:
  1350.                     //            break;
  1351.                     //    }
  1352.                     //}
  1353.                     //else if (data == "2")
  1354.                     //{
  1355.  
  1356.                     //    IvrCharge charge = null;
  1357.                     //    charge = db.IvrCharges.FirstOrDefault(p => p.CustomerTel == callerId && (p.PaymentCode == null || p.PaymentCode == "") && p.ChargeResult == 1);
  1358.                     //    if (charge != null)
  1359.                     //    {
  1360.                     //        data = GetData("fa_GetTrackingCode", 5000, 16);
  1361.                     //        try
  1362.                     //        {
  1363.                     //            charge.PaymentCode = data;
  1364.                     //            charge.PaymentType = 1; // pay in Card
  1365.                     //            charge.PayDate = DateTime.Now;
  1366.                     //            db.SaveChanges();
  1367.                     //            data = GetData("fa_SuccessSetTrackingCode", 500, 1);
  1368.                     //        }
  1369.                     //        catch (Exception ex)
  1370.                     //        {
  1371.                     //            data = GetData("fa_UnSuccessSetTrackingCode", 500, 1);
  1372.                     //        }
  1373.                     //    }
  1374.                     //    else
  1375.                     //        data = GetData("fa_NoRecord", 500, 1);
  1376.  
  1377.                     //}
  1378.                     //else if (data == "3")
  1379.                     //{
  1380.                     //    data = GetData("fa_AccountNumber", 500, 1);
  1381.                     //    for (int i = 0; i < CardNumber.Length; i = i + 2)
  1382.                     //    {
  1383.                     //        string number = CardNumber.Substring(i, 2);
  1384.                     //        key = CommonScript.SayTwoDigitNumber(this, number, true);
  1385.                     //    }
  1386.                     //    data = GetData("fa_CallAgainAfterPay", 500, 1);
  1387.                     //}
  1388.                     // }
  1389.  
  1390.  
  1391.                     //}
  1392.                     #endregion
  1393.                     catch (Exception ex)
  1394.                     {
  1395.                         this.log(identifier, IvrLogTypes.Error, ex.Message);
  1396.                         callState.Comment = "Channel was hung up";
  1397.                         callState.status = "HangUp";
  1398.                         db.SaveChanges();
  1399.                         return;
  1400.                     }
  1401.                     #endregion
  1402.                 }
  1403.  
  1404.                 #region for Parsian Tesr
  1405.  
  1406.                 ///////////////////////////////////////
  1407.                 //#region CustomerCharge
  1408.                 //bool CustomerCharge1 = true;
  1409.                 //if (CustomerCharge1)
  1410.                 //{
  1411.                 //    Console.WriteLine("in CustomerCharge");
  1412.                 //    string telNumber = "";
  1413.                 //    string chargeType = "";
  1414.                 //    try
  1415.                 //    {
  1416.                 //        IVRServices.Tariffs tariffInfo = ivrc.GetUserTariffsFull(callerId);
  1417.                 //        IVRServices.StatusOfTariffGroups statusoftariff = ivrc.GetStatusOfTariffGroups(callerId);
  1418.                 //        int count = 0;
  1419.                 //        bool AcceptTel = false;
  1420.  
  1421.                 //        if (!statusoftariff.IsGigCharge && !statusoftariff.IsMonthCharge)
  1422.                 //        {
  1423.                 //            while (count < 3)
  1424.                 //            {
  1425.                 //                if (count == 0)
  1426.                 //                    data = GetData("fa_InActiveService", 500, 1);
  1427.                 //                else
  1428.                 //                    data = GetData("fa_TelInActiveService", 500, 1);
  1429.                 //                data = GetData("fa_EnterTel2", 7000, 11);
  1430.                 //                if (data.StartsWith("0"))
  1431.                 //                    data = data.Substring(1);
  1432.                 //                telNumber = data;
  1433.                 //                Console.WriteLine("tellll: " + telNumber);
  1434.                 //                tariffInfo = ivrc.GetUserTariffsFull(telNumber);
  1435.                 //                statusoftariff = ivrc.GetStatusOfTariffGroups(telNumber);
  1436.                 //                if (statusoftariff.IsGigCharge || statusoftariff.IsMonthCharge)
  1437.                 //                {
  1438.                 //                    data = GetData("fa_TelNumberIs", 500, 1);
  1439.                 //                    for (int i = 0; i < telNumber.Length; i = i + 2)
  1440.                 //                    {
  1441.                 //                        string number = telNumber.Substring(i, 2);
  1442.                 //                        key = CommonScript.SayTwoDigitNumber(this, number, true);
  1443.                 //                    }
  1444.                 //                    data = GetData("fa_AcceptTel", 5000, 1);
  1445.                 //                    if (data == "1")
  1446.                 //                    {
  1447.                 //                        count = 4;
  1448.                 //                        AcceptTel = true;
  1449.                 //                    }
  1450.                 //                    else if (data == "3")
  1451.                 //                        count = 4;
  1452.                 //                    else if (data == "2")
  1453.                 //                        count++;
  1454.                 //                }
  1455.                 //                else
  1456.                 //                    count++;
  1457.                 //                Console.WriteLine("counter of Tel : " + count);
  1458.                 //            }
  1459.                 //        }
  1460.  
  1461.                 //        if (count >= 3 && !AcceptTel)
  1462.                 //        {
  1463.                 //            data = GetData("fa_InActiveService", 500, 1);
  1464.                 //            StreamFile("fa_Final");
  1465.                 //            Hangup();
  1466.                 //            return;
  1467.                 //        }
  1468.                 //        if (statusoftariff.IsGigCharge && statusoftariff.IsMonthCharge)
  1469.                 //        {
  1470.                 //            data = GetData("fa_ChargeMenu", 1000, 1);
  1471.                 //            if (data == "1")
  1472.                 //                chargeType = "GigCharge";
  1473.                 //            else
  1474.                 //                chargeType = "MonthCharge";
  1475.                 //        }
  1476.  
  1477.                 //        if ((statusoftariff.IsGigCharge && !statusoftariff.IsMonthCharge) || chargeType == "GigCharge")
  1478.                 //        {
  1479.                 //            data = GetData("fa_GetGig", 2000, 2);
  1480.                 //            Console.WriteLine("gig: " + data);
  1481.                 //            int Gig = Convert.ToInt32(data);
  1482.                 //            string TariffId = "";
  1483.                 //            switch (Gig)
  1484.                 //            {
  1485.                 //                case 1:
  1486.                 //                    TariffId = "1025";
  1487.                 //                    break;
  1488.                 //                case 2:
  1489.                 //                    TariffId = "1026";
  1490.                 //                    break;
  1491.                 //                case 3:
  1492.                 //                    TariffId = "1027";
  1493.                 //                    break;
  1494.                 //                case 4:
  1495.                 //                    TariffId = "1028";
  1496.                 //                    break;
  1497.                 //                case 5:
  1498.                 //                    TariffId = "1029";
  1499.                 //                    break;
  1500.                 //                case 6:
  1501.                 //                    TariffId = "1030";
  1502.                 //                    break;
  1503.                 //                case 7:
  1504.                 //                    TariffId = "1031";
  1505.                 //                    break;
  1506.                 //                case 8:
  1507.                 //                    TariffId = "1032";
  1508.                 //                    break;
  1509.                 //                case 9:
  1510.                 //                    TariffId = "1033";
  1511.                 //                    break;
  1512.                 //                case 10:
  1513.                 //                    TariffId = "1034";
  1514.                 //                    break;
  1515.                 //                default:
  1516.                 //                    break;
  1517.                 //            }
  1518.                 //            Console.WriteLine("TariffId = " + TariffId);
  1519.                 //            var tariff = tariffInfo.GigCharge.FirstOrDefault(o => o.Id == TariffId);
  1520.                 //            if (tariff != null)
  1521.                 //            {
  1522.                 //                PriceLong = tariff.TotalPrice;
  1523.                 //                if (callerId == "05138408626")
  1524.                 //                    PriceLong = 10000;
  1525.                 //                serviceName = tariff.Name;
  1526.                 //            }
  1527.                 //            string Price = PriceLong.ToString();
  1528.                 //            Console.WriteLine("Price: " + Price);
  1529.                 //            data = GetData("fa_WantToCharge1", 500, 1);
  1530.                 //            switch (Gig.ToString().Length)
  1531.                 //            {
  1532.                 //                case 1:
  1533.                 //                    key = CommonScript.SayOneDigitNumber(this, Gig.ToString(), false);
  1534.                 //                    break;
  1535.                 //                case 2:
  1536.                 //                    key = CommonScript.SayTwoDigitNumber(this, Gig.ToString(), false);
  1537.                 //                    break;
  1538.                 //            }
  1539.                 //            data = GetData("fa_WantToCharge2", 500, 1);
  1540.                 //            switch (Price.Length)
  1541.                 //            {
  1542.                 //                case 1:
  1543.                 //                    key = CommonScript.SayOneDigitNumber(this, Price, false);
  1544.                 //                    break;
  1545.                 //                case 2:
  1546.                 //                    key = CommonScript.SayTwoDigitNumber(this, Price, false);
  1547.                 //                    break;
  1548.                 //                case 3:
  1549.                 //                    key = CommonScript.SayThreeDigitNumber(this, Price, false);
  1550.                 //                    break;
  1551.                 //                case 4:
  1552.                 //                    key = CommonScript.SayFourDigitNumber(this, Price, false);
  1553.                 //                    break;
  1554.                 //                case 5:
  1555.                 //                    key = CommonScript.SayFiveDigitNumber(this, Price, false);
  1556.                 //                    break;
  1557.                 //                case 6:
  1558.                 //                    key = CommonScript.SaySixDigitNumber(this, Price, false);
  1559.                 //                    break;
  1560.                 //                case 7:
  1561.                 //                    key = CommonScript.SaySevenDigitNumber(this, Price, false);
  1562.                 //                    break;
  1563.                 //                default:
  1564.                 //                    break;
  1565.                 //            }
  1566.                 //            data = GetData("fa_WantToCharge_Continue", 8000, 1);
  1567.                 //            if (data == "1") // Customer Want To Charge
  1568.                 //            {
  1569.                 //                counterPlaySound = 0;
  1570.                 //                rpeatSound = true;
  1571.                 //                while (counterPlaySound < 2 && rpeatSound)
  1572.                 //                {
  1573.                 //                    Console.WriteLine("counter : " + counterPlaySound);
  1574.                 //                    if (counterPlaySound == 0)
  1575.                 //                        data = GetData("fa_GetMobileNumber1", 4000, 11);
  1576.                 //                    else
  1577.                 //                        data = GetData("fa_GetCorrectMobileNumber", 4000, 11);
  1578.                 //                    counterPlaySound++;
  1579.  
  1580.                 //                    if (!string.IsNullOrEmpty(data) && data.StartsWith("0"))
  1581.                 //                        data = data.TrimStart("0".ToCharArray());
  1582.                 //                    if (!string.IsNullOrEmpty(data) && data.Length > 10)
  1583.                 //                        data = data.Substring(0, 10);
  1584.  
  1585.                 //                    if (data.Length == 10)
  1586.                 //                    {
  1587.                 //                        rpeatSound = false;
  1588.                 //                        mobileNumber = data;
  1589.                 //                        try
  1590.                 //                        {
  1591.                 //                            long pricelong = Convert.ToInt64(Price);
  1592.                 //                            string customertel = telNumber == "" ? callerId : telNumber;
  1593.                 //                            IvrCharge qm = new IvrCharge
  1594.                 //                            {
  1595.                 //                                CustomerTel = customertel,
  1596.                 //                                Amount = pricelong,
  1597.                 //                                TariffCode = TariffId,
  1598.                 //                                TariffName = serviceName,
  1599.                 //                                MobileNumber = mobileNumber,
  1600.                 //                                ChargeType = 0 // charge Gig
  1601.                 //                            };
  1602.  
  1603.                 //                            db.IvrCharges.Add(qm);
  1604.                 //                            db.SaveChanges();
  1605.                 //                            InsertId = qm.Id;
  1606.  
  1607.                 //                        }
  1608.                 //                        catch (Exception ex)
  1609.                 //                        {
  1610.                 //                            Console.WriteLine("Erorr : " + ex.Message);
  1611.                 //                        }
  1612.  
  1613.                 //                        string pricelength = "";
  1614.                 //                        // int IdLength = InsertId.ToString().Length;
  1615.                 //                        string StoreCode = ConfigurationManager.AppSettings["StoreCode"];
  1616.                 //                        string storcodeLen = "";
  1617.                 //                        if (StoreCode.Length < 10)
  1618.                 //                            storcodeLen = "0" + StoreCode.Length.ToString();
  1619.                 //                        else
  1620.                 //                            storcodeLen = StoreCode.Length.ToString();
  1621.  
  1622.                 //                        if (Price.Length < 10)
  1623.                 //                            pricelength = "0" + Price.Length.ToString();
  1624.                 //                        else
  1625.                 //                            pricelength = Price.Length.ToString();
  1626.  
  1627.                 //                        try
  1628.                 //                        {
  1629.                 //                            ManagerConnection manager = new ManagerConnection(
  1630.                 //                            ConfigurationManager.AppSettings["Asterisk.Manager.Ip"],
  1631.                 //                            int.Parse(ConfigurationManager.AppSettings["Asterisk.Manager.Port"]),
  1632.                 //                            ConfigurationManager.AppSettings["Asterisk.Manager.User"],
  1633.                 //                            ConfigurationManager.AppSettings["Asterisk.Manager.Secret"]);
  1634.                 //                            manager.Login();
  1635.                 //                            RedirectAction ra = new RedirectAction(request.Channel.ToString(), "Pecopayment", "2020" + storcodeLen + StoreCode + pricelength + Price + InsertId.ToString(), 1);
  1636.                 //                            GetData("fa_ConnectToBank", 1000);
  1637.                 //                            ManagerResponse rr = manager.SendAction(ra);
  1638.                 //                            manager.Logoff();
  1639.                 //                        }
  1640.                 //                        catch (Exception ex)
  1641.                 //                        {
  1642.                 //                            Console.WriteLine("errrrrorrrr: " + ex.Message);
  1643.                 //                        }
  1644.  
  1645.                 //                    }
  1646.                 //                }
  1647.                 //            }
  1648.  
  1649.  
  1650.                 //        }
  1651.                 //        else if ((statusoftariff.IsMonthCharge && !statusoftariff.IsGigCharge) || chargeType == "MonthCharge")
  1652.                 //        {
  1653.                 //            data = GetData("fa_GetMonth", 500, 2);
  1654.                 //            int month = Convert.ToInt32(data);
  1655.                 //            string TariffId = "";
  1656.                 //            switch (month)
  1657.                 //            {
  1658.                 //                case 1:
  1659.                 //                    TariffId = "1044";
  1660.                 //                    break;
  1661.                 //                case 2:
  1662.                 //                    TariffId = "1049";
  1663.                 //                    break;
  1664.                 //                default:
  1665.                 //                    break;
  1666.                 //            }
  1667.                 //            var tariff = tariffInfo.MonthCharge.FirstOrDefault(o => o.Id == TariffId);
  1668.                 //            if (tariff != null)
  1669.                 //            {
  1670.                 //                PriceLong = tariff.TotalPrice;
  1671.                 //                Console.WriteLine("Caaaa: " + callerId);
  1672.                 //                if (callerId == "05138408626")
  1673.                 //                    PriceLong = 10000;
  1674.                 //                serviceName = tariff.Name;
  1675.                 //            }
  1676.                 //            string Price = PriceLong.ToString();
  1677.                 //            Console.WriteLine("Price: " + Price);
  1678.                 //            data = GetData("fa_WantToCharge1", 500, 1);
  1679.                 //            key = CommonScript.SayOneDigitNumber(this, month.ToString(), false);
  1680.                 //            data = GetData("fa_WantToCharge3", 500, 1);
  1681.                 //            switch (Price.Length)
  1682.                 //            {
  1683.                 //                case 1:
  1684.                 //                    key = CommonScript.SayOneDigitNumber(this, Price, false);
  1685.                 //                    break;
  1686.                 //                case 2:
  1687.                 //                    key = CommonScript.SayTwoDigitNumber(this, Price, false);
  1688.                 //                    break;
  1689.                 //                case 3:
  1690.                 //                    key = CommonScript.SayThreeDigitNumber(this, Price, false);
  1691.                 //                    break;
  1692.                 //                case 4:
  1693.                 //                    key = CommonScript.SayFourDigitNumber(this, Price, false);
  1694.                 //                    break;
  1695.                 //                case 5:
  1696.                 //                    key = CommonScript.SayFiveDigitNumber(this, Price, false);
  1697.                 //                    break;
  1698.                 //                case 6:
  1699.                 //                    key = CommonScript.SaySixDigitNumber(this, Price, false);
  1700.                 //                    break;
  1701.                 //                case 7:
  1702.                 //                    key = CommonScript.SaySevenDigitNumber(this, Price, false);
  1703.                 //                    break;
  1704.                 //                default:
  1705.                 //                    break;
  1706.                 //            }
  1707.                 //            data = GetData("fa_WantToCharge_Continue", 8000, 1);
  1708.                 //            if (data == "1") // Customer Want To Charge
  1709.                 //            {
  1710.                 //                counterPlaySound = 0;
  1711.                 //                rpeatSound = true;
  1712.                 //                while (counterPlaySound < 2 && rpeatSound)
  1713.                 //                {
  1714.                 //                    Console.WriteLine("counter : " + counterPlaySound);
  1715.                 //                    if (counterPlaySound == 0)
  1716.                 //                        data = GetData("fa_GetMobileNumber1", 4000, 11);
  1717.                 //                    else
  1718.                 //                        data = GetData("fa_GetCorrectMobileNumber", 4000, 11);
  1719.                 //                    counterPlaySound++;
  1720.                 //                    if (!string.IsNullOrEmpty(data) && data.StartsWith("0"))
  1721.                 //                        data = data.TrimStart("0".ToCharArray());
  1722.                 //                    if (!string.IsNullOrEmpty(data) && data.Length > 10)
  1723.                 //                        data = data.Substring(0, 10);
  1724.  
  1725.                 //                    if (data.Length == 10)
  1726.                 //                    {
  1727.                 //                        rpeatSound = false;
  1728.                 //                        mobileNumber = data;
  1729.                 //                        try
  1730.                 //                        {
  1731.                 //                            long pricelong = Convert.ToInt64(Price);
  1732.                 //                            string customertel = telNumber == "" ? callerId : telNumber;
  1733.                 //                            IvrCharge qm = new IvrCharge
  1734.                 //                            {
  1735.                 //                                CustomerTel = customertel,
  1736.                 //                                Amount = pricelong,
  1737.                 //                                TariffCode = TariffId,
  1738.                 //                                TariffName = serviceName,
  1739.                 //                                MobileNumber = mobileNumber,
  1740.                 //                                ChargeType = 1 // charge Month
  1741.                 //                            };
  1742.  
  1743.                 //                            db.IvrCharges.Add(qm);
  1744.                 //                            db.SaveChanges();
  1745.                 //                            InsertId = qm.Id;
  1746.  
  1747.                 //                        }
  1748.                 //                        catch (Exception ex)
  1749.                 //                        {
  1750.                 //                            Console.WriteLine("Erorr : " + ex.Message);
  1751.                 //                        }
  1752.  
  1753.                 //                        string pricelength = "";
  1754.                 //                        // int IdLength = InsertId.ToString().Length;
  1755.                 //                        string StoreCode = ConfigurationManager.AppSettings["StoreCode"];
  1756.                 //                        string storcodeLen = "";
  1757.                 //                        if (StoreCode.Length < 10)
  1758.                 //                            storcodeLen = "0" + StoreCode.Length.ToString();
  1759.                 //                        else
  1760.                 //                            storcodeLen = StoreCode.Length.ToString();
  1761.  
  1762.                 //                        if (Price.Length < 10)
  1763.                 //                            pricelength = "0" + Price.Length.ToString();
  1764.                 //                        else
  1765.                 //                            pricelength = Price.Length.ToString();
  1766.  
  1767.                 //                        try
  1768.                 //                        {
  1769.                 //                            ManagerConnection manager = new ManagerConnection(
  1770.                 //                            ConfigurationManager.AppSettings["Asterisk.Manager.Ip"],
  1771.                 //                            int.Parse(ConfigurationManager.AppSettings["Asterisk.Manager.Port"]),
  1772.                 //                            ConfigurationManager.AppSettings["Asterisk.Manager.User"],
  1773.                 //                            ConfigurationManager.AppSettings["Asterisk.Manager.Secret"]);
  1774.                 //                            manager.Login();
  1775.                 //                            RedirectAction ra = new RedirectAction(request.Channel.ToString(), "Pecopayment", "2020" + storcodeLen + StoreCode + pricelength + Price + InsertId.ToString(), 1);
  1776.                 //                            GetData("fa_ConnectToBank", 1000);
  1777.                 //                            ManagerResponse rr = manager.SendAction(ra);
  1778.                 //                            manager.Logoff();
  1779.                 //                        }
  1780.                 //                        catch (Exception ex)
  1781.                 //                        {
  1782.                 //                            Console.WriteLine("errrrrorrrr: " + ex.Message);
  1783.                 //                        }
  1784.  
  1785.                 //                    }
  1786.                 //                }
  1787.                 //            }
  1788.  
  1789.                 //        }
  1790.                 //        else
  1791.                 //            data = GetData("fa_InActiveService", 500, 1);
  1792.                 //        //#endregion
  1793.  
  1794.                 //        //IVRServices.TariffInfoResult[] tariffInfo = ivrc.GetUserTariffs(callerId);
  1795.  
  1796.  
  1797.                 //        //if (tariffInfo != null && tariffInfo.Length > 0)
  1798.                 //        //{
  1799.                 //        //    var tariff = tariffInfo.FirstOrDefault(o => o.Name == serviceName);
  1800.                 //        //    if (tariff != null)
  1801.                 //        //    {
  1802.                 //        //        ServiceId = tariff.Id;
  1803.                 //        //        PriceLong = tariff.TotalPrice;
  1804.                 //        //    }
  1805.  
  1806.                 //        //    string Price = PriceLong.ToString();
  1807.                 //        //    Console.WriteLine("Price: " + Price);
  1808.                 //        //    data = GetData("fa_WantToCharge", 500, 1);
  1809.                 //        //    switch (Price.Length)
  1810.                 //        //    {
  1811.                 //        //        case 1:
  1812.                 //        //            key = CommonScript.SayOneDigitNumber(this, Price, false);
  1813.                 //        //            break;
  1814.                 //        //        case 2:
  1815.                 //        //            key = CommonScript.SayTwoDigitNumber(this, Price, false);
  1816.                 //        //            break;
  1817.                 //        //        case 3:
  1818.                 //        //            key = CommonScript.SayThreeDigitNumber(this, Price, false);
  1819.                 //        //            break;
  1820.                 //        //        case 4:
  1821.                 //        //            key = CommonScript.SayFourDigitNumber(this, Price, false);
  1822.                 //        //            break;
  1823.                 //        //        case 5:
  1824.                 //        //            key = CommonScript.SayFiveDigitNumber(this, Price, false);
  1825.                 //        //            break;
  1826.                 //        //        case 6:
  1827.                 //        //            key = CommonScript.SaySixDigitNumber(this, Price, false);
  1828.                 //        //            break;
  1829.                 //        //        case 7:
  1830.                 //        //            key = CommonScript.SaySevenDigitNumber(this, Price, false);
  1831.                 //        //            break;
  1832.                 //        //        default:
  1833.                 //        //            break;
  1834.                 //        //    }
  1835.                 //        //    data = GetData("fa_WantToCharge_Continue", 8000, 1);
  1836.                 //        //    if (data == "1") // Customer Want To Charge
  1837.                 //        //    {
  1838.                 //        //        counterPlaySound = 0;
  1839.                 //        //        rpeatSound = true;
  1840.                 //        //        while (counterPlaySound < 2 && rpeatSound)
  1841.                 //        //        {
  1842.                 //        //            Console.WriteLine("counter : " + counterPlaySound);
  1843.                 //        //            if (counterPlaySound == 0)
  1844.                 //        //                data = GetData("fa_GetMobileNumber1", 4000, 11);
  1845.                 //        //            else
  1846.                 //        //                data = GetData("fa_GetCorrectMobileNumber", 4000, 11);
  1847.                 //        //            counterPlaySound++;
  1848.                 //        //            if (!string.IsNullOrEmpty(data) && data.StartsWith("0"))
  1849.                 //        //                data = data.TrimStart("0".ToCharArray());
  1850.                 //        //            if (!string.IsNullOrEmpty(data) && data.Length > 10)
  1851.                 //        //                data = data.Substring(0, 10);
  1852.  
  1853.                 //        //            if (data.Length == 10)
  1854.                 //        //            {
  1855.                 //        //                rpeatSound = false;
  1856.                 //        //                mobileNumber = data;
  1857.                 //        //                try
  1858.                 //        //                {
  1859.                 //        //                    long pricelong = Convert.ToInt64(Price);
  1860.                 //        //                    IvrCharge qm = new IvrCharge
  1861.                 //        //                    {
  1862.                 //        //                        CustomerTel = callerId,
  1863.                 //        //                        Amount = pricelong,
  1864.                 //        //                        TariffCode = ServiceId,
  1865.                 //        //                        TariffName = serviceName,
  1866.                 //        //                        MobileNumber = mobileNumber
  1867.                 //        //                    };
  1868.  
  1869.                 //        //                    db.IvrCharges.Add(qm);
  1870.                 //        //                    db.SaveChanges();
  1871.                 //        //                    InsertId = qm.Id;
  1872.  
  1873.                 //        //                }
  1874.                 //        //                catch (Exception ex)
  1875.                 //        //                {
  1876.                 //        //                    Console.WriteLine("Erorr : " + ex.Message);
  1877.                 //        //                }
  1878.  
  1879.                 //        //                string pricelength = "";
  1880.                 //        //                // int IdLength = InsertId.ToString().Length;
  1881.                 //        //                string StoreCode = ConfigurationManager.AppSettings["StoreCode"];
  1882.                 //        //                string storcodeLen = "";
  1883.                 //        //                if (StoreCode.Length < 10)
  1884.                 //        //                    storcodeLen = "0" + StoreCode.Length.ToString();
  1885.                 //        //                else
  1886.                 //        //                    storcodeLen = StoreCode.Length.ToString();
  1887.  
  1888.                 //        //                if (Price.Length < 10)
  1889.                 //        //                    pricelength = "0" + Price.Length.ToString();
  1890.                 //        //                else
  1891.                 //        //                    pricelength = Price.Length.ToString();
  1892.  
  1893.                 //        //                try
  1894.                 //        //                {
  1895.                 //        //                    ManagerConnection manager = new ManagerConnection(
  1896.                 //        //                    ConfigurationManager.AppSettings["Asterisk.Manager.Ip"],
  1897.                 //        //                    int.Parse(ConfigurationManager.AppSettings["Asterisk.Manager.Port"]),
  1898.                 //        //                    ConfigurationManager.AppSettings["Asterisk.Manager.User"],
  1899.                 //        //                    ConfigurationManager.AppSettings["Asterisk.Manager.Secret"]);
  1900.                 //        //                    manager.Login();
  1901.                 //        //                    RedirectAction ra = new RedirectAction(request.Channel.ToString(), "Pecopayment", "2020" + storcodeLen + StoreCode + pricelength + Price + InsertId.ToString(), 1);
  1902.                 //        //                    GetData("fa_ConnectToBank", 1000);
  1903.                 //        //                    ManagerResponse rr = manager.SendAction(ra);
  1904.                 //        //                    manager.Logoff();
  1905.                 //        //                }
  1906.                 //        //                catch (Exception ex)
  1907.                 //        //                {
  1908.                 //        //                    Console.WriteLine("errrrrorrrr: " + ex.Message);
  1909.                 //        //                }
  1910.  
  1911.                 //        //            }
  1912.                 //        //        }
  1913.                 //        //    }
  1914.                 //        //}
  1915.                 //        //else
  1916.                 //        //{
  1917.                 //        //    data = GetData("fa_InActiveService", 500, 1);
  1918.                 //        //    StreamFile("fa_Final");
  1919.                 //        //    Hangup();
  1920.                 //        //    return;
  1921.                 //        //}
  1922.                 //    }
  1923.                 //    catch (Exception ex)
  1924.                 //    {
  1925.                 //        this.log(identifier, IvrLogTypes.Error, ex.Message);
  1926.                 //        GetData("fa_ErrorInConnection", 1000);
  1927.                 //    }
  1928.  
  1929.                 //}
  1930.                 //#endregion
  1931.                 #endregion
  1932.                 StreamFile("fa_Final");
  1933.                 Hangup();
  1934.                 return;
  1935.             }
  1936.  
  1937.         }
  1938.  
  1939.         public static int SendSMS(string result, string recipient)
  1940.         {
  1941.             string ServiceUse = ConfigurationManager.AppSettings["SmsServiceUsed"];
  1942.             Console.WriteLine("ServiceUse : " + ServiceUse);
  1943.             Console.WriteLine("recipient : " + recipient);
  1944.             if (ServiceUse == "Rightel")
  1945.             {
  1946.                 HttpWebRequest HTTP_Request = (HttpWebRequest)WebRequest.Create("http://91.229.215.222/service/sendsms.php?sim=" + recipient + "&text=" + result);
  1947.                 HTTP_Request.Method = "POST";
  1948.                 HTTP_Request.ContentType = "application/x-www-form-urlencoded";
  1949.                 //HTTP_Request.ContentLength = Data.Length;
  1950.  
  1951.                 Stream NewStream = HTTP_Request.GetRequestStream();
  1952.                 // NewStream.Write(Data, 0, Data.Length);
  1953.                 NewStream.Close();
  1954.  
  1955.                 WebResponse Response = HTTP_Request.GetResponse();
  1956.                 Stream ResponseStream = Response.GetResponseStream();
  1957.                 StreamReader ResponseReader = new StreamReader(ResponseStream);
  1958.                 return int.Parse(ResponseReader.ReadToEnd());
  1959.             }
  1960.             else if (ServiceUse == "Hostiran")
  1961.             {
  1962.                 Console.WriteLine("In Hostiran Block");
  1963.                 SmsService.SmsWebServicePortClient ic = new SmsService.SmsWebServicePortClient();
  1964.                 int SendResult = ic.send("goldnet1", "789654", "0" + recipient, result, "", 0);
  1965.                 return SendResult;
  1966.             }
  1967.             else
  1968.                 return 0;
  1969.         }
  1970.         //private void LoadConfigConnection()
  1971.         //{
  1972.  
  1973.         //    ServiceWrappers.Patner ar = new ServiceWrappers.Patner();
  1974.         //    string servers = ConfigurationManager.AppSettings["AgentReseller.WS.Server"];
  1975.         //    string username = ConfigurationManager.AppSettings["AgentReseller.WS.Username"];
  1976.         //    string password = ConfigurationManager.AppSettings["AgentReseller.WS.Password"];
  1977.         //    ServiceWrappers.ConnectionInfoCollection cIC = new ServiceWrappers.ConnectionInfoCollection();
  1978.         //    string[] allServers = servers.Split('*');
  1979.         //    for (int i = 0; i < allServers.Length; i++)
  1980.         //    {
  1981.         //        ServiceWrappers.ConnectionInfo tmpCInfo = new ServiceWrappers.ConnectionInfo("AgentReseller" /*+ i.ToString()*/, allServers[i], "-1", username, password);
  1982.         //        cIC.AddConnection(tmpCInfo);
  1983.         //    }
  1984.  
  1985.         //    ar.SetConnectionStrings(cIC);
  1986.         //}
  1987.  
  1988.         public static string GetEstelamService(string XMLStr)
  1989.         {
  1990.             XDocument doc = XDocument.Parse(XMLStr);
  1991.             var list = doc.Root.Elements("code").Select(element => element.Value).FirstOrDefault();
  1992.             return list;
  1993.  
  1994.         }
  1995.  
  1996.         //public static string GetInfoOfSpecialService(string XMLStr, string serviceName = "3 گیگ ترافیک مازاد")
  1997.         //{
  1998.  
  1999.         //    XDocument doc = XDocument.Parse(XMLStr);
  2000.  
  2001.         //    var list = doc.Root.Elements()
  2002.         //                       .Select(row => new MyServices(int.Parse(row.Element("service_id").Value),
  2003.         //                                              row.Element("service_name").Value,
  2004.         //                                              row.Element("service_price").Value,
  2005.         //                                              row.Element("service_credit").Value)).ToList();
  2006.  
  2007.         //    var foundItem = list.SingleOrDefault(item => item.ServiceName == serviceName);
  2008.         //    return foundItem.ServiceId + "*" + foundItem.ServicePrice + "*" + serviceName;
  2009.         //}
  2010.  
  2011.         static void DoSomething()
  2012.         {
  2013.             try
  2014.             {
  2015.                 try
  2016.                 {
  2017.                     var ic = new ResellerPanelService.ResellerPanelServiceClient(); // Main Server
  2018.                     //var ic = new ServiceReference1.ResellerPanelServiceClient(); // test server
  2019.                     Console.WriteLine("After new webserviceee");
  2020.                     ResellerId = ic.GetOwnerResellerCisco(callerId);
  2021.                     Console.WriteLine("After Get Data from WebService");
  2022.                 }
  2023.                 catch (ThreadAbortException)
  2024.                 {
  2025.  
  2026.                 }
  2027.             }
  2028.             catch (Exception ex)
  2029.             {
  2030.                 Console.WriteLine("error Service :" + ex.Message);
  2031.             }
  2032.         }
  2033.     }
  2034. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement