Skip to content

Commit 8bb45ce

Browse files
authored
Merge pull request #8 from Gonkers/dotnet5
.NET 5
2 parents 074146b + 62122be commit 8bb45ce

File tree

92 files changed

+25931
-9544
lines changed

Some content is hidden

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

92 files changed

+25931
-9544
lines changed

ScryfallApi.sln

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27004.2009
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30717.126
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScryfallApi.Client", "src\ScryfallApi.Client\ScryfallApi.Client.csproj", "{80A567E0-6C64-46BE-A724-83E13344A8D0}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C470746D-B24E-4759-B7A3-6C8EDD801544}"
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScryfallApi.WebSample", "samples\ScryfallApi.WebSample\ScryfallApi.WebSample.csproj", "{383BF6C1-47B7-47E8-8428-B3A114EFC3B0}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScryfallApi.NetFxExample", "samples\ScryfallApi.NetFxExample\ScryfallApi.NetFxExample.csproj", "{9EE20F37-E50E-4395-A37D-979AD38D995A}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -23,12 +25,17 @@ Global
2325
{383BF6C1-47B7-47E8-8428-B3A114EFC3B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
2426
{383BF6C1-47B7-47E8-8428-B3A114EFC3B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
2527
{383BF6C1-47B7-47E8-8428-B3A114EFC3B0}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{9EE20F37-E50E-4395-A37D-979AD38D995A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{9EE20F37-E50E-4395-A37D-979AD38D995A}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{9EE20F37-E50E-4395-A37D-979AD38D995A}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{9EE20F37-E50E-4395-A37D-979AD38D995A}.Release|Any CPU.Build.0 = Release|Any CPU
2632
EndGlobalSection
2733
GlobalSection(SolutionProperties) = preSolution
2834
HideSolutionNode = FALSE
2935
EndGlobalSection
3036
GlobalSection(NestedProjects) = preSolution
3137
{383BF6C1-47B7-47E8-8428-B3A114EFC3B0} = {C470746D-B24E-4759-B7A3-6C8EDD801544}
38+
{9EE20F37-E50E-4395-A37D-979AD38D995A} = {C470746D-B24E-4759-B7A3-6C8EDD801544}
3239
EndGlobalSection
3340
GlobalSection(ExtensibilityGlobals) = postSolution
3441
SolutionGuid = {4C1168D1-1DC7-410F-9D8C-E23492A1FD2F}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using ScryfallApi.Client;
2+
using ScryfallApi.Client.Models;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Net.Http;
6+
using System.Threading.Tasks;
7+
8+
namespace ScryfallApi.NetFxExample
9+
{
10+
class Program
11+
{
12+
static async Task Main(string[] args)
13+
{
14+
var httpClient = new HttpClient { BaseAddress = ScryfallApiClientConfig.GetDefault().ScryfallApiBaseAddress };
15+
var client = new ScryfallApiClient(httpClient);
16+
do
17+
{
18+
try
19+
{
20+
var randomCard = await client.Cards.GetRandom();
21+
Console.Clear();
22+
Console.WriteLine(DrawCard(randomCard));
23+
}
24+
catch (ScryfallApiException ex)
25+
{
26+
Console.Clear();
27+
Console.WriteLine($"Error: {ex.Message}");
28+
Console.WriteLine($"Status Code: {ex.ResponseStatusCode}");
29+
Console.WriteLine($"Remote Call: {ex.RequestMethod} {ex.RequestUri}");
30+
}
31+
Console.WriteLine(Environment.NewLine + "Press any key for a new card. Press Esc to quit.");
32+
} while (Console.ReadKey().Key != ConsoleKey.Escape);
33+
}
34+
35+
static string DrawCard(Card card)
36+
{
37+
const int TitleWidth = 31;
38+
var cardName = card.Name + new string(' ', TitleWidth);
39+
var title = cardName.Substring(0, TitleWidth - 1 - card.ManaCost.Length) + " " + card.ManaCost;
40+
var type = (card.TypeLine + new string(' ', TitleWidth)).Substring(0, TitleWidth);
41+
42+
var cardText = SplitOnWidth(card.OracleText, 29);
43+
var text0 = cardText.Count > 0 ? cardText[0] : new string(' ', 29);
44+
var text1 = cardText.Count > 1 ? cardText[1] : new string(' ', 29);
45+
var text2 = cardText.Count > 2 ? cardText[2] : new string(' ', 29);
46+
var text3 = cardText.Count > 3 ? cardText[3] : new string(' ', 29);
47+
48+
return $@"
49+
/---------------------------------\
50+
| {title} |
51+
|+-------------------------------+|
52+
|| \||/ ||
53+
|| | @___oo ||
54+
|| /\ /\ / (__,,,,| ||
55+
|| ) /^\) ^\/ _) ||
56+
|| ) /^\/ _) ||
57+
|| ) _ / / _) ||
58+
|| /\ )/\/ || | )_) ||
59+
|| < > |(,,) )__) ||
60+
|| || / \)___)\ ||
61+
|| | \____( )___) )___ ||
62+
|| \______(_______;;; __;;; ||
63+
|+-------------------------------+|
64+
| {type} |
65+
|+-------------------------------+|
66+
|| {text0} ||
67+
|| {text1} ||
68+
|| {text2} ||
69+
|| {text3} ||
70+
|+-------------------------------+|
71+
\---------------------------------/";
72+
}
73+
74+
static List<string> SplitOnWidth(string text, int width)
75+
{
76+
var rawLines = text.Split(new[] { "\n" }, StringSplitOptions.None);
77+
var textLines = new List<string>();
78+
for (int i = 0; i < rawLines.Length; i++)
79+
{
80+
var line = rawLines[i];
81+
while (line.Length > 0)
82+
{
83+
if (line.Length <= width)
84+
{
85+
textLines.Add((line + new string(' ', width)).Substring(0, width));
86+
line = string.Empty;
87+
}
88+
else
89+
{
90+
textLines.Add(line.Substring(0, width));
91+
line = line.Remove(0, width);
92+
}
93+
}
94+
}
95+
return textLines;
96+
}
97+
}
98+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ScryfallApi.NetFxExample")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ScryfallApi.NetFxExample")]
13+
[assembly: AssemblyCopyright("Copyright © 2020")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("9ee20f37-e50e-4395-a37d-979ad38d995a")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{9EE20F37-E50E-4395-A37D-979AD38D995A}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>ScryfallApi.NetFxExample</RootNamespace>
10+
<AssemblyName>ScryfallApi.NetFxExample</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="Microsoft.Extensions.Caching.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
37+
<HintPath>..\..\packages\Microsoft.Extensions.Caching.Abstractions.5.0.0\lib\net461\Microsoft.Extensions.Caching.Abstractions.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
40+
<HintPath>..\..\packages\Microsoft.Extensions.Primitives.5.0.0\lib\net461\Microsoft.Extensions.Primitives.dll</HintPath>
41+
</Reference>
42+
<Reference Include="System" />
43+
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
44+
<HintPath>..\..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
45+
</Reference>
46+
<Reference Include="System.Core" />
47+
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
48+
<HintPath>..\..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
49+
</Reference>
50+
<Reference Include="System.Numerics" />
51+
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
52+
<HintPath>..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
53+
</Reference>
54+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
55+
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
56+
</Reference>
57+
<Reference Include="System.Xml.Linq" />
58+
<Reference Include="System.Data.DataSetExtensions" />
59+
<Reference Include="Microsoft.CSharp" />
60+
<Reference Include="System.Data" />
61+
<Reference Include="System.Net.Http" />
62+
<Reference Include="System.Xml" />
63+
</ItemGroup>
64+
<ItemGroup>
65+
<Compile Include="Program.cs" />
66+
<Compile Include="Properties\AssemblyInfo.cs" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<None Include="App.config" />
70+
<None Include="packages.config" />
71+
</ItemGroup>
72+
<ItemGroup>
73+
<ProjectReference Include="..\..\src\ScryfallApi.Client\ScryfallApi.Client.csproj">
74+
<Project>{80a567e0-6c64-46be-a724-83e13344a8d0}</Project>
75+
<Name>ScryfallApi.Client</Name>
76+
</ProjectReference>
77+
</ItemGroup>
78+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
79+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.Extensions.Caching.Abstractions" version="5.0.0" targetFramework="net472" />
4+
<package id="Microsoft.Extensions.Primitives" version="5.0.0" targetFramework="net472" />
5+
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
6+
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
7+
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
8+
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
9+
</packages>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@page
2+
@model ScryfallApi.WebSample.Pages.CardsModel
3+
@{
4+
<form method="get">
5+
<select name="set" asp-items="Model.SetList" onchange="submit()"></select>
6+
</form>
7+
8+
if (Model.CardList is not null)
9+
{
10+
<p>
11+
@foreach (var card in Model.CardList)
12+
{
13+
<a href="@card.ScryfallUri"><img alt="@card.Name" title="@card.Name" src="@card.ImageUris["small"]" /></a>
14+
}
15+
</p>
16+
}
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.AspNetCore.Mvc.RazorPages;
7+
using Microsoft.AspNetCore.Mvc.Rendering;
8+
using ScryfallApi.Client;
9+
using ScryfallApi.Client.Models;
10+
11+
namespace ScryfallApi.WebSample.Pages
12+
{
13+
public class CardsModel : PageModel
14+
{
15+
private readonly ScryfallApiClient _scryfallApi;
16+
public List<SelectListItem> SetList { get; set; }
17+
public ICollection<Card> CardList { get; set; }
18+
19+
public CardsModel(ScryfallApiClient scryfallApi)
20+
{
21+
_scryfallApi = scryfallApi ?? throw new ArgumentNullException(nameof(scryfallApi));
22+
}
23+
24+
public async Task<IActionResult> OnGet([FromQuery] string set)
25+
{
26+
var sets = await _scryfallApi.Sets.Get();
27+
SetList = sets.Data.OrderBy(s => s.Name).Select(s => new SelectListItem(s.Name, s.Code)).ToList();
28+
29+
var selectedItem = SetList.FirstOrDefault(li => li.Value.Equals(set));
30+
if (selectedItem is not null)
31+
{
32+
selectedItem.Selected = true;
33+
CardList = (await _scryfallApi.Cards.Search($"e:{selectedItem.Value}", 1, SearchOptions.CardSort.Name)).Data;
34+
}
35+
else
36+
CardList = new List<Card>();
37+
38+
return Page();
39+
}
40+
}
41+
}

samples/ScryfallApi.WebSample/Pages/Error.cshtml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
<h3>Development Mode</h3>
1818
<p>
19-
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
2020
</p>
2121
<p>
22-
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
2326
</p>

samples/ScryfallApi.WebSample/Pages/Error.cshtml.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using Microsoft.Extensions.Logging;
14
using System;
25
using System.Collections.Generic;
36
using System.Diagnostics;
47
using System.Linq;
58
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore.Mvc;
7-
using Microsoft.AspNetCore.Mvc.RazorPages;
89

910
namespace ScryfallApi.WebSample.Pages
1011
{
12+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
13+
[IgnoreAntiforgeryToken]
1114
public class ErrorModel : PageModel
1215
{
1316
public string RequestId { get; set; }
1417

1518
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
1619

17-
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
20+
private readonly ILogger<ErrorModel> _logger;
21+
22+
public ErrorModel(ILogger<ErrorModel> logger)
23+
{
24+
_logger = logger;
25+
}
26+
1827
public void OnGet()
1928
{
2029
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;

0 commit comments

Comments
 (0)