├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md └── starting ├── TheCodeCamp.sln └── TheCodeCamp ├── App_Start ├── AutofacConfig.cs ├── FilterConfig.cs ├── RouteConfig.cs └── WebApiConfig.cs ├── Areas └── HelpPage │ ├── ApiDescriptionExtensions.cs │ ├── App_Start │ └── HelpPageConfig.cs │ ├── Controllers │ └── HelpController.cs │ ├── HelpPage.css │ ├── HelpPageAreaRegistration.cs │ ├── HelpPageConfigurationExtensions.cs │ ├── ModelDescriptions │ ├── CollectionModelDescription.cs │ ├── ComplexTypeModelDescription.cs │ ├── DictionaryModelDescription.cs │ ├── EnumTypeModelDescription.cs │ ├── EnumValueDescription.cs │ ├── IModelDocumentationProvider.cs │ ├── KeyValuePairModelDescription.cs │ ├── ModelDescription.cs │ ├── ModelDescriptionGenerator.cs │ ├── ModelNameAttribute.cs │ ├── ModelNameHelper.cs │ ├── ParameterAnnotation.cs │ ├── ParameterDescription.cs │ └── SimpleTypeModelDescription.cs │ ├── Models │ └── HelpPageApiModel.cs │ ├── SampleGeneration │ ├── HelpPageSampleGenerator.cs │ ├── HelpPageSampleKey.cs │ ├── ImageSample.cs │ ├── InvalidSample.cs │ ├── ObjectGenerator.cs │ ├── SampleDirection.cs │ └── TextSample.cs │ ├── Views │ ├── Help │ │ ├── Api.cshtml │ │ ├── DisplayTemplates │ │ │ ├── ApiGroup.cshtml │ │ │ ├── CollectionModelDescription.cshtml │ │ │ ├── ComplexTypeModelDescription.cshtml │ │ │ ├── DictionaryModelDescription.cshtml │ │ │ ├── EnumTypeModelDescription.cshtml │ │ │ ├── HelpPageApiModel.cshtml │ │ │ ├── ImageSample.cshtml │ │ │ ├── InvalidSample.cshtml │ │ │ ├── KeyValuePairModelDescription.cshtml │ │ │ ├── ModelDescriptionLink.cshtml │ │ │ ├── Parameters.cshtml │ │ │ ├── Samples.cshtml │ │ │ ├── SimpleTypeModelDescription.cshtml │ │ │ └── TextSample.cshtml │ │ ├── Index.cshtml │ │ └── ResourceModel.cshtml │ ├── Shared │ │ └── _Layout.cshtml │ ├── Web.config │ └── _ViewStart.cshtml │ └── XmlDocumentationProvider.cs ├── Controllers └── ValuesController.cs ├── Data ├── CampContext.cs ├── CampRepository.cs ├── Entities │ ├── Camp.cs │ ├── Location.cs │ ├── Speaker.cs │ └── Talk.cs ├── ICampRepository.cs └── Migrations │ ├── 201901030609030_InitialCreate.cs │ ├── 201901030609030_InitialCreate.designer.cs │ ├── 201901030609030_InitialCreate.resx │ ├── 201901030630577_Initial.cs │ ├── 201901030630577_Initial.designer.cs │ ├── 201901030630577_Initial.resx │ └── Configuration.cs ├── Global.asax ├── Global.asax.cs ├── Properties └── AssemblyInfo.cs ├── TheCodeCamp.csproj ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── favicon.ico └── packages.config /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015/2017 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # Visual Studio 2017 auto generated files 34 | Generated\ Files/ 35 | 36 | # MSTest test Results 37 | [Tt]est[Rr]esult*/ 38 | [Bb]uild[Ll]og.* 39 | 40 | # NUNIT 41 | *.VisualState.xml 42 | TestResult.xml 43 | 44 | # Build Results of an ATL Project 45 | [Dd]ebugPS/ 46 | [Rr]eleasePS/ 47 | dlldata.c 48 | 49 | # Benchmark Results 50 | BenchmarkDotNet.Artifacts/ 51 | 52 | # .NET Core 53 | project.lock.json 54 | project.fragment.lock.json 55 | artifacts/ 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_h.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *_wpftmp.csproj 81 | *.log 82 | *.vspscc 83 | *.vssscc 84 | .builds 85 | *.pidb 86 | *.svclog 87 | *.scc 88 | 89 | # Chutzpah Test files 90 | _Chutzpah* 91 | 92 | # Visual C++ cache files 93 | ipch/ 94 | *.aps 95 | *.ncb 96 | *.opendb 97 | *.opensdf 98 | *.sdf 99 | *.cachefile 100 | *.VC.db 101 | *.VC.VC.opendb 102 | 103 | # Visual Studio profiler 104 | *.psess 105 | *.vsp 106 | *.vspx 107 | *.sap 108 | 109 | # Visual Studio Trace Files 110 | *.e2e 111 | 112 | # TFS 2012 Local Workspace 113 | $tf/ 114 | 115 | # Guidance Automation Toolkit 116 | *.gpState 117 | 118 | # ReSharper is a .NET coding add-in 119 | _ReSharper*/ 120 | *.[Rr]e[Ss]harper 121 | *.DotSettings.user 122 | 123 | # JustCode is a .NET coding add-in 124 | .JustCode 125 | 126 | # TeamCity is a build add-in 127 | _TeamCity* 128 | 129 | # DotCover is a Code Coverage Tool 130 | *.dotCover 131 | 132 | # AxoCover is a Code Coverage Tool 133 | .axoCover/* 134 | !.axoCover/settings.json 135 | 136 | # Visual Studio code coverage results 137 | *.coverage 138 | *.coveragexml 139 | 140 | # NCrunch 141 | _NCrunch_* 142 | .*crunch*.local.xml 143 | nCrunchTemp_* 144 | 145 | # MightyMoose 146 | *.mm.* 147 | AutoTest.Net/ 148 | 149 | # Web workbench (sass) 150 | .sass-cache/ 151 | 152 | # Installshield output folder 153 | [Ee]xpress/ 154 | 155 | # DocProject is a documentation generator add-in 156 | DocProject/buildhelp/ 157 | DocProject/Help/*.HxT 158 | DocProject/Help/*.HxC 159 | DocProject/Help/*.hhc 160 | DocProject/Help/*.hhk 161 | DocProject/Help/*.hhp 162 | DocProject/Help/Html2 163 | DocProject/Help/html 164 | 165 | # Click-Once directory 166 | publish/ 167 | 168 | # Publish Web Output 169 | *.[Pp]ublish.xml 170 | *.azurePubxml 171 | # Note: Comment the next line if you want to checkin your web deploy settings, 172 | # but database connection strings (with potential passwords) will be unencrypted 173 | *.pubxml 174 | *.publishproj 175 | 176 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 177 | # checkin your Azure Web App publish settings, but sensitive information contained 178 | # in these scripts will be unencrypted 179 | PublishScripts/ 180 | 181 | # NuGet Packages 182 | *.nupkg 183 | # The packages folder can be ignored because of Package Restore 184 | **/[Pp]ackages/* 185 | # except build/, which is used as an MSBuild target. 186 | !**/[Pp]ackages/build/ 187 | # Uncomment if necessary however generally it will be regenerated when needed 188 | #!**/[Pp]ackages/repositories.config 189 | # NuGet v3's project.json files produces more ignorable files 190 | *.nuget.props 191 | *.nuget.targets 192 | 193 | # Microsoft Azure Build Output 194 | csx/ 195 | *.build.csdef 196 | 197 | # Microsoft Azure Emulator 198 | ecf/ 199 | rcf/ 200 | 201 | # Windows Store app package directories and files 202 | AppPackages/ 203 | BundleArtifacts/ 204 | Package.StoreAssociation.xml 205 | _pkginfo.txt 206 | *.appx 207 | 208 | # Visual Studio cache files 209 | # files ending in .cache can be ignored 210 | *.[Cc]ache 211 | # but keep track of directories ending in .cache 212 | !*.[Cc]ache/ 213 | 214 | # Others 215 | ClientBin/ 216 | ~$* 217 | *~ 218 | *.dbmdl 219 | *.dbproj.schemaview 220 | *.jfm 221 | *.pfx 222 | *.publishsettings 223 | orleans.codegen.cs 224 | 225 | # Including strong name files can present a security risk 226 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 227 | #*.snk 228 | 229 | # Since there are multiple workflows, uncomment next line to ignore bower_components 230 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 231 | #bower_components/ 232 | 233 | # RIA/Silverlight projects 234 | Generated_Code/ 235 | 236 | # Backup & report files from converting an old project file 237 | # to a newer Visual Studio version. Backup files are not needed, 238 | # because we have git ;-) 239 | _UpgradeReport_Files/ 240 | Backup*/ 241 | UpgradeLog*.XML 242 | UpgradeLog*.htm 243 | ServiceFabricBackup/ 244 | *.rptproj.bak 245 | 246 | # SQL Server files 247 | *.mdf 248 | *.ldf 249 | *.ndf 250 | 251 | # Business Intelligence projects 252 | *.rdl.data 253 | *.bim.layout 254 | *.bim_*.settings 255 | *.rptproj.rsuser 256 | 257 | # Microsoft Fakes 258 | FakesAssemblies/ 259 | 260 | # GhostDoc plugin setting file 261 | *.GhostDoc.xml 262 | 263 | # Node.js Tools for Visual Studio 264 | .ntvs_analysis.dat 265 | node_modules/ 266 | 267 | # Visual Studio 6 build log 268 | *.plg 269 | 270 | # Visual Studio 6 workspace options file 271 | *.opt 272 | 273 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 274 | *.vbw 275 | 276 | # Visual Studio LightSwitch build output 277 | **/*.HTMLClient/GeneratedArtifacts 278 | **/*.DesktopClient/GeneratedArtifacts 279 | **/*.DesktopClient/ModelManifest.xml 280 | **/*.Server/GeneratedArtifacts 281 | **/*.Server/ModelManifest.xml 282 | _Pvt_Extensions 283 | 284 | # Paket dependency manager 285 | .paket/paket.exe 286 | paket-files/ 287 | 288 | # FAKE - F# Make 289 | .fake/ 290 | 291 | # JetBrains Rider 292 | .idea/ 293 | *.sln.iml 294 | 295 | # CodeRush personal settings 296 | .cr/personal 297 | 298 | # Python Tools for Visual Studio (PTVS) 299 | __pycache__/ 300 | *.pyc 301 | 302 | # Cake - Uncomment if you are using it 303 | # tools/** 304 | # !tools/packages.config 305 | 306 | # Tabs Studio 307 | *.tss 308 | 309 | # Telerik's JustMock configuration file 310 | *.jmconfig 311 | 312 | # BizTalk build output 313 | *.btp.cs 314 | *.btm.cs 315 | *.odx.cs 316 | *.xsd.cs 317 | 318 | # OpenCover UI analysis results 319 | OpenCover/ 320 | 321 | # Azure Stream Analytics local run output 322 | ASALocalRun/ 323 | 324 | # MSBuild Binary and Structured Log 325 | *.binlog 326 | 327 | # NVidia Nsight GPU debugger configuration file 328 | *.nvuser 329 | 330 | # MFractors (Xamarin productivity tool) working folder 331 | .mfractor/ 332 | 333 | # Local History for Visual Studio 334 | .localhistory/ 335 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Shawn Wildermuth 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebApiFundamentals 2 | -------------------------------------------------------------------------------- /starting/TheCodeCamp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.102 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheCodeCamp", "TheCodeCamp\TheCodeCamp.csproj", "{715EEC2D-FFB8-46AF-B845-2367732818CB}" 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 | {715EEC2D-FFB8-46AF-B845-2367732818CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {715EEC2D-FFB8-46AF-B845-2367732818CB}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {715EEC2D-FFB8-46AF-B845-2367732818CB}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {715EEC2D-FFB8-46AF-B845-2367732818CB}.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 = {92776829-E9AD-46AF-8712-1251F0BB7E7F} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/App_Start/AutofacConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Web.Http; 8 | using Autofac; 9 | using Autofac.Integration.WebApi; 10 | using TheCodeCamp.Data; 11 | 12 | namespace TheCodeCamp 13 | { 14 | public class AutofacConfig 15 | { 16 | public static void Register() 17 | { 18 | var bldr = new ContainerBuilder(); 19 | var config = GlobalConfiguration.Configuration; 20 | bldr.RegisterApiControllers(Assembly.GetExecutingAssembly()); 21 | RegisterServices(bldr); 22 | bldr.RegisterWebApiFilterProvider(config); 23 | bldr.RegisterWebApiModelBinderProvider(); 24 | var container = bldr.Build(); 25 | config.DependencyResolver = new AutofacWebApiDependencyResolver(container); 26 | } 27 | 28 | private static void RegisterServices(ContainerBuilder bldr) 29 | { 30 | bldr.RegisterType() 31 | .InstancePerRequest(); 32 | 33 | bldr.RegisterType() 34 | .As() 35 | .InstancePerRequest(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace TheCodeCamp 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace TheCodeCamp 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace TheCodeCamp 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API configuration and services 13 | AutofacConfig.Register(); 14 | 15 | // Web API routes 16 | config.MapHttpAttributeRoutes(); 17 | 18 | config.Routes.MapHttpRoute( 19 | name: "DefaultApi", 20 | routeTemplate: "api/{controller}/{id}", 21 | defaults: new { id = RouteParameter.Optional } 22 | ); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ApiDescriptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Web; 4 | using System.Web.Http.Description; 5 | 6 | namespace TheCodeCamp.Areas.HelpPage 7 | { 8 | public static class ApiDescriptionExtensions 9 | { 10 | /// 11 | /// Generates an URI-friendly ID for the . E.g. "Get-Values-id_name" instead of "GetValues/{id}?name={name}" 12 | /// 13 | /// The . 14 | /// The ID as a string. 15 | public static string GetFriendlyId(this ApiDescription description) 16 | { 17 | string path = description.RelativePath; 18 | string[] urlParts = path.Split('?'); 19 | string localPath = urlParts[0]; 20 | string queryKeyString = null; 21 | if (urlParts.Length > 1) 22 | { 23 | string query = urlParts[1]; 24 | string[] queryKeys = HttpUtility.ParseQueryString(query).AllKeys; 25 | queryKeyString = String.Join("_", queryKeys); 26 | } 27 | 28 | StringBuilder friendlyPath = new StringBuilder(); 29 | friendlyPath.AppendFormat("{0}-{1}", 30 | description.HttpMethod.Method, 31 | localPath.Replace("/", "-").Replace("{", String.Empty).Replace("}", String.Empty)); 32 | if (queryKeyString != null) 33 | { 34 | friendlyPath.AppendFormat("_{0}", queryKeyString.Replace('.', '-')); 35 | } 36 | return friendlyPath.ToString(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/App_Start/HelpPageConfig.cs: -------------------------------------------------------------------------------- 1 | // Uncomment the following to provide samples for PageResult. Must also add the Microsoft.AspNet.WebApi.OData 2 | // package to your project. 3 | ////#define Handle_PageResultOfT 4 | 5 | using System; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Diagnostics; 9 | using System.Diagnostics.CodeAnalysis; 10 | using System.Linq; 11 | using System.Net.Http.Headers; 12 | using System.Reflection; 13 | using System.Web; 14 | using System.Web.Http; 15 | #if Handle_PageResultOfT 16 | using System.Web.Http.OData; 17 | #endif 18 | 19 | namespace TheCodeCamp.Areas.HelpPage 20 | { 21 | /// 22 | /// Use this class to customize the Help Page. 23 | /// For example you can set a custom to supply the documentation 24 | /// or you can provide the samples for the requests/responses. 25 | /// 26 | public static class HelpPageConfig 27 | { 28 | [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", 29 | MessageId = "TheCodeCamp.Areas.HelpPage.TextSample.#ctor(System.String)", 30 | Justification = "End users may choose to merge this string with existing localized resources.")] 31 | [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", 32 | MessageId = "bsonspec", 33 | Justification = "Part of a URI.")] 34 | public static void Register(HttpConfiguration config) 35 | { 36 | //// Uncomment the following to use the documentation from XML documentation file. 37 | //config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml"))); 38 | 39 | //// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type. 40 | //// Also, the string arrays will be used for IEnumerable. The sample objects will be serialized into different media type 41 | //// formats by the available formatters. 42 | //config.SetSampleObjects(new Dictionary 43 | //{ 44 | // {typeof(string), "sample string"}, 45 | // {typeof(IEnumerable), new string[]{"sample 1", "sample 2"}} 46 | //}); 47 | 48 | // Extend the following to provide factories for types not handled automatically (those lacking parameterless 49 | // constructors) or for which you prefer to use non-default property values. Line below provides a fallback 50 | // since automatic handling will fail and GeneratePageResult handles only a single type. 51 | #if Handle_PageResultOfT 52 | config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult); 53 | #endif 54 | 55 | // Extend the following to use a preset object directly as the sample for all actions that support a media 56 | // type, regardless of the body parameter or return type. The lines below avoid display of binary content. 57 | // The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object. 58 | config.SetSampleForMediaType( 59 | new TextSample("Binary JSON content. See http://bsonspec.org for details."), 60 | new MediaTypeHeaderValue("application/bson")); 61 | 62 | //// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format 63 | //// and have IEnumerable as the body parameter or return type. 64 | //config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable)); 65 | 66 | //// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values" 67 | //// and action named "Put". 68 | //config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put"); 69 | 70 | //// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png" 71 | //// on the controller named "Values" and action named "Get" with parameter "id". 72 | //config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id"); 73 | 74 | //// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent. 75 | //// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter. 76 | //config.SetActualRequestType(typeof(string), "Values", "Get"); 77 | 78 | //// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent. 79 | //// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string. 80 | //config.SetActualResponseType(typeof(string), "Values", "Post"); 81 | } 82 | 83 | #if Handle_PageResultOfT 84 | private static object GeneratePageResult(HelpPageSampleGenerator sampleGenerator, Type type) 85 | { 86 | if (type.IsGenericType) 87 | { 88 | Type openGenericType = type.GetGenericTypeDefinition(); 89 | if (openGenericType == typeof(PageResult<>)) 90 | { 91 | // Get the T in PageResult 92 | Type[] typeParameters = type.GetGenericArguments(); 93 | Debug.Assert(typeParameters.Length == 1); 94 | 95 | // Create an enumeration to pass as the first parameter to the PageResult constuctor 96 | Type itemsType = typeof(List<>).MakeGenericType(typeParameters); 97 | object items = sampleGenerator.GetSampleObject(itemsType); 98 | 99 | // Fill in the other information needed to invoke the PageResult constuctor 100 | Type[] parameterTypes = new Type[] { itemsType, typeof(Uri), typeof(long?), }; 101 | object[] parameters = new object[] { items, null, (long)ObjectGenerator.DefaultCollectionSize, }; 102 | 103 | // Call PageResult(IEnumerable items, Uri nextPageLink, long? count) constructor 104 | ConstructorInfo constructor = type.GetConstructor(parameterTypes); 105 | return constructor.Invoke(parameters); 106 | } 107 | } 108 | 109 | return null; 110 | } 111 | #endif 112 | } 113 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Controllers/HelpController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web.Http; 3 | using System.Web.Mvc; 4 | using TheCodeCamp.Areas.HelpPage.ModelDescriptions; 5 | using TheCodeCamp.Areas.HelpPage.Models; 6 | 7 | namespace TheCodeCamp.Areas.HelpPage.Controllers 8 | { 9 | /// 10 | /// The controller that will handle requests for the help page. 11 | /// 12 | public class HelpController : Controller 13 | { 14 | private const string ErrorViewName = "Error"; 15 | 16 | public HelpController() 17 | : this(GlobalConfiguration.Configuration) 18 | { 19 | } 20 | 21 | public HelpController(HttpConfiguration config) 22 | { 23 | Configuration = config; 24 | } 25 | 26 | public HttpConfiguration Configuration { get; private set; } 27 | 28 | public ActionResult Index() 29 | { 30 | ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider(); 31 | return View(Configuration.Services.GetApiExplorer().ApiDescriptions); 32 | } 33 | 34 | public ActionResult Api(string apiId) 35 | { 36 | if (!String.IsNullOrEmpty(apiId)) 37 | { 38 | HelpPageApiModel apiModel = Configuration.GetHelpPageApiModel(apiId); 39 | if (apiModel != null) 40 | { 41 | return View(apiModel); 42 | } 43 | } 44 | 45 | return View(ErrorViewName); 46 | } 47 | 48 | public ActionResult ResourceModel(string modelName) 49 | { 50 | if (!String.IsNullOrEmpty(modelName)) 51 | { 52 | ModelDescriptionGenerator modelDescriptionGenerator = Configuration.GetModelDescriptionGenerator(); 53 | ModelDescription modelDescription; 54 | if (modelDescriptionGenerator.GeneratedModels.TryGetValue(modelName, out modelDescription)) 55 | { 56 | return View(modelDescription); 57 | } 58 | } 59 | 60 | return View(ErrorViewName); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/HelpPage.css: -------------------------------------------------------------------------------- 1 | .help-page h1, 2 | .help-page .h1, 3 | .help-page h2, 4 | .help-page .h2, 5 | .help-page h3, 6 | .help-page .h3, 7 | #body.help-page, 8 | .help-page-table th, 9 | .help-page-table pre, 10 | .help-page-table p { 11 | font-family: "Segoe UI Light", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif; 12 | } 13 | 14 | .help-page pre.wrapped { 15 | white-space: -moz-pre-wrap; 16 | white-space: -pre-wrap; 17 | white-space: -o-pre-wrap; 18 | white-space: pre-wrap; 19 | } 20 | 21 | .help-page .warning-message-container { 22 | margin-top: 20px; 23 | padding: 0 10px; 24 | color: #525252; 25 | background: #EFDCA9; 26 | border: 1px solid #CCCCCC; 27 | } 28 | 29 | .help-page-table { 30 | width: 100%; 31 | border-collapse: collapse; 32 | text-align: left; 33 | margin: 0px 0px 20px 0px; 34 | border-top: 1px solid #D4D4D4; 35 | } 36 | 37 | .help-page-table th { 38 | text-align: left; 39 | font-weight: bold; 40 | border-bottom: 1px solid #D4D4D4; 41 | padding: 5px 6px 5px 6px; 42 | } 43 | 44 | .help-page-table td { 45 | border-bottom: 1px solid #D4D4D4; 46 | padding: 10px 8px 10px 8px; 47 | vertical-align: top; 48 | } 49 | 50 | .help-page-table pre, 51 | .help-page-table p { 52 | margin: 0px; 53 | padding: 0px; 54 | font-family: inherit; 55 | font-size: 100%; 56 | } 57 | 58 | .help-page-table tbody tr:hover td { 59 | background-color: #F3F3F3; 60 | } 61 | 62 | .help-page a:hover { 63 | background-color: transparent; 64 | } 65 | 66 | .help-page .sample-header { 67 | border: 2px solid #D4D4D4; 68 | background: #00497E; 69 | color: #FFFFFF; 70 | padding: 8px 15px; 71 | border-bottom: none; 72 | display: inline-block; 73 | margin: 10px 0px 0px 0px; 74 | } 75 | 76 | .help-page .sample-content { 77 | display: block; 78 | border-width: 0; 79 | padding: 15px 20px; 80 | background: #FFFFFF; 81 | border: 2px solid #D4D4D4; 82 | margin: 0px 0px 10px 0px; 83 | } 84 | 85 | .help-page .api-name { 86 | width: 40%; 87 | } 88 | 89 | .help-page .api-documentation { 90 | width: 60%; 91 | } 92 | 93 | .help-page .parameter-name { 94 | width: 20%; 95 | } 96 | 97 | .help-page .parameter-documentation { 98 | width: 40%; 99 | } 100 | 101 | .help-page .parameter-type { 102 | width: 20%; 103 | } 104 | 105 | .help-page .parameter-annotations { 106 | width: 20%; 107 | } 108 | 109 | .help-page h1, 110 | .help-page .h1 { 111 | font-size: 36px; 112 | line-height: normal; 113 | } 114 | 115 | .help-page h2, 116 | .help-page .h2 { 117 | font-size: 24px; 118 | } 119 | 120 | .help-page h3, 121 | .help-page .h3 { 122 | font-size: 20px; 123 | } 124 | 125 | #body.help-page { 126 | font-size: 14px; 127 | line-height: 143%; 128 | color: #333; 129 | } 130 | 131 | .help-page a { 132 | color: #0000EE; 133 | text-decoration: none; 134 | } 135 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/HelpPageAreaRegistration.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using System.Web.Mvc; 3 | 4 | namespace TheCodeCamp.Areas.HelpPage 5 | { 6 | public class HelpPageAreaRegistration : AreaRegistration 7 | { 8 | public override string AreaName 9 | { 10 | get 11 | { 12 | return "HelpPage"; 13 | } 14 | } 15 | 16 | public override void RegisterArea(AreaRegistrationContext context) 17 | { 18 | context.MapRoute( 19 | "HelpPage_Default", 20 | "Help/{action}/{apiId}", 21 | new { controller = "Help", action = "Index", apiId = UrlParameter.Optional }); 22 | 23 | HelpPageConfig.Register(GlobalConfiguration.Configuration); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/CollectionModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class CollectionModelDescription : ModelDescription 4 | { 5 | public ModelDescription ElementDescription { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/ComplexTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | 3 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 4 | { 5 | public class ComplexTypeModelDescription : ModelDescription 6 | { 7 | public ComplexTypeModelDescription() 8 | { 9 | Properties = new Collection(); 10 | } 11 | 12 | public Collection Properties { get; private set; } 13 | } 14 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/DictionaryModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class DictionaryModelDescription : KeyValuePairModelDescription 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/EnumTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | 4 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 5 | { 6 | public class EnumTypeModelDescription : ModelDescription 7 | { 8 | public EnumTypeModelDescription() 9 | { 10 | Values = new Collection(); 11 | } 12 | 13 | public Collection Values { get; private set; } 14 | } 15 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/EnumValueDescription.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class EnumValueDescription 4 | { 5 | public string Documentation { get; set; } 6 | 7 | public string Name { get; set; } 8 | 9 | public string Value { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/IModelDocumentationProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 5 | { 6 | public interface IModelDocumentationProvider 7 | { 8 | string GetDocumentation(MemberInfo member); 9 | 10 | string GetDocumentation(Type type); 11 | } 12 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/KeyValuePairModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class KeyValuePairModelDescription : ModelDescription 4 | { 5 | public ModelDescription KeyModelDescription { get; set; } 6 | 7 | public ModelDescription ValueModelDescription { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/ModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 4 | { 5 | /// 6 | /// Describes a type model. 7 | /// 8 | public abstract class ModelDescription 9 | { 10 | public string Documentation { get; set; } 11 | 12 | public Type ModelType { get; set; } 13 | 14 | public string Name { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/ModelDescriptionGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Collections.Specialized; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.Globalization; 7 | using System.Reflection; 8 | using System.Runtime.Serialization; 9 | using System.Web.Http; 10 | using System.Web.Http.Description; 11 | using System.Xml.Serialization; 12 | using Newtonsoft.Json; 13 | 14 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 15 | { 16 | /// 17 | /// Generates model descriptions for given types. 18 | /// 19 | public class ModelDescriptionGenerator 20 | { 21 | // Modify this to support more data annotation attributes. 22 | private readonly IDictionary> AnnotationTextGenerator = new Dictionary> 23 | { 24 | { typeof(RequiredAttribute), a => "Required" }, 25 | { typeof(RangeAttribute), a => 26 | { 27 | RangeAttribute range = (RangeAttribute)a; 28 | return String.Format(CultureInfo.CurrentCulture, "Range: inclusive between {0} and {1}", range.Minimum, range.Maximum); 29 | } 30 | }, 31 | { typeof(MaxLengthAttribute), a => 32 | { 33 | MaxLengthAttribute maxLength = (MaxLengthAttribute)a; 34 | return String.Format(CultureInfo.CurrentCulture, "Max length: {0}", maxLength.Length); 35 | } 36 | }, 37 | { typeof(MinLengthAttribute), a => 38 | { 39 | MinLengthAttribute minLength = (MinLengthAttribute)a; 40 | return String.Format(CultureInfo.CurrentCulture, "Min length: {0}", minLength.Length); 41 | } 42 | }, 43 | { typeof(StringLengthAttribute), a => 44 | { 45 | StringLengthAttribute strLength = (StringLengthAttribute)a; 46 | return String.Format(CultureInfo.CurrentCulture, "String length: inclusive between {0} and {1}", strLength.MinimumLength, strLength.MaximumLength); 47 | } 48 | }, 49 | { typeof(DataTypeAttribute), a => 50 | { 51 | DataTypeAttribute dataType = (DataTypeAttribute)a; 52 | return String.Format(CultureInfo.CurrentCulture, "Data type: {0}", dataType.CustomDataType ?? dataType.DataType.ToString()); 53 | } 54 | }, 55 | { typeof(RegularExpressionAttribute), a => 56 | { 57 | RegularExpressionAttribute regularExpression = (RegularExpressionAttribute)a; 58 | return String.Format(CultureInfo.CurrentCulture, "Matching regular expression pattern: {0}", regularExpression.Pattern); 59 | } 60 | }, 61 | }; 62 | 63 | // Modify this to add more default documentations. 64 | private readonly IDictionary DefaultTypeDocumentation = new Dictionary 65 | { 66 | { typeof(Int16), "integer" }, 67 | { typeof(Int32), "integer" }, 68 | { typeof(Int64), "integer" }, 69 | { typeof(UInt16), "unsigned integer" }, 70 | { typeof(UInt32), "unsigned integer" }, 71 | { typeof(UInt64), "unsigned integer" }, 72 | { typeof(Byte), "byte" }, 73 | { typeof(Char), "character" }, 74 | { typeof(SByte), "signed byte" }, 75 | { typeof(Uri), "URI" }, 76 | { typeof(Single), "decimal number" }, 77 | { typeof(Double), "decimal number" }, 78 | { typeof(Decimal), "decimal number" }, 79 | { typeof(String), "string" }, 80 | { typeof(Guid), "globally unique identifier" }, 81 | { typeof(TimeSpan), "time interval" }, 82 | { typeof(DateTime), "date" }, 83 | { typeof(DateTimeOffset), "date" }, 84 | { typeof(Boolean), "boolean" }, 85 | }; 86 | 87 | private Lazy _documentationProvider; 88 | 89 | public ModelDescriptionGenerator(HttpConfiguration config) 90 | { 91 | if (config == null) 92 | { 93 | throw new ArgumentNullException("config"); 94 | } 95 | 96 | _documentationProvider = new Lazy(() => config.Services.GetDocumentationProvider() as IModelDocumentationProvider); 97 | GeneratedModels = new Dictionary(StringComparer.OrdinalIgnoreCase); 98 | } 99 | 100 | public Dictionary GeneratedModels { get; private set; } 101 | 102 | private IModelDocumentationProvider DocumentationProvider 103 | { 104 | get 105 | { 106 | return _documentationProvider.Value; 107 | } 108 | } 109 | 110 | public ModelDescription GetOrCreateModelDescription(Type modelType) 111 | { 112 | if (modelType == null) 113 | { 114 | throw new ArgumentNullException("modelType"); 115 | } 116 | 117 | Type underlyingType = Nullable.GetUnderlyingType(modelType); 118 | if (underlyingType != null) 119 | { 120 | modelType = underlyingType; 121 | } 122 | 123 | ModelDescription modelDescription; 124 | string modelName = ModelNameHelper.GetModelName(modelType); 125 | if (GeneratedModels.TryGetValue(modelName, out modelDescription)) 126 | { 127 | if (modelType != modelDescription.ModelType) 128 | { 129 | throw new InvalidOperationException( 130 | String.Format( 131 | CultureInfo.CurrentCulture, 132 | "A model description could not be created. Duplicate model name '{0}' was found for types '{1}' and '{2}'. " + 133 | "Use the [ModelName] attribute to change the model name for at least one of the types so that it has a unique name.", 134 | modelName, 135 | modelDescription.ModelType.FullName, 136 | modelType.FullName)); 137 | } 138 | 139 | return modelDescription; 140 | } 141 | 142 | if (DefaultTypeDocumentation.ContainsKey(modelType)) 143 | { 144 | return GenerateSimpleTypeModelDescription(modelType); 145 | } 146 | 147 | if (modelType.IsEnum) 148 | { 149 | return GenerateEnumTypeModelDescription(modelType); 150 | } 151 | 152 | if (modelType.IsGenericType) 153 | { 154 | Type[] genericArguments = modelType.GetGenericArguments(); 155 | 156 | if (genericArguments.Length == 1) 157 | { 158 | Type enumerableType = typeof(IEnumerable<>).MakeGenericType(genericArguments); 159 | if (enumerableType.IsAssignableFrom(modelType)) 160 | { 161 | return GenerateCollectionModelDescription(modelType, genericArguments[0]); 162 | } 163 | } 164 | if (genericArguments.Length == 2) 165 | { 166 | Type dictionaryType = typeof(IDictionary<,>).MakeGenericType(genericArguments); 167 | if (dictionaryType.IsAssignableFrom(modelType)) 168 | { 169 | return GenerateDictionaryModelDescription(modelType, genericArguments[0], genericArguments[1]); 170 | } 171 | 172 | Type keyValuePairType = typeof(KeyValuePair<,>).MakeGenericType(genericArguments); 173 | if (keyValuePairType.IsAssignableFrom(modelType)) 174 | { 175 | return GenerateKeyValuePairModelDescription(modelType, genericArguments[0], genericArguments[1]); 176 | } 177 | } 178 | } 179 | 180 | if (modelType.IsArray) 181 | { 182 | Type elementType = modelType.GetElementType(); 183 | return GenerateCollectionModelDescription(modelType, elementType); 184 | } 185 | 186 | if (modelType == typeof(NameValueCollection)) 187 | { 188 | return GenerateDictionaryModelDescription(modelType, typeof(string), typeof(string)); 189 | } 190 | 191 | if (typeof(IDictionary).IsAssignableFrom(modelType)) 192 | { 193 | return GenerateDictionaryModelDescription(modelType, typeof(object), typeof(object)); 194 | } 195 | 196 | if (typeof(IEnumerable).IsAssignableFrom(modelType)) 197 | { 198 | return GenerateCollectionModelDescription(modelType, typeof(object)); 199 | } 200 | 201 | return GenerateComplexTypeModelDescription(modelType); 202 | } 203 | 204 | // Change this to provide different name for the member. 205 | private static string GetMemberName(MemberInfo member, bool hasDataContractAttribute) 206 | { 207 | JsonPropertyAttribute jsonProperty = member.GetCustomAttribute(); 208 | if (jsonProperty != null && !String.IsNullOrEmpty(jsonProperty.PropertyName)) 209 | { 210 | return jsonProperty.PropertyName; 211 | } 212 | 213 | if (hasDataContractAttribute) 214 | { 215 | DataMemberAttribute dataMember = member.GetCustomAttribute(); 216 | if (dataMember != null && !String.IsNullOrEmpty(dataMember.Name)) 217 | { 218 | return dataMember.Name; 219 | } 220 | } 221 | 222 | return member.Name; 223 | } 224 | 225 | private static bool ShouldDisplayMember(MemberInfo member, bool hasDataContractAttribute) 226 | { 227 | JsonIgnoreAttribute jsonIgnore = member.GetCustomAttribute(); 228 | XmlIgnoreAttribute xmlIgnore = member.GetCustomAttribute(); 229 | IgnoreDataMemberAttribute ignoreDataMember = member.GetCustomAttribute(); 230 | NonSerializedAttribute nonSerialized = member.GetCustomAttribute(); 231 | ApiExplorerSettingsAttribute apiExplorerSetting = member.GetCustomAttribute(); 232 | 233 | bool hasMemberAttribute = member.DeclaringType.IsEnum ? 234 | member.GetCustomAttribute() != null : 235 | member.GetCustomAttribute() != null; 236 | 237 | // Display member only if all the followings are true: 238 | // no JsonIgnoreAttribute 239 | // no XmlIgnoreAttribute 240 | // no IgnoreDataMemberAttribute 241 | // no NonSerializedAttribute 242 | // no ApiExplorerSettingsAttribute with IgnoreApi set to true 243 | // no DataContractAttribute without DataMemberAttribute or EnumMemberAttribute 244 | return jsonIgnore == null && 245 | xmlIgnore == null && 246 | ignoreDataMember == null && 247 | nonSerialized == null && 248 | (apiExplorerSetting == null || !apiExplorerSetting.IgnoreApi) && 249 | (!hasDataContractAttribute || hasMemberAttribute); 250 | } 251 | 252 | private string CreateDefaultDocumentation(Type type) 253 | { 254 | string documentation; 255 | if (DefaultTypeDocumentation.TryGetValue(type, out documentation)) 256 | { 257 | return documentation; 258 | } 259 | if (DocumentationProvider != null) 260 | { 261 | documentation = DocumentationProvider.GetDocumentation(type); 262 | } 263 | 264 | return documentation; 265 | } 266 | 267 | private void GenerateAnnotations(MemberInfo property, ParameterDescription propertyModel) 268 | { 269 | List annotations = new List(); 270 | 271 | IEnumerable attributes = property.GetCustomAttributes(); 272 | foreach (Attribute attribute in attributes) 273 | { 274 | Func textGenerator; 275 | if (AnnotationTextGenerator.TryGetValue(attribute.GetType(), out textGenerator)) 276 | { 277 | annotations.Add( 278 | new ParameterAnnotation 279 | { 280 | AnnotationAttribute = attribute, 281 | Documentation = textGenerator(attribute) 282 | }); 283 | } 284 | } 285 | 286 | // Rearrange the annotations 287 | annotations.Sort((x, y) => 288 | { 289 | // Special-case RequiredAttribute so that it shows up on top 290 | if (x.AnnotationAttribute is RequiredAttribute) 291 | { 292 | return -1; 293 | } 294 | if (y.AnnotationAttribute is RequiredAttribute) 295 | { 296 | return 1; 297 | } 298 | 299 | // Sort the rest based on alphabetic order of the documentation 300 | return String.Compare(x.Documentation, y.Documentation, StringComparison.OrdinalIgnoreCase); 301 | }); 302 | 303 | foreach (ParameterAnnotation annotation in annotations) 304 | { 305 | propertyModel.Annotations.Add(annotation); 306 | } 307 | } 308 | 309 | private CollectionModelDescription GenerateCollectionModelDescription(Type modelType, Type elementType) 310 | { 311 | ModelDescription collectionModelDescription = GetOrCreateModelDescription(elementType); 312 | if (collectionModelDescription != null) 313 | { 314 | return new CollectionModelDescription 315 | { 316 | Name = ModelNameHelper.GetModelName(modelType), 317 | ModelType = modelType, 318 | ElementDescription = collectionModelDescription 319 | }; 320 | } 321 | 322 | return null; 323 | } 324 | 325 | private ModelDescription GenerateComplexTypeModelDescription(Type modelType) 326 | { 327 | ComplexTypeModelDescription complexModelDescription = new ComplexTypeModelDescription 328 | { 329 | Name = ModelNameHelper.GetModelName(modelType), 330 | ModelType = modelType, 331 | Documentation = CreateDefaultDocumentation(modelType) 332 | }; 333 | 334 | GeneratedModels.Add(complexModelDescription.Name, complexModelDescription); 335 | bool hasDataContractAttribute = modelType.GetCustomAttribute() != null; 336 | PropertyInfo[] properties = modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance); 337 | foreach (PropertyInfo property in properties) 338 | { 339 | if (ShouldDisplayMember(property, hasDataContractAttribute)) 340 | { 341 | ParameterDescription propertyModel = new ParameterDescription 342 | { 343 | Name = GetMemberName(property, hasDataContractAttribute) 344 | }; 345 | 346 | if (DocumentationProvider != null) 347 | { 348 | propertyModel.Documentation = DocumentationProvider.GetDocumentation(property); 349 | } 350 | 351 | GenerateAnnotations(property, propertyModel); 352 | complexModelDescription.Properties.Add(propertyModel); 353 | propertyModel.TypeDescription = GetOrCreateModelDescription(property.PropertyType); 354 | } 355 | } 356 | 357 | FieldInfo[] fields = modelType.GetFields(BindingFlags.Public | BindingFlags.Instance); 358 | foreach (FieldInfo field in fields) 359 | { 360 | if (ShouldDisplayMember(field, hasDataContractAttribute)) 361 | { 362 | ParameterDescription propertyModel = new ParameterDescription 363 | { 364 | Name = GetMemberName(field, hasDataContractAttribute) 365 | }; 366 | 367 | if (DocumentationProvider != null) 368 | { 369 | propertyModel.Documentation = DocumentationProvider.GetDocumentation(field); 370 | } 371 | 372 | complexModelDescription.Properties.Add(propertyModel); 373 | propertyModel.TypeDescription = GetOrCreateModelDescription(field.FieldType); 374 | } 375 | } 376 | 377 | return complexModelDescription; 378 | } 379 | 380 | private DictionaryModelDescription GenerateDictionaryModelDescription(Type modelType, Type keyType, Type valueType) 381 | { 382 | ModelDescription keyModelDescription = GetOrCreateModelDescription(keyType); 383 | ModelDescription valueModelDescription = GetOrCreateModelDescription(valueType); 384 | 385 | return new DictionaryModelDescription 386 | { 387 | Name = ModelNameHelper.GetModelName(modelType), 388 | ModelType = modelType, 389 | KeyModelDescription = keyModelDescription, 390 | ValueModelDescription = valueModelDescription 391 | }; 392 | } 393 | 394 | private EnumTypeModelDescription GenerateEnumTypeModelDescription(Type modelType) 395 | { 396 | EnumTypeModelDescription enumDescription = new EnumTypeModelDescription 397 | { 398 | Name = ModelNameHelper.GetModelName(modelType), 399 | ModelType = modelType, 400 | Documentation = CreateDefaultDocumentation(modelType) 401 | }; 402 | bool hasDataContractAttribute = modelType.GetCustomAttribute() != null; 403 | foreach (FieldInfo field in modelType.GetFields(BindingFlags.Public | BindingFlags.Static)) 404 | { 405 | if (ShouldDisplayMember(field, hasDataContractAttribute)) 406 | { 407 | EnumValueDescription enumValue = new EnumValueDescription 408 | { 409 | Name = field.Name, 410 | Value = field.GetRawConstantValue().ToString() 411 | }; 412 | if (DocumentationProvider != null) 413 | { 414 | enumValue.Documentation = DocumentationProvider.GetDocumentation(field); 415 | } 416 | enumDescription.Values.Add(enumValue); 417 | } 418 | } 419 | GeneratedModels.Add(enumDescription.Name, enumDescription); 420 | 421 | return enumDescription; 422 | } 423 | 424 | private KeyValuePairModelDescription GenerateKeyValuePairModelDescription(Type modelType, Type keyType, Type valueType) 425 | { 426 | ModelDescription keyModelDescription = GetOrCreateModelDescription(keyType); 427 | ModelDescription valueModelDescription = GetOrCreateModelDescription(valueType); 428 | 429 | return new KeyValuePairModelDescription 430 | { 431 | Name = ModelNameHelper.GetModelName(modelType), 432 | ModelType = modelType, 433 | KeyModelDescription = keyModelDescription, 434 | ValueModelDescription = valueModelDescription 435 | }; 436 | } 437 | 438 | private ModelDescription GenerateSimpleTypeModelDescription(Type modelType) 439 | { 440 | SimpleTypeModelDescription simpleModelDescription = new SimpleTypeModelDescription 441 | { 442 | Name = ModelNameHelper.GetModelName(modelType), 443 | ModelType = modelType, 444 | Documentation = CreateDefaultDocumentation(modelType) 445 | }; 446 | GeneratedModels.Add(simpleModelDescription.Name, simpleModelDescription); 447 | 448 | return simpleModelDescription; 449 | } 450 | } 451 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/ModelNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 4 | { 5 | /// 6 | /// Use this attribute to change the name of the generated for a type. 7 | /// 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = false, Inherited = false)] 9 | public sealed class ModelNameAttribute : Attribute 10 | { 11 | public ModelNameAttribute(string name) 12 | { 13 | Name = name; 14 | } 15 | 16 | public string Name { get; private set; } 17 | } 18 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/ModelNameHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 7 | { 8 | internal static class ModelNameHelper 9 | { 10 | // Modify this to provide custom model name mapping. 11 | public static string GetModelName(Type type) 12 | { 13 | ModelNameAttribute modelNameAttribute = type.GetCustomAttribute(); 14 | if (modelNameAttribute != null && !String.IsNullOrEmpty(modelNameAttribute.Name)) 15 | { 16 | return modelNameAttribute.Name; 17 | } 18 | 19 | string modelName = type.Name; 20 | if (type.IsGenericType) 21 | { 22 | // Format the generic type name to something like: GenericOfAgurment1AndArgument2 23 | Type genericType = type.GetGenericTypeDefinition(); 24 | Type[] genericArguments = type.GetGenericArguments(); 25 | string genericTypeName = genericType.Name; 26 | 27 | // Trim the generic parameter counts from the name 28 | genericTypeName = genericTypeName.Substring(0, genericTypeName.IndexOf('`')); 29 | string[] argumentTypeNames = genericArguments.Select(t => GetModelName(t)).ToArray(); 30 | modelName = String.Format(CultureInfo.InvariantCulture, "{0}Of{1}", genericTypeName, String.Join("And", argumentTypeNames)); 31 | } 32 | 33 | return modelName; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/ParameterAnnotation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 4 | { 5 | public class ParameterAnnotation 6 | { 7 | public Attribute AnnotationAttribute { get; set; } 8 | 9 | public string Documentation { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/ParameterDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | 4 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 5 | { 6 | public class ParameterDescription 7 | { 8 | public ParameterDescription() 9 | { 10 | Annotations = new Collection(); 11 | } 12 | 13 | public Collection Annotations { get; private set; } 14 | 15 | public string Documentation { get; set; } 16 | 17 | public string Name { get; set; } 18 | 19 | public ModelDescription TypeDescription { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/ModelDescriptions/SimpleTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class SimpleTypeModelDescription : ModelDescription 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Models/HelpPageApiModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | using System.Net.Http.Headers; 4 | using System.Web.Http.Description; 5 | using TheCodeCamp.Areas.HelpPage.ModelDescriptions; 6 | 7 | namespace TheCodeCamp.Areas.HelpPage.Models 8 | { 9 | /// 10 | /// The model that represents an API displayed on the help page. 11 | /// 12 | public class HelpPageApiModel 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public HelpPageApiModel() 18 | { 19 | UriParameters = new Collection(); 20 | SampleRequests = new Dictionary(); 21 | SampleResponses = new Dictionary(); 22 | ErrorMessages = new Collection(); 23 | } 24 | 25 | /// 26 | /// Gets or sets the that describes the API. 27 | /// 28 | public ApiDescription ApiDescription { get; set; } 29 | 30 | /// 31 | /// Gets or sets the collection that describes the URI parameters for the API. 32 | /// 33 | public Collection UriParameters { get; private set; } 34 | 35 | /// 36 | /// Gets or sets the documentation for the request. 37 | /// 38 | public string RequestDocumentation { get; set; } 39 | 40 | /// 41 | /// Gets or sets the that describes the request body. 42 | /// 43 | public ModelDescription RequestModelDescription { get; set; } 44 | 45 | /// 46 | /// Gets the request body parameter descriptions. 47 | /// 48 | public IList RequestBodyParameters 49 | { 50 | get 51 | { 52 | return GetParameterDescriptions(RequestModelDescription); 53 | } 54 | } 55 | 56 | /// 57 | /// Gets or sets the that describes the resource. 58 | /// 59 | public ModelDescription ResourceDescription { get; set; } 60 | 61 | /// 62 | /// Gets the resource property descriptions. 63 | /// 64 | public IList ResourceProperties 65 | { 66 | get 67 | { 68 | return GetParameterDescriptions(ResourceDescription); 69 | } 70 | } 71 | 72 | /// 73 | /// Gets the sample requests associated with the API. 74 | /// 75 | public IDictionary SampleRequests { get; private set; } 76 | 77 | /// 78 | /// Gets the sample responses associated with the API. 79 | /// 80 | public IDictionary SampleResponses { get; private set; } 81 | 82 | /// 83 | /// Gets the error messages associated with this model. 84 | /// 85 | public Collection ErrorMessages { get; private set; } 86 | 87 | private static IList GetParameterDescriptions(ModelDescription modelDescription) 88 | { 89 | ComplexTypeModelDescription complexTypeModelDescription = modelDescription as ComplexTypeModelDescription; 90 | if (complexTypeModelDescription != null) 91 | { 92 | return complexTypeModelDescription.Properties; 93 | } 94 | 95 | CollectionModelDescription collectionModelDescription = modelDescription as CollectionModelDescription; 96 | if (collectionModelDescription != null) 97 | { 98 | complexTypeModelDescription = collectionModelDescription.ElementDescription as ComplexTypeModelDescription; 99 | if (complexTypeModelDescription != null) 100 | { 101 | return complexTypeModelDescription.Properties; 102 | } 103 | } 104 | 105 | return null; 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/SampleGeneration/HelpPageSampleGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.ComponentModel; 5 | using System.Diagnostics.CodeAnalysis; 6 | using System.Globalization; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Net.Http; 10 | using System.Net.Http.Formatting; 11 | using System.Net.Http.Headers; 12 | using System.Web.Http.Description; 13 | using System.Xml.Linq; 14 | using Newtonsoft.Json; 15 | 16 | namespace TheCodeCamp.Areas.HelpPage 17 | { 18 | /// 19 | /// This class will generate the samples for the help page. 20 | /// 21 | public class HelpPageSampleGenerator 22 | { 23 | /// 24 | /// Initializes a new instance of the class. 25 | /// 26 | public HelpPageSampleGenerator() 27 | { 28 | ActualHttpMessageTypes = new Dictionary(); 29 | ActionSamples = new Dictionary(); 30 | SampleObjects = new Dictionary(); 31 | SampleObjectFactories = new List> 32 | { 33 | DefaultSampleObjectFactory, 34 | }; 35 | } 36 | 37 | /// 38 | /// Gets CLR types that are used as the content of or . 39 | /// 40 | public IDictionary ActualHttpMessageTypes { get; internal set; } 41 | 42 | /// 43 | /// Gets the objects that are used directly as samples for certain actions. 44 | /// 45 | public IDictionary ActionSamples { get; internal set; } 46 | 47 | /// 48 | /// Gets the objects that are serialized as samples by the supported formatters. 49 | /// 50 | public IDictionary SampleObjects { get; internal set; } 51 | 52 | /// 53 | /// Gets factories for the objects that the supported formatters will serialize as samples. Processed in order, 54 | /// stopping when the factory successfully returns a non- object. 55 | /// 56 | /// 57 | /// Collection includes just initially. Use 58 | /// SampleObjectFactories.Insert(0, func) to provide an override and 59 | /// SampleObjectFactories.Add(func) to provide a fallback. 60 | [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", 61 | Justification = "This is an appropriate nesting of generic types")] 62 | public IList> SampleObjectFactories { get; private set; } 63 | 64 | /// 65 | /// Gets the request body samples for a given . 66 | /// 67 | /// The . 68 | /// The samples keyed by media type. 69 | public IDictionary GetSampleRequests(ApiDescription api) 70 | { 71 | return GetSample(api, SampleDirection.Request); 72 | } 73 | 74 | /// 75 | /// Gets the response body samples for a given . 76 | /// 77 | /// The . 78 | /// The samples keyed by media type. 79 | public IDictionary GetSampleResponses(ApiDescription api) 80 | { 81 | return GetSample(api, SampleDirection.Response); 82 | } 83 | 84 | /// 85 | /// Gets the request or response body samples. 86 | /// 87 | /// The . 88 | /// The value indicating whether the sample is for a request or for a response. 89 | /// The samples keyed by media type. 90 | public virtual IDictionary GetSample(ApiDescription api, SampleDirection sampleDirection) 91 | { 92 | if (api == null) 93 | { 94 | throw new ArgumentNullException("api"); 95 | } 96 | string controllerName = api.ActionDescriptor.ControllerDescriptor.ControllerName; 97 | string actionName = api.ActionDescriptor.ActionName; 98 | IEnumerable parameterNames = api.ParameterDescriptions.Select(p => p.Name); 99 | Collection formatters; 100 | Type type = ResolveType(api, controllerName, actionName, parameterNames, sampleDirection, out formatters); 101 | var samples = new Dictionary(); 102 | 103 | // Use the samples provided directly for actions 104 | var actionSamples = GetAllActionSamples(controllerName, actionName, parameterNames, sampleDirection); 105 | foreach (var actionSample in actionSamples) 106 | { 107 | samples.Add(actionSample.Key.MediaType, WrapSampleIfString(actionSample.Value)); 108 | } 109 | 110 | // Do the sample generation based on formatters only if an action doesn't return an HttpResponseMessage. 111 | // Here we cannot rely on formatters because we don't know what's in the HttpResponseMessage, it might not even use formatters. 112 | if (type != null && !typeof(HttpResponseMessage).IsAssignableFrom(type)) 113 | { 114 | object sampleObject = GetSampleObject(type); 115 | foreach (var formatter in formatters) 116 | { 117 | foreach (MediaTypeHeaderValue mediaType in formatter.SupportedMediaTypes) 118 | { 119 | if (!samples.ContainsKey(mediaType)) 120 | { 121 | object sample = GetActionSample(controllerName, actionName, parameterNames, type, formatter, mediaType, sampleDirection); 122 | 123 | // If no sample found, try generate sample using formatter and sample object 124 | if (sample == null && sampleObject != null) 125 | { 126 | sample = WriteSampleObjectUsingFormatter(formatter, sampleObject, type, mediaType); 127 | } 128 | 129 | samples.Add(mediaType, WrapSampleIfString(sample)); 130 | } 131 | } 132 | } 133 | } 134 | 135 | return samples; 136 | } 137 | 138 | /// 139 | /// Search for samples that are provided directly through . 140 | /// 141 | /// Name of the controller. 142 | /// Name of the action. 143 | /// The parameter names. 144 | /// The CLR type. 145 | /// The formatter. 146 | /// The media type. 147 | /// The value indicating whether the sample is for a request or for a response. 148 | /// The sample that matches the parameters. 149 | public virtual object GetActionSample(string controllerName, string actionName, IEnumerable parameterNames, Type type, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType, SampleDirection sampleDirection) 150 | { 151 | object sample; 152 | 153 | // First, try to get the sample provided for the specified mediaType, sampleDirection, controllerName, actionName and parameterNames. 154 | // If not found, try to get the sample provided for the specified mediaType, sampleDirection, controllerName and actionName regardless of the parameterNames. 155 | // If still not found, try to get the sample provided for the specified mediaType and type. 156 | // Finally, try to get the sample provided for the specified mediaType. 157 | if (ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, sampleDirection, controllerName, actionName, parameterNames), out sample) || 158 | ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, sampleDirection, controllerName, actionName, new[] { "*" }), out sample) || 159 | ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, type), out sample) || 160 | ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType), out sample)) 161 | { 162 | return sample; 163 | } 164 | 165 | return null; 166 | } 167 | 168 | /// 169 | /// Gets the sample object that will be serialized by the formatters. 170 | /// First, it will look at the . If no sample object is found, it will try to create 171 | /// one using (which wraps an ) and other 172 | /// factories in . 173 | /// 174 | /// The type. 175 | /// The sample object. 176 | [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", 177 | Justification = "Even if all items in SampleObjectFactories throw, problem will be visible as missing sample.")] 178 | public virtual object GetSampleObject(Type type) 179 | { 180 | object sampleObject; 181 | 182 | if (!SampleObjects.TryGetValue(type, out sampleObject)) 183 | { 184 | // No specific object available, try our factories. 185 | foreach (Func factory in SampleObjectFactories) 186 | { 187 | if (factory == null) 188 | { 189 | continue; 190 | } 191 | 192 | try 193 | { 194 | sampleObject = factory(this, type); 195 | if (sampleObject != null) 196 | { 197 | break; 198 | } 199 | } 200 | catch 201 | { 202 | // Ignore any problems encountered in the factory; go on to the next one (if any). 203 | } 204 | } 205 | } 206 | 207 | return sampleObject; 208 | } 209 | 210 | /// 211 | /// Resolves the actual type of passed to the in an action. 212 | /// 213 | /// The . 214 | /// The type. 215 | public virtual Type ResolveHttpRequestMessageType(ApiDescription api) 216 | { 217 | string controllerName = api.ActionDescriptor.ControllerDescriptor.ControllerName; 218 | string actionName = api.ActionDescriptor.ActionName; 219 | IEnumerable parameterNames = api.ParameterDescriptions.Select(p => p.Name); 220 | Collection formatters; 221 | return ResolveType(api, controllerName, actionName, parameterNames, SampleDirection.Request, out formatters); 222 | } 223 | 224 | /// 225 | /// Resolves the type of the action parameter or return value when or is used. 226 | /// 227 | /// The . 228 | /// Name of the controller. 229 | /// Name of the action. 230 | /// The parameter names. 231 | /// The value indicating whether the sample is for a request or a response. 232 | /// The formatters. 233 | [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", Justification = "This is only used in advanced scenarios.")] 234 | public virtual Type ResolveType(ApiDescription api, string controllerName, string actionName, IEnumerable parameterNames, SampleDirection sampleDirection, out Collection formatters) 235 | { 236 | if (!Enum.IsDefined(typeof(SampleDirection), sampleDirection)) 237 | { 238 | throw new InvalidEnumArgumentException("sampleDirection", (int)sampleDirection, typeof(SampleDirection)); 239 | } 240 | if (api == null) 241 | { 242 | throw new ArgumentNullException("api"); 243 | } 244 | Type type; 245 | if (ActualHttpMessageTypes.TryGetValue(new HelpPageSampleKey(sampleDirection, controllerName, actionName, parameterNames), out type) || 246 | ActualHttpMessageTypes.TryGetValue(new HelpPageSampleKey(sampleDirection, controllerName, actionName, new[] { "*" }), out type)) 247 | { 248 | // Re-compute the supported formatters based on type 249 | Collection newFormatters = new Collection(); 250 | foreach (var formatter in api.ActionDescriptor.Configuration.Formatters) 251 | { 252 | if (IsFormatSupported(sampleDirection, formatter, type)) 253 | { 254 | newFormatters.Add(formatter); 255 | } 256 | } 257 | formatters = newFormatters; 258 | } 259 | else 260 | { 261 | switch (sampleDirection) 262 | { 263 | case SampleDirection.Request: 264 | ApiParameterDescription requestBodyParameter = api.ParameterDescriptions.FirstOrDefault(p => p.Source == ApiParameterSource.FromBody); 265 | type = requestBodyParameter == null ? null : requestBodyParameter.ParameterDescriptor.ParameterType; 266 | formatters = api.SupportedRequestBodyFormatters; 267 | break; 268 | case SampleDirection.Response: 269 | default: 270 | type = api.ResponseDescription.ResponseType ?? api.ResponseDescription.DeclaredType; 271 | formatters = api.SupportedResponseFormatters; 272 | break; 273 | } 274 | } 275 | 276 | return type; 277 | } 278 | 279 | /// 280 | /// Writes the sample object using formatter. 281 | /// 282 | /// The formatter. 283 | /// The value. 284 | /// The type. 285 | /// Type of the media. 286 | /// 287 | [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "The exception is recorded as InvalidSample.")] 288 | public virtual object WriteSampleObjectUsingFormatter(MediaTypeFormatter formatter, object value, Type type, MediaTypeHeaderValue mediaType) 289 | { 290 | if (formatter == null) 291 | { 292 | throw new ArgumentNullException("formatter"); 293 | } 294 | if (mediaType == null) 295 | { 296 | throw new ArgumentNullException("mediaType"); 297 | } 298 | 299 | object sample = String.Empty; 300 | MemoryStream ms = null; 301 | HttpContent content = null; 302 | try 303 | { 304 | if (formatter.CanWriteType(type)) 305 | { 306 | ms = new MemoryStream(); 307 | content = new ObjectContent(type, value, formatter, mediaType); 308 | formatter.WriteToStreamAsync(type, value, ms, content, null).Wait(); 309 | ms.Position = 0; 310 | StreamReader reader = new StreamReader(ms); 311 | string serializedSampleString = reader.ReadToEnd(); 312 | if (mediaType.MediaType.ToUpperInvariant().Contains("XML")) 313 | { 314 | serializedSampleString = TryFormatXml(serializedSampleString); 315 | } 316 | else if (mediaType.MediaType.ToUpperInvariant().Contains("JSON")) 317 | { 318 | serializedSampleString = TryFormatJson(serializedSampleString); 319 | } 320 | 321 | sample = new TextSample(serializedSampleString); 322 | } 323 | else 324 | { 325 | sample = new InvalidSample(String.Format( 326 | CultureInfo.CurrentCulture, 327 | "Failed to generate the sample for media type '{0}'. Cannot use formatter '{1}' to write type '{2}'.", 328 | mediaType, 329 | formatter.GetType().Name, 330 | type.Name)); 331 | } 332 | } 333 | catch (Exception e) 334 | { 335 | sample = new InvalidSample(String.Format( 336 | CultureInfo.CurrentCulture, 337 | "An exception has occurred while using the formatter '{0}' to generate sample for media type '{1}'. Exception message: {2}", 338 | formatter.GetType().Name, 339 | mediaType.MediaType, 340 | UnwrapException(e).Message)); 341 | } 342 | finally 343 | { 344 | if (ms != null) 345 | { 346 | ms.Dispose(); 347 | } 348 | if (content != null) 349 | { 350 | content.Dispose(); 351 | } 352 | } 353 | 354 | return sample; 355 | } 356 | 357 | internal static Exception UnwrapException(Exception exception) 358 | { 359 | AggregateException aggregateException = exception as AggregateException; 360 | if (aggregateException != null) 361 | { 362 | return aggregateException.Flatten().InnerException; 363 | } 364 | return exception; 365 | } 366 | 367 | // Default factory for sample objects 368 | private static object DefaultSampleObjectFactory(HelpPageSampleGenerator sampleGenerator, Type type) 369 | { 370 | // Try to create a default sample object 371 | ObjectGenerator objectGenerator = new ObjectGenerator(); 372 | return objectGenerator.GenerateObject(type); 373 | } 374 | 375 | [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Handling the failure by returning the original string.")] 376 | private static string TryFormatJson(string str) 377 | { 378 | try 379 | { 380 | object parsedJson = JsonConvert.DeserializeObject(str); 381 | return JsonConvert.SerializeObject(parsedJson, Formatting.Indented); 382 | } 383 | catch 384 | { 385 | // can't parse JSON, return the original string 386 | return str; 387 | } 388 | } 389 | 390 | [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Handling the failure by returning the original string.")] 391 | private static string TryFormatXml(string str) 392 | { 393 | try 394 | { 395 | XDocument xml = XDocument.Parse(str); 396 | return xml.ToString(); 397 | } 398 | catch 399 | { 400 | // can't parse XML, return the original string 401 | return str; 402 | } 403 | } 404 | 405 | private static bool IsFormatSupported(SampleDirection sampleDirection, MediaTypeFormatter formatter, Type type) 406 | { 407 | switch (sampleDirection) 408 | { 409 | case SampleDirection.Request: 410 | return formatter.CanReadType(type); 411 | case SampleDirection.Response: 412 | return formatter.CanWriteType(type); 413 | } 414 | return false; 415 | } 416 | 417 | private IEnumerable> GetAllActionSamples(string controllerName, string actionName, IEnumerable parameterNames, SampleDirection sampleDirection) 418 | { 419 | HashSet parameterNamesSet = new HashSet(parameterNames, StringComparer.OrdinalIgnoreCase); 420 | foreach (var sample in ActionSamples) 421 | { 422 | HelpPageSampleKey sampleKey = sample.Key; 423 | if (String.Equals(controllerName, sampleKey.ControllerName, StringComparison.OrdinalIgnoreCase) && 424 | String.Equals(actionName, sampleKey.ActionName, StringComparison.OrdinalIgnoreCase) && 425 | (sampleKey.ParameterNames.SetEquals(new[] { "*" }) || parameterNamesSet.SetEquals(sampleKey.ParameterNames)) && 426 | sampleDirection == sampleKey.SampleDirection) 427 | { 428 | yield return sample; 429 | } 430 | } 431 | } 432 | 433 | private static object WrapSampleIfString(object sample) 434 | { 435 | string stringSample = sample as string; 436 | if (stringSample != null) 437 | { 438 | return new TextSample(stringSample); 439 | } 440 | 441 | return sample; 442 | } 443 | } 444 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/SampleGeneration/HelpPageSampleKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Net.Http.Headers; 5 | 6 | namespace TheCodeCamp.Areas.HelpPage 7 | { 8 | /// 9 | /// This is used to identify the place where the sample should be applied. 10 | /// 11 | public class HelpPageSampleKey 12 | { 13 | /// 14 | /// Creates a new based on media type. 15 | /// 16 | /// The media type. 17 | public HelpPageSampleKey(MediaTypeHeaderValue mediaType) 18 | { 19 | if (mediaType == null) 20 | { 21 | throw new ArgumentNullException("mediaType"); 22 | } 23 | 24 | ActionName = String.Empty; 25 | ControllerName = String.Empty; 26 | MediaType = mediaType; 27 | ParameterNames = new HashSet(StringComparer.OrdinalIgnoreCase); 28 | } 29 | 30 | /// 31 | /// Creates a new based on media type and CLR type. 32 | /// 33 | /// The media type. 34 | /// The CLR type. 35 | public HelpPageSampleKey(MediaTypeHeaderValue mediaType, Type type) 36 | : this(mediaType) 37 | { 38 | if (type == null) 39 | { 40 | throw new ArgumentNullException("type"); 41 | } 42 | 43 | ParameterType = type; 44 | } 45 | 46 | /// 47 | /// Creates a new based on , controller name, action name and parameter names. 48 | /// 49 | /// The . 50 | /// Name of the controller. 51 | /// Name of the action. 52 | /// The parameter names. 53 | public HelpPageSampleKey(SampleDirection sampleDirection, string controllerName, string actionName, IEnumerable parameterNames) 54 | { 55 | if (!Enum.IsDefined(typeof(SampleDirection), sampleDirection)) 56 | { 57 | throw new InvalidEnumArgumentException("sampleDirection", (int)sampleDirection, typeof(SampleDirection)); 58 | } 59 | if (controllerName == null) 60 | { 61 | throw new ArgumentNullException("controllerName"); 62 | } 63 | if (actionName == null) 64 | { 65 | throw new ArgumentNullException("actionName"); 66 | } 67 | if (parameterNames == null) 68 | { 69 | throw new ArgumentNullException("parameterNames"); 70 | } 71 | 72 | ControllerName = controllerName; 73 | ActionName = actionName; 74 | ParameterNames = new HashSet(parameterNames, StringComparer.OrdinalIgnoreCase); 75 | SampleDirection = sampleDirection; 76 | } 77 | 78 | /// 79 | /// Creates a new based on media type, , controller name, action name and parameter names. 80 | /// 81 | /// The media type. 82 | /// The . 83 | /// Name of the controller. 84 | /// Name of the action. 85 | /// The parameter names. 86 | public HelpPageSampleKey(MediaTypeHeaderValue mediaType, SampleDirection sampleDirection, string controllerName, string actionName, IEnumerable parameterNames) 87 | : this(sampleDirection, controllerName, actionName, parameterNames) 88 | { 89 | if (mediaType == null) 90 | { 91 | throw new ArgumentNullException("mediaType"); 92 | } 93 | 94 | MediaType = mediaType; 95 | } 96 | 97 | /// 98 | /// Gets the name of the controller. 99 | /// 100 | /// 101 | /// The name of the controller. 102 | /// 103 | public string ControllerName { get; private set; } 104 | 105 | /// 106 | /// Gets the name of the action. 107 | /// 108 | /// 109 | /// The name of the action. 110 | /// 111 | public string ActionName { get; private set; } 112 | 113 | /// 114 | /// Gets the media type. 115 | /// 116 | /// 117 | /// The media type. 118 | /// 119 | public MediaTypeHeaderValue MediaType { get; private set; } 120 | 121 | /// 122 | /// Gets the parameter names. 123 | /// 124 | public HashSet ParameterNames { get; private set; } 125 | 126 | public Type ParameterType { get; private set; } 127 | 128 | /// 129 | /// Gets the . 130 | /// 131 | public SampleDirection? SampleDirection { get; private set; } 132 | 133 | public override bool Equals(object obj) 134 | { 135 | HelpPageSampleKey otherKey = obj as HelpPageSampleKey; 136 | if (otherKey == null) 137 | { 138 | return false; 139 | } 140 | 141 | return String.Equals(ControllerName, otherKey.ControllerName, StringComparison.OrdinalIgnoreCase) && 142 | String.Equals(ActionName, otherKey.ActionName, StringComparison.OrdinalIgnoreCase) && 143 | (MediaType == otherKey.MediaType || (MediaType != null && MediaType.Equals(otherKey.MediaType))) && 144 | ParameterType == otherKey.ParameterType && 145 | SampleDirection == otherKey.SampleDirection && 146 | ParameterNames.SetEquals(otherKey.ParameterNames); 147 | } 148 | 149 | public override int GetHashCode() 150 | { 151 | int hashCode = ControllerName.ToUpperInvariant().GetHashCode() ^ ActionName.ToUpperInvariant().GetHashCode(); 152 | if (MediaType != null) 153 | { 154 | hashCode ^= MediaType.GetHashCode(); 155 | } 156 | if (SampleDirection != null) 157 | { 158 | hashCode ^= SampleDirection.GetHashCode(); 159 | } 160 | if (ParameterType != null) 161 | { 162 | hashCode ^= ParameterType.GetHashCode(); 163 | } 164 | foreach (string parameterName in ParameterNames) 165 | { 166 | hashCode ^= parameterName.ToUpperInvariant().GetHashCode(); 167 | } 168 | 169 | return hashCode; 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/SampleGeneration/ImageSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TheCodeCamp.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an image sample on the help page. There's a display template named ImageSample associated with this class. 7 | /// 8 | public class ImageSample 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The URL of an image. 14 | public ImageSample(string src) 15 | { 16 | if (src == null) 17 | { 18 | throw new ArgumentNullException("src"); 19 | } 20 | Src = src; 21 | } 22 | 23 | public string Src { get; private set; } 24 | 25 | public override bool Equals(object obj) 26 | { 27 | ImageSample other = obj as ImageSample; 28 | return other != null && Src == other.Src; 29 | } 30 | 31 | public override int GetHashCode() 32 | { 33 | return Src.GetHashCode(); 34 | } 35 | 36 | public override string ToString() 37 | { 38 | return Src; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/SampleGeneration/InvalidSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TheCodeCamp.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an invalid sample on the help page. There's a display template named InvalidSample associated with this class. 7 | /// 8 | public class InvalidSample 9 | { 10 | public InvalidSample(string errorMessage) 11 | { 12 | if (errorMessage == null) 13 | { 14 | throw new ArgumentNullException("errorMessage"); 15 | } 16 | ErrorMessage = errorMessage; 17 | } 18 | 19 | public string ErrorMessage { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | InvalidSample other = obj as InvalidSample; 24 | return other != null && ErrorMessage == other.ErrorMessage; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return ErrorMessage.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return ErrorMessage; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/SampleGeneration/ObjectGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics.CodeAnalysis; 5 | using System.Globalization; 6 | using System.Linq; 7 | using System.Reflection; 8 | 9 | namespace TheCodeCamp.Areas.HelpPage 10 | { 11 | /// 12 | /// This class will create an object of a given type and populate it with sample data. 13 | /// 14 | public class ObjectGenerator 15 | { 16 | internal const int DefaultCollectionSize = 2; 17 | private readonly SimpleTypeObjectGenerator SimpleObjectGenerator = new SimpleTypeObjectGenerator(); 18 | 19 | /// 20 | /// Generates an object for a given type. The type needs to be public, have a public default constructor and settable public properties/fields. Currently it supports the following types: 21 | /// Simple types: , , , , , etc. 22 | /// Complex types: POCO types. 23 | /// Nullables: . 24 | /// Arrays: arrays of simple types or complex types. 25 | /// Key value pairs: 26 | /// Tuples: , , etc 27 | /// Dictionaries: or anything deriving from . 28 | /// Collections: , , , , , or anything deriving from or . 29 | /// Queryables: , . 30 | /// 31 | /// The type. 32 | /// An object of the given type. 33 | public object GenerateObject(Type type) 34 | { 35 | return GenerateObject(type, new Dictionary()); 36 | } 37 | 38 | [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Here we just want to return null if anything goes wrong.")] 39 | private object GenerateObject(Type type, Dictionary createdObjectReferences) 40 | { 41 | try 42 | { 43 | if (SimpleTypeObjectGenerator.CanGenerateObject(type)) 44 | { 45 | return SimpleObjectGenerator.GenerateObject(type); 46 | } 47 | 48 | if (type.IsArray) 49 | { 50 | return GenerateArray(type, DefaultCollectionSize, createdObjectReferences); 51 | } 52 | 53 | if (type.IsGenericType) 54 | { 55 | return GenerateGenericType(type, DefaultCollectionSize, createdObjectReferences); 56 | } 57 | 58 | if (type == typeof(IDictionary)) 59 | { 60 | return GenerateDictionary(typeof(Hashtable), DefaultCollectionSize, createdObjectReferences); 61 | } 62 | 63 | if (typeof(IDictionary).IsAssignableFrom(type)) 64 | { 65 | return GenerateDictionary(type, DefaultCollectionSize, createdObjectReferences); 66 | } 67 | 68 | if (type == typeof(IList) || 69 | type == typeof(IEnumerable) || 70 | type == typeof(ICollection)) 71 | { 72 | return GenerateCollection(typeof(ArrayList), DefaultCollectionSize, createdObjectReferences); 73 | } 74 | 75 | if (typeof(IList).IsAssignableFrom(type)) 76 | { 77 | return GenerateCollection(type, DefaultCollectionSize, createdObjectReferences); 78 | } 79 | 80 | if (type == typeof(IQueryable)) 81 | { 82 | return GenerateQueryable(type, DefaultCollectionSize, createdObjectReferences); 83 | } 84 | 85 | if (type.IsEnum) 86 | { 87 | return GenerateEnum(type); 88 | } 89 | 90 | if (type.IsPublic || type.IsNestedPublic) 91 | { 92 | return GenerateComplexObject(type, createdObjectReferences); 93 | } 94 | } 95 | catch 96 | { 97 | // Returns null if anything fails 98 | return null; 99 | } 100 | 101 | return null; 102 | } 103 | 104 | private static object GenerateGenericType(Type type, int collectionSize, Dictionary createdObjectReferences) 105 | { 106 | Type genericTypeDefinition = type.GetGenericTypeDefinition(); 107 | if (genericTypeDefinition == typeof(Nullable<>)) 108 | { 109 | return GenerateNullable(type, createdObjectReferences); 110 | } 111 | 112 | if (genericTypeDefinition == typeof(KeyValuePair<,>)) 113 | { 114 | return GenerateKeyValuePair(type, createdObjectReferences); 115 | } 116 | 117 | if (IsTuple(genericTypeDefinition)) 118 | { 119 | return GenerateTuple(type, createdObjectReferences); 120 | } 121 | 122 | Type[] genericArguments = type.GetGenericArguments(); 123 | if (genericArguments.Length == 1) 124 | { 125 | if (genericTypeDefinition == typeof(IList<>) || 126 | genericTypeDefinition == typeof(IEnumerable<>) || 127 | genericTypeDefinition == typeof(ICollection<>)) 128 | { 129 | Type collectionType = typeof(List<>).MakeGenericType(genericArguments); 130 | return GenerateCollection(collectionType, collectionSize, createdObjectReferences); 131 | } 132 | 133 | if (genericTypeDefinition == typeof(IQueryable<>)) 134 | { 135 | return GenerateQueryable(type, collectionSize, createdObjectReferences); 136 | } 137 | 138 | Type closedCollectionType = typeof(ICollection<>).MakeGenericType(genericArguments[0]); 139 | if (closedCollectionType.IsAssignableFrom(type)) 140 | { 141 | return GenerateCollection(type, collectionSize, createdObjectReferences); 142 | } 143 | } 144 | 145 | if (genericArguments.Length == 2) 146 | { 147 | if (genericTypeDefinition == typeof(IDictionary<,>)) 148 | { 149 | Type dictionaryType = typeof(Dictionary<,>).MakeGenericType(genericArguments); 150 | return GenerateDictionary(dictionaryType, collectionSize, createdObjectReferences); 151 | } 152 | 153 | Type closedDictionaryType = typeof(IDictionary<,>).MakeGenericType(genericArguments[0], genericArguments[1]); 154 | if (closedDictionaryType.IsAssignableFrom(type)) 155 | { 156 | return GenerateDictionary(type, collectionSize, createdObjectReferences); 157 | } 158 | } 159 | 160 | if (type.IsPublic || type.IsNestedPublic) 161 | { 162 | return GenerateComplexObject(type, createdObjectReferences); 163 | } 164 | 165 | return null; 166 | } 167 | 168 | private static object GenerateTuple(Type type, Dictionary createdObjectReferences) 169 | { 170 | Type[] genericArgs = type.GetGenericArguments(); 171 | object[] parameterValues = new object[genericArgs.Length]; 172 | bool failedToCreateTuple = true; 173 | ObjectGenerator objectGenerator = new ObjectGenerator(); 174 | for (int i = 0; i < genericArgs.Length; i++) 175 | { 176 | parameterValues[i] = objectGenerator.GenerateObject(genericArgs[i], createdObjectReferences); 177 | failedToCreateTuple &= parameterValues[i] == null; 178 | } 179 | if (failedToCreateTuple) 180 | { 181 | return null; 182 | } 183 | object result = Activator.CreateInstance(type, parameterValues); 184 | return result; 185 | } 186 | 187 | private static bool IsTuple(Type genericTypeDefinition) 188 | { 189 | return genericTypeDefinition == typeof(Tuple<>) || 190 | genericTypeDefinition == typeof(Tuple<,>) || 191 | genericTypeDefinition == typeof(Tuple<,,>) || 192 | genericTypeDefinition == typeof(Tuple<,,,>) || 193 | genericTypeDefinition == typeof(Tuple<,,,,>) || 194 | genericTypeDefinition == typeof(Tuple<,,,,,>) || 195 | genericTypeDefinition == typeof(Tuple<,,,,,,>) || 196 | genericTypeDefinition == typeof(Tuple<,,,,,,,>); 197 | } 198 | 199 | private static object GenerateKeyValuePair(Type keyValuePairType, Dictionary createdObjectReferences) 200 | { 201 | Type[] genericArgs = keyValuePairType.GetGenericArguments(); 202 | Type typeK = genericArgs[0]; 203 | Type typeV = genericArgs[1]; 204 | ObjectGenerator objectGenerator = new ObjectGenerator(); 205 | object keyObject = objectGenerator.GenerateObject(typeK, createdObjectReferences); 206 | object valueObject = objectGenerator.GenerateObject(typeV, createdObjectReferences); 207 | if (keyObject == null && valueObject == null) 208 | { 209 | // Failed to create key and values 210 | return null; 211 | } 212 | object result = Activator.CreateInstance(keyValuePairType, keyObject, valueObject); 213 | return result; 214 | } 215 | 216 | private static object GenerateArray(Type arrayType, int size, Dictionary createdObjectReferences) 217 | { 218 | Type type = arrayType.GetElementType(); 219 | Array result = Array.CreateInstance(type, size); 220 | bool areAllElementsNull = true; 221 | ObjectGenerator objectGenerator = new ObjectGenerator(); 222 | for (int i = 0; i < size; i++) 223 | { 224 | object element = objectGenerator.GenerateObject(type, createdObjectReferences); 225 | result.SetValue(element, i); 226 | areAllElementsNull &= element == null; 227 | } 228 | 229 | if (areAllElementsNull) 230 | { 231 | return null; 232 | } 233 | 234 | return result; 235 | } 236 | 237 | private static object GenerateDictionary(Type dictionaryType, int size, Dictionary createdObjectReferences) 238 | { 239 | Type typeK = typeof(object); 240 | Type typeV = typeof(object); 241 | if (dictionaryType.IsGenericType) 242 | { 243 | Type[] genericArgs = dictionaryType.GetGenericArguments(); 244 | typeK = genericArgs[0]; 245 | typeV = genericArgs[1]; 246 | } 247 | 248 | object result = Activator.CreateInstance(dictionaryType); 249 | MethodInfo addMethod = dictionaryType.GetMethod("Add") ?? dictionaryType.GetMethod("TryAdd"); 250 | MethodInfo containsMethod = dictionaryType.GetMethod("Contains") ?? dictionaryType.GetMethod("ContainsKey"); 251 | ObjectGenerator objectGenerator = new ObjectGenerator(); 252 | for (int i = 0; i < size; i++) 253 | { 254 | object newKey = objectGenerator.GenerateObject(typeK, createdObjectReferences); 255 | if (newKey == null) 256 | { 257 | // Cannot generate a valid key 258 | return null; 259 | } 260 | 261 | bool containsKey = (bool)containsMethod.Invoke(result, new object[] { newKey }); 262 | if (!containsKey) 263 | { 264 | object newValue = objectGenerator.GenerateObject(typeV, createdObjectReferences); 265 | addMethod.Invoke(result, new object[] { newKey, newValue }); 266 | } 267 | } 268 | 269 | return result; 270 | } 271 | 272 | private static object GenerateEnum(Type enumType) 273 | { 274 | Array possibleValues = Enum.GetValues(enumType); 275 | if (possibleValues.Length > 0) 276 | { 277 | return possibleValues.GetValue(0); 278 | } 279 | return null; 280 | } 281 | 282 | private static object GenerateQueryable(Type queryableType, int size, Dictionary createdObjectReferences) 283 | { 284 | bool isGeneric = queryableType.IsGenericType; 285 | object list; 286 | if (isGeneric) 287 | { 288 | Type listType = typeof(List<>).MakeGenericType(queryableType.GetGenericArguments()); 289 | list = GenerateCollection(listType, size, createdObjectReferences); 290 | } 291 | else 292 | { 293 | list = GenerateArray(typeof(object[]), size, createdObjectReferences); 294 | } 295 | if (list == null) 296 | { 297 | return null; 298 | } 299 | if (isGeneric) 300 | { 301 | Type argumentType = typeof(IEnumerable<>).MakeGenericType(queryableType.GetGenericArguments()); 302 | MethodInfo asQueryableMethod = typeof(Queryable).GetMethod("AsQueryable", new[] { argumentType }); 303 | return asQueryableMethod.Invoke(null, new[] { list }); 304 | } 305 | 306 | return Queryable.AsQueryable((IEnumerable)list); 307 | } 308 | 309 | private static object GenerateCollection(Type collectionType, int size, Dictionary createdObjectReferences) 310 | { 311 | Type type = collectionType.IsGenericType ? 312 | collectionType.GetGenericArguments()[0] : 313 | typeof(object); 314 | object result = Activator.CreateInstance(collectionType); 315 | MethodInfo addMethod = collectionType.GetMethod("Add"); 316 | bool areAllElementsNull = true; 317 | ObjectGenerator objectGenerator = new ObjectGenerator(); 318 | for (int i = 0; i < size; i++) 319 | { 320 | object element = objectGenerator.GenerateObject(type, createdObjectReferences); 321 | addMethod.Invoke(result, new object[] { element }); 322 | areAllElementsNull &= element == null; 323 | } 324 | 325 | if (areAllElementsNull) 326 | { 327 | return null; 328 | } 329 | 330 | return result; 331 | } 332 | 333 | private static object GenerateNullable(Type nullableType, Dictionary createdObjectReferences) 334 | { 335 | Type type = nullableType.GetGenericArguments()[0]; 336 | ObjectGenerator objectGenerator = new ObjectGenerator(); 337 | return objectGenerator.GenerateObject(type, createdObjectReferences); 338 | } 339 | 340 | private static object GenerateComplexObject(Type type, Dictionary createdObjectReferences) 341 | { 342 | object result = null; 343 | 344 | if (createdObjectReferences.TryGetValue(type, out result)) 345 | { 346 | // The object has been created already, just return it. This will handle the circular reference case. 347 | return result; 348 | } 349 | 350 | if (type.IsValueType) 351 | { 352 | result = Activator.CreateInstance(type); 353 | } 354 | else 355 | { 356 | ConstructorInfo defaultCtor = type.GetConstructor(Type.EmptyTypes); 357 | if (defaultCtor == null) 358 | { 359 | // Cannot instantiate the type because it doesn't have a default constructor 360 | return null; 361 | } 362 | 363 | result = defaultCtor.Invoke(new object[0]); 364 | } 365 | createdObjectReferences.Add(type, result); 366 | SetPublicProperties(type, result, createdObjectReferences); 367 | SetPublicFields(type, result, createdObjectReferences); 368 | return result; 369 | } 370 | 371 | private static void SetPublicProperties(Type type, object obj, Dictionary createdObjectReferences) 372 | { 373 | PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); 374 | ObjectGenerator objectGenerator = new ObjectGenerator(); 375 | foreach (PropertyInfo property in properties) 376 | { 377 | if (property.CanWrite) 378 | { 379 | object propertyValue = objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences); 380 | property.SetValue(obj, propertyValue, null); 381 | } 382 | } 383 | } 384 | 385 | private static void SetPublicFields(Type type, object obj, Dictionary createdObjectReferences) 386 | { 387 | FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance); 388 | ObjectGenerator objectGenerator = new ObjectGenerator(); 389 | foreach (FieldInfo field in fields) 390 | { 391 | object fieldValue = objectGenerator.GenerateObject(field.FieldType, createdObjectReferences); 392 | field.SetValue(obj, fieldValue); 393 | } 394 | } 395 | 396 | private class SimpleTypeObjectGenerator 397 | { 398 | private long _index = 0; 399 | private static readonly Dictionary> DefaultGenerators = InitializeGenerators(); 400 | 401 | [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "These are simple type factories and cannot be split up.")] 402 | private static Dictionary> InitializeGenerators() 403 | { 404 | return new Dictionary> 405 | { 406 | { typeof(Boolean), index => true }, 407 | { typeof(Byte), index => (Byte)64 }, 408 | { typeof(Char), index => (Char)65 }, 409 | { typeof(DateTime), index => DateTime.Now }, 410 | { typeof(DateTimeOffset), index => new DateTimeOffset(DateTime.Now) }, 411 | { typeof(DBNull), index => DBNull.Value }, 412 | { typeof(Decimal), index => (Decimal)index }, 413 | { typeof(Double), index => (Double)(index + 0.1) }, 414 | { typeof(Guid), index => Guid.NewGuid() }, 415 | { typeof(Int16), index => (Int16)(index % Int16.MaxValue) }, 416 | { typeof(Int32), index => (Int32)(index % Int32.MaxValue) }, 417 | { typeof(Int64), index => (Int64)index }, 418 | { typeof(Object), index => new object() }, 419 | { typeof(SByte), index => (SByte)64 }, 420 | { typeof(Single), index => (Single)(index + 0.1) }, 421 | { 422 | typeof(String), index => 423 | { 424 | return String.Format(CultureInfo.CurrentCulture, "sample string {0}", index); 425 | } 426 | }, 427 | { 428 | typeof(TimeSpan), index => 429 | { 430 | return TimeSpan.FromTicks(1234567); 431 | } 432 | }, 433 | { typeof(UInt16), index => (UInt16)(index % UInt16.MaxValue) }, 434 | { typeof(UInt32), index => (UInt32)(index % UInt32.MaxValue) }, 435 | { typeof(UInt64), index => (UInt64)index }, 436 | { 437 | typeof(Uri), index => 438 | { 439 | return new Uri(String.Format(CultureInfo.CurrentCulture, "http://webapihelppage{0}.com", index)); 440 | } 441 | }, 442 | }; 443 | } 444 | 445 | public static bool CanGenerateObject(Type type) 446 | { 447 | return DefaultGenerators.ContainsKey(type); 448 | } 449 | 450 | public object GenerateObject(Type type) 451 | { 452 | return DefaultGenerators[type](++_index); 453 | } 454 | } 455 | } 456 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/SampleGeneration/SampleDirection.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Areas.HelpPage 2 | { 3 | /// 4 | /// Indicates whether the sample is used for request or response 5 | /// 6 | public enum SampleDirection 7 | { 8 | Request = 0, 9 | Response 10 | } 11 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/SampleGeneration/TextSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TheCodeCamp.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents a preformatted text sample on the help page. There's a display template named TextSample associated with this class. 7 | /// 8 | public class TextSample 9 | { 10 | public TextSample(string text) 11 | { 12 | if (text == null) 13 | { 14 | throw new ArgumentNullException("text"); 15 | } 16 | Text = text; 17 | } 18 | 19 | public string Text { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | TextSample other = obj as TextSample; 24 | return other != null && Text == other.Text; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return Text.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return Text; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/Api.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using TheCodeCamp.Areas.HelpPage.Models 3 | @model HelpPageApiModel 4 | 5 | @{ 6 | var description = Model.ApiDescription; 7 | ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath; 8 | } 9 | 10 | 11 |
12 | 19 |
20 | @Html.DisplayForModel() 21 |
22 |
23 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/ApiGroup.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using TheCodeCamp.Areas.HelpPage 5 | @using TheCodeCamp.Areas.HelpPage.Models 6 | @model IGrouping 7 | 8 | @{ 9 | var controllerDocumentation = ViewBag.DocumentationProvider != null ? 10 | ViewBag.DocumentationProvider.GetDocumentation(Model.Key) : 11 | null; 12 | } 13 | 14 |

@Model.Key.ControllerName

15 | @if (!String.IsNullOrEmpty(controllerDocumentation)) 16 | { 17 |

@controllerDocumentation

18 | } 19 | 20 | 21 | 22 | 23 | 24 | @foreach (var api in Model) 25 | { 26 | 27 | 28 | 38 | 39 | } 40 | 41 |
APIDescription
@api.HttpMethod.Method @api.RelativePath 29 | @if (api.Documentation != null) 30 | { 31 |

@api.Documentation

32 | } 33 | else 34 | { 35 |

No documentation available.

36 | } 37 |
-------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/CollectionModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | @model CollectionModelDescription 3 | @if (Model.ElementDescription is ComplexTypeModelDescription) 4 | { 5 | @Html.DisplayFor(m => m.ElementDescription) 6 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/ComplexTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | @model ComplexTypeModelDescription 3 | @Html.DisplayFor(m => m.Properties, "Parameters") -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/DictionaryModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | @model DictionaryModelDescription 3 | Dictionary of @Html.DisplayFor(m => Model.KeyModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.KeyModelDescription }) [key] 4 | and @Html.DisplayFor(m => Model.ValueModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ValueModelDescription }) [value] -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/EnumTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | @model EnumTypeModelDescription 3 | 4 |

Possible enumeration values:

5 | 6 | 7 | 8 | 9 | 10 | 11 | @foreach (EnumValueDescription value in Model.Values) 12 | { 13 | 14 | 15 | 18 | 21 | 22 | } 23 | 24 |
NameValueDescription
@value.Name 16 |

@value.Value

17 |
19 |

@value.Documentation

20 |
-------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/HelpPageApiModel.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Description 3 | @using TheCodeCamp.Areas.HelpPage.Models 4 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 5 | @model HelpPageApiModel 6 | 7 | @{ 8 | ApiDescription description = Model.ApiDescription; 9 | } 10 |

@description.HttpMethod.Method @description.RelativePath

11 |
12 |

@description.Documentation

13 | 14 |

Request Information

15 | 16 |

URI Parameters

17 | @Html.DisplayFor(m => m.UriParameters, "Parameters") 18 | 19 |

Body Parameters

20 | 21 |

@Model.RequestDocumentation

22 | 23 | @if (Model.RequestModelDescription != null) 24 | { 25 | @Html.DisplayFor(m => m.RequestModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.RequestModelDescription }) 26 | if (Model.RequestBodyParameters != null) 27 | { 28 | @Html.DisplayFor(m => m.RequestBodyParameters, "Parameters") 29 | } 30 | } 31 | else 32 | { 33 |

None.

34 | } 35 | 36 | @if (Model.SampleRequests.Count > 0) 37 | { 38 |

Request Formats

39 | @Html.DisplayFor(m => m.SampleRequests, "Samples") 40 | } 41 | 42 |

Response Information

43 | 44 |

Resource Description

45 | 46 |

@description.ResponseDescription.Documentation

47 | 48 | @if (Model.ResourceDescription != null) 49 | { 50 | @Html.DisplayFor(m => m.ResourceDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ResourceDescription }) 51 | if (Model.ResourceProperties != null) 52 | { 53 | @Html.DisplayFor(m => m.ResourceProperties, "Parameters") 54 | } 55 | } 56 | else 57 | { 58 |

None.

59 | } 60 | 61 | @if (Model.SampleResponses.Count > 0) 62 | { 63 |

Response Formats

64 | @Html.DisplayFor(m => m.SampleResponses, "Samples") 65 | } 66 | 67 |
-------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/ImageSample.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage 2 | @model ImageSample 3 | 4 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/InvalidSample.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage 2 | @model InvalidSample 3 | 4 | @if (HttpContext.Current.IsDebuggingEnabled) 5 | { 6 |
7 |

@Model.ErrorMessage

8 |
9 | } 10 | else 11 | { 12 |

Sample not available.

13 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/KeyValuePairModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | @model KeyValuePairModelDescription 3 | Pair of @Html.DisplayFor(m => Model.KeyModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.KeyModelDescription }) [key] 4 | and @Html.DisplayFor(m => Model.ValueModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ValueModelDescription }) [value] -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/ModelDescriptionLink.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | @model Type 3 | @{ 4 | ModelDescription modelDescription = ViewBag.modelDescription; 5 | if (modelDescription is ComplexTypeModelDescription || modelDescription is EnumTypeModelDescription) 6 | { 7 | if (Model == typeof(Object)) 8 | { 9 | @:Object 10 | } 11 | else 12 | { 13 | @Html.ActionLink(modelDescription.Name, "ResourceModel", "Help", new { modelName = modelDescription.Name }, null) 14 | } 15 | } 16 | else if (modelDescription is CollectionModelDescription) 17 | { 18 | var collectionDescription = modelDescription as CollectionModelDescription; 19 | var elementDescription = collectionDescription.ElementDescription; 20 | @:Collection of @Html.DisplayFor(m => elementDescription.ModelType, "ModelDescriptionLink", new { modelDescription = elementDescription }) 21 | } 22 | else 23 | { 24 | @Html.DisplayFor(m => modelDescription) 25 | } 26 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/Parameters.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Collections.Generic 2 | @using System.Collections.ObjectModel 3 | @using System.Web.Http.Description 4 | @using System.Threading 5 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 6 | @model IList 7 | 8 | @if (Model.Count > 0) 9 | { 10 | 11 | 12 | 13 | 14 | 15 | @foreach (ParameterDescription parameter in Model) 16 | { 17 | ModelDescription modelDescription = parameter.TypeDescription; 18 | 19 | 20 | 23 | 26 | 39 | 40 | } 41 | 42 |
NameDescriptionTypeAdditional information
@parameter.Name 21 |

@parameter.Documentation

22 |
24 | @Html.DisplayFor(m => modelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = modelDescription }) 25 | 27 | @if (parameter.Annotations.Count > 0) 28 | { 29 | foreach (var annotation in parameter.Annotations) 30 | { 31 |

@annotation.Documentation

32 | } 33 | } 34 | else 35 | { 36 |

None.

37 | } 38 |
43 | } 44 | else 45 | { 46 |

None.

47 | } 48 | 49 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/Samples.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Net.Http.Headers 2 | @model Dictionary 3 | 4 | @{ 5 | // Group the samples into a single tab if they are the same. 6 | Dictionary samples = Model.GroupBy(pair => pair.Value).ToDictionary( 7 | pair => String.Join(", ", pair.Select(m => m.Key.ToString()).ToArray()), 8 | pair => pair.Key); 9 | var mediaTypes = samples.Keys; 10 | } 11 |
12 | @foreach (var mediaType in mediaTypes) 13 | { 14 |

@mediaType

15 |
16 | Sample: 17 | @{ 18 | var sample = samples[mediaType]; 19 | if (sample == null) 20 | { 21 |

Sample not available.

22 | } 23 | else 24 | { 25 | @Html.DisplayFor(s => sample); 26 | } 27 | } 28 |
29 | } 30 |
-------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/SimpleTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 2 | @model SimpleTypeModelDescription 3 | @Model.Documentation -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/DisplayTemplates/TextSample.cshtml: -------------------------------------------------------------------------------- 1 | @using TheCodeCamp.Areas.HelpPage 2 | @model TextSample 3 | 4 |
5 | @Model.Text
6 | 
-------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using System.Collections.ObjectModel 5 | @using TheCodeCamp.Areas.HelpPage.Models 6 | @model Collection 7 | 8 | @{ 9 | ViewBag.Title = "ASP.NET Web API Help Page"; 10 | 11 | // Group APIs by controller 12 | ILookup apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor); 13 | } 14 | 15 | 16 |
17 |
18 |
19 |

@ViewBag.Title

20 |
21 |
22 |
23 |
24 | 32 |
33 | @foreach (var group in apiGroups) 34 | { 35 | @Html.DisplayFor(m => group, "ApiGroup") 36 | } 37 |
38 |
39 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Help/ResourceModel.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using TheCodeCamp.Areas.HelpPage.ModelDescriptions 3 | @model ModelDescription 4 | 5 | 6 |
7 | 14 |

@Model.Name

15 |

@Model.Documentation

16 |
17 | @Html.DisplayFor(m => Model) 18 |
19 |
20 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewBag.Title 7 | @RenderSection("scripts", required: false) 8 | 9 | 10 | @RenderBody() 11 | 12 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | // Change the Layout path below to blend the look and feel of the help page with your existing web pages. 3 | Layout = "~/Areas/HelpPage/Views/Shared/_Layout.cshtml"; 4 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Areas/HelpPage/XmlDocumentationProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Web.Http.Controllers; 6 | using System.Web.Http.Description; 7 | using System.Xml.XPath; 8 | using TheCodeCamp.Areas.HelpPage.ModelDescriptions; 9 | 10 | namespace TheCodeCamp.Areas.HelpPage 11 | { 12 | /// 13 | /// A custom that reads the API documentation from an XML documentation file. 14 | /// 15 | public class XmlDocumentationProvider : IDocumentationProvider, IModelDocumentationProvider 16 | { 17 | private XPathNavigator _documentNavigator; 18 | private const string TypeExpression = "/doc/members/member[@name='T:{0}']"; 19 | private const string MethodExpression = "/doc/members/member[@name='M:{0}']"; 20 | private const string PropertyExpression = "/doc/members/member[@name='P:{0}']"; 21 | private const string FieldExpression = "/doc/members/member[@name='F:{0}']"; 22 | private const string ParameterExpression = "param[@name='{0}']"; 23 | 24 | /// 25 | /// Initializes a new instance of the class. 26 | /// 27 | /// The physical path to XML document. 28 | public XmlDocumentationProvider(string documentPath) 29 | { 30 | if (documentPath == null) 31 | { 32 | throw new ArgumentNullException("documentPath"); 33 | } 34 | XPathDocument xpath = new XPathDocument(documentPath); 35 | _documentNavigator = xpath.CreateNavigator(); 36 | } 37 | 38 | public string GetDocumentation(HttpControllerDescriptor controllerDescriptor) 39 | { 40 | XPathNavigator typeNode = GetTypeNode(controllerDescriptor.ControllerType); 41 | return GetTagValue(typeNode, "summary"); 42 | } 43 | 44 | public virtual string GetDocumentation(HttpActionDescriptor actionDescriptor) 45 | { 46 | XPathNavigator methodNode = GetMethodNode(actionDescriptor); 47 | return GetTagValue(methodNode, "summary"); 48 | } 49 | 50 | public virtual string GetDocumentation(HttpParameterDescriptor parameterDescriptor) 51 | { 52 | ReflectedHttpParameterDescriptor reflectedParameterDescriptor = parameterDescriptor as ReflectedHttpParameterDescriptor; 53 | if (reflectedParameterDescriptor != null) 54 | { 55 | XPathNavigator methodNode = GetMethodNode(reflectedParameterDescriptor.ActionDescriptor); 56 | if (methodNode != null) 57 | { 58 | string parameterName = reflectedParameterDescriptor.ParameterInfo.Name; 59 | XPathNavigator parameterNode = methodNode.SelectSingleNode(String.Format(CultureInfo.InvariantCulture, ParameterExpression, parameterName)); 60 | if (parameterNode != null) 61 | { 62 | return parameterNode.Value.Trim(); 63 | } 64 | } 65 | } 66 | 67 | return null; 68 | } 69 | 70 | public string GetResponseDocumentation(HttpActionDescriptor actionDescriptor) 71 | { 72 | XPathNavigator methodNode = GetMethodNode(actionDescriptor); 73 | return GetTagValue(methodNode, "returns"); 74 | } 75 | 76 | public string GetDocumentation(MemberInfo member) 77 | { 78 | string memberName = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", GetTypeName(member.DeclaringType), member.Name); 79 | string expression = member.MemberType == MemberTypes.Field ? FieldExpression : PropertyExpression; 80 | string selectExpression = String.Format(CultureInfo.InvariantCulture, expression, memberName); 81 | XPathNavigator propertyNode = _documentNavigator.SelectSingleNode(selectExpression); 82 | return GetTagValue(propertyNode, "summary"); 83 | } 84 | 85 | public string GetDocumentation(Type type) 86 | { 87 | XPathNavigator typeNode = GetTypeNode(type); 88 | return GetTagValue(typeNode, "summary"); 89 | } 90 | 91 | private XPathNavigator GetMethodNode(HttpActionDescriptor actionDescriptor) 92 | { 93 | ReflectedHttpActionDescriptor reflectedActionDescriptor = actionDescriptor as ReflectedHttpActionDescriptor; 94 | if (reflectedActionDescriptor != null) 95 | { 96 | string selectExpression = String.Format(CultureInfo.InvariantCulture, MethodExpression, GetMemberName(reflectedActionDescriptor.MethodInfo)); 97 | return _documentNavigator.SelectSingleNode(selectExpression); 98 | } 99 | 100 | return null; 101 | } 102 | 103 | private static string GetMemberName(MethodInfo method) 104 | { 105 | string name = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", GetTypeName(method.DeclaringType), method.Name); 106 | ParameterInfo[] parameters = method.GetParameters(); 107 | if (parameters.Length != 0) 108 | { 109 | string[] parameterTypeNames = parameters.Select(param => GetTypeName(param.ParameterType)).ToArray(); 110 | name += String.Format(CultureInfo.InvariantCulture, "({0})", String.Join(",", parameterTypeNames)); 111 | } 112 | 113 | return name; 114 | } 115 | 116 | private static string GetTagValue(XPathNavigator parentNode, string tagName) 117 | { 118 | if (parentNode != null) 119 | { 120 | XPathNavigator node = parentNode.SelectSingleNode(tagName); 121 | if (node != null) 122 | { 123 | return node.Value.Trim(); 124 | } 125 | } 126 | 127 | return null; 128 | } 129 | 130 | private XPathNavigator GetTypeNode(Type type) 131 | { 132 | string controllerTypeName = GetTypeName(type); 133 | string selectExpression = String.Format(CultureInfo.InvariantCulture, TypeExpression, controllerTypeName); 134 | return _documentNavigator.SelectSingleNode(selectExpression); 135 | } 136 | 137 | private static string GetTypeName(Type type) 138 | { 139 | string name = type.FullName; 140 | if (type.IsGenericType) 141 | { 142 | // Format the generic type name to something like: Generic{System.Int32,System.String} 143 | Type genericType = type.GetGenericTypeDefinition(); 144 | Type[] genericArguments = type.GetGenericArguments(); 145 | string genericTypeName = genericType.FullName; 146 | 147 | // Trim the generic parameter counts from the name 148 | genericTypeName = genericTypeName.Substring(0, genericTypeName.IndexOf('`')); 149 | string[] argumentTypeNames = genericArguments.Select(t => GetTypeName(t)).ToArray(); 150 | name = String.Format(CultureInfo.InvariantCulture, "{0}{{{1}}}", genericTypeName, String.Join(",", argumentTypeNames)); 151 | } 152 | if (type.IsNested) 153 | { 154 | // Changing the nested type name from OuterType+InnerType to OuterType.InnerType to match the XML documentation syntax. 155 | name = name.Replace("+", "."); 156 | } 157 | 158 | return name; 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Threading.Tasks; 7 | using System.Web.Http; 8 | using TheCodeCamp.Data; 9 | 10 | namespace TheCodeCamp.Controllers 11 | { 12 | public class ValuesController : ApiController 13 | { 14 | public string[] Get() 15 | { 16 | return new[] { "Hello", "From", "Pluralsight" }; 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/CampContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.Entity; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using TheCodeCamp.Migrations; 8 | 9 | namespace TheCodeCamp.Data 10 | { 11 | public class CampContext : DbContext 12 | { 13 | public CampContext() : base("CodeCampConnectionString") 14 | { 15 | Database.SetInitializer(new MigrateDatabaseToLatestVersion()); 16 | } 17 | 18 | public DbSet Camps { get; set; } 19 | public DbSet Speakers { get; set; } 20 | public DbSet Talks { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/CampRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Data.Entity; 7 | 8 | namespace TheCodeCamp.Data 9 | { 10 | public class CampRepository : ICampRepository 11 | { 12 | private readonly CampContext _context; 13 | 14 | public CampRepository(CampContext context) 15 | { 16 | _context = context; 17 | } 18 | 19 | public void AddCamp(Camp camp) 20 | { 21 | _context.Camps.Add(camp); 22 | } 23 | 24 | public void AddTalk(Talk talk) 25 | { 26 | _context.Talks.Add(talk); 27 | } 28 | 29 | public void AddSpeaker(Speaker speaker) 30 | { 31 | _context.Speakers.Add(speaker); 32 | } 33 | 34 | public void DeleteCamp(Camp camp) 35 | { 36 | _context.Camps.Remove(camp); 37 | } 38 | 39 | public void DeleteTalk(Talk talk) 40 | { 41 | _context.Talks.Remove(talk); 42 | } 43 | 44 | public void DeleteSpeaker(Speaker speaker) 45 | { 46 | _context.Speakers.Remove(speaker); 47 | } 48 | 49 | public async Task SaveChangesAsync() 50 | { 51 | // Only return success if at least one row was changed 52 | return (await _context.SaveChangesAsync()) > 0; 53 | } 54 | 55 | public async Task GetAllCampsByEventDate(DateTime dateTime, bool includeTalks = false) 56 | { 57 | IQueryable query = _context.Camps 58 | .Include(c => c.Location); 59 | 60 | if (includeTalks) 61 | { 62 | query = query 63 | .Include(c => c.Talks.Select(t => t.Speaker)); 64 | } 65 | 66 | // Order It 67 | query = query.OrderByDescending(c => c.EventDate) 68 | .Where(c => c.EventDate == dateTime); 69 | 70 | return await query.ToArrayAsync(); 71 | } 72 | 73 | public async Task GetAllCampsAsync(bool includeTalks = false) 74 | { 75 | IQueryable query = _context.Camps 76 | .Include(c => c.Location); 77 | 78 | if (includeTalks) 79 | { 80 | query = query 81 | .Include(c => c.Talks.Select(t => t.Speaker)); 82 | } 83 | 84 | // Order It 85 | query = query.OrderByDescending(c => c.EventDate); 86 | 87 | return await query.ToArrayAsync(); 88 | } 89 | 90 | public async Task GetCampAsync(string moniker, bool includeTalks = false) 91 | { 92 | IQueryable query = _context.Camps 93 | .Include(c => c.Location); 94 | 95 | if (includeTalks) 96 | { 97 | query = query.Include(c => c.Talks.Select(t => t.Speaker)); 98 | } 99 | 100 | // Query It 101 | query = query.Where(c => c.Moniker == moniker); 102 | 103 | return await query.FirstOrDefaultAsync(); 104 | } 105 | 106 | public async Task GetTalksByMonikerAsync(string moniker, bool includeSpeakers = false) 107 | { 108 | IQueryable query = _context.Talks; 109 | 110 | if (includeSpeakers) 111 | { 112 | query = query 113 | .Include(t => t.Speaker); 114 | } 115 | 116 | // Add Query 117 | query = query 118 | .Where(t => t.Camp.Moniker == moniker) 119 | .OrderByDescending(t => t.Title); 120 | 121 | return await query.ToArrayAsync(); 122 | } 123 | 124 | public async Task GetTalkByMonikerAsync(string moniker, int talkId, bool includeSpeakers = false) 125 | { 126 | IQueryable query = _context.Talks; 127 | 128 | if (includeSpeakers) 129 | { 130 | query = query 131 | .Include(t => t.Speaker); 132 | } 133 | 134 | // Add Query 135 | query = query 136 | .Where(t => t.TalkId == talkId && t.Camp.Moniker == moniker); 137 | 138 | return await query.FirstOrDefaultAsync(); 139 | } 140 | 141 | public async Task GetSpeakersByMonikerAsync(string moniker) 142 | { 143 | IQueryable query = _context.Talks 144 | .Where(t => t.Camp.Moniker == moniker) 145 | .Select(t => t.Speaker) 146 | .Where(s => s != null) 147 | .OrderBy(s => s.LastName) 148 | .Distinct(); 149 | 150 | return await query.ToArrayAsync(); 151 | } 152 | 153 | public async Task GetAllSpeakersAsync() 154 | { 155 | var query = _context.Speakers 156 | .OrderBy(t => t.LastName); 157 | 158 | return await query.ToArrayAsync(); 159 | } 160 | 161 | 162 | public async Task GetSpeakerAsync(int speakerId) 163 | { 164 | var query = _context.Speakers 165 | .Where(t => t.SpeakerId == speakerId); 166 | 167 | return await query.FirstOrDefaultAsync(); 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Entities/Camp.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace TheCodeCamp.Data 6 | { 7 | public class Camp 8 | { 9 | public int CampId { get; set; } 10 | public string Name { get; set; } 11 | public string Moniker { get; set; } 12 | public Location Location { get; set; } 13 | public DateTime EventDate { get; set; } = DateTime.MinValue; 14 | public int Length { get; set; } = 1; 15 | public ICollection Talks { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Entities/Location.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Data 2 | { 3 | public class Location 4 | { 5 | public int LocationId { get; set; } 6 | public string VenueName { get; set; } 7 | public string Address1 { get; set; } 8 | public string Address2 { get; set; } 9 | public string Address3 { get; set; } 10 | public string CityTown { get; set; } 11 | public string StateProvince { get; set; } 12 | public string PostalCode { get; set; } 13 | public string Country { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Entities/Speaker.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Data 2 | { 3 | public class Speaker 4 | { 5 | public int SpeakerId { get; set; } 6 | public string FirstName { get; set; } 7 | public string LastName { get; set; } 8 | public string MiddleName { get; set; } 9 | public string Company { get; set; } 10 | public string CompanyUrl { get; set; } 11 | public string BlogUrl { get; set; } 12 | public string Twitter { get; set; } 13 | public string GitHub { get; set; } 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Entities/Talk.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Data 2 | { 3 | public class Talk 4 | { 5 | public int TalkId { get; set; } 6 | public Camp Camp { get; set; } 7 | public string Title { get; set; } 8 | public string Abstract { get; set; } 9 | public int Level { get; set; } 10 | public Speaker Speaker { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/ICampRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | 5 | namespace TheCodeCamp.Data 6 | { 7 | public interface ICampRepository 8 | { 9 | // General 10 | Task SaveChangesAsync(); 11 | 12 | // Camps 13 | void AddCamp(Camp camp); 14 | void DeleteCamp(Camp camp); 15 | Task GetAllCampsAsync(bool includeTalks = false); 16 | Task GetCampAsync(string moniker, bool includeTalks = false); 17 | Task GetAllCampsByEventDate(DateTime dateTime, bool includeTalks = false); 18 | 19 | // Talks 20 | void AddTalk(Talk talk); 21 | void DeleteTalk(Talk talk); 22 | Task GetTalkByMonikerAsync(string moniker, int talkId, bool includeSpeakers = false); 23 | Task GetTalksByMonikerAsync(string moniker, bool includeSpeakers = false); 24 | 25 | // Speakers 26 | void AddSpeaker(Speaker speaker); 27 | void DeleteSpeaker(Speaker speaker); 28 | Task GetSpeakersByMonikerAsync(string moniker); 29 | Task GetSpeakerAsync(int speakerId); 30 | Task GetAllSpeakersAsync(); 31 | 32 | } 33 | } -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Migrations/201901030609030_InitialCreate.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Migrations 2 | { 3 | using System; 4 | using System.Data.Entity.Migrations; 5 | 6 | public partial class InitialCreate : DbMigration 7 | { 8 | public override void Up() 9 | { 10 | CreateTable( 11 | "dbo.Camps", 12 | c => new 13 | { 14 | CampId = c.Int(nullable: false, identity: true), 15 | Name = c.String(), 16 | Moniker = c.String(), 17 | EventDate = c.DateTime(nullable: false), 18 | Length = c.Int(nullable: false), 19 | Location_LocationId = c.Int(), 20 | }) 21 | .PrimaryKey(t => t.CampId) 22 | .ForeignKey("dbo.Locations", t => t.Location_LocationId) 23 | .Index(t => t.Location_LocationId); 24 | 25 | CreateTable( 26 | "dbo.Locations", 27 | c => new 28 | { 29 | LocationId = c.Int(nullable: false, identity: true), 30 | VenueName = c.String(), 31 | Address1 = c.String(), 32 | Address2 = c.String(), 33 | Address3 = c.String(), 34 | CityTown = c.String(), 35 | StateProvince = c.String(), 36 | PostalCode = c.String(), 37 | Country = c.String(), 38 | }) 39 | .PrimaryKey(t => t.LocationId); 40 | 41 | CreateTable( 42 | "dbo.Talks", 43 | c => new 44 | { 45 | TalkId = c.Int(nullable: false, identity: true), 46 | Title = c.String(), 47 | Abstract = c.String(), 48 | Level = c.Int(nullable: false), 49 | Camp_CampId = c.Int(), 50 | Speaker_SpeakerId = c.Int(), 51 | }) 52 | .PrimaryKey(t => t.TalkId) 53 | .ForeignKey("dbo.Camps", t => t.Camp_CampId) 54 | .ForeignKey("dbo.Speakers", t => t.Speaker_SpeakerId) 55 | .Index(t => t.Camp_CampId) 56 | .Index(t => t.Speaker_SpeakerId); 57 | 58 | CreateTable( 59 | "dbo.Speakers", 60 | c => new 61 | { 62 | SpeakerId = c.Int(nullable: false, identity: true), 63 | FirstName = c.String(), 64 | LastName = c.String(), 65 | MiddleName = c.String(), 66 | Company = c.String(), 67 | CompanyUrl = c.String(), 68 | BlogUrl = c.String(), 69 | Twitter = c.String(), 70 | GitHub = c.String(), 71 | }) 72 | .PrimaryKey(t => t.SpeakerId); 73 | 74 | } 75 | 76 | public override void Down() 77 | { 78 | DropForeignKey("dbo.Talks", "Speaker_SpeakerId", "dbo.Speakers"); 79 | DropForeignKey("dbo.Talks", "Camp_CampId", "dbo.Camps"); 80 | DropForeignKey("dbo.Camps", "Location_LocationId", "dbo.Locations"); 81 | DropIndex("dbo.Talks", new[] { "Speaker_SpeakerId" }); 82 | DropIndex("dbo.Talks", new[] { "Camp_CampId" }); 83 | DropIndex("dbo.Camps", new[] { "Location_LocationId" }); 84 | DropTable("dbo.Speakers"); 85 | DropTable("dbo.Talks"); 86 | DropTable("dbo.Locations"); 87 | DropTable("dbo.Camps"); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Migrations/201901030609030_InitialCreate.designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | namespace TheCodeCamp.Migrations 3 | { 4 | using System.CodeDom.Compiler; 5 | using System.Data.Entity.Migrations; 6 | using System.Data.Entity.Migrations.Infrastructure; 7 | using System.Resources; 8 | 9 | [GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")] 10 | public sealed partial class InitialCreate : IMigrationMetadata 11 | { 12 | private readonly ResourceManager Resources = new ResourceManager(typeof(InitialCreate)); 13 | 14 | string IMigrationMetadata.Id 15 | { 16 | get { return "201901030609030_InitialCreate"; } 17 | } 18 | 19 | string IMigrationMetadata.Source 20 | { 21 | get { return null; } 22 | } 23 | 24 | string IMigrationMetadata.Target 25 | { 26 | get { return Resources.GetString("Target"); } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Migrations/201901030609030_InitialCreate.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 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 122 | 123 | 124 | dbo 125 | 126 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Migrations/201901030630577_Initial.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Migrations 2 | { 3 | using System; 4 | using System.Data.Entity.Migrations; 5 | 6 | public partial class Initial : DbMigration 7 | { 8 | public override void Up() 9 | { 10 | } 11 | 12 | public override void Down() 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Migrations/201901030630577_Initial.designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | namespace TheCodeCamp.Migrations 3 | { 4 | using System.CodeDom.Compiler; 5 | using System.Data.Entity.Migrations; 6 | using System.Data.Entity.Migrations.Infrastructure; 7 | using System.Resources; 8 | 9 | [GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")] 10 | public sealed partial class Initial : IMigrationMetadata 11 | { 12 | private readonly ResourceManager Resources = new ResourceManager(typeof(Initial)); 13 | 14 | string IMigrationMetadata.Id 15 | { 16 | get { return "201901030630577_Initial"; } 17 | } 18 | 19 | string IMigrationMetadata.Source 20 | { 21 | get { return null; } 22 | } 23 | 24 | string IMigrationMetadata.Target 25 | { 26 | get { return Resources.GetString("Target"); } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Migrations/201901030630577_Initial.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 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 122 | 123 | 124 | dbo 125 | 126 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Data/Migrations/Configuration.cs: -------------------------------------------------------------------------------- 1 | namespace TheCodeCamp.Migrations 2 | { 3 | using System; 4 | using System.Data.Entity; 5 | using System.Data.Entity.Migrations; 6 | using System.Linq; 7 | using TheCodeCamp.Data; 8 | 9 | internal sealed class Configuration : DbMigrationsConfiguration 10 | { 11 | public Configuration() 12 | { 13 | AutomaticMigrationsEnabled = true; 14 | ContextKey = "TheCodeCamp.Data.CampContext"; 15 | } 16 | 17 | protected override void Seed(CampContext ctx) 18 | { 19 | if (!ctx.Camps.Any()) 20 | { 21 | ctx.Camps.AddOrUpdate(x => x.CampId, 22 | new Camp() 23 | { 24 | CampId = 1, 25 | Moniker = "ATL2018", 26 | Name = "Atlanta Code Camp", 27 | EventDate = new DateTime(2018, 10, 18), 28 | Location = new Location() 29 | { 30 | VenueName = "Atlanta Convention Center", 31 | Address1 = "123 Main Street", 32 | CityTown = "Atlanta", 33 | StateProvince = "GA", 34 | PostalCode = "12345", 35 | Country = "USA" 36 | }, 37 | Length = 1, 38 | Talks = new Talk[] 39 | { 40 | new Talk 41 | { 42 | TalkId = 1, 43 | Title = "Entity Framework From Scratch", 44 | Abstract = "Entity Framework from scratch in an hour. Probably cover it all", 45 | Level = 100, 46 | Speaker = new Speaker 47 | { 48 | SpeakerId = 1, 49 | FirstName = "Shawn", 50 | LastName = "Wildermuth", 51 | BlogUrl = "http://wildermuth.com", 52 | Company = "Wilder Minds LLC", 53 | CompanyUrl = "http://wilderminds.com", 54 | GitHub = "shawnwildermuth", 55 | Twitter = "shawnwildermuth" 56 | } 57 | }, 58 | new Talk 59 | { 60 | TalkId = 2, 61 | Title = "Writing Sample Data Made Easy", 62 | Abstract = "Thinking of good sample data examples is tiring.", 63 | Level = 200, 64 | Speaker = new Speaker 65 | { 66 | SpeakerId = 2, 67 | FirstName = "Resa", 68 | LastName = "Wildermuth", 69 | BlogUrl = "http://shawnandresa.com", 70 | Company = "Wilder Minds LLC", 71 | CompanyUrl = "http://wilderminds.com", 72 | GitHub = "resawildermuth", 73 | Twitter = "resawildermuth" 74 | } 75 | } 76 | } 77 | }); 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="TheCodeCamp.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Web; 6 | using System.Web.Http; 7 | using System.Web.Mvc; 8 | using System.Web.Optimization; 9 | using System.Web.Routing; 10 | using Autofac; 11 | using Autofac.Integration.WebApi; 12 | 13 | namespace TheCodeCamp 14 | { 15 | public class WebApiApplication : System.Web.HttpApplication 16 | { 17 | protected void Application_Start() 18 | { 19 | AreaRegistration.RegisterAllAreas(); 20 | GlobalConfiguration.Configure(WebApiConfig.Register); 21 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 22 | RouteConfig.RegisterRoutes(RouteTable.Routes); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 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("TheCodeCamp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TheCodeCamp")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 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("371175cf-ea56-4b29-a9c0-5033ff0b5abe")] 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 Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/TheCodeCamp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | 9 | 10 | 2.0 11 | {715EEC2D-FFB8-46AF-B845-2367732818CB} 12 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 13 | Library 14 | Properties 15 | TheCodeCamp 16 | TheCodeCamp 17 | v4.6.1 18 | false 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | true 31 | full 32 | false 33 | bin\ 34 | DEBUG;TRACE 35 | prompt 36 | 4 37 | 38 | 39 | true 40 | pdbonly 41 | true 42 | bin\ 43 | TRACE 44 | prompt 45 | 4 46 | 47 | 48 | 49 | ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll 50 | 51 | 52 | ..\packages\Autofac.WebApi2.4.2.0\lib\net45\Autofac.Integration.WebApi.dll 53 | 54 | 55 | ..\packages\CommonServiceLocator.2.0.4\lib\net46\CommonServiceLocator.dll 56 | 57 | 58 | ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll 59 | 60 | 61 | ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll 62 | 63 | 64 | ..\packages\Microsoft.AspNet.TelemetryCorrelation.1.0.5\lib\net45\Microsoft.AspNet.TelemetryCorrelation.dll 65 | 66 | 67 | ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll 68 | 69 | 70 | 71 | ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll 72 | 73 | 74 | 75 | 76 | ..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll 77 | 78 | 79 | 80 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll 89 | 90 | 91 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll 92 | 93 | 94 | ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll 95 | 96 | 97 | ..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll 98 | 99 | 100 | ..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll 101 | 102 | 103 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll 104 | 105 | 106 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll 107 | 108 | 109 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | True 120 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 121 | 122 | 123 | 124 | 125 | 126 | 127 | ..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll 128 | 129 | 130 | ..\packages\WebActivatorEx.2.2.0\lib\net40\WebActivatorEx.dll 131 | 132 | 133 | True 134 | ..\packages\WebGrease.1.6.0\lib\WebGrease.dll 135 | 136 | 137 | True 138 | ..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 201901030609030_InitialCreate.cs 185 | 186 | 187 | 188 | 201901030630577_Initial.cs 189 | 190 | 191 | Global.asax 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | Web.config 203 | 204 | 205 | Web.config 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 201901030609030_InitialCreate.cs 237 | 238 | 239 | 201901030630577_Initial.cs 240 | 241 | 242 | 243 | 10.0 244 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | True 257 | True 258 | 50452 259 | / 260 | http://localhost:6600/ 261 | False 262 | False 263 | 264 | 265 | False 266 | 267 | 268 | 269 | 270 | 271 | 272 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 273 | 274 | 275 | 276 | 282 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /starting/TheCodeCamp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psauthor/WebApiFundamentals/f780b97ccadc9a5ebc04abdf9f6777f7eb9e134e/starting/TheCodeCamp/favicon.ico -------------------------------------------------------------------------------- /starting/TheCodeCamp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | --------------------------------------------------------------------------------