Skip to content

Commit

Permalink
Set Session
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Jul 31, 2023
1 parent 8913a04 commit e309334
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/FishyFlip/ATProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public ATProtocol(ATProtocolOptions options)
this.client = options.HttpClient ?? throw new NullReferenceException(nameof(options.HttpClient));
this.webSocketProtocol = new ATWebSocketProtocol(this);
this.webSocketProtocol.OnConnectionUpdated += this.WebSocketProtocolOnConnectionUpdated;
this.sessionManager = new SessionManager(this);
if (options.Session is not null)
{
this.sessionManager = new SessionManager(this, options.Session);
}
else
{
this.sessionManager = new SessionManager(this);
}
}

/// <summary>
Expand All @@ -39,6 +46,11 @@ public ATProtocol(ATProtocolOptions options)
/// </summary>
public event EventHandler<SubscriptionConnectionStatusEventArgs>? OnConnectionUpdated;

/// <summary>
/// Event for when a session is updated.
/// </summary>
public event EventHandler<SessionUpdatedEventArgs>? OnSessionUpdated;

/// <summary>
/// Gets the ATProtocol Options.
/// </summary>
Expand Down Expand Up @@ -207,20 +219,21 @@ internal void OnUserLoggedIn(Session session)
{
if (this.sessionManager is null)
{
this.sessionManager = new SessionManager(this, session);
}
else
{
this.sessionManager.SetSession(session);
this.sessionManager = new SessionManager(this);
}

this.SetSession(session);
}

/// <summary>
/// Sets the current session.
/// </summary>
/// <param name="session"><see cref="Session"/>.</param>
internal void SetSession(Session session)
=> this.sessionManager?.SetSession(session);
{
this.sessionManager?.SetSession(session);
this.OnSessionUpdated?.Invoke(this, new SessionUpdatedEventArgs(session, this.BaseAddress));
}

private void Dispose(bool disposing)
{
Expand Down
33 changes: 33 additions & 0 deletions src/FishyFlip/Events/SessionUpdatedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <copyright file="SessionUpdatedEventArgs.cs" company="Drastic Actions">
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

namespace FishyFlip.Events;

/// <summary>
/// Session Updated Event Args.
/// Fires when a session updates.
/// </summary>
public class SessionUpdatedEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="SessionUpdatedEventArgs"/> class.
/// </summary>
/// <param name="session"><see cref="Session"/>.</param>
/// <param name="uri">The Instance Uri.</param>
public SessionUpdatedEventArgs(Session session, Uri? uri)
{
this.Session = session;
this.InstanceUri = uri;
}

/// <summary>
/// Gets the Session.
/// </summary>
public Session Session { get; }

/// <summary>
/// Gets the Instance Uri.
/// </summary>
public Uri? InstanceUri { get; }
}

0 comments on commit e309334

Please sign in to comment.