Skip to content
Merged
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
83 changes: 1 addition & 82 deletions SySML2.NET.REST/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,91 +9,10 @@

namespace SySML2.NET.REST
{
using System;
using System.Threading;
using System.Threading.Tasks;

using SysML2.NET.Dal;
using SysML2.NET.PSM;
using SysML2.NET.PSM.DTO;

/// <summary>
/// Definition of the <see cref="ISession"/> that holds the connection to a server of the Systems Modeling API and Services
/// </summary>
public interface ISession
public interface ISession : ISessionContext, ISessionLifecycle
{
/// <summary>
/// Gets the <see cref="IAssembler"/> that holds the element model of the current commit
/// </summary>
IAssembler Assembler { get; }

/// <summary>
/// Gets the <see cref="IPsmApiClient"/> of the open connection, or <c>null</c> when the session is closed
/// </summary>
IPsmApiClient Client { get; }

/// <summary>
/// Gets the project and commit whose element model the session holds, or <c>null</c> when it holds none
/// </summary>
(Guid ProjectId, Guid CommitId)? CurrentCommit { get; }

/// <summary>
/// Closes the connection to the server and drops the element model it read
/// </summary>
void Close();

/// <summary>
/// Loads the element model of the head of a branch into the <see cref="Assembler"/>, leaving it empty when the branch has no commit
/// </summary>
/// <param name="projectId">
/// The identifier of the project
/// </param>
/// <param name="branchId">
/// The identifier of the branch
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/> that cancels the operation
/// </param>
/// <returns>
/// An awaitable <see cref="Task"/>
/// </returns>
/// <exception cref="InvalidOperationException">
/// Thrown when the session is closed, or when the server links a page of elements that it already returned
/// </exception>
Task LoadBranchHead(Guid projectId, Guid branchId, CancellationToken cancellationToken);

/// <summary>
/// Loads the element model of a commit into the <see cref="Assembler"/>, read once per commit since a commit is immutable (Systems Modeling API and Services §7.1.2)
/// </summary>
/// <param name="projectId">
/// The identifier of the project
/// </param>
/// <param name="commitId">
/// The identifier of the commit
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/> that cancels the operation
/// </param>
/// <returns>
/// An awaitable <see cref="Task"/>
/// </returns>
/// <exception cref="InvalidOperationException">
/// Thrown when the session is closed, or when the server links a page of elements that it already returned
/// </exception>
Task LoadCommit(Guid projectId, Guid commitId, CancellationToken cancellationToken);

/// <summary>
/// Opens a connection to the server, replacing any open connection, and reads the first page of its projects
/// </summary>
/// <param name="baseAddress">
/// The absolute base address of the server
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/> that cancels the operation
/// </param>
/// <returns>
/// The first page of the projects of the server
/// </returns>
Task<PagedResult<Project>> Open(Uri baseAddress, CancellationToken cancellationToken);
}
}
78 changes: 78 additions & 0 deletions SySML2.NET.REST/ISessionContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// ------------------------------------------------------------------------------------------------
// <copyright file="ISessionContext.cs" company="Starion Group S.A.">
//
// Copyright (C) 2022-2026 Starion Group S.A.
// SPDX-License-Identifier: Apache-2.0
//
// </copyright>
// ------------------------------------------------------------------------------------------------

namespace SySML2.NET.REST
{
using System;
using System.Threading;
using System.Threading.Tasks;

using SysML2.NET.Dal;

/// <summary>
/// Definition of the <see cref="ISessionContext"/> that reads from the connection of a session and loads its element model, without opening or closing it
/// </summary>
public interface ISessionContext
{
/// <summary>
/// Gets the <see cref="IAssembler"/> that holds the element model of the current commit
/// </summary>
IAssembler Assembler { get; }

/// <summary>
/// Gets the <see cref="IPsmApiClient"/> of the open connection, or <c>null</c> when the session is closed
/// </summary>
IPsmApiClient Client { get; }

/// <summary>
/// Gets the project and commit whose element model the session holds, or <c>null</c> when it holds none
/// </summary>
(Guid ProjectId, Guid CommitId)? CurrentCommit { get; }

/// <summary>
/// Loads the element model of the head of a branch into the <see cref="Assembler"/>, leaving it empty when the branch has no commit
/// </summary>
/// <param name="projectId">
/// The identifier of the project
/// </param>
/// <param name="branchId">
/// The identifier of the branch
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/> that cancels the operation
/// </param>
/// <returns>
/// An awaitable <see cref="Task"/>
/// </returns>
/// <exception cref="InvalidOperationException">
/// Thrown when the session is closed, or when the server links a page of elements that it already returned
/// </exception>
Task LoadBranchHead(Guid projectId, Guid branchId, CancellationToken cancellationToken);

/// <summary>
/// Loads the element model of a commit into the <see cref="Assembler"/>, read once per commit since a commit is immutable (Systems Modeling API and Services §7.1.2)
/// </summary>
/// <param name="projectId">
/// The identifier of the project
/// </param>
/// <param name="commitId">
/// The identifier of the commit
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/> that cancels the operation
/// </param>
/// <returns>
/// An awaitable <see cref="Task"/>
/// </returns>
/// <exception cref="InvalidOperationException">
/// Thrown when the session is closed, or when the server links a page of elements that it already returned
/// </exception>
Task LoadCommit(Guid projectId, Guid commitId, CancellationToken cancellationToken);
}
}
49 changes: 49 additions & 0 deletions SySML2.NET.REST/ISessionLifecycle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ------------------------------------------------------------------------------------------------
// <copyright file="ISessionLifecycle.cs" company="Starion Group S.A.">
//
// Copyright (C) 2022-2026 Starion Group S.A.
// SPDX-License-Identifier: Apache-2.0
//
// </copyright>
// ------------------------------------------------------------------------------------------------

namespace SySML2.NET.REST
{
using System;
using System.Threading;
using System.Threading.Tasks;

using SysML2.NET.PSM;
using SysML2.NET.PSM.DTO;

/// <summary>
/// Definition of the <see cref="ISessionLifecycle"/> that opens and closes the connection of a session to a server of the Systems Modeling API and Services
/// </summary>
public interface ISessionLifecycle
{
/// <summary>
/// Closes the connection to the server and drops the element model it read
/// </summary>
void Close();

/// <summary>
/// Opens a connection to the server, replacing any open connection, and reads the first page of its projects
/// </summary>
/// <param name="baseAddress">
/// The absolute base address of the server
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/> that cancels the operation
/// </param>
/// <returns>
/// The first page of the projects of the server
/// </returns>
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="baseAddress"/> is <c>null</c>
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown when <paramref name="baseAddress"/> is not absolute
/// </exception>
Task<PagedResult<Project>> Open(Uri baseAddress, CancellationToken cancellationToken);
}
}
Loading