Skip to content

Commit 748b09c

Browse files
committed
initial
0 parents  commit 748b09c

File tree

7 files changed

+425
-0
lines changed

7 files changed

+425
-0
lines changed

.gitignore

Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### VisualStudio template
3+
## Ignore Visual Studio temporary files, build results, and
4+
## files generated by popular Visual Studio add-ons.
5+
##
6+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
7+
8+
# User-specific files
9+
*.suo
10+
*.user
11+
*.userosscache
12+
*.sln.docstates
13+
14+
# User-specific files (MonoDevelop/Xamarin Studio)
15+
*.userprefs
16+
17+
# Build results
18+
[Dd]ebug/
19+
[Dd]ebugPublic/
20+
[Rr]elease/
21+
[Rr]eleases/
22+
x64/
23+
x86/
24+
bld/
25+
[Bb]in/
26+
[Oo]bj/
27+
[Ll]og/
28+
29+
# Visual Studio 2015 cache/options directory
30+
.vs/
31+
# Uncomment if you have tasks that create the project's static files in wwwroot
32+
#wwwroot/
33+
34+
# MSTest test Results
35+
[Tt]est[Rr]esult*/
36+
[Bb]uild[Ll]og.*
37+
38+
# NUNIT
39+
*.VisualState.xml
40+
TestResult.xml
41+
42+
# Build Results of an ATL Project
43+
[Dd]ebugPS/
44+
[Rr]eleasePS/
45+
dlldata.c
46+
47+
# Benchmark Results
48+
BenchmarkDotNet.Artifacts/
49+
50+
# .NET Core
51+
project.lock.json
52+
project.fragment.lock.json
53+
artifacts/
54+
**/Properties/launchSettings.json
55+
56+
*_i.c
57+
*_p.c
58+
*_i.h
59+
*.ilk
60+
*.meta
61+
*.obj
62+
*.pch
63+
*.pdb
64+
*.pgc
65+
*.pgd
66+
*.rsp
67+
*.sbr
68+
*.tlb
69+
*.tli
70+
*.tlh
71+
*.tmp
72+
*.tmp_proj
73+
*.log
74+
*.vspscc
75+
*.vssscc
76+
.builds
77+
*.pidb
78+
*.svclog
79+
*.scc
80+
81+
# Chutzpah Test files
82+
_Chutzpah*
83+
84+
# Visual C++ cache files
85+
ipch/
86+
*.aps
87+
*.ncb
88+
*.opendb
89+
*.opensdf
90+
*.sdf
91+
*.cachefile
92+
*.VC.db
93+
*.VC.VC.opendb
94+
95+
# Visual Studio profiler
96+
*.psess
97+
*.vsp
98+
*.vspx
99+
*.sap
100+
101+
# Visual Studio Trace Files
102+
*.e2e
103+
104+
# TFS 2012 Local Workspace
105+
$tf/
106+
107+
# Guidance Automation Toolkit
108+
*.gpState
109+
110+
# ReSharper is a .NET coding add-in
111+
_ReSharper*/
112+
*.[Rr]e[Ss]harper
113+
*.DotSettings.user
114+
115+
# JustCode is a .NET coding add-in
116+
.JustCode
117+
118+
# TeamCity is a build add-in
119+
_TeamCity*
120+
121+
# DotCover is a Code Coverage Tool
122+
*.dotCover
123+
124+
# AxoCover is a Code Coverage Tool
125+
.axoCover/*
126+
!.axoCover/settings.json
127+
128+
# Visual Studio code coverage results
129+
*.coverage
130+
*.coveragexml
131+
132+
# NCrunch
133+
_NCrunch_*
134+
.*crunch*.local.xml
135+
nCrunchTemp_*
136+
137+
# MightyMoose
138+
*.mm.*
139+
AutoTest.Net/
140+
141+
# Web workbench (sass)
142+
.sass-cache/
143+
144+
# Installshield output folder
145+
[Ee]xpress/
146+
147+
# DocProject is a documentation generator add-in
148+
DocProject/buildhelp/
149+
DocProject/Help/*.HxT
150+
DocProject/Help/*.HxC
151+
DocProject/Help/*.hhc
152+
DocProject/Help/*.hhk
153+
DocProject/Help/*.hhp
154+
DocProject/Help/Html2
155+
DocProject/Help/html
156+
157+
# Click-Once directory
158+
publish/
159+
160+
# Publish Web Output
161+
*.[Pp]ublish.xml
162+
*.azurePubxml
163+
# Note: Comment the next line if you want to checkin your web deploy settings,
164+
# but database connection strings (with potential passwords) will be unencrypted
165+
*.pubxml
166+
*.publishproj
167+
168+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
169+
# checkin your Azure Web App publish settings, but sensitive information contained
170+
# in these scripts will be unencrypted
171+
PublishScripts/
172+
173+
# NuGet Packages
174+
*.nupkg
175+
# The packages folder can be ignored because of Package Restore
176+
**/[Pp]ackages/*
177+
# except build/, which is used as an MSBuild target.
178+
!**/[Pp]ackages/build/
179+
# Uncomment if necessary however generally it will be regenerated when needed
180+
#!**/[Pp]ackages/repositories.config
181+
# NuGet v3's project.json files produces more ignorable files
182+
*.nuget.props
183+
*.nuget.targets
184+
185+
# Microsoft Azure Build Output
186+
csx/
187+
*.build.csdef
188+
189+
# Microsoft Azure Emulator
190+
ecf/
191+
rcf/
192+
193+
# Windows Store app package directories and files
194+
AppPackages/
195+
BundleArtifacts/
196+
Package.StoreAssociation.xml
197+
_pkginfo.txt
198+
*.appx
199+
200+
# Visual Studio cache files
201+
# files ending in .cache can be ignored
202+
*.[Cc]ache
203+
# but keep track of directories ending in .cache
204+
!*.[Cc]ache/
205+
206+
# Others
207+
ClientBin/
208+
~$*
209+
*~
210+
*.dbmdl
211+
*.dbproj.schemaview
212+
*.jfm
213+
*.pfx
214+
*.publishsettings
215+
orleans.codegen.cs
216+
217+
# Since there are multiple workflows, uncomment next line to ignore bower_components
218+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
219+
#bower_components/
220+
221+
# RIA/Silverlight projects
222+
Generated_Code/
223+
224+
# Backup & report files from converting an old project file
225+
# to a newer Visual Studio version. Backup files are not needed,
226+
# because we have git ;-)
227+
_UpgradeReport_Files/
228+
Backup*/
229+
UpgradeLog*.XML
230+
UpgradeLog*.htm
231+
232+
# SQL Server files
233+
*.mdf
234+
*.ldf
235+
*.ndf
236+
237+
# Business Intelligence projects
238+
*.rdl.data
239+
*.bim.layout
240+
*.bim_*.settings
241+
242+
# Microsoft Fakes
243+
FakesAssemblies/
244+
245+
# GhostDoc plugin setting file
246+
*.GhostDoc.xml
247+
248+
# Node.js Tools for Visual Studio
249+
.ntvs_analysis.dat
250+
node_modules/
251+
252+
# Typescript v1 declaration files
253+
typings/
254+
255+
# Visual Studio 6 build log
256+
*.plg
257+
258+
# Visual Studio 6 workspace options file
259+
*.opt
260+
261+
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
262+
*.vbw
263+
264+
# Visual Studio LightSwitch build output
265+
**/*.HTMLClient/GeneratedArtifacts
266+
**/*.DesktopClient/GeneratedArtifacts
267+
**/*.DesktopClient/ModelManifest.xml
268+
**/*.Server/GeneratedArtifacts
269+
**/*.Server/ModelManifest.xml
270+
_Pvt_Extensions
271+
272+
# Paket dependency manager
273+
.paket/paket.exe
274+
paket-files/
275+
276+
# FAKE - F# Make
277+
.fake/
278+
279+
# JetBrains Rider
280+
.idea/
281+
*.sln.iml
282+
283+
# CodeRush
284+
.cr/
285+
286+
# Python Tools for Visual Studio (PTVS)
287+
__pycache__/
288+
*.pyc
289+
290+
# Cake - Uncomment if you are using it
291+
# tools/**
292+
# !tools/packages.config
293+
294+
# Tabs Studio
295+
*.tss
296+
297+
# Telerik's JustMock configuration file
298+
*.jmconfig
299+
300+
# BizTalk build output
301+
*.btp.cs
302+
*.btm.cs
303+
*.odx.cs
304+
*.xsd.cs
305+
306+
# OpenCover UI analysis results
307+
OpenCover/
308+
309+

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "dependencies/Carter"]
2+
path = dependencies/Carter
3+
url = [email protected]:CarterCommunity/Carter.git

dependencies/Carter

Submodule Carter added at 71ac6c5

src/Carter.HtmlNegotiator.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>

src/DefaultViewLocator.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
namespace HtmlNegotiator
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.Http;
8+
9+
public class DefaultViewLocator : IViewLocator
10+
{
11+
private readonly IDictionary<Type, string> mappings;
12+
13+
private readonly IDictionary<Type, string> htmlMappings;
14+
15+
public DefaultViewLocator(IDictionary<Type, string> mappings)
16+
{
17+
this.mappings = mappings;
18+
this.htmlMappings = new Dictionary<Type, string>();
19+
}
20+
21+
public string GetView(object model, HttpContext httpContext)
22+
{
23+
string viewName = string.Empty;
24+
try
25+
{
26+
viewName = this.mappings[model.GetType()];
27+
}
28+
catch (Exception)
29+
{
30+
return string.Empty;
31+
}
32+
33+
if (this.htmlMappings.ContainsKey(model.GetType()))
34+
{
35+
return this.htmlMappings[model.GetType()];
36+
}
37+
38+
var env = (IHostingEnvironment)httpContext.RequestServices.GetService(typeof(IHostingEnvironment));
39+
40+
try
41+
{
42+
var html = File.ReadAllText(Path.Combine(env.ContentRootPath, viewName));
43+
44+
this.htmlMappings.Add(model.GetType(), html);
45+
46+
return html;
47+
}
48+
catch (FileNotFoundException)
49+
{
50+
return string.Empty;
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)