TEXT 52
Untitled Guest on 25th December 2024 07:59:41 AM
  1. public void device_CallEstablished(object sender, CallEstablishedEventArgs e)
  2. {
  3.     // Assuming you can retrieve ANI and National Code using DeviceNumber from the database
  4.     string deviceNumber = e.DeviceNumber;
  5.  
  6.     // Query your database to get ANI and NationalCode based on DeviceNumber
  7.     string ani = GetAniFromDatabase(deviceNumber);  // You'll implement this method
  8.     string nationalCode = GetNationalCodeFromDatabase(deviceNumber);  // You'll implement this method
  9.  
  10.     // Now you have all the data to send in the API call
  11.     SendCallInformationApi(ani, nationalCode, deviceNumber);
  12.  
  13.     // If CallEstablished events need to be displayed in a UI list view:
  14.     if (menuEventsCallEstablished.Checked)
  15.     {
  16.         // Prepare event arguments for the list view
  17.         CallEventsListViewEventArgs args = new CallEventsListViewEventArgs(
  18.             sender as Device,
  19.             EVENT_NAME_CALL_ESTABLISHED,
  20.             e.EventTime,
  21.             string.Empty,
  22.             e.DeviceNumber,
  23.             string.Empty,
  24.             string.Empty,
  25.             string.Empty
  26.         );
  27.  
  28.         // Update the CallEventsListView (if necessary)
  29.         UpdateCallEventsListViewWrapper(sender as Device, args);
  30.  
  31.         // Optionally handle database operations
  32.         dbContext dal = new dbContext();
  33.         DeviceNumberModel model = new DeviceNumberModel
  34.         {
  35.             DeviceNumber = e.ConnectedDevice.DeviceNumber
  36.         };
  37.         dal.GetDeviceNumber(model);
  38.     }
  39. }
  40.  
  41. // Example method to get ANI from the database
  42. public string GetAniFromDatabase(string deviceNumber)
  43. {
  44.     // This is a placeholder; implement the actual database query
  45.     // For example, using Entity Framework or ADO.NET:
  46.     dbContext dal = new dbContext();
  47.     var record = dal.CollectDigit.FirstOrDefault(c => c.DeviceNumber == deviceNumber);
  48.     return record?.Ani;  // Return the ANI or handle null cases
  49. }
  50.  
  51. // Example method to get NationalCode from the database
  52. public string GetNationalCodeFromDatabase(string deviceNumber)
  53. {
  54.     // This is a placeholder; implement the actual database query
  55.     dbContext dal = new dbContext();
  56.     var record = dal.CollectDigit.FirstOrDefault(c => c.DeviceNumber == deviceNumber);
  57.     return record?.NationalCode;  // Return the NationalCode or handle null cases
  58. }
  59.  
  60. // API call method (no changes here)
  61. public static void SendCallInformationApi(string ani, string nationalCode, string deviceNumber)
  62. {
  63.     try
  64.     {
  65.         // FastAPI URL endpoint
  66.         string baseUrl = "http://192.168.0.133:8080/items/"; // Replace with your actual FastAPI endpoint
  67.  
  68.         // Initialize RestClient and RestRequest
  69.         var client = new RestClient(baseUrl);
  70.         var request = new RestRequest(); // FastAPI expects a GET request
  71.         request.Method = Method.Get;
  72.  
  73.         // Add the necessary parameters to the request
  74.         request.AddParameter("Ani", ani);
  75.         request.AddParameter("NationalCode", nationalCode);
  76.         request.AddParameter("DeviceNumber", deviceNumber);
  77.  
  78.         // Execute the API request synchronously
  79.         RestResponse response = client.Execute(request);
  80.  
  81.         // If the response is not successful, handle it silently or throw an exception
  82.         if (!response.IsSuccessStatusCode)
  83.         {
  84.             throw new Exception($"API call failed with status: {response.StatusCode}");
  85.         }
  86.     }
  87.     catch (Exception)
  88.     {
  89.         // Silently catch errors (no logging or throw if needed)
  90.     }
  91. }

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.