- public void device_CallEstablished(object sender, CallEstablishedEventArgs e)
- {
- // Assuming you can retrieve ANI and National Code using DeviceNumber from the database
- string deviceNumber = e.DeviceNumber;
- // Query your database to get ANI and NationalCode based on DeviceNumber
- string ani = GetAniFromDatabase(deviceNumber); // You'll implement this method
- string nationalCode = GetNationalCodeFromDatabase(deviceNumber); // You'll implement this method
- // Now you have all the data to send in the API call
- SendCallInformationApi(ani, nationalCode, deviceNumber);
- // If CallEstablished events need to be displayed in a UI list view:
- if (menuEventsCallEstablished.Checked)
- {
- // Prepare event arguments for the list view
- CallEventsListViewEventArgs args = new CallEventsListViewEventArgs(
- sender as Device,
- EVENT_NAME_CALL_ESTABLISHED,
- e.EventTime,
- string.Empty,
- e.DeviceNumber,
- string.Empty,
- string.Empty,
- string.Empty
- );
- // Update the CallEventsListView (if necessary)
- UpdateCallEventsListViewWrapper(sender as Device, args);
- // Optionally handle database operations
- dbContext dal = new dbContext();
- DeviceNumberModel model = new DeviceNumberModel
- {
- DeviceNumber = e.ConnectedDevice.DeviceNumber
- };
- dal.GetDeviceNumber(model);
- }
- }
- // Example method to get ANI from the database
- public string GetAniFromDatabase(string deviceNumber)
- {
- // This is a placeholder; implement the actual database query
- // For example, using Entity Framework or ADO.NET:
- dbContext dal = new dbContext();
- var record = dal.CollectDigit.FirstOrDefault(c => c.DeviceNumber == deviceNumber);
- return record?.Ani; // Return the ANI or handle null cases
- }
- // Example method to get NationalCode from the database
- public string GetNationalCodeFromDatabase(string deviceNumber)
- {
- // This is a placeholder; implement the actual database query
- dbContext dal = new dbContext();
- var record = dal.CollectDigit.FirstOrDefault(c => c.DeviceNumber == deviceNumber);
- return record?.NationalCode; // Return the NationalCode or handle null cases
- }
- // API call method (no changes here)
- public static void SendCallInformationApi(string ani, string nationalCode, string deviceNumber)
- {
- try
- {
- // FastAPI URL endpoint
- string baseUrl = "http://192.168.0.133:8080/items/"; // Replace with your actual FastAPI endpoint
- // Initialize RestClient and RestRequest
- var client = new RestClient(baseUrl);
- var request = new RestRequest(); // FastAPI expects a GET request
- request.Method = Method.Get;
- // Add the necessary parameters to the request
- request.AddParameter("Ani", ani);
- request.AddParameter("NationalCode", nationalCode);
- request.AddParameter("DeviceNumber", deviceNumber);
- // Execute the API request synchronously
- RestResponse response = client.Execute(request);
- // If the response is not successful, handle it silently or throw an exception
- if (!response.IsSuccessStatusCode)
- {
- throw new Exception($"API call failed with status: {response.StatusCode}");
- }
- }
- catch (Exception)
- {
- // Silently catch errors (no logging or throw if needed)
- }
- }
Recent Pastes