diff options
| author | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
|---|---|---|
| committer | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
| commit | 48facb797ed912e4ea6b04b17d1ff190ac2daac4 (patch) | |
| tree | 8dae77a31670a888d733484cb17dd4077d5444e8 /MediaBrowser.Controller/Session | |
| parent | c32d8656382a0eacb301692e0084377fc433ae9b (diff) | |
Update to 3.5.2 and .net core 2.1
Diffstat (limited to 'MediaBrowser.Controller/Session')
| -rw-r--r-- | MediaBrowser.Controller/Session/AuthenticationRequest.cs | 17 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Session/ISessionController.cs | 121 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Session/ISessionControllerFactory.cs | 16 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Session/ISessionManager.cs | 336 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Session/SessionEventArgs.cs | 9 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Session/SessionInfo.cs | 309 |
6 files changed, 0 insertions, 808 deletions
diff --git a/MediaBrowser.Controller/Session/AuthenticationRequest.cs b/MediaBrowser.Controller/Session/AuthenticationRequest.cs deleted file mode 100644 index 1b684fa8f..000000000 --- a/MediaBrowser.Controller/Session/AuthenticationRequest.cs +++ /dev/null @@ -1,17 +0,0 @@ - -namespace MediaBrowser.Controller.Session -{ - public class AuthenticationRequest - { - public string Username { get; set; } - public string UserId { get; set; } - public string Password { get; set; } - public string PasswordSha1 { get; set; } - public string PasswordMd5 { get; set; } - public string App { get; set; } - public string AppVersion { get; set; } - public string DeviceId { get; set; } - public string DeviceName { get; set; } - public string RemoteEndPoint { get; set; } - } -} diff --git a/MediaBrowser.Controller/Session/ISessionController.cs b/MediaBrowser.Controller/Session/ISessionController.cs deleted file mode 100644 index 0d8c207b6..000000000 --- a/MediaBrowser.Controller/Session/ISessionController.cs +++ /dev/null @@ -1,121 +0,0 @@ -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Session; -using MediaBrowser.Model.System; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Controller.Session -{ - public interface ISessionController - { - /// <summary> - /// Gets a value indicating whether this instance is session active. - /// </summary> - /// <value><c>true</c> if this instance is session active; otherwise, <c>false</c>.</value> - bool IsSessionActive { get; } - - /// <summary> - /// Gets a value indicating whether [supports media remote control]. - /// </summary> - /// <value><c>true</c> if [supports media remote control]; otherwise, <c>false</c>.</value> - bool SupportsMediaControl { get; } - - /// <summary> - /// Sends the play command. - /// </summary> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendPlayCommand(PlayRequest command, CancellationToken cancellationToken); - - /// <summary> - /// Sends the playstate command. - /// </summary> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken); - - /// <summary> - /// Sends the generic command. - /// </summary> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken); - - /// <summary> - /// Sends the library update info. - /// </summary> - /// <param name="info">The info.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendLibraryUpdateInfo(LibraryUpdateInfo info, CancellationToken cancellationToken); - - /// <summary> - /// Sends the restart required message. - /// </summary> - Task SendRestartRequiredNotification(CancellationToken cancellationToken); - - /// <summary> - /// Sends the user data change info. - /// </summary> - /// <param name="info">The info.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendUserDataChangeInfo(UserDataChangeInfo info, CancellationToken cancellationToken); - - /// <summary> - /// Sends the server shutdown notification. - /// </summary> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendServerShutdownNotification(CancellationToken cancellationToken); - - /// <summary> - /// Sends the session ended notification. - /// </summary> - /// <param name="sessionInfo">The session information.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendSessionEndedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken); - - /// <summary> - /// Sends the playback start notification. - /// </summary> - /// <param name="sessionInfo">The session information.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendPlaybackStartNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken); - - /// <summary> - /// Sends the playback start notification. - /// </summary> - /// <param name="sessionInfo">The session information.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendPlaybackStoppedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken); - - /// <summary> - /// Sends the server restart notification. - /// </summary> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendServerRestartNotification(CancellationToken cancellationToken); - - /// <summary> - /// Sends the message. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="name">The name.</param> - /// <param name="data">The data.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendMessage<T>(string name, T data, CancellationToken cancellationToken); - - /// <summary> - /// Called when [activity]. - /// </summary> - void OnActivity(); - } -} diff --git a/MediaBrowser.Controller/Session/ISessionControllerFactory.cs b/MediaBrowser.Controller/Session/ISessionControllerFactory.cs deleted file mode 100644 index 92862e462..000000000 --- a/MediaBrowser.Controller/Session/ISessionControllerFactory.cs +++ /dev/null @@ -1,16 +0,0 @@ - -namespace MediaBrowser.Controller.Session -{ - /// <summary> - /// Interface ISesssionControllerFactory - /// </summary> - public interface ISessionControllerFactory - { - /// <summary> - /// Gets the session controller. - /// </summary> - /// <param name="session">The session.</param> - /// <returns>ISessionController.</returns> - ISessionController GetSessionController(SessionInfo session); - } -} diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs deleted file mode 100644 index 603e5ef76..000000000 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ /dev/null @@ -1,336 +0,0 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Security; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Session; -using MediaBrowser.Model.Users; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Controller.Session -{ - /// <summary> - /// Interface ISessionManager - /// </summary> - public interface ISessionManager - { - /// <summary> - /// Occurs when [playback start]. - /// </summary> - event EventHandler<PlaybackProgressEventArgs> PlaybackStart; - - /// <summary> - /// Occurs when [playback progress]. - /// </summary> - event EventHandler<PlaybackProgressEventArgs> PlaybackProgress; - - /// <summary> - /// Occurs when [playback stopped]. - /// </summary> - event EventHandler<PlaybackStopEventArgs> PlaybackStopped; - - /// <summary> - /// Occurs when [session started]. - /// </summary> - event EventHandler<SessionEventArgs> SessionStarted; - - /// <summary> - /// Occurs when [session ended]. - /// </summary> - event EventHandler<SessionEventArgs> SessionEnded; - - event EventHandler<SessionEventArgs> SessionActivity; - - /// <summary> - /// Occurs when [capabilities changed]. - /// </summary> - event EventHandler<SessionEventArgs> CapabilitiesChanged; - - /// <summary> - /// Occurs when [authentication failed]. - /// </summary> - event EventHandler<GenericEventArgs<AuthenticationRequest>> AuthenticationFailed; - - /// <summary> - /// Occurs when [authentication succeeded]. - /// </summary> - event EventHandler<GenericEventArgs<AuthenticationRequest>> AuthenticationSucceeded; - - /// <summary> - /// Gets the sessions. - /// </summary> - /// <value>The sessions.</value> - IEnumerable<SessionInfo> Sessions { get; } - - /// <summary> - /// Adds the parts. - /// </summary> - /// <param name="sessionFactories">The session factories.</param> - void AddParts(IEnumerable<ISessionControllerFactory> sessionFactories); - - /// <summary> - /// Logs the user activity. - /// </summary> - /// <param name="appName">Type of the client.</param> - /// <param name="appVersion">The app version.</param> - /// <param name="deviceId">The device id.</param> - /// <param name="deviceName">Name of the device.</param> - /// <param name="remoteEndPoint">The remote end point.</param> - /// <param name="user">The user.</param> - /// <returns>Task.</returns> - /// <exception cref="System.ArgumentNullException">user</exception> - Task<SessionInfo> LogSessionActivity(string appName, string appVersion, string deviceId, string deviceName, string remoteEndPoint, User user); - - /// <summary> - /// Used to report that playback has started for an item - /// </summary> - /// <param name="info">The info.</param> - /// <returns>Task.</returns> - Task OnPlaybackStart(PlaybackStartInfo info); - - /// <summary> - /// Used to report playback progress for an item - /// </summary> - /// <param name="info">The info.</param> - /// <returns>Task.</returns> - /// <exception cref="System.ArgumentNullException"></exception> - Task OnPlaybackProgress(PlaybackProgressInfo info); - - Task OnPlaybackProgress(PlaybackProgressInfo info, bool isAutomated); - - /// <summary> - /// Used to report that playback has ended for an item - /// </summary> - /// <param name="info">The info.</param> - /// <returns>Task.</returns> - /// <exception cref="System.ArgumentNullException"></exception> - Task OnPlaybackStopped(PlaybackStopInfo info); - - /// <summary> - /// Reports the session ended. - /// </summary> - /// <param name="sessionId">The session identifier.</param> - /// <returns>Task.</returns> - void ReportSessionEnded(string sessionId); - - /// <summary> - /// Gets the session info dto. - /// </summary> - /// <param name="session">The session.</param> - /// <returns>SessionInfoDto.</returns> - SessionInfoDto GetSessionInfoDto(SessionInfo session); - - /// <summary> - /// Sends the general command. - /// </summary> - /// <param name="controllingSessionId">The controlling session identifier.</param> - /// <param name="sessionId">The session identifier.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendGeneralCommand(string controllingSessionId, string sessionId, GeneralCommand command, CancellationToken cancellationToken); - - /// <summary> - /// Sends the message command. - /// </summary> - /// <param name="controllingSessionId">The controlling session identifier.</param> - /// <param name="sessionId">The session id.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendMessageCommand(string controllingSessionId, string sessionId, MessageCommand command, CancellationToken cancellationToken); - - /// <summary> - /// Sends the play command. - /// </summary> - /// <param name="controllingSessionId">The controlling session identifier.</param> - /// <param name="sessionId">The session id.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendPlayCommand(string controllingSessionId, string sessionId, PlayRequest command, CancellationToken cancellationToken); - - /// <summary> - /// Sends the browse command. - /// </summary> - /// <param name="controllingSessionId">The controlling session identifier.</param> - /// <param name="sessionId">The session id.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendBrowseCommand(string controllingSessionId, string sessionId, BrowseRequest command, CancellationToken cancellationToken); - - /// <summary> - /// Sends the playstate command. - /// </summary> - /// <param name="controllingSessionId">The controlling session identifier.</param> - /// <param name="sessionId">The session id.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendPlaystateCommand(string controllingSessionId, string sessionId, PlaystateRequest command, CancellationToken cancellationToken); - - /// <summary> - /// Sends the message to admin sessions. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="name">The name.</param> - /// <param name="data">The data.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendMessageToAdminSessions<T>(string name, T data, CancellationToken cancellationToken); - - /// <summary> - /// Sends the message to user sessions. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns>Task.</returns> - Task SendMessageToUserSessions<T>(List<string> userIds, string name, T data, CancellationToken cancellationToken); - - /// <summary> - /// Sends the message to user device sessions. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="deviceId">The device identifier.</param> - /// <param name="name">The name.</param> - /// <param name="data">The data.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendMessageToUserDeviceSessions<T>(string deviceId, string name, T data, - CancellationToken cancellationToken); - - /// <summary> - /// Sends the restart required message. - /// </summary> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendRestartRequiredNotification(CancellationToken cancellationToken); - - /// <summary> - /// Sends the server shutdown notification. - /// </summary> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendServerShutdownNotification(CancellationToken cancellationToken); - - /// <summary> - /// Sends the server restart notification. - /// </summary> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendServerRestartNotification(CancellationToken cancellationToken); - - /// <summary> - /// Adds the additional user. - /// </summary> - /// <param name="sessionId">The session identifier.</param> - /// <param name="userId">The user identifier.</param> - void AddAdditionalUser(string sessionId, string userId); - - /// <summary> - /// Removes the additional user. - /// </summary> - /// <param name="sessionId">The session identifier.</param> - /// <param name="userId">The user identifier.</param> - void RemoveAdditionalUser(string sessionId, string userId); - - /// <summary> - /// Reports the now viewing item. - /// </summary> - /// <param name="sessionId">The session identifier.</param> - /// <param name="itemId">The item identifier.</param> - void ReportNowViewingItem(string sessionId, string itemId); - - /// <summary> - /// Reports the now viewing item. - /// </summary> - /// <param name="sessionId">The session identifier.</param> - /// <param name="item">The item.</param> - void ReportNowViewingItem(string sessionId, BaseItemDto item); - - /// <summary> - /// Authenticates the new session. - /// </summary> - /// <param name="request">The request.</param> - /// <returns>Task{SessionInfo}.</returns> - Task<AuthenticationResult> AuthenticateNewSession(AuthenticationRequest request); - - /// <summary> - /// Creates the new session. - /// </summary> - /// <param name="request">The request.</param> - /// <returns>Task<AuthenticationResult>.</returns> - Task<AuthenticationResult> CreateNewSession(AuthenticationRequest request); - - /// <summary> - /// Reports the capabilities. - /// </summary> - /// <param name="sessionId">The session identifier.</param> - /// <param name="capabilities">The capabilities.</param> - void ReportCapabilities(string sessionId, ClientCapabilities capabilities); - - /// <summary> - /// Reports the transcoding information. - /// </summary> - /// <param name="deviceId">The device identifier.</param> - /// <param name="info">The information.</param> - void ReportTranscodingInfo(string deviceId, TranscodingInfo info); - - /// <summary> - /// Clears the transcoding information. - /// </summary> - /// <param name="deviceId">The device identifier.</param> - void ClearTranscodingInfo(string deviceId); - - /// <summary> - /// Gets the session. - /// </summary> - /// <param name="deviceId">The device identifier.</param> - /// <param name="client">The client.</param> - /// <param name="version">The version.</param> - /// <returns>SessionInfo.</returns> - SessionInfo GetSession(string deviceId, string client, string version); - - /// <summary> - /// Gets the session by authentication token. - /// </summary> - /// <param name="token">The token.</param> - /// <param name="deviceId">The device identifier.</param> - /// <param name="remoteEndpoint">The remote endpoint.</param> - /// <returns>SessionInfo.</returns> - Task<SessionInfo> GetSessionByAuthenticationToken(string token, string deviceId, string remoteEndpoint); - - /// <summary> - /// Gets the session by authentication token. - /// </summary> - /// <param name="info">The information.</param> - /// <param name="deviceId">The device identifier.</param> - /// <param name="remoteEndpoint">The remote endpoint.</param> - /// <param name="appVersion">The application version.</param> - /// <returns>Task<SessionInfo>.</returns> - Task<SessionInfo> GetSessionByAuthenticationToken(AuthenticationInfo info, string deviceId, string remoteEndpoint, string appVersion); - - /// <summary> - /// Logouts the specified access token. - /// </summary> - /// <param name="accessToken">The access token.</param> - /// <returns>Task.</returns> - void Logout(string accessToken); - - /// <summary> - /// Revokes the user tokens. - /// </summary> - /// <returns>Task.</returns> - void RevokeUserTokens(string userId, string currentAccessToken); - - /// <summary> - /// Revokes the token. - /// </summary> - /// <param name="id">The identifier.</param> - /// <returns>Task.</returns> - void RevokeToken(string id); - } -}
\ No newline at end of file diff --git a/MediaBrowser.Controller/Session/SessionEventArgs.cs b/MediaBrowser.Controller/Session/SessionEventArgs.cs deleted file mode 100644 index 96daa6ec9..000000000 --- a/MediaBrowser.Controller/Session/SessionEventArgs.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace MediaBrowser.Controller.Session -{ - public class SessionEventArgs : EventArgs - { - public SessionInfo SessionInfo { get; set; } - } -} diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs deleted file mode 100644 index 367a7a467..000000000 --- a/MediaBrowser.Controller/Session/SessionInfo.cs +++ /dev/null @@ -1,309 +0,0 @@ -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Session; -using System; -using System.Collections.Generic; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Threading; - -namespace MediaBrowser.Controller.Session -{ - /// <summary> - /// Class SessionInfo - /// </summary> - public class SessionInfo : IDisposable - { - private ISessionManager _sessionManager; - private readonly ILogger _logger; - - public SessionInfo(ISessionManager sessionManager, ILogger logger) - { - _sessionManager = sessionManager; - _logger = logger; - - AdditionalUsers = new SessionUserInfo[] { }; - PlayState = new PlayerStateInfo(); - } - - public PlayerStateInfo PlayState { get; set; } - - public SessionUserInfo[] AdditionalUsers { get; set; } - - public ClientCapabilities Capabilities { get; set; } - - /// <summary> - /// Gets or sets the remote end point. - /// </summary> - /// <value>The remote end point.</value> - public string RemoteEndPoint { get; set; } - - /// <summary> - /// Gets or sets the playable media types. - /// </summary> - /// <value>The playable media types.</value> - public string[] PlayableMediaTypes - { - get - { - if (Capabilities == null) - { - return new string[] { }; - } - return Capabilities.PlayableMediaTypes; - } - } - - /// <summary> - /// Gets or sets the id. - /// </summary> - /// <value>The id.</value> - public string Id { get; set; } - - /// <summary> - /// Gets or sets the user id. - /// </summary> - /// <value>The user id.</value> - public Guid? UserId { get; set; } - - /// <summary> - /// Gets or sets the username. - /// </summary> - /// <value>The username.</value> - public string UserName { get; set; } - - /// <summary> - /// Gets or sets the type of the client. - /// </summary> - /// <value>The type of the client.</value> - public string Client { get; set; } - - /// <summary> - /// Gets or sets the last activity date. - /// </summary> - /// <value>The last activity date.</value> - public DateTime LastActivityDate { get; set; } - - /// <summary> - /// Gets or sets the last playback check in. - /// </summary> - /// <value>The last playback check in.</value> - public DateTime LastPlaybackCheckIn { get; set; } - - /// <summary> - /// Gets or sets the name of the device. - /// </summary> - /// <value>The name of the device.</value> - public string DeviceName { get; set; } - - /// <summary> - /// Gets or sets the name of the now viewing item. - /// </summary> - /// <value>The name of the now viewing item.</value> - public BaseItemDto NowViewingItem { get; set; } - - /// <summary> - /// Gets or sets the now playing item. - /// </summary> - /// <value>The now playing item.</value> - public BaseItemDto NowPlayingItem { get; set; } - - public BaseItem FullNowPlayingItem { get; set; } - - /// <summary> - /// Gets or sets the device id. - /// </summary> - /// <value>The device id.</value> - public string DeviceId { get; set; } - - /// <summary> - /// Gets or sets the application version. - /// </summary> - /// <value>The application version.</value> - public string ApplicationVersion { get; set; } - - /// <summary> - /// Gets or sets the session controller. - /// </summary> - /// <value>The session controller.</value> - public ISessionController SessionController { get; set; } - - /// <summary> - /// Gets or sets the application icon URL. - /// </summary> - /// <value>The application icon URL.</value> - public string AppIconUrl { get; set; } - - /// <summary> - /// Gets or sets the supported commands. - /// </summary> - /// <value>The supported commands.</value> - public string[] SupportedCommands - { - get - { - if (Capabilities == null) - { - return new string[] { }; - } - return Capabilities.SupportedCommands; - } - } - - public TranscodingInfo TranscodingInfo { get; set; } - - /// <summary> - /// Gets a value indicating whether this instance is active. - /// </summary> - /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value> - public bool IsActive - { - get - { - if (SessionController != null) - { - return SessionController.IsSessionActive; - } - - return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 10; - } - } - - public bool SupportsMediaControl - { - get - { - if (Capabilities == null || !Capabilities.SupportsMediaControl) - { - return false; - } - - if (SessionController != null) - { - return SessionController.SupportsMediaControl; - } - - return false; - } - } - - public bool ContainsUser(string userId) - { - return ContainsUser(new Guid(userId)); - } - - public bool ContainsUser(Guid userId) - { - if ((UserId ?? Guid.Empty) == userId) - { - return true; - } - - foreach (var additionalUser in AdditionalUsers) - { - if (userId == new Guid(additionalUser.UserId)) - { - return true; - } - } - return false; - } - - private readonly object _progressLock = new object(); - private ITimer _progressTimer; - private PlaybackProgressInfo _lastProgressInfo; - - public void StartAutomaticProgress(ITimerFactory timerFactory, PlaybackProgressInfo progressInfo) - { - if (_disposed) - { - return; - } - - lock (_progressLock) - { - _lastProgressInfo = progressInfo; - - if (_progressTimer == null) - { - _progressTimer = timerFactory.Create(OnProgressTimerCallback, null, 1000, 1000); - } - else - { - _progressTimer.Change(1000, 1000); - } - } - } - - // 1 second - private const long ProgressIncrement = 10000000; - - private async void OnProgressTimerCallback(object state) - { - if (_disposed) - { - return; - } - - var progressInfo = _lastProgressInfo; - if (progressInfo == null) - { - return; - } - if (progressInfo.IsPaused) - { - return; - } - - var positionTicks = progressInfo.PositionTicks ?? 0; - if (positionTicks < 0) - { - positionTicks = 0; - } - - var newPositionTicks = positionTicks + ProgressIncrement; - var item = progressInfo.Item; - long? runtimeTicks = item == null ? null : item.RunTimeTicks; - - // Don't report beyond the runtime - if (runtimeTicks.HasValue && newPositionTicks >= runtimeTicks.Value) - { - return; - } - - progressInfo.PositionTicks = newPositionTicks; - - try - { - await _sessionManager.OnPlaybackProgress(progressInfo, true).ConfigureAwait(false); - } - catch (Exception ex) - { - _logger.ErrorException("Error reporting playback progress", ex); - } - } - - public void StopAutomaticProgress() - { - lock (_progressLock) - { - if (_progressTimer != null) - { - _progressTimer.Dispose(); - _progressTimer = null; - } - _lastProgressInfo = null; - } - } - - private bool _disposed = false; - - public void Dispose() - { - _disposed = true; - - StopAutomaticProgress(); - _sessionManager = null; - GC.SuppressFinalize(this); - } - } -} |
