From 373d55fc65f27f48a5ee33e0ceca4865fce6d10f Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sat, 4 Apr 2020 17:42:05 +0100 Subject: [PATCH] re modeling --- AES.UpGram.Console/Program.cs | 20 +++++++------------ AES.UpGram.Core/Connector.cs | 10 +++++----- AES.UpGram.Core/User.cs | 8 ++++---- AES.UpGram.Model/Entity/BaseEntity.cs | 5 ++++- .../Entity/ConfigurationEntity.cs | 9 +++++++-- .../EnumAction.cs | 12 +++++++++++ .../UpSocial.UpGram.Infra.CrossCutting.csproj | 7 +++++++ UpSocial.sln | 7 +++++++ 8 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 UpSocial.UpGram.Infra.CrossCutting/EnumAction.cs create mode 100644 UpSocial.UpGram.Infra.CrossCutting/UpSocial.UpGram.Infra.CrossCutting.csproj diff --git a/AES.UpGram.Console/Program.cs b/AES.UpGram.Console/Program.cs index 641146e..f82a383 100644 --- a/AES.UpGram.Console/Program.cs +++ b/AES.UpGram.Console/Program.cs @@ -8,20 +8,14 @@ class Program { static void Main(string[] args) { - #region Account Detail + var account = new BaseService().Get(1); + var config = new BaseService().Get(1); - var service = new BaseService(); - var account = service.Get(1); + config.UserName = account.Name; + config.Password = account.Password; - var connector = new Connector(new AccountEntity() - { - Name = account.Name, - Password = account.Password - }); - - #endregion - - var login = connector.Login().Result; + var upGramConn = new Connector(config); + var login = upGramConn.Login().Result; if (login) { @@ -44,7 +38,7 @@ static void Main(string[] args) - connector.Logout(); + upGramConn.Logout(); } } } diff --git a/AES.UpGram.Core/Connector.cs b/AES.UpGram.Core/Connector.cs index ee74df0..a2e13bf 100644 --- a/AES.UpGram.Core/Connector.cs +++ b/AES.UpGram.Core/Connector.cs @@ -17,23 +17,23 @@ public class Connector static readonly LogLevel _logLevel = LogLevel.Exceptions; static readonly int _requestDelayFromSec = 2; - public Connector(AccountEntity account) + public Connector(ConfigurationEntity configuration) { _apiConnector = InstaApiBuilder.CreateBuilder() .UseLogger(new DebugLogger(_logLevel)) .SetRequestDelay(RequestDelay.FromSeconds(_requestDelayFromSec, _requestDelayFromSec)) .SetSessionHandler(new FileSessionHandler() { - FilePath = $"{account.Name.ToLower()}.bin" + FilePath = $"{configuration.UserName.ToLower()}.bin" }) .SetUser(new UserSessionData() { - UserName = account.Name, - Password = account.Password, + UserName = configuration.UserName, + Password = configuration.Password, }) .Build(); - User = new Lazy(() => new User(_apiConnector.UserProcessor, account)); + User = new Lazy(() => new User(_apiConnector.UserProcessor, configuration)); } #region Log diff --git a/AES.UpGram.Core/User.cs b/AES.UpGram.Core/User.cs index 14004e8..51dda1a 100644 --- a/AES.UpGram.Core/User.cs +++ b/AES.UpGram.Core/User.cs @@ -11,12 +11,12 @@ public class User { static IUserProcessor _apiUserProcessor; static PaginationParameters _paginationParameters; - static AccountEntity _account; + static ConfigurationEntity _configuration; static readonly int _pagingData = 100; - public User(IUserProcessor apiUserProcessor, AccountEntity account) + public User(IUserProcessor apiUserProcessor, ConfigurationEntity configuration) { - _account = account; + _configuration = configuration; _apiUserProcessor = apiUserProcessor; _paginationParameters = PaginationParameters.MaxPagesToLoad(1); } @@ -53,7 +53,7 @@ public async Task Follow(string userName, string fromNextId = null) public async Task UnFollow() { - var result = await _apiUserProcessor.GetUserFollowingAsync(_account.Name, _paginationParameters); + var result = await _apiUserProcessor.GetUserFollowingAsync(_configuration.UserName, _paginationParameters); if (result.Succeeded) { diff --git a/AES.UpGram.Model/Entity/BaseEntity.cs b/AES.UpGram.Model/Entity/BaseEntity.cs index e81a37b..7fe87bc 100644 --- a/AES.UpGram.Model/Entity/BaseEntity.cs +++ b/AES.UpGram.Model/Entity/BaseEntity.cs @@ -1,7 +1,10 @@ -namespace UpSocial.UpGram.Domain.Entity +using Dapper.Contrib.Extensions; + +namespace UpSocial.UpGram.Domain.Entity { public abstract class BaseEntity { + [Key] public virtual int Id { get; set; } } } diff --git a/AES.UpGram.Model/Entity/ConfigurationEntity.cs b/AES.UpGram.Model/Entity/ConfigurationEntity.cs index 9cd6c4b..4e9fe91 100644 --- a/AES.UpGram.Model/Entity/ConfigurationEntity.cs +++ b/AES.UpGram.Model/Entity/ConfigurationEntity.cs @@ -1,9 +1,14 @@ -namespace UpSocial.UpGram.Domain.Entity +using Dapper.Contrib.Extensions; + +namespace UpSocial.UpGram.Domain.Entity { + [Table("Configuration")] public class ConfigurationEntity : BaseEntity { + public string UserName { get; set; } + public string Password { get; set; } public int RequestDelay { get; set; } public int LogLevel { get; set; } - public int PagingData { get; set; } = 100; + public int PagingData { get; set; } } } diff --git a/UpSocial.UpGram.Infra.CrossCutting/EnumAction.cs b/UpSocial.UpGram.Infra.CrossCutting/EnumAction.cs new file mode 100644 index 0000000..635ee23 --- /dev/null +++ b/UpSocial.UpGram.Infra.CrossCutting/EnumAction.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace UpSocial.UpGram.Infra.CrossCutting +{ + public enum EnumAction + { + Followers_Requesting = 0, + Following_Removing = 1 + } +} diff --git a/UpSocial.UpGram.Infra.CrossCutting/UpSocial.UpGram.Infra.CrossCutting.csproj b/UpSocial.UpGram.Infra.CrossCutting/UpSocial.UpGram.Infra.CrossCutting.csproj new file mode 100644 index 0000000..cb63190 --- /dev/null +++ b/UpSocial.UpGram.Infra.CrossCutting/UpSocial.UpGram.Infra.CrossCutting.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp3.1 + + + diff --git a/UpSocial.sln b/UpSocial.sln index 5b49c6e..c0e3590 100644 --- a/UpSocial.sln +++ b/UpSocial.sln @@ -25,6 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4.2 - CrossCutting", "4.2 - EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpSocial.UpGram.Service", "UpSocial.UpGram.Service\UpSocial.UpGram.Service.csproj", "{A60AC678-3488-4CBF-B257-C465A078951C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpSocial.UpGram.Infra.CrossCutting", "UpSocial.UpGram.Infra.CrossCutting\UpSocial.UpGram.Infra.CrossCutting.csproj", "{84280E1E-45D1-4596-9CBB-69D29BE2D04D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {A60AC678-3488-4CBF-B257-C465A078951C}.Debug|Any CPU.Build.0 = Debug|Any CPU {A60AC678-3488-4CBF-B257-C465A078951C}.Release|Any CPU.ActiveCfg = Release|Any CPU {A60AC678-3488-4CBF-B257-C465A078951C}.Release|Any CPU.Build.0 = Release|Any CPU + {84280E1E-45D1-4596-9CBB-69D29BE2D04D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84280E1E-45D1-4596-9CBB-69D29BE2D04D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84280E1E-45D1-4596-9CBB-69D29BE2D04D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84280E1E-45D1-4596-9CBB-69D29BE2D04D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -63,6 +69,7 @@ Global {AB4F756D-729F-4E62-B643-CDF627D8D19C} = {1AD5E386-3C89-46E0-AA9F-815114390B0A} {2319999B-D299-4B9A-9AE9-916FD5E2E3F7} = {1AD5E386-3C89-46E0-AA9F-815114390B0A} {A60AC678-3488-4CBF-B257-C465A078951C} = {0A367BC1-FD76-4982-95BD-3F0D3D7C6431} + {84280E1E-45D1-4596-9CBB-69D29BE2D04D} = {2319999B-D299-4B9A-9AE9-916FD5E2E3F7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {839E66DB-2407-4970-A1CA-DE6FC59D3C49}