Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
406 changes: 406 additions & 0 deletions Cliente_Github/.gitignore

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions Cliente_Github/Cliente_Github.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.810.5
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cliente_Github", "Cliente_Github\Cliente_Github.csproj", "{5FDBE070-3420-4D81-83DD-72C4F95B98A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cliente_Github_Testes", "Cliente_Github_Testes\Cliente_Github_Testes.csproj", "{201E7C8C-8B6E-49B5-9F67-E6BBB3E75053}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5FDBE070-3420-4D81-83DD-72C4F95B98A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5FDBE070-3420-4D81-83DD-72C4F95B98A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FDBE070-3420-4D81-83DD-72C4F95B98A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5FDBE070-3420-4D81-83DD-72C4F95B98A7}.Release|Any CPU.Build.0 = Release|Any CPU
{201E7C8C-8B6E-49B5-9F67-E6BBB3E75053}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{201E7C8C-8B6E-49B5-9F67-E6BBB3E75053}.Debug|Any CPU.Build.0 = Debug|Any CPU
{201E7C8C-8B6E-49B5-9F67-E6BBB3E75053}.Release|Any CPU.ActiveCfg = Release|Any CPU
{201E7C8C-8B6E-49B5-9F67-E6BBB3E75053}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0520CD35-8141-4B48-8A05-3D4C8CDFB01A}
EndGlobalSection
EndGlobal
115 changes: 115 additions & 0 deletions Cliente_Github/Cliente_Github/Classes/clsGithub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Octokit;

namespace Cliente_Github.Classes
{
public class clsGithub
{
public bool login(string usuario, string senha)
{
bool ret = false;

try
{
User user = Task.Run(async () => await getGitHubUserAsync(usuario, senha)).Result;

ret = (user != null);

}
catch (Exception)
{

}
return ret;
}

public IReadOnlyList<Repository> getGitHubRepository(string usuario, string senha, bool star = false)
{
IReadOnlyList<Repository> Repositorios = null;
GitHubClient client = this.GetGitHubClient(usuario, senha);
User user = Task.Run(async () => await getGitHubUserAsync(usuario, senha)).Result;
if (user != null)
{
try
{
if (star)
{
Repositorios = Task.Run(async () => await client.Activity.Starring.GetAllForUser(user.Login)).Result;
} else
{
Repositorios = Task.Run(async () => await client.Repository.GetAllForUser(user.Login)).Result;
}

}
catch (Exception)
{

}
}

return Repositorios;

}

public List<Repository> getReposFiltro(string usuario, string senha, string filtro)
{
List<Repository> Repositorios = new List<Repository>();
GitHubClient client = this.GetGitHubClient(usuario, senha);
User user = Task.Run(async () => await getGitHubUserAsync(usuario, senha)).Result;
if(user != null)
{
SearchRepositoriesRequest sRepository = new SearchRepositoriesRequest(filtro);
sRepository.User = user.Login;

SearchRepositoryResult sRepositoryResults = Task.Run(async () => await client.Search.SearchRepo(sRepository)).Result;
foreach(Repository repo in sRepositoryResults.Items)
{
if(repo.Owner.Login == usuario)
{
Repositorios.Add(repo);
}
}
}
return Repositorios;
}

private async Task<User> getGitHubUserAsync(string usuario, string senha)
{

User user = null;
GitHubClient client = this.GetGitHubClient(usuario, senha);

try
{
user = await client.User.Get(usuario);

}
catch (Exception)
{

}
return user;

}

private GitHubClient GetGitHubClient(string usuario, string senha)
{
GitHubClient client = null;
Credentials basicAuth = null;
try
{
client = new GitHubClient(new ProductHeaderValue(usuario));
basicAuth = new Credentials(usuario, senha, AuthenticationType.Basic);
client.Credentials = basicAuth;
}
catch (Exception)
{

}
return client;
}

}
}
33 changes: 33 additions & 0 deletions Cliente_Github/Cliente_Github/Cliente_Github.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Description>Teste de seleção para Gerente de Desenvolvimento - Magrathea
Candidato: Luicil Fernandes
(c) 2021 Luicil Fernandes</Description>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<None Remove="Views\" />
<None Remove="Models\" />
<None Remove="Controllers\" />
<None Remove="Octokit" />
<None Remove="Classes\" />
<None Remove="Views\Login\" />
<None Remove="Views\Repositorios\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\" />
<Folder Include="Models\" />
<Folder Include="Controllers\" />
<Folder Include="Classes\" />
<Folder Include="Views\Login\" />
<Folder Include="Views\Repositorios\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Octokit" Version="0.50.0" />
</ItemGroup>
</Project>
63 changes: 63 additions & 0 deletions Cliente_Github/Cliente_Github/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;

namespace Cliente_Github.Controllers
{

public class LoginController : Controller
{

public IActionResult Index()
{
return View();
}

public IActionResult logingithub()
{
ViewBag.error = "Breve aqui: Login com o GitHub !";
return View("Index");
}

public IActionResult Login(string username, string password)
{
HttpContext.Session.SetString("username", "");
HttpContext.Session.SetString("password", "");

if (username != null && password != null)
{
Classes.clsGithub cgh = new Classes.clsGithub();
var ret = cgh.login(username, password);

if (ret)
{
//IReadOnlyList<Octokit.Repository> repos = cgh.getGitHubRepository(username, password);

//IList<Models.Repositorio> repositorio = new List<Models.Repositorio>();
//foreach (var rep in repos)
//{
// repositorio.Add(new Models.Repositorio() { Id = rep.Id, Descricao = rep.FullName, Nome = rep.Name, Url = rep.Url });
//}

HttpContext.Session.SetString("username", username);
HttpContext.Session.SetString("password", password);
return RedirectToAction("Stars", "Repositorios");
//return View("../Repositorios/Repositorios");
}
else
{
ViewBag.error = "Usuário e/ou Senha incorreto(s)";
return View("Index");
}
}
else
{
ViewBag.error = "Usuário e/ou Senha incorreto(s)";
return View("Index");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;


namespace Cliente_Github.Controllers
{
public class RepositoriosController : Controller
{

public IActionResult Repositorios()
{

string username = HttpContext.Session.GetString("username");
string password = HttpContext.Session.GetString("password");

if(username == "" | password == "")
{
return RedirectToAction("Index", "Login");
} else {
Classes.clsGithub cgh = new Classes.clsGithub();
IReadOnlyList<Octokit.Repository> repos = cgh.getGitHubRepository(username, password);
return View(MontaModel(repos));
}
}

public IActionResult Logout()
{
HttpContext.Session.SetString("username", "");
HttpContext.Session.SetString("password", "");

return RedirectToAction("Index","Login");
}

public IActionResult Stars()
{
Classes.clsGithub cgh = new Classes.clsGithub();
string username = HttpContext.Session.GetString("username");
string password = HttpContext.Session.GetString("password");

IReadOnlyList<Octokit.Repository> repos = cgh.getGitHubRepository(username, password, true);

return View("Repositorios", MontaModel(repos));

}

public IActionResult Pesquisar(string pesquisar)
{
string username = HttpContext.Session.GetString("username");
string password = HttpContext.Session.GetString("password");
Classes.clsGithub cgh = new Classes.clsGithub();

List<Octokit.Repository> repos = null;
if (pesquisar != "")
{
repos = cgh.getReposFiltro(username, password, pesquisar);
return View("Repositorios", MontaModel(repos));
}
return View("Repositorios", cgh.getGitHubRepository(username, password, true));
}

private List<Models.Repositorio> MontaModel(IReadOnlyList<Octokit.Repository> repos)
{
List<Models.Repositorio> repositorio = new List<Models.Repositorio>();
if(repos != null)
{
foreach (var repo in repos)
{
repositorio.Add(new Models.Repositorio()
{
Id = repo.Id,
Descricao = repo.Description,
Nome = repo.Name,
Url = repo.Url
});
}

}
return repositorio;
}

}
}
11 changes: 11 additions & 0 deletions Cliente_Github/Cliente_Github/Models/Repositorio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
namespace Cliente_Github.Models
{
public class Repositorio
{
public long Id { get; set; }
public string Nome { get; set; }
public string Descricao { get; set; }
public string Url { get; set; }
}
}
26 changes: 26 additions & 0 deletions Cliente_Github/Cliente_Github/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Cliente_Github
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Loading