Skip to content

Commit

Permalink
re modeling
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre authored and Alexandre committed Apr 4, 2020
1 parent 59b8e2d commit 373d55f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 25 deletions.
20 changes: 7 additions & 13 deletions AES.UpGram.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ class Program
{
static void Main(string[] args)
{
#region Account Detail
var account = new BaseService<AccountEntity>().Get(1);
var config = new BaseService<ConfigurationEntity>().Get(1);

var service = new BaseService<AccountEntity>();
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)
{
Expand All @@ -44,7 +38,7 @@ static void Main(string[] args)



connector.Logout();
upGramConn.Logout();
}
}
}
10 changes: 5 additions & 5 deletions AES.UpGram.Core/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<User>(() => new User(_apiConnector.UserProcessor, account));
User = new Lazy<User>(() => new User(_apiConnector.UserProcessor, configuration));
}

#region Log
Expand Down
8 changes: 4 additions & 4 deletions AES.UpGram.Core/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -53,7 +53,7 @@ public async Task<string> Follow(string userName, string fromNextId = null)

public async Task<InstaUserShortList> UnFollow()
{
var result = await _apiUserProcessor.GetUserFollowingAsync(_account.Name, _paginationParameters);
var result = await _apiUserProcessor.GetUserFollowingAsync(_configuration.UserName, _paginationParameters);

if (result.Succeeded)
{
Expand Down
5 changes: 4 additions & 1 deletion AES.UpGram.Model/Entity/BaseEntity.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
9 changes: 7 additions & 2 deletions AES.UpGram.Model/Entity/ConfigurationEntity.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
12 changes: 12 additions & 0 deletions UpSocial.UpGram.Infra.CrossCutting/EnumAction.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
7 changes: 7 additions & 0 deletions UpSocial.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}
Expand Down

0 comments on commit 373d55f

Please sign in to comment.