TEXT 61
Api call devicemonitor Reza Guest on 24th December 2024 09:50:36 AM
  1. SendWisperApi("cleared", e.DeviceNumber); ---call establish
  2.  
  3.  
  4. ------ api function
  5. static void SendWisperApi(string state, string agent_number)
  6. {
  7.     try
  8.     {
  9.         string url = String.Format("/Home/CallMonitorApi");
  10.  
  11.         var client = new RestClient(System.Configuration.ConfigurationManager.AppSettings["iisserver"].ToString());
  12.         var request = new RestRequest(url, Method.Post);
  13.  
  14.  
  15.  
  16.         request.AddParameter("state", state);
  17.         request.AddParameter("agent_number", agent_number);
  18.         RestResponse response = client.Execute(request);
  19.  
  20.  
  21.  
  22.         if (response.IsSuccessStatusCode)
  23.         {
  24.             // Request was successful
  25.             string responseContent = response.Content;
  26.             WriteLog(String.Format($"send wisper established ok agent number{agent_number}"));
  27.         }
  28.         else
  29.         {
  30.             // Request failed
  31.             WriteLog("API request failed with status code: " + response.StatusCode);
  32.         }
  33.     }
  34.  
  35.     catch (Exception ex)
  36.     {
  37.         WriteLog("Failed and got error: " + ex.Message);
  38.     }
  39. }
  40.  
  41. --- loging function
  42.  
  43. public static void WriteLog(string logMessage, bool addTimeStamp = true)
  44. {
  45.     var path = AppDomain.CurrentDomain.BaseDirectory;
  46.     if (!Directory.Exists(path))
  47.         Directory.CreateDirectory(path);
  48.  
  49.     var filePath = String.Format("{0}\\callmonitor_log\\myservice_{1}.txt",
  50.         path,
  51.         DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.CurrentCulture)
  52.         );
  53.  
  54.     if (addTimeStamp)
  55.         logMessage = String.Format("[{0}] - {1}\r\n",
  56.             DateTime.Now.ToString("HH:mm:ss", CultureInfo.CurrentCulture),
  57.             logMessage);
  58.  
  59.     File.AppendAllText(filePath, logMessage);
  60. }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.