Exemplo n.º 1
0
        public void OnRecvData(string sHead, string sContent)
        {
            //decode message
            RRequest.OnReply(this, sHead, sContent);

            //mPendingRequests.IndexOfKey(callid)

            return;
        }
Exemplo n.º 2
0
        public static void OnReply(RClient host, string sHeader, string sContent)
        {
            //mPendingRequests.IndexOfKey(callid)

            //update mPendingRequests

            DateTime now = DateTime.Now;

            if (now.Hour == host.lastReportAt.Hour)
            {
                host.HourRecvCounter++;
                host.DayRecvCounter++;
                host.TotalRecvCounter++;
            }
            else
            {
                if (now.Day == host.lastReportAt.Day)
                {
                    host.HourRecvCounter = 0;
                    host.DayRecvCounter++;
                    host.TotalRecvCounter++;
                }
                else
                {
                    host.HourRecvCounter = 0;
                    host.DayRecvCounter  = 0;
                    host.TotalRecvCounter++;
                }
            }

            if ((sHeader == "ROUTEREQUEST") && (sContent.Length > 100))
            {
                List <string> Paras   = sContent.Split(',').ToList <string>();
                RRequest      request = host.mPendingRequests[Paras[0]];
                request.routeList.Clear();
                int iLoop = (Paras.Count - 3) / 5;
                for (int i = 0; i < iLoop; i++)
                {
                    availableRoutes ar = new availableRoutes();
                    ar.NAPName      = Paras[i * 5 + 3];
                    ar.SRC          = Paras[i * 5 + 4];
                    ar.DST          = Paras[i * 5 + 5];
                    ar.IfAlreadyTry = false;
                    ar.IfSuccess    = false;
                    ar.SuccessTime  = DateTime.MinValue;
                    ar.IP           = "123.456.78.9";
                    request.routeList.Add(ar);
                }
                request.Process_ROUTEREQUEST();
            }
            else //if ((sHeader == "ROUTEREQUEST") && (sContent.Length > 100))
            {
                //Log.Error("Unexpected reply");
            }
        }
Exemplo n.º 3
0
        void sendRequest(RRequest request)
        {
            if (client.IsConnected)
            {
                string sTrySend = @"<cmd>ROUTEREQUEST;" + request.CallID + @",60133878332,2228613803088967,ACECALL,202.96.74.13</cmd>";
                byte[] bData    = Encoding.ASCII.GetBytes(sTrySend);
                client.Send(bData);
            }



            //Log.Info("Send request[{0}]", request.CallID);
        }
Exemplo n.º 4
0
        protected override void OnWork()
        {
            lock (Locker)
            {
            }

            try
            {
                if (requestID >= this.mMaxCalls)
                {
                    SleepMS(1000);
                    return;
                }

                DateTime now = DateTime.Now;
                if (now.Hour == lastReportAt.Hour)
                {
                    this.HourCounter++;
                    this.DayCounter++;
                    this.TotalCounter++;
                }
                else
                {
                    if (now.Day == lastReportAt.Day)
                    {
                        this.HourCounter = 0;
                        this.DayCounter++;
                        this.TotalCounter++;
                    }
                    else
                    {
                        this.HourCounter = 0;
                        this.DayCounter  = 0;
                        this.TotalCounter++;
                    }
                }

                if (this.lastReportAt == DateTime.MinValue ||
                    this.lastReportAt.Hour != now.Hour)
                {
                    //Log.Info("Hourly report: [{0}]: hour:{1} day:{2} total:{3}", this.mID, this.HourCounter, this.DayCounter, this.TotalCounter);
                    this.lastReportAt = now;
                }

                requestID++;
                if (requestID <= 100)
                {
                    string call_id =
                        now.ToString("yyyyMMdd")
                        + ("00" + mID.ToString()).RightStr(2)
                        + ("00000000" + requestID.ToString()).RightStr(8);

                    //Console.WriteLine("callid is {0}", call_id);
                    Log.Write("callid is {0}", call_id);


                    RRequest request = new RRequest(this, call_id);
                    mPendingRequests.Add(request.CallID, request);
                    sendRequest(request);


                    int sleep = MyLib.Rand.RandomInt(1, 100);
                    SleepMS(sleep);
                    //
                }



                SleepMS(100);

                foreach (KeyValuePair <string, RRequest> kvp in mPendingRequests)
                {
                    //Console.WriteLine(kvp.Value);
                    //Console.WriteLine(kvp.Key);

                    foreach (availableRoutes araaa in kvp.Value.routeList)
                    {
                        TimeSpan ts = DateTime.Now - araaa.SuccessTime;
                        if ((araaa.IfSuccess == true) && (ts.TotalSeconds > 60))
                        {
                            string sTrySend = @"<cmd>CALLSTOP;" + kvp.Key + @"," + araaa.SRC + @"," + araaa.DST + @"," + araaa.NAPName + @",12.34.56.789" + @"," + araaa.SuccessTime.ToString("yyyy/MM/dd HH:mm") + @"," + araaa.SuccessTime.ToString("yyyy/MM/dd HH:mm") + @"," + DateTime.Now.ToString("yyyy/MM/dd HH:mm") + @"," + (int)ts.TotalSeconds + @"</cmd>";

                            byte[] bData = Encoding.ASCII.GetBytes(sTrySend);
                            client.Send(bData);
                            araaa.SuccessTime = DateTime.MaxValue;

                            //Console.WriteLine("{0} have success trying", octlaaa.CallID);
                            Log.Write("{0} have success trying", kvp.Key);
                            break;
                        }
                    }
                }   // end foreach
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }