Compare commits
2 Commits
541af27593
...
0bbd7466cd
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bbd7466cd | |||
| 5e0d281f89 |
@ -6,8 +6,4 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.9" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,5 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BackupPipefy.Domain\BackupPipefy.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -1,22 +1,53 @@
|
||||
namespace BackupPipefy.Infrastructure.Services
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BackupPipefy.Infrastructure.Services
|
||||
{
|
||||
public class PipefyClient
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly PipefyTokenService _tokenService;
|
||||
|
||||
public PipefyClient(string apiToken)
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiToken}");
|
||||
public PipefyClient(PipefyTokenService tokenService, bool useProxy = false)
|
||||
{
|
||||
if (useProxy)
|
||||
{
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
Proxy = new WebProxy("127.0.0.1", 8888),
|
||||
UseProxy = true,
|
||||
ServerCertificateCustomValidationCallback = (HttpRequestMessage req, X509Certificate2? cert, X509Chain? chain, SslPolicyErrors errors) => true
|
||||
};
|
||||
|
||||
_httpClient = new HttpClient(handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
}
|
||||
|
||||
_tokenService = tokenService;
|
||||
}
|
||||
|
||||
public async Task<string> GetCardsAsync(int pipeId, DateTime? lastUpdated = null)
|
||||
public async Task<string> GetCardsAsync(int pipeId, DateTime lastUpdated)
|
||||
{
|
||||
// Aqui você vai montar sua query GraphQL real
|
||||
string query = "{ allCards { edges { node { id updated_at } } } }";
|
||||
var token = await _tokenService.GetTokenAsync();
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
// Montar GraphQL e enviar request
|
||||
// Exemplo simplificado:
|
||||
var query = new
|
||||
{
|
||||
query = @"{ allCards(pipeId: 303718996, after: \""WyIxLjAiLCI1MC4wIiw4MTgzNjgwNzhd\""){ edges{ node{ id title emailMessagingAddress } } pageInfo{ endCursor hasNextPage } }}"
|
||||
};
|
||||
|
||||
var payload = new { query };
|
||||
var content = new StringContent(System.Text.Json.JsonSerializer.Serialize(payload), System.Text.Encoding.UTF8, "application/json");
|
||||
var content = new StringContent(System.Text.Json.JsonSerializer.Serialize(query));
|
||||
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
||||
|
||||
var response = await _httpClient.PostAsync("https://api.pipefy.com/graphql", content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
@ -24,4 +55,4 @@
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.9">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BackupPipefy.Application\BackupPipefy.Application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -1,2 +1,40 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
||||
using BackupPipefy.Infrastructure.Data;
|
||||
using BackupPipefy.Infrastructure.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: false);
|
||||
|
||||
var config = builder.Build();
|
||||
|
||||
string connStr = config["Database:ConnectionString"];
|
||||
int pipeId = int.Parse(config["Pipefy:PipeId"]);
|
||||
int requestsPerMinute = int.Parse(config["Pipefy:RequestsPerMinute"]);
|
||||
string clientId = config["Pipefy:ClientId"];
|
||||
string clientSecret = config["Pipefy:ClientSecret"];
|
||||
string tokenUrl = config["Pipefy:TokenUrl"];
|
||||
string personalAccessToken = config["Pipefy:PersonalAccessToken"];
|
||||
|
||||
var options = new DbContextOptionsBuilder<BackupContext>()
|
||||
.UseNpgsql(connStr)
|
||||
.Options;
|
||||
|
||||
using var context = new BackupContext(options);
|
||||
context.Database.Migrate();
|
||||
|
||||
var tokenService = new PipefyTokenService(clientId, clientSecret, tokenUrl, useProxy: true, personalAccessToken);
|
||||
var pipefyClient = new PipefyClient(tokenService, useProxy: true);
|
||||
|
||||
var service = new BackupService(pipefyClient, context, requestsPerMinute);
|
||||
|
||||
await service.RunBackup(pipeId);
|
||||
|
||||
Console.WriteLine("Backup concluído!");
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,9 @@ EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackupPipefy.Application", "BackupPipefy.Application\BackupPipefy.Application.csproj", "{BF4AC360-863B-4DFB-BA9D-EB18AFAEF0D9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackupPipefy.Presentation", "BackupPipefy.Presentation\BackupPipefy.Presentation.csproj", "{291174C2-E63C-4B88-A7E5-DB6F9A179C45}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{44852B24-092C-4E5A-84C0-0103C837A0EA} = {44852B24-092C-4E5A-84C0-0103C837A0EA}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackupPipefy.Tests", "BackupPipefy.Tests\BackupPipefy.Tests.csproj", "{940E3A0D-69ED-45AD-A4D3-BEB726DE595E}"
|
||||
EndProject
|
||||
@ -87,4 +90,7 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {19627F70-4980-412B-8F4E-72D5ABECF00E}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user