diff --git a/.vs/DeskHubSharp/v15/.suo b/.vs/DeskHubSharp/v15/.suo index f0f52bb..cd668ae 100644 Binary files a/.vs/DeskHubSharp/v15/.suo and b/.vs/DeskHubSharp/v15/.suo differ diff --git a/.vs/DeskHubSharp/v15/Server/sqlite3/storage.ide b/.vs/DeskHubSharp/v15/Server/sqlite3/storage.ide index 3e73441..b36fb0b 100644 Binary files a/.vs/DeskHubSharp/v15/Server/sqlite3/storage.ide and b/.vs/DeskHubSharp/v15/Server/sqlite3/storage.ide differ diff --git a/DeskHubSharp/BusinessLayer/Request.cs b/DeskHubSharp/BusinessLayer/Request.cs index 85167bf..6936274 100644 --- a/DeskHubSharp/BusinessLayer/Request.cs +++ b/DeskHubSharp/BusinessLayer/Request.cs @@ -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 { get; set; } - public Request(string query) { _query = query; + _api = new ApiDataService(_query); } - //public Request(string query, Object function) - //{ - // _query = query; - //} - - /// - /// Calls API for repo and basic user data - /// - /// - 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>(x); - - //ObservableCollection test = new ObservableCollection() - //{ - // 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(); } - - /// - /// Calls API for detailed user data - /// - 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(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."; - } - + _api.UserRequest(); } - /// - /// Calls API for detailed branch data - /// - public void BranchRequest() + public void PerformBranchRequest() { - try - { - var client = new RestClient(_apiEndpoint); + _api.BranchRequest(); + } - 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>(x); - - RequestList.branchDetail = deserailized; - } - catch (NullReferenceException) - { - ErrorWindow err = new ErrorWindow(); - err.txtblk_error.Text = "We couldn't gather user data. Please try again."; - } + public Owner GetUserData() + { + Owner owner = new Owner(); + return owner; } } diff --git a/DeskHubSharp/DAL/ApiDataService.cs b/DeskHubSharp/DAL/ApiDataService.cs new file mode 100644 index 0000000..bbfde1b --- /dev/null +++ b/DeskHubSharp/DAL/ApiDataService.cs @@ -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 { get; set; } + + public ApiDataService(string query) + { + _query = query; + _apiEndpoint = DataConfig.dataConfString; + } + + //public Request(string query, Object function) + //{ + // _query = query; + //} + + /// + /// Calls API for repo and basic user data + /// + /// + 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>(x); + + //ObservableCollection test = new ObservableCollection() + //{ + // 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"; + } + } + + + /// + /// Calls API for detailed user data + /// + 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(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."; + } + + } + + /// + /// Calls API for detailed branch data + /// + 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>(x); + + RequestList.branchDetail = deserailized; + } + catch (NullReferenceException) + { + ErrorWindow err = new ErrorWindow(); + err.txtblk_error.Text = "We couldn't gather user data. Please try again."; + } + } + + } +} diff --git a/DeskHubSharp/DAL/IDataService.cs b/DeskHubSharp/DAL/IDataService.cs index 524d14e..1d367b8 100644 --- a/DeskHubSharp/DAL/IDataService.cs +++ b/DeskHubSharp/DAL/IDataService.cs @@ -8,7 +8,11 @@ namespace DeskHubSharp { public interface IDataService { - List ReadAll(); - void WriteAll(List user); + //List ReadAll(); + //void WriteAll(List user); + + void SearchRequest(); + void UserRequest(); + void BranchRequest(); } } diff --git a/DeskHubSharp/DAL/XmlDataService.cs b/DeskHubSharp/DAL/XmlDataService.cs deleted file mode 100644 index 756b7b0..0000000 --- a/DeskHubSharp/DAL/XmlDataService.cs +++ /dev/null @@ -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 ReadAll() - { - List Users = new List(); - XmlSerializer serializer = new XmlSerializer(typeof(List), new XmlRootAttribute("Users")); - - try - { - StreamReader reader = new StreamReader(_dataFilePath); - using (reader) - { - Users = (List)serializer.Deserialize(reader); - } - - } - catch (Exception) - { - throw; - } - - return Users; - } - - public void WriteAll(List Users) - { - XmlSerializer serializer = new XmlSerializer(typeof(List), 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; - } - } -} diff --git a/DeskHubSharp/Data/DataConfig.cs b/DeskHubSharp/Data/DataConfig.cs index 354c259..abca955 100644 --- a/DeskHubSharp/Data/DataConfig.cs +++ b/DeskHubSharp/Data/DataConfig.cs @@ -8,6 +8,6 @@ namespace DeskHubSharp { class DataConfig { - public string dataConfString = ""; + public static string dataConfString = "https://api.github.com/"; } } diff --git a/DeskHubSharp/DeskHubSharp.csproj b/DeskHubSharp/DeskHubSharp.csproj index 4b9c64c..ff95bab 100644 --- a/DeskHubSharp/DeskHubSharp.csproj +++ b/DeskHubSharp/DeskHubSharp.csproj @@ -71,6 +71,7 @@ MSBuild:Compile + @@ -107,9 +108,8 @@ Code - + - DetailWindow.xaml diff --git a/DeskHubSharp/DetailWindow.xaml b/DeskHubSharp/DetailWindow.xaml index bab7521..16ca90e 100644 --- a/DeskHubSharp/DetailWindow.xaml +++ b/DeskHubSharp/DetailWindow.xaml @@ -10,19 +10,13 @@