Skip to content

Commit 890d960

Browse files
committed
Updated input param of SetRegion to take boolean
1 parent 8421405 commit 890d960

File tree

1 file changed

+61
-68
lines changed

1 file changed

+61
-68
lines changed

Call_Automation_GCCH/Call_Automation_GCCH/Controllers/CallAutomationEventsController.cs

Lines changed: 61 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,68 @@ public IActionResult HandleCallbacks([FromBody] CloudEvent[] cloudEvents)
166166
return Problem($"Error processing callbacks: {ex.Message}");
167167
}
168168
}
169+
/// <summary>
170+
/// Updates the IsArizona configuration and switches PMA endpoint accordingly
171+
/// </summary>
172+
/// <param name="isArizona">Boolean flag to determine which PMA endpoint to use</param>
173+
/// <returns>Action result indicating success or error</returns>
174+
[HttpPost("/setRegion")]
175+
[Tags("Region Configuration")]
176+
public IActionResult SetRegion(bool isArizona)
177+
{
178+
try
179+
{
180+
_logger.LogInformation($"Changing region configuration. IsArizona: {isArizona}");
181+
182+
// Get the current configuration section
183+
var configSection = HttpContext.RequestServices.GetRequiredService<IConfiguration>().GetSection("CommunicationSettings");
184+
185+
// Get the current endpoint being used to determine if an update is needed
186+
string currentEndpoint = _service.GetCurrentPmaEndpoint() ?? string.Empty;
187+
string newEndpoint = isArizona
188+
? configSection["PmaEndpointArizona"] ?? string.Empty
189+
: configSection["PmaEndpointTexas"] ?? string.Empty;
190+
191+
// Check if new endpoint is empty
192+
if (string.IsNullOrEmpty(newEndpoint))
193+
{
194+
_logger.LogWarning($"The {(isArizona ? "PmaEndpointArizona" : "PmaEndpointTexas")} setting is empty");
195+
}
196+
197+
// Only update if the endpoint would actually change
198+
if (currentEndpoint == newEndpoint)
199+
{
200+
if (string.IsNullOrEmpty(currentEndpoint))
201+
{
202+
return Ok($"Configuration unchanged as the endpoints are empty");
203+
}
204+
else
205+
{
206+
return Ok($"Configuration unchanged. Already using {(isArizona ? "Arizona" : "Texas")} region.");
207+
}
208+
}
169209

210+
// Update the IsArizona setting in memory
211+
((IConfigurationSection)configSection.GetSection("IsArizona")).Value = isArizona.ToString();
212+
213+
// Update the client with the new endpoint
214+
var connectionString = configSection["AcsConnectionString"] ?? string.Empty;
215+
if (string.IsNullOrEmpty(connectionString))
216+
{
217+
_logger.LogError("AcsConnectionString is empty");
218+
return Problem("AcsConnectionString is empty");
219+
}
220+
221+
_service.UpdateClient(connectionString, newEndpoint);
222+
223+
return Ok($"Region updated successfully to {(isArizona ? "Arizona" : "Texas")}.");
224+
}
225+
catch (Exception ex)
226+
{
227+
_logger.LogError($"Error updating region configuration: {ex.Message}");
228+
return Problem($"Failed to update region configuration: {ex.Message}");
229+
}
230+
}
170231
/// <summary>
171232
/// Processes individual call automation events
172233
/// </summary>
@@ -381,74 +442,6 @@ private void ProcessCallEvent(CallAutomationEventBase parsedEvent)
381442
_logger.LogInformation($"Recording State: {recordingStateChanged.State}");
382443
}
383444
}
384-
385-
/// <summary>
386-
/// Updates the IsArizona configuration and switches PMA endpoint accordingly
387-
/// </summary>
388-
/// <param name="isArizona">Boolean flag to determine which PMA endpoint to use</param>
389-
/// <returns>Action result indicating success or error</returns>
390-
[HttpPost("setRegion")]
391-
public IActionResult SetRegion([FromBody] RegionConfigRequest request)
392-
{
393-
try
394-
{
395-
_logger.LogInformation($"Changing region configuration. IsArizona: {request.IsArizona}");
396-
397-
// Get the current configuration section
398-
var configSection = HttpContext.RequestServices.GetRequiredService<IConfiguration>().GetSection("CommunicationSettings");
399-
400-
// Get the current endpoint being used to determine if an update is needed
401-
string currentEndpoint = _service.GetCurrentPmaEndpoint() ?? string.Empty;
402-
string newEndpoint = request.IsArizona
403-
? configSection["PmaEndpointArizona"] ?? string.Empty
404-
: configSection["PmaEndpointTexas"] ?? string.Empty;
405-
406-
// Check if new endpoint is empty
407-
if (string.IsNullOrEmpty(newEndpoint))
408-
{
409-
_logger.LogWarning($"The {(request.IsArizona ? "PmaEndpointArizona" : "PmaEndpointTexas")} setting is empty");
410-
}
411-
412-
// Only update if the endpoint would actually change
413-
if (currentEndpoint == newEndpoint)
414-
{
415-
if(string.IsNullOrEmpty(currentEndpoint))
416-
{
417-
return Ok($"Configuration unchanged as the endpoints are empty");
418-
}
419-
else
420-
{
421-
return Ok($"Configuration unchanged. Already using {(request.IsArizona ? "Arizona" : "Texas")} region.");
422-
}
423-
}
424-
425-
// Update the IsArizona setting in memory
426-
((IConfigurationSection)configSection.GetSection("IsArizona")).Value = request.IsArizona.ToString();
427-
428-
// Update the client with the new endpoint
429-
var connectionString = configSection["AcsConnectionString"] ?? string.Empty;
430-
if (string.IsNullOrEmpty(connectionString))
431-
{
432-
_logger.LogError("AcsConnectionString is empty");
433-
return Problem("AcsConnectionString is empty");
434-
}
435-
436-
_service.UpdateClient(connectionString, newEndpoint);
437-
438-
return Ok($"Region updated successfully to {(request.IsArizona ? "Arizona" : "Texas")}.");
439-
}
440-
catch (Exception ex)
441-
{
442-
_logger.LogError($"Error updating region configuration: {ex.Message}");
443-
return Problem($"Failed to update region configuration: {ex.Message}");
444-
}
445-
}
446-
447-
// Request model for setting the region
448-
public class RegionConfigRequest
449-
{
450-
public bool IsArizona { get; set; }
451-
}
452445
}
453446
}
454447

0 commit comments

Comments
 (0)