From e5175a6cebc1c4161a035f08327bc22b2f954568 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 25 Oct 2019 15:24:37 +0800 Subject: [PATCH] code cleanup --- src/DotNetCore.CAP.MySql/MySqlDataStorage.cs | 2 +- .../Abstractions/CapPublisher.cs | 2 +- ...SubscribeAttribute.cs => CAP.Attribute.cs} | 13 +++- src/DotNetCore.CAP/Cap.Header.cs | 13 ---- src/DotNetCore.CAP/ICallbackPublisher.cs | 19 ------ .../IConsumerServiceSelector.Default.cs | 2 +- src/DotNetCore.CAP/IStorageConnection.cs | 62 ------------------- .../ISubscribeExecutor.Default.cs | 1 - .../{Infrastructure => Internal}/Helper.cs | 2 +- .../Internal/IMessageSender.Default.cs | 1 - .../{Infrastructure => Internal}/ObjectId.cs | 2 +- .../SnowflakeId.cs | 2 +- .../StatusName.cs | 2 +- .../WaitHandleEx.cs | 2 +- .../Persistence/CapPublishedMessage.cs | 25 -------- .../Persistence/CapReceivedMessage.cs | 39 ------------ .../Persistence/IDashboardQuerying.cs | 26 -------- .../Persistence/IDataStorage.cs | 28 +-------- 18 files changed, 19 insertions(+), 224 deletions(-) rename src/DotNetCore.CAP/{CAP.SubscribeAttribute.cs => CAP.Attribute.cs} (71%) delete mode 100644 src/DotNetCore.CAP/Cap.Header.cs delete mode 100644 src/DotNetCore.CAP/ICallbackPublisher.cs delete mode 100644 src/DotNetCore.CAP/IStorageConnection.cs rename src/DotNetCore.CAP/{Infrastructure => Internal}/Helper.cs (98%) rename src/DotNetCore.CAP/{Infrastructure => Internal}/ObjectId.cs (99%) rename src/DotNetCore.CAP/{Infrastructure => Internal}/SnowflakeId.cs (98%) rename src/DotNetCore.CAP/{Infrastructure => Internal}/StatusName.cs (88%) rename src/DotNetCore.CAP/{Infrastructure => Internal}/WaitHandleEx.cs (96%) delete mode 100644 src/DotNetCore.CAP/Persistence/CapPublishedMessage.cs delete mode 100644 src/DotNetCore.CAP/Persistence/CapReceivedMessage.cs delete mode 100644 src/DotNetCore.CAP/Persistence/IDashboardQuerying.cs diff --git a/src/DotNetCore.CAP.MySql/MySqlDataStorage.cs b/src/DotNetCore.CAP.MySql/MySqlDataStorage.cs index 3b640de..96aff83 100644 --- a/src/DotNetCore.CAP.MySql/MySqlDataStorage.cs +++ b/src/DotNetCore.CAP.MySql/MySqlDataStorage.cs @@ -4,7 +4,7 @@ using System.Data; using System.Threading; using System.Threading.Tasks; using Dapper; -using DotNetCore.CAP.Infrastructure; +using DotNetCore.CAP.Internal; using DotNetCore.CAP.Messages; using DotNetCore.CAP.Persistence; using DotNetCore.CAP.Serialization; diff --git a/src/DotNetCore.CAP/Abstractions/CapPublisher.cs b/src/DotNetCore.CAP/Abstractions/CapPublisher.cs index 25c9927..13df6a9 100644 --- a/src/DotNetCore.CAP/Abstractions/CapPublisher.cs +++ b/src/DotNetCore.CAP/Abstractions/CapPublisher.cs @@ -7,7 +7,7 @@ using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using DotNetCore.CAP.Diagnostics; -using DotNetCore.CAP.Infrastructure; +using DotNetCore.CAP.Internal; using DotNetCore.CAP.Messages; using DotNetCore.CAP.Persistence; using Microsoft.Extensions.DependencyInjection; diff --git a/src/DotNetCore.CAP/CAP.SubscribeAttribute.cs b/src/DotNetCore.CAP/CAP.Attribute.cs similarity index 71% rename from src/DotNetCore.CAP/CAP.SubscribeAttribute.cs rename to src/DotNetCore.CAP/CAP.Attribute.cs index fda43e2..242bc47 100644 --- a/src/DotNetCore.CAP/CAP.SubscribeAttribute.cs +++ b/src/DotNetCore.CAP/CAP.Attribute.cs @@ -2,14 +2,13 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; using DotNetCore.CAP.Abstractions; // ReSharper disable once CheckNamespace namespace DotNetCore.CAP { - /// - /// An attribute for subscribe event bus message. - /// public class CapSubscribeAttribute : TopicAttribute { public CapSubscribeAttribute(string name) @@ -29,4 +28,12 @@ namespace DotNetCore.CAP { } + + public class CapHeader : ReadOnlyDictionary + { + public CapHeader(IDictionary dictionary) : base(dictionary) + { + + } + } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/Cap.Header.cs b/src/DotNetCore.CAP/Cap.Header.cs deleted file mode 100644 index 657f5cc..0000000 --- a/src/DotNetCore.CAP/Cap.Header.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; - -namespace DotNetCore.CAP -{ - public class CapHeader : ReadOnlyDictionary - { - public CapHeader(IDictionary dictionary) : base(dictionary) - { - - } - } -} \ No newline at end of file diff --git a/src/DotNetCore.CAP/ICallbackPublisher.cs b/src/DotNetCore.CAP/ICallbackPublisher.cs deleted file mode 100644 index 01d8920..0000000 --- a/src/DotNetCore.CAP/ICallbackPublisher.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) .NET Core Community. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System.Threading.Tasks; -using DotNetCore.CAP.Messages; - -namespace DotNetCore.CAP -{ - /// - /// A callback that is sent to Producer after a successful consumer execution - /// - public interface ICallbackPublisher - { - /// - /// Publish a callback message - /// - Task PublishCallbackAsync(CapPublishedMessage obj); - } -} \ No newline at end of file diff --git a/src/DotNetCore.CAP/IConsumerServiceSelector.Default.cs b/src/DotNetCore.CAP/IConsumerServiceSelector.Default.cs index 4039bf6..e7b9a56 100644 --- a/src/DotNetCore.CAP/IConsumerServiceSelector.Default.cs +++ b/src/DotNetCore.CAP/IConsumerServiceSelector.Default.cs @@ -7,9 +7,9 @@ using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using DotNetCore.CAP.Abstractions; -using DotNetCore.CAP.Infrastructure; using Microsoft.Extensions.DependencyInjection; using System.Collections.Concurrent; +using DotNetCore.CAP.Internal; using Microsoft.Extensions.Options; namespace DotNetCore.CAP diff --git a/src/DotNetCore.CAP/IStorageConnection.cs b/src/DotNetCore.CAP/IStorageConnection.cs deleted file mode 100644 index 5ce8d9e..0000000 --- a/src/DotNetCore.CAP/IStorageConnection.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) .NET Core Community. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Threading.Tasks; -using DotNetCore.CAP.Messages; - -namespace DotNetCore.CAP -{ - /// - /// Represents a connection to the storage. - /// - public interface IStorageConnection - { - //Sent messages - - /// - /// Returns the message with the given id. - /// - /// The message's id. - Task GetPublishedMessageAsync(long id); - - /// - /// Returns executed failed messages. - /// - Task> GetPublishedMessagesOfNeedRetry(); - - // Received messages - - /// - /// Stores the message. - /// - /// The message to store. - void StoreReceivedMessage(CapReceivedMessage message); - - /// - /// Returns the message with the given id. - /// - /// The message's id. - Task GetReceivedMessageAsync(long id); - - /// - /// Returns executed failed message. - /// - Task> GetReceivedMessagesOfNeedRetry(); - - - /// - /// Change specified message's state of published message - /// - /// Message id - /// State name - bool ChangePublishedState(long messageId, string state); - - /// - /// Change specified message's state of received message - /// - /// Message id - /// State name - bool ChangeReceivedState(long messageId, string state); - } -} \ No newline at end of file diff --git a/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs b/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs index 8b2625e..8d2dacd 100644 --- a/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs +++ b/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using DotNetCore.CAP.Diagnostics; -using DotNetCore.CAP.Infrastructure; using DotNetCore.CAP.Internal; using DotNetCore.CAP.Messages; using DotNetCore.CAP.Persistence; diff --git a/src/DotNetCore.CAP/Infrastructure/Helper.cs b/src/DotNetCore.CAP/Internal/Helper.cs similarity index 98% rename from src/DotNetCore.CAP/Infrastructure/Helper.cs rename to src/DotNetCore.CAP/Internal/Helper.cs index 4acc33f..a1084e2 100644 --- a/src/DotNetCore.CAP/Infrastructure/Helper.cs +++ b/src/DotNetCore.CAP/Internal/Helper.cs @@ -5,7 +5,7 @@ using System; using System.ComponentModel; using System.Reflection; -namespace DotNetCore.CAP.Infrastructure +namespace DotNetCore.CAP.Internal { public static class Helper { diff --git a/src/DotNetCore.CAP/Internal/IMessageSender.Default.cs b/src/DotNetCore.CAP/Internal/IMessageSender.Default.cs index b014b89..8cf6f5b 100644 --- a/src/DotNetCore.CAP/Internal/IMessageSender.Default.cs +++ b/src/DotNetCore.CAP/Internal/IMessageSender.Default.cs @@ -5,7 +5,6 @@ using System; using System.Diagnostics; using System.Threading.Tasks; using DotNetCore.CAP.Diagnostics; -using DotNetCore.CAP.Infrastructure; using DotNetCore.CAP.Messages; using DotNetCore.CAP.Persistence; using DotNetCore.CAP.Processor; diff --git a/src/DotNetCore.CAP/Infrastructure/ObjectId.cs b/src/DotNetCore.CAP/Internal/ObjectId.cs similarity index 99% rename from src/DotNetCore.CAP/Infrastructure/ObjectId.cs rename to src/DotNetCore.CAP/Internal/ObjectId.cs index 8d84a6f..3dab571 100644 --- a/src/DotNetCore.CAP/Infrastructure/ObjectId.cs +++ b/src/DotNetCore.CAP/Internal/ObjectId.cs @@ -9,7 +9,7 @@ using System.Security.Cryptography; using System.Text; using System.Threading; -namespace DotNetCore.CAP.Infrastructure +namespace DotNetCore.CAP.Internal { /// /// Represents an ObjectId diff --git a/src/DotNetCore.CAP/Infrastructure/SnowflakeId.cs b/src/DotNetCore.CAP/Internal/SnowflakeId.cs similarity index 98% rename from src/DotNetCore.CAP/Infrastructure/SnowflakeId.cs rename to src/DotNetCore.CAP/Internal/SnowflakeId.cs index 339d254..b1670e3 100644 --- a/src/DotNetCore.CAP/Infrastructure/SnowflakeId.cs +++ b/src/DotNetCore.CAP/Internal/SnowflakeId.cs @@ -3,7 +3,7 @@ using System; -namespace DotNetCore.CAP.Infrastructure +namespace DotNetCore.CAP.Internal { public class SnowflakeId { diff --git a/src/DotNetCore.CAP/Infrastructure/StatusName.cs b/src/DotNetCore.CAP/Internal/StatusName.cs similarity index 88% rename from src/DotNetCore.CAP/Infrastructure/StatusName.cs rename to src/DotNetCore.CAP/Internal/StatusName.cs index 018e28d..d4463de 100644 --- a/src/DotNetCore.CAP/Infrastructure/StatusName.cs +++ b/src/DotNetCore.CAP/Internal/StatusName.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Core Community. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -namespace DotNetCore.CAP.Infrastructure +namespace DotNetCore.CAP.Internal { /// /// The message status name. diff --git a/src/DotNetCore.CAP/Infrastructure/WaitHandleEx.cs b/src/DotNetCore.CAP/Internal/WaitHandleEx.cs similarity index 96% rename from src/DotNetCore.CAP/Infrastructure/WaitHandleEx.cs rename to src/DotNetCore.CAP/Internal/WaitHandleEx.cs index 14ed410..e5f5ba2 100644 --- a/src/DotNetCore.CAP/Infrastructure/WaitHandleEx.cs +++ b/src/DotNetCore.CAP/Internal/WaitHandleEx.cs @@ -5,7 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; -namespace DotNetCore.CAP.Infrastructure +namespace DotNetCore.CAP.Internal { public static class WaitHandleEx { diff --git a/src/DotNetCore.CAP/Persistence/CapPublishedMessage.cs b/src/DotNetCore.CAP/Persistence/CapPublishedMessage.cs deleted file mode 100644 index 8d68ed1..0000000 --- a/src/DotNetCore.CAP/Persistence/CapPublishedMessage.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) .NET Core Community. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System; - -namespace DotNetCore.CAP.Messages -{ - public class CapPublishedMessage - { - public CapPublishedMessage() - { - Added = DateTime.Now; - } - - public Message Message { get; set; } - - public DateTime Added { get; set; } - - public DateTime? ExpiresAt { get; set; } - - public int Retries { get; set; } - - public string StatusName { get; set; } - } -} \ No newline at end of file diff --git a/src/DotNetCore.CAP/Persistence/CapReceivedMessage.cs b/src/DotNetCore.CAP/Persistence/CapReceivedMessage.cs deleted file mode 100644 index 1e29561..0000000 --- a/src/DotNetCore.CAP/Persistence/CapReceivedMessage.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Core Community. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System; - -namespace DotNetCore.CAP.Messages -{ - public class CapReceivedMessage - { - /// - /// Initializes a new instance of . - /// - public CapReceivedMessage() - { - Added = DateTime.Now; - } - - public long Id { get; set; } - - public string Group { get; set; } - - public string Name { get; set; } - - public string Content { get; set; } - - public DateTime Added { get; set; } - - public DateTime? ExpiresAt { get; set; } - - public int Retries { get; set; } - - public string StatusName { get; set; } - - public override string ToString() - { - return "name:" + Name + ", group:" + Group + ", content:" + Content; - } - } -} \ No newline at end of file diff --git a/src/DotNetCore.CAP/Persistence/IDashboardQuerying.cs b/src/DotNetCore.CAP/Persistence/IDashboardQuerying.cs deleted file mode 100644 index 384a1f2..0000000 --- a/src/DotNetCore.CAP/Persistence/IDashboardQuerying.cs +++ /dev/null @@ -1,26 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using DotNetCore.CAP.Dashboard.Monitoring; -//using DotNetCore.CAP.Messages; - -//namespace DotNetCore.CAP.Persistence -//{ -// public interface IDashboardQuerying -// { -// StatisticsDto GetStatistics(); - -// IList Messages(MessageQueryDto queryDto); - -// int PublishedFailedCount(); - -// int PublishedSucceededCount(); - -// int ReceivedFailedCount(); - -// int ReceivedSucceededCount(); - -// IDictionary HourlySucceededJobs(MessageType type); - -// IDictionary HourlyFailedJobs(MessageType type); -// } -//} diff --git a/src/DotNetCore.CAP/Persistence/IDataStorage.cs b/src/DotNetCore.CAP/Persistence/IDataStorage.cs index ab18dca..41255c2 100644 --- a/src/DotNetCore.CAP/Persistence/IDataStorage.cs +++ b/src/DotNetCore.CAP/Persistence/IDataStorage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using DotNetCore.CAP.Infrastructure; +using DotNetCore.CAP.Internal; using DotNetCore.CAP.Messages; namespace DotNetCore.CAP.Persistence @@ -22,31 +22,5 @@ namespace DotNetCore.CAP.Persistence Task> GetPublishedMessagesOfNeedRetry(); Task> GetReceivedMessagesOfNeedRetry(); - - //Task GetPublishedMessageAsync(long id); - //Task GetReceivedMessageAsync(long id); - - //public void UpdateMessage(CapPublishedMessage message) - //{ - // if (message == null) - // { - // throw new ArgumentNullException(nameof(message)); - // } - - // var sql = - // $"UPDATE `{_prefix}.published` SET `Retries` = @Retries,`Content`= @Content,`ExpiresAt` = @ExpiresAt,`StatusName`=@StatusName WHERE `Id`=@Id;"; - // _dbConnection.Execute(sql, message); - //} - - //public void UpdateMessage(CapReceivedMessage message) - //{ - // if (message == null) - // { - // throw new ArgumentNullException(nameof(message)); - // } - - // var sql = $"UPDATE `{_prefix}.received` SET `Retries` = @Retries,`Content`= @Content,`ExpiresAt` = @ExpiresAt,`StatusName`=@StatusName WHERE `Id`=@Id;"; - // _dbConnection.Execute(sql, message); - //} } }