architecture changes; application has hit beta

This commit is contained in:
Wyatt Miller 2018-12-06 01:03:58 -05:00
parent 7222766e81
commit 425bb6113d
22 changed files with 243 additions and 229 deletions

Binary file not shown.

View File

@ -1,133 +1,41 @@
using RestSharp;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Collections.ObjectModel;
namespace DeskHubSharp
{
class Request
public class Request
{
// TODO: this is rudimentary, fix it
// i.e. try catch statements\
// TODO: Add BranchRequest function
private string _apiEndpoint = "https://api.github.com/";
private ApiDataService _api;
private string _query;
public List<RepoDetail> RepoDetail { get; set; }
public Request(string query)
{
_query = query;
_api = new ApiDataService(_query);
}
//public Request(string query, Object function)
//{
// _query = query;
//}
/// <summary>
/// Calls API for repo and basic user data
/// </summary>
/// <returns></returns>
public void SearchRequest()
public void PerformSearchRequest()
{
try
{
var client = new RestClient(_apiEndpoint);
RestRequest requestRepo = new RestRequest($"users/{_query}/repos", Method.GET);
var response = client.Execute(requestRepo);
var x = response.Content;
var deserialized = JsonConvert.DeserializeObject<ObservableCollection<RepoDetail>>(x);
//ObservableCollection<RepoDetail> test = new ObservableCollection<RepoDetail>()
//{
// new RepoDetail()
// {
// Login = "John",
// Password = "pw"
// }
//};
if (deserialized.Count == 0)
{
throw new Exception();
}
else
{
RequestList.repoDetail = deserialized;
}
}
catch (Exception)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "We couldn't gather repository data. Please try again";
}
_api.SearchRequest();
}
/// <summary>
/// Calls API for detailed user data
/// </summary>
public void UserRequest()
public void PerformUserRequest()
{
try
{
var client = new RestClient(_apiEndpoint);
RestRequest requestUser = new RestRequest($"users/{_query}", Method.GET);
var response = client.Execute(requestUser);
string x = response.Content;
var deserailized = JsonConvert.DeserializeObject<User>(x);
if (deserailized == null)
{
throw new Exception();
}
else
{
RequestList.userDetail = deserailized;
_api.UserRequest();
}
}
catch (NullReferenceException)
public void PerformBranchRequest()
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "We couldn't gather user data. Please try again.";
_api.BranchRequest();
}
}
/// <summary>
/// Calls API for detailed branch data
/// </summary>
public void BranchRequest()
public Owner GetUserData()
{
try
{
var client = new RestClient(_apiEndpoint);
RestRequest requestUser = new RestRequest($"/repos/{RequestList.userDetail.login}/{_query}/branches", Method.GET);
var response = client.Execute(requestUser);
string x = response.Content;
var deserailized = JsonConvert.DeserializeObject<ObservableCollection<Branch>>(x);
RequestList.branchDetail = deserailized;
}
catch (NullReferenceException)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "We couldn't gather user data. Please try again.";
}
Owner owner = new Owner();
return owner;
}
}

View File

@ -0,0 +1,135 @@
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Collections.ObjectModel;
namespace DeskHubSharp
{
class ApiDataService : IDataService
{
// TODO: this is rudimentary, fix it
// i.e. try catch statements\
// TODO: Add BranchRequest function
private string _apiEndpoint;
private string _query;
public List<RepoDetail> RepoDetail { get; set; }
public ApiDataService(string query)
{
_query = query;
_apiEndpoint = DataConfig.dataConfString;
}
//public Request(string query, Object function)
//{
// _query = query;
//}
/// <summary>
/// Calls API for repo and basic user data
/// </summary>
/// <returns></returns>
public void SearchRequest()
{
try
{
var client = new RestClient(_apiEndpoint);
RestRequest requestRepo = new RestRequest($"users/{_query}/repos", Method.GET);
var response = client.Execute(requestRepo);
var x = response.Content;
var deserialized = JsonConvert.DeserializeObject<ObservableCollection<RepoDetail>>(x);
//ObservableCollection<RepoDetail> test = new ObservableCollection<RepoDetail>()
//{
// new RepoDetail()
// {
// Login = "John",
// Password = "pw"
// }
//};
if (deserialized.Count == 0)
{
throw new Exception();
}
else
{
RequestList.repoDetail = deserialized;
}
}
catch (Exception)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "We couldn't gather repository data. Please try again";
}
}
/// <summary>
/// Calls API for detailed user data
/// </summary>
public void UserRequest()
{
try
{
var client = new RestClient(_apiEndpoint);
RestRequest requestUser = new RestRequest($"users/{_query}", Method.GET);
var response = client.Execute(requestUser);
string x = response.Content;
var deserailized = JsonConvert.DeserializeObject<User>(x);
if (deserailized == null)
{
throw new Exception();
}
else
{
RequestList.userDetail = deserailized;
}
}
catch (NullReferenceException)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "We couldn't gather user data. Please try again.";
}
}
/// <summary>
/// Calls API for detailed branch data
/// </summary>
public void BranchRequest()
{
try
{
var client = new RestClient(_apiEndpoint);
RestRequest requestUser = new RestRequest($"/repos/{RequestList.userDetail.login}/{_query}/branches", Method.GET);
var response = client.Execute(requestUser);
string x = response.Content;
var deserailized = JsonConvert.DeserializeObject<ObservableCollection<Branch>>(x);
RequestList.branchDetail = deserailized;
}
catch (NullReferenceException)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "We couldn't gather user data. Please try again.";
}
}
}
}

View File

@ -8,7 +8,11 @@ namespace DeskHubSharp
{
public interface IDataService
{
List<Search> ReadAll();
void WriteAll(List<Search> user);
//List<Search> ReadAll();
//void WriteAll(List<Search> user);
void SearchRequest();
void UserRequest();
void BranchRequest();
}
}

View File

@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.IO;
namespace DeskHubSharp
{
class XmlDataService
{
private readonly string _dataFilePath;
public List<User> ReadAll()
{
List<User> Users = new List<User>();
XmlSerializer serializer = new XmlSerializer(typeof(List<User>), new XmlRootAttribute("Users"));
try
{
StreamReader reader = new StreamReader(_dataFilePath);
using (reader)
{
Users = (List<User>)serializer.Deserialize(reader);
}
}
catch (Exception)
{
throw;
}
return Users;
}
public void WriteAll(List<User> Users)
{
XmlSerializer serializer = new XmlSerializer(typeof(List<User>), new XmlRootAttribute("Users"));
try
{
StreamWriter writer = new StreamWriter(_dataFilePath);
using (writer)
{
serializer.Serialize(writer, Users);
}
}
catch (Exception)
{
throw;
}
}
public XmlDataService()
{
}
public XmlDataService(string datafile)
{
_dataFilePath = datafile;
}
}
}

View File

@ -8,6 +8,6 @@ namespace DeskHubSharp
{
class DataConfig
{
public string dataConfString = "";
public static string dataConfString = "https://api.github.com/";
}
}

View File

@ -71,6 +71,7 @@
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>
<Compile Include="BusinessLayer\Request.cs" />
<Compile Include="DAL\JsonDataService.cs" />
<Compile Include="Models\Branch.cs" />
<Compile Include="Models\Email.cs" />
@ -107,9 +108,8 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="BusinessLayer\EmailBLL.cs" />
<Compile Include="BusinessLayer\Request.cs" />
<Compile Include="DAL\ApiDataService.cs" />
<Compile Include="DAL\IDataService.cs" />
<Compile Include="DAL\XmlDataService.cs" />
<Compile Include="Data\DataConfig.cs" />
<Compile Include="DetailWindow.xaml.cs">
<DependentUpon>DetailWindow.xaml</DependentUpon>

View File

@ -10,19 +10,13 @@
<Label x:Name="lbl_reponame" Content="Repository Name" HorizontalAlignment="Left" Margin="10,57,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.603,-0.2" Width="374" FontSize="20"/>
<Label x:Name="lbl_title" Content="Details" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="81" FontSize="24"/>
<Button x:Name="btn_close" Content="Close" HorizontalAlignment="Left" Margin="309,389,0,0" VerticalAlignment="Top" Width="75" Background="#FFFFABAB" Click="btn_close_Click"/>
<TextBlock x:Name="txtblk_clonelnk" Margin="147,377,195,12" FontSize="20" RenderTransformOrigin="0.238,1.236">
<Hyperlink NavigateUri="{Binding}" RequestNavigate="Hyperlink_RequestNavigate">
Clone
</Hyperlink>
</TextBlock>
<TextBlock Margin="204,386,118,17">
<Hyperlink NavigateUri="{Binding}" RequestNavigate="Hyperlink_RequestNavigate_1">
GitHub Page
</Hyperlink>
</TextBlock>
<TextBlock x:Name="txtblk_language" HorizontalAlignment="Left" Margin="13,99,0,0" TextWrapping="Wrap" Text="This repo is mostly crappy code!" VerticalAlignment="Top" Height="25" Width="223" FontSize="14"/>
<TextBlock x:Name="txtblk_stargazers" HorizontalAlignment="Left" Margin="13,129,0,0" TextWrapping="Wrap" Text="This repo has 0 stargazers!" VerticalAlignment="Top" Height="24" Width="186" FontSize="14"/>
<ComboBox x:Name="cmbbox_branches" HorizontalAlignment="Left" Margin="13,377,0,0" VerticalAlignment="Top" Width="120" Height="32"/>
<Label x:Name="lbl_branch" Content="What branch do you want to download?" HorizontalAlignment="Left" Margin="13,346,0,0" VerticalAlignment="Top" Width="223"/>
<TextBlock x:Name="txtblk_language" HorizontalAlignment="Left" Margin="13,120,0,0" TextWrapping="Wrap" Text="This repo is mostly some code." VerticalAlignment="Top" Height="25" Width="223" FontSize="14"/>
<TextBlock x:Name="txtblk_stargazers" HorizontalAlignment="Left" Margin="13,150,0,0" TextWrapping="Wrap" Text="This repo has 0 stargazers." VerticalAlignment="Top" Height="24" Width="186" FontSize="14"/>
<ComboBox x:Name="cmbbox_branches" HorizontalAlignment="Left" Margin="13,389,0,0" VerticalAlignment="Top" Width="120" Height="19"/>
<Label x:Name="lbl_branch" Content="What branch do you want to download?" HorizontalAlignment="Left" Margin="13,358,0,0" VerticalAlignment="Top" Width="223" Padding="1,5,5,5" RenderTransformOrigin="0.537,0.517"/>
<TextBlock x:Name="txtblk_watchers" HorizontalAlignment="Left" Margin="13,179,0,0" TextWrapping="Wrap" Text="This repo has 0 watchers." VerticalAlignment="Top" Width="209" FontSize="14" Height="24"/>
<TextBlock x:Name="txtblk_forks" HorizontalAlignment="Left" Margin="13,208,0,0" TextWrapping="Wrap" Text="This repo has 0 forks." VerticalAlignment="Top" FontSize="14" Height="20" Width="223"/>
<Button x:Name="btn_page" Content="GitHub Page" HorizontalAlignment="Left" Margin="13,333,0,0" VerticalAlignment="Top" Width="88" RenderTransformOrigin="0.29,1.69" Click="btn_page_Click"/>
<Button x:Name="btn_clone" Content="Clone" HorizontalAlignment="Left" Margin="147,388,0,0" VerticalAlignment="Top" Width="75" Click="btn_clone_Click"/>
</Grid>
</Window>

View File

@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@ -21,23 +22,37 @@ namespace DeskHubSharp
public partial class DetailWindow : Window
{
private RepoDetail _repoDetail;
private Request _request;
private Owner _owner;
public DetailWindow(RepoDetail repoDetail)
{
InitializeComponent();
_repoDetail = repoDetail;
Request request = new Request(_repoDetail.name);
_request = new Request(_repoDetail.name);
RepoInfo info = new RepoInfo();
request.BranchRequest();
_request.PerformBranchRequest();
var stuff = info.GetBranchNameComboBox();
cmbbox_branches.ItemsSource = stuff;
lbl_reponame.Content = _repoDetail.full_name;
if (_repoDetail.language != null)
{
txtblk_language.Text = $"This repo is mostly {_repoDetail.language} code.";
}
else
{
txtblk_language.Text = "This repo doesn't have any code.";
}
lbl_reponame.Content = _repoDetail.full_name;
txtblk_stargazers.Text = $"This repo has {_repoDetail.stargazers_count} stargazers.";
txtblk_watchers.Text = $"This repo has {_repoDetail.watchers_count} watchers.";
txtblk_forks.Text = $"This repo has {_repoDetail.forks_count} forks.";
}
private void btn_close_Click(object sender, RoutedEventArgs e)
@ -45,14 +60,26 @@ namespace DeskHubSharp
this.Close();
}
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
private void btn_clone_Click(object sender, RoutedEventArgs e)
{
if (cmbbox_branches.Text == "")
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "Please select a branch to clone.";
}
else
{
_owner = new Owner();
string link = "https://github.com/" + _repoDetail.owner.login + "/" + _repoDetail.name + "/archive/" + cmbbox_branches.Text + ".zip";
Process.Start(link);
}
}
private void Hyperlink_RequestNavigate_1(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
private void btn_page_Click(object sender, RoutedEventArgs e)
{
Process.Start($"{_repoDetail.html_url}");
}
}
}

View File

@ -23,6 +23,8 @@ namespace DeskHubSharp
{
private ObservableCollection<RepoDetail> _repoDetail;
private User _userDetail;
private Request _request;
private RepoInfo _repoInfo;
public MainWindow()
{
@ -41,15 +43,15 @@ namespace DeskHubSharp
}
catch (IndexOutOfRangeException)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "Please pick a repository!";
err.ShowDialog();
ShowErrorMessage("Please pick a repository!");
}
catch (NullReferenceException)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "Please search for a user with the Search button!";
err.ShowDialog();
ShowErrorMessage("Please search for a user with the Search button!");
}
catch (ArgumentOutOfRangeException)
{
ShowErrorMessage("MEME REVIEW!");
}
}
@ -82,7 +84,6 @@ namespace DeskHubSharp
SearchWindow search = new SearchWindow();
search.ShowDialog();
RepoInfo info = new RepoInfo();
Owner owner = new Owner();
var stuff = info.GetRepoInfoList();
@ -106,5 +107,12 @@ namespace DeskHubSharp
txtblk_repocount.Text = $"{_userDetail.login} has {_userDetail.public_repos} public repositories.";
}
}
public void ShowErrorMessage(string message)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = message;
err.ShowDialog();
}
}
}

View File

@ -4,6 +4,7 @@ namespace DeskHubSharp
{
// TODO: The RepoDetail class is called from the code behind, fix it
public class RepoDetail
{
public Owner Owner { get; set; }

View File

@ -19,6 +19,9 @@ namespace DeskHubSharp
/// </summary>
public partial class SearchWindow : Window
{
private Request _request;
public SearchWindow()
{
InitializeComponent();
@ -39,9 +42,9 @@ namespace DeskHubSharp
}
else
{
Request request = new Request(txtbox_query.Text);
request.SearchRequest();
request.UserRequest();
_request = new Request(txtbox_query.Text);
_request.PerformSearchRequest();
_request.PerformUserRequest();
this.Close();
}

View File

@ -1,4 +1,4 @@
#pragma checksum "..\..\App.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "5E7C2DBB667F025FC5CA90C6A4E4064F"
#pragma checksum "..\..\App.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "8924CF88FE4A7948C7314277251E7D79D8D8F350"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.

View File

@ -1,4 +1,4 @@
#pragma checksum "..\..\App.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "5E7C2DBB667F025FC5CA90C6A4E4064F"
#pragma checksum "..\..\App.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "8924CF88FE4A7948C7314277251E7D79D8D8F350"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.

View File

@ -1 +1 @@
c5d282543c3b37678a7432b9472aa380cdfd2ea1
126931593991507bb071b2be67ad4cd72eeb0287

View File

@ -4,16 +4,16 @@
winexe
C#
.cs
C:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\obj\Debug\
C:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\obj\Debug\
DeskHubSharp
none
false
DEBUG;TRACE
C:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\App.xaml
C:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\App.xaml
7-86569338
261659884516
20-856998346
26-1609030936
20415715258
AboutWindow.xaml;DetailWindow.xaml;ErrorWindow.xaml;FeedbackWindow.xaml;HelpWindow.xaml;MainWindow.xaml;SearchWindow.xaml;
False

View File

@ -4,16 +4,16 @@
winexe
C#
.cs
C:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\obj\Debug\
C:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\obj\Debug\
DeskHubSharp
none
false
DEBUG;TRACE
C:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\App.xaml
C:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\App.xaml
7-86569338
30428560335
20-856998346
30-1807549293
20415715258
AboutWindow.xaml;DetailWindow.xaml;ErrorWindow.xaml;FeedbackWindow.xaml;HelpWindow.xaml;MainWindow.xaml;SearchWindow.xaml;
False

View File

@ -1,10 +1,10 @@

FC:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\AboutWindow.xaml;;
FC:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\DetailWindow.xaml;;
FC:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\ErrorWindow.xaml;;
FC:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\FeedbackWindow.xaml;;
FC:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\HelpWindow.xaml;;
FC:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\MainWindow.xaml;;
FC:\Users\mill1159\Desktop\DeskHubSharp\DeskHubSharp\SearchWindow.xaml;;
FC:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\AboutWindow.xaml;;
FC:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\DetailWindow.xaml;;
FC:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\ErrorWindow.xaml;;
FC:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\FeedbackWindow.xaml;;
FC:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\HelpWindow.xaml;;
FC:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\MainWindow.xaml;;
FC:\Users\Wyatt\Desktop\Source\DeskHubSharp\DeskHubSharp\SearchWindow.xaml;;

View File

@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "3C69E49B02EA13170DBA0849627181DA"
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "0EAA4E5953DD54A83EF84C8979256F95CA55AC47"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.

View File

@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "3C69E49B02EA13170DBA0849627181DA"
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "0EAA4E5953DD54A83EF84C8979256F95CA55AC47"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.