Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77688eb

Browse files
Lesson 3 code files uploaded
1 parent 4590eeb commit 77688eb

File tree

142 files changed

+25103
-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.

142 files changed

+25103
-0
lines changed

‎Lesson03/SystemInfo.sln‎

Lines changed: 25 additions & 0 deletions
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 15
4+
VisualStudioVersion = 15.0.26730.8
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemInfo", "SystemInfo\SystemInfo.csproj", "{76988CF2-D6F7-4126-A5AB-A1B903B59746}"
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+
{76988CF2-D6F7-4126-A5AB-A1B903B59746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{76988CF2-D6F7-4126-A5AB-A1B903B59746}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{76988CF2-D6F7-4126-A5AB-A1B903B59746}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{76988CF2-D6F7-4126-A5AB-A1B903B59746}.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 = {5D9775F0-5633-4C15-A89D-EF65D2D90329}
24+
EndGlobalSection
25+
EndGlobal

‎Lesson03/SystemInfo/.bowerrc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "wwwroot/lib"
3+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using SystemInfo.Models;
8+
9+
namespace SystemInfo.Controllers
10+
{
11+
public class HomeController : Controller
12+
{
13+
public IActionResult Index()
14+
{
15+
return View();
16+
}
17+
18+
public IActionResult About()
19+
{
20+
//ViewData["Message"] = "Your application description page.";
21+
22+
return View();
23+
}
24+
25+
public IActionResult Contact()
26+
{
27+
//ViewData["Message"] = "Your contact page.";
28+
29+
return View();
30+
}
31+
32+
public IActionResult Error()
33+
{
34+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
35+
}
36+
}
37+
}
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
using DarkSky.Models;
2+
using DarkSky.Services;
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Newtonsoft.Json;
6+
using System.Globalization;
7+
using System.IO;
8+
using System.Net.Http;
9+
using System.Runtime.InteropServices;
10+
using System.Threading.Tasks;
11+
using static System.Math;
12+
13+
namespace SystemInfo.Controllers
14+
{
15+
public class InformationController : Controller
16+
{
17+
public string PublicIP { get; set; } = "IP Lookup Failed";
18+
public double Long { get; set; }
19+
public double Latt { get; set; }
20+
public string City { get; set; }
21+
public string CurrentWeatherIcon { get; set; }
22+
public string WeatherAttribution { get; set; }
23+
public string CurrentTemp { get; set; } = "undetermined";
24+
public string DayWeatherSummary { get; set; }
25+
public string TempUnitOfMeasure { get; set; }
26+
private readonly IHostingEnvironment _hostEnv;
27+
28+
public InformationController(IHostingEnvironment hostingEnvironment)
29+
{
30+
_hostEnv = hostingEnvironment;
31+
}
32+
33+
public IActionResult Index()
34+
{
35+
return View();
36+
}
37+
38+
public IActionResult GetInfo()
39+
{
40+
Models.InformationModel model = new Models.InformationModel();
41+
model.OperatingSystem = RuntimeInformation.OSDescription;
42+
model.FrameworkDescription = RuntimeInformation.FrameworkDescription;
43+
model.OSArchitecture = RuntimeInformation.OSArchitecture.ToString();
44+
model.ProcessArchitecture = RuntimeInformation.ProcessArchitecture.ToString();
45+
46+
string title = string.Empty;
47+
string OSArchitecture = string.Empty;
48+
49+
if (model.OSArchitecture.ToUpper().Equals("X64")) { OSArchitecture = "64-bit"; } else { OSArchitecture = "32-bit"; }
50+
51+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { title = $"Windows {OSArchitecture}"; }
52+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { title = $"OSX {OSArchitecture}"; }
53+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { title = $"Linux {OSArchitecture}"; }
54+
55+
GetLocationInfo().Wait();
56+
model.IPAddressString = PublicIP;
57+
58+
GetWeatherInfo().Wait();
59+
model.CurrentIcon = CurrentWeatherIcon;
60+
model.WeatherBy = WeatherAttribution;
61+
model.CurrentTemperature = CurrentTemp;
62+
model.DailySummary = DayWeatherSummary;
63+
model.CurrentCity = City;
64+
model.UnitOfMeasure = TempUnitOfMeasure;
65+
66+
model.InfoTitle = title;
67+
return View(model);
68+
}
69+
70+
71+
72+
#region GetLocationInfo
73+
/// <summary>
74+
/// https://ipapi.co
75+
/// </summary>
76+
/// <returns>Full location information</returns>
77+
private async Task GetLocationInfo()
78+
{
79+
var httpClient = new HttpClient();
80+
string json = await httpClient.GetStringAsync("https://ipapi.co/json");
81+
LocationInfo info = JsonConvert.DeserializeObject<LocationInfo>(json);
82+
83+
PublicIP = info.ip;
84+
Long = info.longitude;
85+
Latt = info.latitude;
86+
City = info.city;
87+
}
88+
#endregion
89+
90+
#region GetWeatherInfo
91+
/// <summary>
92+
/// https://darksky.net
93+
/// </summary>
94+
/// <returns>Weather Info for current location from Dark Sky</returns>
95+
private async Task GetWeatherInfo()
96+
{
97+
string apiKey = "e17b4001a6010f38fceb6ec98672431c";
98+
DarkSkyService weather = new DarkSkyService(apiKey);
99+
DarkSkyService.OptionalParameters optParms = GetUnitOfMeasure();
100+
var foreCast = await weather.GetForecast(Latt, Long, optParms);
101+
102+
string iconFilename = GetCurrentWeatherIcon(foreCast.Response.Currently.Icon);
103+
string svgFile = Path.Combine(_hostEnv.ContentRootPath, "climacons", iconFilename);
104+
CurrentWeatherIcon = System.IO.File.ReadAllText($"{svgFile}");
105+
106+
WeatherAttribution = foreCast.AttributionLine;
107+
DayWeatherSummary = foreCast.Response.Daily.Summary;
108+
if (foreCast.Response.Currently.Temperature.HasValue)
109+
CurrentTemp = Round(foreCast.Response.Currently.Temperature.Value, 0).ToString();
110+
}
111+
#endregion
112+
113+
#region Find Unit of Measure
114+
/// <summary>
115+
/// Find Imperial or Metric UOM
116+
/// </summary>
117+
/// <returns>A boolean = Imperial or Metric UOM</returns>
118+
private DarkSkyService.OptionalParameters GetUnitOfMeasure()
119+
{
120+
bool blnMetric = RegionInfo.CurrentRegion.IsMetric;
121+
DarkSkyService.OptionalParameters optParms = new DarkSkyService.OptionalParameters();
122+
if (blnMetric)
123+
{
124+
optParms.MeasurementUnits = "si";
125+
TempUnitOfMeasure = "C";
126+
}
127+
else
128+
{
129+
optParms.MeasurementUnits = "us";
130+
TempUnitOfMeasure = "F";
131+
}
132+
return optParms;
133+
}
134+
#endregion
135+
136+
#region GetCurrentWeatherIcon
137+
/// <summary>
138+
/// Climacons
139+
/// 75 climatically categorised pictographs for web and UI design by @adamwhitcroft.
140+
/// Visit http://adamwhitcroft.com/climacons/ for more information.
141+
///
142+
/// License
143+
/// You are free to use any of the Climacons Icons (the "icons") in any personal or commercial work without obligation of payment(monetary or otherwise) or attribution,
144+
/// however a credit for the work would be appreciated.
145+
/// Do not redistribute or sell and do not claim creative credit.
146+
/// Intellectual property rights are not transferred with the download of the icons.
147+
/// </summary>
148+
/// <param name="ic"></param>
149+
/// <returns>The icon name</returns>
150+
private string GetCurrentWeatherIcon(Icon ic)
151+
{
152+
string iconFilename = string.Empty;
153+
154+
switch (ic)
155+
{
156+
case Icon.ClearDay:
157+
iconFilename = "Sun.svg";
158+
break;
159+
160+
case Icon.ClearNight:
161+
iconFilename = "Moon.svg";
162+
break;
163+
164+
case Icon.Cloudy:
165+
iconFilename = "Cloud.svg";
166+
break;
167+
168+
case Icon.Fog:
169+
iconFilename = "Cloud-Fog.svg";
170+
break;
171+
172+
case Icon.PartlyCloudyDay:
173+
iconFilename = "Cloud-Sun.svg";
174+
break;
175+
176+
case Icon.PartlyCloudyNight:
177+
iconFilename = "Cloud-Moon.svg";
178+
break;
179+
180+
case Icon.Rain:
181+
iconFilename = "Cloud-Rain.svg";
182+
break;
183+
184+
case Icon.Snow:
185+
iconFilename = "Snowflake.svg";
186+
break;
187+
188+
case Icon.Wind:
189+
iconFilename = "Wind.svg";
190+
break;
191+
default:
192+
iconFilename = "Thermometer.svg";
193+
break;
194+
}
195+
return iconFilename;
196+
}
197+
#endregion
198+
}
199+
200+
201+
202+
public class LocationInfo
203+
{
204+
public string ip { get; set; }
205+
public string city { get; set; }
206+
public string region { get; set; }
207+
public string region_code { get; set; }
208+
public string country { get; set; }
209+
public string country_name { get; set; }
210+
public string postal { get; set; }
211+
public double latitude { get; set; }
212+
public double longitude { get; set; }
213+
public string timezone { get; set; }
214+
public string asn { get; set; }
215+
public string org { get; set; }
216+
}
217+
}
218+
219+
220+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace SystemInfo.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace SystemInfo.Models
2+
{
3+
public class InformationModel
4+
{
5+
public string OperatingSystem { get; set; }
6+
public string InfoTitle { get; set; }
7+
public string FrameworkDescription { get; set; }
8+
public string OSArchitecture { get; set; }
9+
public string ProcessArchitecture { get; set; }
10+
public string Memory { get; set; }
11+
public string IPAddressString { get; set; }
12+
public string WeatherBy { get; set; }
13+
public string CurrentTemperature { get; set; }
14+
public string CurrentIcon { get; set; }
15+
public string DailySummary { get; set; }
16+
public string CurrentCity { get; set; }
17+
public string UnitOfMeasure { get; set; }
18+
}
19+
}

‎Lesson03/SystemInfo/Program.cs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace SystemInfo
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
BuildWebHost(args).Run();
18+
}
19+
20+
public static IWebHost BuildWebHost(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
22+
.UseStartup<Startup>()
23+
.Build();
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
4+
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
5+
-->
6+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
7+
<PropertyGroup>
8+
<WebPublishMethod>FileSystem</WebPublishMethod>
9+
<PublishProvider>FileSystem</PublishProvider>
10+
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
11+
<LastUsedPlatform>Any CPU</LastUsedPlatform>
12+
<SiteUrlToLaunchAfterPublish />
13+
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
14+
<ExcludeApp_Data>False</ExcludeApp_Data>
15+
<ProjectGuid>76988cf2-d6f7-4126-a5ab-a1b903b59746</ProjectGuid>
16+
<publishUrl>bin\Release\PublishOutput</publishUrl>
17+
<DeleteExistingFiles>False</DeleteExistingFiles>
18+
</PropertyGroup>
19+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:50239/",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"SystemInfo": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "http://localhost:50240/"
25+
}
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /