Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/ai avatar #6591

Open
wants to merge 4 commits into
base: DevelNUI
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/Tizen.AIAvatar/src/AIServices/Core/RestClient/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ namespace Tizen.AIAvatar
/// A class that provides methods to execute REST requests and handle responses.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class RestClient : IRestClient
public class RestClient : IRestClient, IDisposable
{
private readonly HttpClient _httpClient;
private bool _disposed = false;

/// <summary>
/// Initializes a new instance of the RestClient class with the specified HttpClient.
Expand All @@ -38,7 +39,7 @@ public class RestClient : IRestClient
[EditorBrowsable(EditorBrowsableState.Never)]
public RestClient(HttpClient httpClient)
{
_httpClient = httpClient;
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
}

/// <summary>
Expand Down Expand Up @@ -91,7 +92,24 @@ public async Task<RestResponse> ExecuteAsync(RestRequest request)
[EditorBrowsable(EditorBrowsableState.Never)]
public void Dispose()
{
_httpClient?.Dispose();
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Disposes of the resources used by the RestClient.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_httpClient.Dispose();
}
_disposed = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ public IRestClient GetClient(string endpoint)
{
if (!_clients.ContainsKey(endpoint))
{
var client = new RestClient(new HttpClient
{
BaseAddress = new Uri(endpoint)
});
var httpClient = new HttpClient { BaseAddress = new Uri(endpoint) };
var client = new RestClient(httpClient);
_clients[endpoint] = client;
}
return _clients[endpoint];
Expand Down
24 changes: 18 additions & 6 deletions src/Tizen.AIAvatar/src/Multimedia/Audio/AudioPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,13 @@ private void OnStateChanged(object sender, AudioPlayerChangedEventArgs state)
audioPlayback?.Prepare();
Log.Debug(LogTag, "Audio is playing.");
}
catch (NullReferenceException e)
catch (ArgumentNullException ex)
{
Log.Error(LogTag, $"NullReferenceException in Playing state: {e.Message}");
Log.Error(LogTag, $"ArgumentNullException in Playing state: {ex.Message}");
}
catch (InvalidOperationException ex)
{
Log.Error(LogTag, $"InvalidOperationException in Playing state: {ex.Message}");
}
catch (Exception e)
{
Expand All @@ -343,9 +347,13 @@ private void OnStateChanged(object sender, AudioPlayerChangedEventArgs state)

Log.Debug(LogTag, "Audio is paused.");
}
catch (NullReferenceException e)
catch (ArgumentNullException ex)
{
Log.Error(LogTag, $"ArgumentNullException in Paused state: {ex.Message}");
}
catch (InvalidOperationException ex)
{
Log.Error(LogTag, $"NullReferenceException in Paused state: {e.Message}");
Log.Error(LogTag, $"InvalidOperationException in Paused state: {ex.Message}");
}
catch (Exception e)
{
Expand All @@ -370,9 +378,13 @@ private void OnStateChanged(object sender, AudioPlayerChangedEventArgs state)

Log.Debug(LogTag, "Audio is stopped.");
}
catch (NullReferenceException e)
catch (ArgumentNullException ex)
{
Log.Error(LogTag, $"ArgumentNullException in Stopped/Finished state: {ex.Message}");
}
catch (InvalidOperationException ex)
{
Log.Error(LogTag, $"NullReferenceException in Stopped/Finished state: {e.Message}");
Log.Error(LogTag, $"InvalidOperationException in Stopped/Finished state: {ex.Message}");
}
catch (Exception e)
{
Expand Down
Loading