Skip to content

Commit 9652bc8

Browse files
author
Lee
committed
First Commit
1 parent ce39b0e commit 9652bc8

File tree

484 files changed

+55560
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

484 files changed

+55560
-0
lines changed

CSharpApp.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30011.22
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpApp", "CSharpApp\CSharpApp.csproj", "{70D7E0BB-80E4-4075-B2B9-91B5BE879664}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{70D7E0BB-80E4-4075-B2B9-91B5BE879664}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{70D7E0BB-80E4-4075-B2B9-91B5BE879664}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{70D7E0BB-80E4-4075-B2B9-91B5BE879664}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{70D7E0BB-80E4-4075-B2B9-91B5BE879664}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3D785DA5-014D-4E5B-BB7F-E9D43D7DCEF8}
24+
EndGlobalSection
25+
EndGlobal

CSharpApp/CSharpApp.csproj

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<Company>John Deere</Company>
6+
<Product>MyJohnDeereAPI-OAuth2_CSharp-Example</Product>
7+
<Authors>John Deere</Authors>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.0.0" />
12+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
13+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
14+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
15+
</ItemGroup>
16+
17+
</Project>

CSharpApp/CSharpApp.csproj.user

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
5+
<Controller_SelectedScaffolderCategoryPath>root/Controller</Controller_SelectedScaffolderCategoryPath>
6+
<WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth>
7+
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
8+
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
9+
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>True</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
10+
<WebStackScaffolding_LayoutPageFile />
11+
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
12+
</PropertyGroup>
13+
</Project>
+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
using System.IO;
2+
using System.Net.Http;
3+
using System.Net.Http.Headers;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Authentication;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Configuration;
8+
using CSharpApp.Interfaces;
9+
using CSharpApp.Models;
10+
using Newtonsoft.Json;
11+
using Newtonsoft.Json.Linq;
12+
using Formatting = Newtonsoft.Json.Formatting;
13+
14+
namespace CSharpApp.Controllers
15+
{
16+
public class APIController : Controller
17+
{
18+
protected JDeere MySettings { get; set; }
19+
20+
[HttpPost]
21+
public async Task<IActionResult> EditAPIDetailsAsync([FromServices]IConfiguration configuration, string ClientId, string ClientSecret, string AuthorizationEndpoint, string TokenEndpoint, string APIEndPoint)
22+
{
23+
JDeere obj = new JDeere
24+
{
25+
ClientId = ClientId,
26+
ClientSecret = ClientSecret,
27+
AuthorizationEndpoint = AuthorizationEndpoint,
28+
TokenEndpoint = TokenEndpoint,
29+
APIEndPoint = APIEndPoint
30+
};
31+
32+
_writableLocations.Update(opt => {
33+
opt.ClientId = obj.ClientId;
34+
opt.ClientSecret = obj.ClientSecret;
35+
opt.AuthorizationEndpoint = obj.AuthorizationEndpoint;
36+
opt.TokenEndpoint = obj.TokenEndpoint;
37+
opt.APIEndPoint = obj.APIEndPoint;
38+
});
39+
40+
ViewBag.ClientId = configuration["JDeere:ClientId"];
41+
ViewBag.ClientSecret = configuration["JDeere:ClientSecret"];
42+
ViewBag.AuthorizationEndpoint = configuration["JDeere:AuthorizationEndpoint"];
43+
ViewBag.TokenEndpoint = configuration["JDeere:TokenEndpoint"];
44+
ViewBag.APIEndPoint = configuration["JDeere:APIEndPoint"];
45+
46+
TempData["ClientId"] = ViewBag.ClientId;
47+
TempData["ClientSecret"] = ViewBag.ClientSecret;
48+
TempData["AuthorizationEndpoint"] = ViewBag.AuthorizationEndpoint;
49+
TempData["TokenEndpoint"] = ViewBag.TokenEndpoint;
50+
TempData["APIEndPoint"] = ViewBag.APIEndpoint;
51+
52+
var APISave = ViewBag.APIEndPoint;
53+
var settings = new JDeere
54+
{
55+
Token = await HttpContext.GetTokenAsync("access_token")
56+
};
57+
var token = await HttpContext.GetTokenAsync("access_token");
58+
var Url = APISave.ToString();
59+
HttpClient client = new HttpClient();
60+
61+
client.DefaultRequestHeaders.Accept.Clear();
62+
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.deere.axiom.v3+json"));
63+
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
64+
65+
var response = await client.GetAsync(Url);
66+
response.EnsureSuccessStatusCode();
67+
68+
var stream = await response.Content.ReadAsStringAsync();
69+
var djson = JsonConvert.DeserializeObject<Stream>(stream);
70+
var json = JsonConvert.SerializeObject(stream, Formatting.Indented);
71+
var jsonFormatted = JValue.Parse(json).ToString(Formatting.Indented);
72+
ViewBag.APIPath = jsonFormatted.Value.ToString();
73+
74+
return View(obj);
75+
}
76+
77+
private readonly IWritableOptions<JDeere> _writableLocations;
78+
public APIController(IWritableOptions<JDeere> writableLocations)
79+
{
80+
_writableLocations = writableLocations;
81+
}
82+
public async Task<IActionResult> Index([FromServices]IConfiguration configuration, string ClientId, string ClientSecret, string AuthorizationEndpoint, string TokenEndpoint, string APIEndPoint)
83+
{
84+
JDeere obj = new JDeere
85+
{
86+
ClientId = ClientId,
87+
ClientSecret = ClientSecret,
88+
AuthorizationEndpoint = AuthorizationEndpoint,
89+
TokenEndpoint = TokenEndpoint,
90+
APIEndPoint = APIEndPoint
91+
};
92+
93+
_writableLocations.Update(opt => {
94+
opt.ClientId = obj.ClientId;
95+
opt.ClientSecret = obj.ClientSecret;
96+
opt.AuthorizationEndpoint = obj.AuthorizationEndpoint;
97+
opt.TokenEndpoint = obj.TokenEndpoint;
98+
opt.APIEndPoint = obj.APIEndPoint;
99+
});
100+
101+
ViewBag.ClientId = configuration["JDeere:ClientId"];
102+
ViewBag.ClientSecret = configuration["JDeere:ClientSecret"];
103+
ViewBag.AuthorizationEndpoint = configuration["JDeere:AuthorizationEndpoint"];
104+
ViewBag.TokenEndpoint = configuration["JDeere:TokenEndpoint"];
105+
ViewBag.APIEndPoint = configuration["JDeere:APIEndPoint"];
106+
107+
TempData["ClientId"] = ViewBag.ClientId;
108+
TempData["ClientSecret"] = ViewBag.ClientSecret;
109+
TempData["AuthorizationEndpoint"] = ViewBag.AuthorizationEndpoint;
110+
TempData["TokenEndpoint"] = ViewBag.TokenEndpoint;
111+
TempData["APIEndPoint"] = ViewBag.APIEndpoint;
112+
113+
var APISave = TempData["APIEndPoint"];
114+
ViewBag.APIEndPoint = APISave;
115+
116+
var settings = new JDeere
117+
{
118+
Token = await HttpContext.GetTokenAsync("access_token")
119+
};
120+
121+
var token = await HttpContext.GetTokenAsync("access_token");
122+
var Url = APISave.ToString();
123+
HttpClient client = new HttpClient();
124+
125+
client.DefaultRequestHeaders.Accept.Clear();
126+
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.deere.axiom.v3+json"));
127+
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
128+
129+
var response = await client.GetAsync(Url);
130+
response.EnsureSuccessStatusCode();
131+
132+
var stream = await response.Content.ReadAsStringAsync();
133+
var json = JsonConvert.SerializeObject(stream, Formatting.Indented);
134+
var json2 = new JsonResult(json) { SerializerSettings = new JsonSerializerSettings() { Formatting = Formatting.Indented } };
135+
ViewBag.APIPath = json2.Value.ToString();
136+
137+
return View(settings);
138+
}
139+
}
140+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Hosting;
7+
8+
namespace CSharpApp.Controllers
9+
{
10+
public class CloseController : Controller
11+
{
12+
private IHostApplicationLifetime ApplicationLifetime { get; set; }
13+
public CloseController(IHostApplicationLifetime appLifetime)
14+
{
15+
ApplicationLifetime = appLifetime;
16+
}
17+
public IActionResult Index()
18+
{
19+
ApplicationLifetime.StopApplication();
20+
return View();
21+
}
22+
}
23+
}
24+
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Configuration;
3+
using CSharpApp.Models;
4+
5+
namespace CSharpApp.Controllers
6+
{
7+
public class HomeController : Controller
8+
{
9+
private readonly IConfiguration _configuration;
10+
protected JDeere MySettings { get; set; }
11+
public HomeController(IConfiguration configuration)
12+
{
13+
_configuration = configuration;
14+
}
15+
public IActionResult Index()
16+
{
17+
ViewBag.ClientId = _configuration["JDeere:ClientId"];
18+
ViewBag.ClientSecret = _configuration["JDeere:ClientSecret"];
19+
ViewBag.AuthorizationEndpoint = _configuration["JDeere:AuthorizationEndpoint"];
20+
ViewBag.Scopes = _configuration["JDeere:Scopes"];
21+
ViewBag.TokenEndpoint = _configuration["JDeere:TokenEndpoint"];
22+
ViewBag.APIEndpoint = _configuration["JDeere:APIEndpoint"];
23+
24+
TempData["ClientId"] = ViewBag.ClientId;
25+
TempData["ClientSecret"] = ViewBag.ClientSecret;
26+
TempData["AuthorizationEndpoint"] = ViewBag.AuthorizationEndpoint;
27+
TempData["Scopes"] = ViewBag.Scopes;
28+
TempData["TokenEndpoint"] = ViewBag.TokenEndpoint;
29+
TempData["APIEndPoint"] = ViewBag.APIEndpoint;
30+
31+
return View();
32+
}
33+
public IActionResult ReadMe()
34+
{
35+
return View();
36+
}
37+
public IActionResult Privacy()
38+
{
39+
return View();
40+
}
41+
}
42+
}
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Configuration;
3+
using CSharpApp.Interfaces;
4+
using CSharpApp.Models;
5+
6+
namespace CSharpApp.Controllers
7+
{
8+
public class SettingsController : Controller
9+
{
10+
public IActionResult Index([FromServices]IConfiguration configuration)
11+
{
12+
ViewBag.ClientId = configuration["JDeere:ClientId"];
13+
ViewBag.ClientSecret = configuration["JDeere:ClientSecret"];
14+
ViewBag.AuthorizationEndpoint = configuration["JDeere:AuthorizationEndpoint"];
15+
ViewBag.Scopes = configuration["JDeere:Scopes"];
16+
ViewBag.TokenEndpoint = configuration["JDeere:TokenEndpoint"];
17+
ViewBag.APIEndPoint = configuration["JDeere:APIEndPoint"];
18+
19+
return View();
20+
}
21+
[HttpPost]
22+
public IActionResult UpdateSettings(string ClientId, string ClientSecret, string AuthorizationEndpoint, string Scopes, string TokenEndpoint, string APIEndPoint)
23+
{
24+
JDeere obj = new JDeere
25+
{
26+
ClientId = ClientId,
27+
ClientSecret = ClientSecret,
28+
AuthorizationEndpoint = AuthorizationEndpoint,
29+
Scopes = Scopes,
30+
TokenEndpoint = TokenEndpoint,
31+
APIEndPoint = APIEndPoint
32+
};
33+
34+
_writableLocations.Update(opt => {
35+
opt.ClientId = obj.ClientId;
36+
opt.ClientSecret = obj.ClientSecret;
37+
opt.AuthorizationEndpoint = obj.AuthorizationEndpoint;
38+
opt.Scopes = obj.Scopes;
39+
opt.TokenEndpoint = obj.TokenEndpoint;
40+
opt.APIEndPoint = obj.APIEndPoint;
41+
});
42+
return View(obj);
43+
}
44+
45+
private readonly IWritableOptions<JDeere> _writableLocations;
46+
public SettingsController(IWritableOptions<JDeere> writableLocations)
47+
{
48+
_writableLocations = writableLocations;
49+
}
50+
51+
}
52+
}

0 commit comments

Comments
 (0)