Exemplo n.º 1
0
 /// <summary>
 /// 获取历史呼叫
 /// </summary>
 /// <param name="callback"></param>
 public void GetHistoryCalls(Action <IEnumerable <QLCall> > callback)
 {
     if (null != callback)
     {
         var calls   = new List <QLCall>();
         var dicPath = Path.Combine(Application.StartupPath, "History");
         if (!Directory.Exists(dicPath))
         {
             Directory.CreateDirectory(dicPath);
         }
         var filePath = Path.Combine(dicPath, string.Format("history_{0}.log", qlConfig.GetProperty(PropertyKey.PLCM_MFW_KVLIST_KEY_SIP_UserName)));
         if (File.Exists(filePath))
         {
             using (var fs = new FileStream(filePath, FileMode.Open))
             {
                 using (var sr = new StreamReader(fs))
                 {
                     var str = sr.ReadToEnd();
                     if (!string.IsNullOrWhiteSpace(str))
                     {
                         calls = SerializerUtil.DeSerializeJson <List <QLCall> >(str);
                     }
                 }
             }
         }
         calls.AddRange(this._callList);
         callback.Invoke(calls);
     }
 }
Exemplo n.º 2
0
        private static HttpResullt <T> HttpsPost(string uri, object data)
        {
            try
            {
                logger.Debug(string.Format("HttpsPost({0},{1})", uri, SerializerUtil.SerializeJson(data)));
                //HTTPSQ请求
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var req = WebRequest.Create(uri) as HttpWebRequest;
                req.Method      = "POST";
                req.ContentType = "application/json";

                var message = string.Empty;
                if (null != data)
                {
                    message = SerializerUtil.SerializeJson(data);
                }
                byte[] sendBytes = Encoding.GetEncoding("utf-8").GetBytes(message);
                req.ContentLength = sendBytes.Length;
                using (var stream = req.GetRequestStream())
                {
                    stream.Write(sendBytes, 0, sendBytes.Length);
                }

                using (var respStream = req.GetResponse().GetResponseStream())
                {
                    using (var reader = new StreamReader(respStream))
                    {
                        var responseData = reader.ReadToEnd();
                        logger.Info(string.Format("HttpsPost End: {0}", responseData));
                        return(SerializerUtil.DeSerializeJson <HttpResullt <T> >(responseData));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("HttpsPost异常,ex:" + ex.Message);
                throw ex;
            }
        }
Exemplo n.º 3
0
        public static HttpResullt <T> HttpPost(string url, object data)
        {
            try
            {
                logger.Debug(string.Format("HttpPost({0},{1})", url, SerializerUtil.SerializeJson(data)));

                Encoding       myEncode = Encoding.GetEncoding("UTF-8");
                HttpWebRequest req      = (HttpWebRequest)HttpWebRequest.Create(url);
                req.Method      = "POST";
                req.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";

                var message = string.Empty;
                if (null != data)
                {
                    message = SerializerUtil.SerializeJson(data);
                }
                byte[] sendBytes = Encoding.GetEncoding("utf-8").GetBytes(message);
                req.ContentLength = sendBytes.Length;
                using (var stream = req.GetRequestStream())
                {
                    stream.Write(sendBytes, 0, sendBytes.Length);
                }
                using (WebResponse res = req.GetResponse())
                {
                    using (StreamReader sr = new StreamReader(res.GetResponseStream(), myEncode))
                    {
                        string strResult = sr.ReadToEnd();
                        logger.Info(string.Format("HttpPost End: {0}", strResult));
                        return(SerializerUtil.DeSerializeJson <HttpResullt <T> >(strResult));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("HttpsPost异常,ex:" + ex.Message);
                throw ex;
            }
        }
Exemplo n.º 4
0
 public void Dispose()
 {
     if (_callList.Count > 0)
     {
         #region 结束呼叫
         //保存通话记录
         foreach (var call in _callList)
         {
             if (!call.IsActive())
             {
                 PlcmProxy.TerminateCall(call.CallHandle);
                 call.StopTime  = DateTime.Now;
                 call.CallState = CallState.SIP_CALL_CLOSED;
                 call.Reason    = "关闭程序,结束通话";
             }
         }
         #endregion
         #region 保存呼叫
         GetHistoryCalls((calls) =>
         {
             var dicPath = Path.Combine(Application.StartupPath, "History");
             if (!Directory.Exists(dicPath))
             {
                 Directory.CreateDirectory(dicPath);
             }
             var filePath = Path.Combine(dicPath, string.Format("history_{0}.log", qlConfig.GetProperty(PropertyKey.PLCM_MFW_KVLIST_KEY_SIP_UserName)));
             using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
             {
                 using (var sw = new StreamWriter(fs))
                 {
                     var str = SerializerUtil.SerializeJson(calls);
                     sw.Write(str);
                 }
             }
         });
         #endregion
     }
 }