Commit 189b546a authored by yangxiaodong's avatar yangxiaodong

completion comment.

parent bfa24cee
...@@ -2,8 +2,17 @@ ...@@ -2,8 +2,17 @@
namespace Cap.Consistency.EntityFrameworkCore namespace Cap.Consistency.EntityFrameworkCore
{ {
/// <summary>
/// The default implementation of <see cref="ConsistencyMessage{TKey}"/> which uses a string as a primary key.
/// </summary>
public class ConsistencyMessage : ConsistencyMessage<string> public class ConsistencyMessage : ConsistencyMessage<string>
{ {
/// <summary>
/// Initializes a new instance of <see cref="ConsistencyMessage"/>.
/// </summary>
/// <remarks>
/// The Id property is initialized to from a new GUID string value.
/// </remarks>
public ConsistencyMessage() { public ConsistencyMessage() {
Id = Guid.NewGuid().ToString(); Id = Guid.NewGuid().ToString();
SendTime = DateTime.Now; SendTime = DateTime.Now;
...@@ -12,6 +21,9 @@ namespace Cap.Consistency.EntityFrameworkCore ...@@ -12,6 +21,9 @@ namespace Cap.Consistency.EntityFrameworkCore
} }
} }
/// <summary>
/// ConsistencyMessage consume status
/// </summary>
public enum MessageStatus public enum MessageStatus
{ {
Deleted = 0, Deleted = 0,
...@@ -20,6 +32,10 @@ namespace Cap.Consistency.EntityFrameworkCore ...@@ -20,6 +32,10 @@ namespace Cap.Consistency.EntityFrameworkCore
RollbackFailed = 4 RollbackFailed = 4
} }
/// <summary>
/// Represents a message in the consistency system
/// </summary>
/// <typeparam name="TKey">The type used for the primary key for the message.</typeparam>
public class ConsistencyMessage<TKey> where TKey : IEquatable<TKey> public class ConsistencyMessage<TKey> where TKey : IEquatable<TKey>
{ {
public virtual TKey Id { get; set; } public virtual TKey Id { get; set; }
......
...@@ -6,27 +6,58 @@ using Microsoft.EntityFrameworkCore; ...@@ -6,27 +6,58 @@ using Microsoft.EntityFrameworkCore;
namespace Cap.Consistency.EntityFrameworkCore namespace Cap.Consistency.EntityFrameworkCore
{ {
/// <summary>
/// Represents a new instance of a persistence store for messages, using the default implementation
/// of <see cref="ConsistencyMessage{TKey}"/> with a string as a primary key.
/// </summary>
public class ConsistencyMessageStore : ConsistencyMessageStore<ConsistencyMessage, DbContext, string> public class ConsistencyMessageStore : ConsistencyMessageStore<ConsistencyMessage, DbContext, string>
{ {
/// <summary>
/// Constructs a new instance of <see cref="ConsistencyMessageStore"/>.
/// </summary>
/// <param name="context">The <see cref="DbContext"/>.</param>
public ConsistencyMessageStore(DbContext context) : base(context) { public ConsistencyMessageStore(DbContext context) : base(context) {
} }
} }
/// <summary>
/// Creates a new instance of a persistence store for the specified message type.
/// </summary>
/// <typeparam name="TMessage">The type representing a message.</typeparam>
public class ConsistencyMessageStore<TMessage> : ConsistencyMessageStore<TMessage, DbContext, string> public class ConsistencyMessageStore<TMessage> : ConsistencyMessageStore<TMessage, DbContext, string>
where TMessage : ConsistencyMessage<string> where TMessage : ConsistencyMessage<string>
{ {
/// <summary>
/// Constructs a new instance of <see cref="ConsistencyMessageStore{TMessage}"/>.
/// </summary>
/// <param name="context">The <see cref="DbContext"/>.</param>
public ConsistencyMessageStore(DbContext context) : base(context) { public ConsistencyMessageStore(DbContext context) : base(context) {
} }
} }
/// <summary>
/// Represents a new instance of a persistence store for the specified message types.
/// </summary>
/// <typeparam name="TMessage">The type representing a message.</typeparam>
/// <typeparam name="TContext">The type of the data context class used to access the store.</typeparam>
public class ConsistencyMessageStore<TMessage, TContext> : ConsistencyMessageStore<TMessage, TContext, string> public class ConsistencyMessageStore<TMessage, TContext> : ConsistencyMessageStore<TMessage, TContext, string>
where TMessage : ConsistencyMessage<string> where TMessage : ConsistencyMessage<string>
where TContext : DbContext where TContext : DbContext
{ {
/// <summary>
/// Constructs a new instance of <see cref="ConsistencyMessageStore{TMessage, TContext, TKey}"/>.
/// </summary>
/// <param name="context">The <see cref="DbContext"/>.</param>
public ConsistencyMessageStore(TContext context) : base(context) { public ConsistencyMessageStore(TContext context) : base(context) {
} }
} }
/// <summary>
/// Represents a new instance of a persistence store for the specified message types.
/// </summary>
/// <typeparam name="TMessage">The type representing a message.</typeparam>
/// <typeparam name="TContext">The type of the data context class used to access the store.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a message.</typeparam>
public abstract class ConsistencyMessageStore<TMessage, TContext, TKey> : IConsistencyMessageStore<TMessage> public abstract class ConsistencyMessageStore<TMessage, TContext, TKey> : IConsistencyMessageStore<TMessage>
where TMessage : ConsistencyMessage<TKey> where TMessage : ConsistencyMessage<TKey>
where TContext : DbContext where TContext : DbContext
...@@ -34,6 +65,10 @@ namespace Cap.Consistency.EntityFrameworkCore ...@@ -34,6 +65,10 @@ namespace Cap.Consistency.EntityFrameworkCore
{ {
private bool _disposed; private bool _disposed;
/// <summary>
/// Constructs a new instance of <see cref="ConsistencyMessageStore{TMessage, TContext, TKey}"/>.
/// </summary>
/// <param name="context">The <see cref="DbContext"/>.</param>
public ConsistencyMessageStore(TContext context) { public ConsistencyMessageStore(TContext context) {
if (context == null) { if (context == null) {
throw new ArgumentNullException(nameof(context)); throw new ArgumentNullException(nameof(context));
...@@ -46,7 +81,7 @@ namespace Cap.Consistency.EntityFrameworkCore ...@@ -46,7 +81,7 @@ namespace Cap.Consistency.EntityFrameworkCore
private DbSet<TMessage> MessageSet { get { return Context.Set<TMessage>(); } } private DbSet<TMessage> MessageSet { get { return Context.Set<TMessage>(); } }
/// <summary> /// <summary>
/// Creates the specified <paramref name="user"/> in the consistency message store. /// Creates the specified <paramref name="message"/> in the consistency message store.
/// </summary> /// </summary>
/// <param name="message">The message to create.</param> /// <param name="message">The message to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
...@@ -91,7 +126,7 @@ namespace Cap.Consistency.EntityFrameworkCore ...@@ -91,7 +126,7 @@ namespace Cap.Consistency.EntityFrameworkCore
/// <param name="messageId">The message ID to search for.</param> /// <param name="messageId">The message ID to search for.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns> /// <returns>
/// The <see cref="Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="messageId"/> if it exists. /// The <see cref="Task"/> that represents the asynchronous operation, containing the message matching the specified <paramref name="messageId"/> if it exists.
/// </returns> /// </returns>
public virtual Task<TMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) { public virtual Task<TMessage> FindByIdAsync(string messageId, CancellationToken cancellationToken) {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
...@@ -124,6 +159,12 @@ namespace Cap.Consistency.EntityFrameworkCore ...@@ -124,6 +159,12 @@ namespace Cap.Consistency.EntityFrameworkCore
return id.ToString(); return id.ToString();
} }
/// <summary>
/// Gets the message identifier for the specified <paramref name="message"/>.
/// </summary>
/// <param name="message">The message whose identifier should be retrieved.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation, containing the identifier for the specified <paramref name="message"/>.</returns>
public Task<string> GetMessageIdAsync(TMessage message, CancellationToken cancellationToken) { public Task<string> GetMessageIdAsync(TMessage message, CancellationToken cancellationToken) {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed(); ThrowIfDisposed();
...@@ -133,6 +174,12 @@ namespace Cap.Consistency.EntityFrameworkCore ...@@ -133,6 +174,12 @@ namespace Cap.Consistency.EntityFrameworkCore
return Task.FromResult(ConvertIdToString(message.Id)); return Task.FromResult(ConvertIdToString(message.Id));
} }
/// <summary>
/// Updates the specified <paramref name="message"/> in the message store.
/// </summary>
/// <param name="message">The message to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation, containing the <see cref="OperateResult"/> of the update operation.</returns>
public async virtual Task<OperateResult> UpdateAsync(TMessage message, CancellationToken cancellationToken) { public async virtual Task<OperateResult> UpdateAsync(TMessage message, CancellationToken cancellationToken) {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed(); ThrowIfDisposed();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment