Browse Source

refactor

master
yangxiaodong 7 years ago
parent
commit
dccff2acbb
3 changed files with 24 additions and 78 deletions
  1. +12
    -0
      src/Cap.Consistency/ITopicRouteHandler.cs
  2. +0
    -78
      src/Cap.Consistency/OperateResult.cs
  3. +12
    -0
      src/Cap.Consistency/TopicRouteContext.cs

+ 12
- 0
src/Cap.Consistency/ITopicRouteHandler.cs View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Cap.Consistency
{
public interface ITopicRouteHandler
{
Task RouteAsync(TopicRouteContext context);
}
}

+ 0
- 78
src/Cap.Consistency/OperateResult.cs View File

@@ -1,78 +0,0 @@
using System.Collections.Generic;
using System.Linq;

namespace Cap.Consistency
{
/// <summary>
/// Represents the result of an consistent message operation.
/// </summary>
public class OperateResult
{
// ReSharper disable once InconsistentNaming
private static readonly OperateResult _success = new OperateResult { Succeeded = true };

// ReSharper disable once FieldCanBeMadeReadOnly.Local
private List<OperateError> _errors = new List<OperateError>();

/// <summary>
/// Flag indicating whether if the operation succeeded or not.
/// </summary>
public bool Succeeded { get; set; }

/// <summary>
/// An <see cref="IEnumerable{T}"/> of <see cref="OperateError"/>s containing an errors
/// that occurred during the operation.
/// </summary>
/// <value>An <see cref="IEnumerable{T}"/> of <see cref="OperateError"/>s.</value>
public IEnumerable<OperateError> Errors => _errors;

/// <summary>
/// Returns an <see cref="OperateResult"/> indicating a successful identity operation.
/// </summary>
/// <returns>An <see cref="OperateResult"/> indicating a successful operation.</returns>
public static OperateResult Success => _success;

/// <summary>
/// Creates an <see cref="OperateResult"/> indicating a failed operation, with a list of <paramref name="errors"/> if applicable.
/// </summary>
/// <param name="errors">An optional array of <see cref="OperateError"/>s which caused the operation to fail.</param>
/// <returns>An <see cref="OperateResult"/> indicating a failed operation, with a list of <paramref name="errors"/> if applicable.</returns>
public static OperateResult Failed(params OperateError[] errors) {
var result = new OperateResult { Succeeded = false };
if (errors != null) {
result._errors.AddRange(errors);
}
return result;
}

/// <summary>
/// Converts the value of the current <see cref="OperateResult"/> object to its equivalent string representation.
/// </summary>
/// <returns>A string representation of the current <see cref="OperateResult"/> object.</returns>
/// <remarks>
/// If the operation was successful the ToString() will return "Succeeded" otherwise it returned
/// "Failed : " followed by a comma delimited list of error codes from its <see cref="Errors"/> collection, if any.
/// </remarks>
public override string ToString() {
return Succeeded ?
"Succeeded" :
string.Format("{0} : {1}", "Failed", string.Join(",", Errors.Select(x => x.Code).ToList()));
}
}

/// <summary>
/// Encapsulates an error from the operate subsystem.
/// </summary>
public class OperateError
{
/// <summary>
/// Gets or sets ths code for this error.
/// </summary>
public string Code { get; set; }

/// <summary>
/// Gets or sets the description for this error.
/// </summary>
public string Description { get; set; }
}
}

+ 12
- 0
src/Cap.Consistency/TopicRouteContext.cs View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;

namespace Cap.Consistency
{
public class TopicRouteContext
{
public IServiceProvider ServiceProvider { get; set; }

public IList<ITopicRouteHandler> Routes { get; set; }
}
}

Loading…
Cancel
Save