diff --git a/MP-IO/MP-IO.csproj b/MP-IO/MP-IO.csproj index d9ae70b8..8e982d9c 100644 --- a/MP-IO/MP-IO.csproj +++ b/MP-IO/MP-IO.csproj @@ -141,8 +141,8 @@ ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.8\lib\net45\System.Net.Http.Formatting.dll @@ -194,11 +194,11 @@ ..\packages\Microsoft.AspNet.WebPages.3.2.8\lib\net45\System.Web.Helpers.dll - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.8\lib\net45\System.Web.Http.dll - - ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.8\lib\net45\System.Web.Http.WebHost.dll ..\packages\Microsoft.AspNet.Mvc.5.2.8\lib\net45\System.Web.Mvc.dll diff --git a/MP-IO/Web.config b/MP-IO/Web.config index f3101701..c1cfaf30 100644 --- a/MP-IO/Web.config +++ b/MP-IO/Web.config @@ -360,13 +360,13 @@ - + + - - + diff --git a/MP-IO/packages.config b/MP-IO/packages.config index a3916368..8c7544af 100644 --- a/MP-IO/packages.config +++ b/MP-IO/packages.config @@ -14,13 +14,13 @@ - - - - - - - + + + + + + + diff --git a/MP-MAG/Areas/HelpPage/SampleGeneration/HelpPageSampleGenerator.cs b/MP-MAG/Areas/HelpPage/SampleGeneration/HelpPageSampleGenerator.cs index 71aa8e80..64b655d1 100644 --- a/MP-MAG/Areas/HelpPage/SampleGeneration/HelpPageSampleGenerator.cs +++ b/MP-MAG/Areas/HelpPage/SampleGeneration/HelpPageSampleGenerator.cs @@ -20,8 +20,6 @@ namespace MP_MAG.Areas.HelpPage /// public class HelpPageSampleGenerator { - #region Public Constructors - /// /// Initializes a new instance of the class. /// @@ -36,9 +34,10 @@ namespace MP_MAG.Areas.HelpPage }; } - #endregion Public Constructors - - #region Public Properties + /// + /// Gets CLR types that are used as the content of or . + /// + public IDictionary ActualHttpMessageTypes { get; internal set; } /// /// Gets the objects that are used directly as samples for certain actions. @@ -46,9 +45,9 @@ namespace MP_MAG.Areas.HelpPage public IDictionary ActionSamples { get; internal set; } /// - /// Gets CLR types that are used as the content of or . + /// Gets the objects that are serialized as samples by the supported formatters. /// - public IDictionary ActualHttpMessageTypes { get; internal set; } + public IDictionary SampleObjects { get; internal set; } /// /// Gets factories for the objects that the supported formatters will serialize as samples. Processed in order, @@ -63,138 +62,23 @@ namespace MP_MAG.Areas.HelpPage public IList> SampleObjectFactories { get; private set; } /// - /// Gets the objects that are serialized as samples by the supported formatters. + /// Gets the request body samples for a given . /// - public IDictionary SampleObjects { get; internal set; } - - #endregion Public Properties - - #region Private Methods - - // Default factory for sample objects - private static object DefaultSampleObjectFactory(HelpPageSampleGenerator sampleGenerator, Type type) + /// The . + /// The samples keyed by media type. + public IDictionary GetSampleRequests(ApiDescription api) { - // Try to create a default sample object - ObjectGenerator objectGenerator = new ObjectGenerator(); - return objectGenerator.GenerateObject(type); + return GetSample(api, SampleDirection.Request); } - private static bool IsFormatSupported(SampleDirection sampleDirection, MediaTypeFormatter formatter, Type type) - { - switch (sampleDirection) - { - case SampleDirection.Request: - return formatter.CanReadType(type); - - case SampleDirection.Response: - return formatter.CanWriteType(type); - } - return false; - } - - [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Handling the failure by returning the original string.")] - private static string TryFormatJson(string str) - { - try - { - object parsedJson = JsonConvert.DeserializeObject(str); - return JsonConvert.SerializeObject(parsedJson, Formatting.Indented); - } - catch - { - // can't parse JSON, return the original string - return str; - } - } - - [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Handling the failure by returning the original string.")] - private static string TryFormatXml(string str) - { - try - { - XDocument xml = XDocument.Parse(str); - return xml.ToString(); - } - catch - { - // can't parse XML, return the original string - return str; - } - } - - private static object WrapSampleIfString(object sample) - { - string stringSample = sample as string; - if (stringSample != null) - { - return new TextSample(stringSample); - } - - return sample; - } - - private IEnumerable> GetAllActionSamples(string controllerName, string actionName, IEnumerable parameterNames, SampleDirection sampleDirection) - { - HashSet parameterNamesSet = new HashSet(parameterNames, StringComparer.OrdinalIgnoreCase); - foreach (var sample in ActionSamples) - { - HelpPageSampleKey sampleKey = sample.Key; - if (String.Equals(controllerName, sampleKey.ControllerName, StringComparison.OrdinalIgnoreCase) && - String.Equals(actionName, sampleKey.ActionName, StringComparison.OrdinalIgnoreCase) && - (sampleKey.ParameterNames.SetEquals(new[] { "*" }) || parameterNamesSet.SetEquals(sampleKey.ParameterNames)) && - sampleDirection == sampleKey.SampleDirection) - { - yield return sample; - } - } - } - - #endregion Private Methods - - #region Internal Methods - - internal static Exception UnwrapException(Exception exception) - { - AggregateException aggregateException = exception as AggregateException; - if (aggregateException != null) - { - return aggregateException.Flatten().InnerException; - } - return exception; - } - - #endregion Internal Methods - - #region Public Methods - /// - /// Search for samples that are provided directly through . + /// Gets the response body samples for a given . /// - /// Name of the controller. - /// Name of the action. - /// The parameter names. - /// The CLR type. - /// The formatter. - /// The media type. - /// The value indicating whether the sample is for a request or for a response. - /// The sample that matches the parameters. - public virtual object GetActionSample(string controllerName, string actionName, IEnumerable parameterNames, Type type, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType, SampleDirection sampleDirection) + /// The . + /// The samples keyed by media type. + public IDictionary GetSampleResponses(ApiDescription api) { - object sample; - - // First, try to get the sample provided for the specified mediaType, sampleDirection, controllerName, actionName and parameterNames. - // If not found, try to get the sample provided for the specified mediaType, sampleDirection, controllerName and actionName regardless of the parameterNames. - // If still not found, try to get the sample provided for the specified mediaType and type. - // Finally, try to get the sample provided for the specified mediaType. - if (ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, sampleDirection, controllerName, actionName, parameterNames), out sample) || - ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, sampleDirection, controllerName, actionName, new[] { "*" }), out sample) || - ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, type), out sample) || - ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType), out sample)) - { - return sample; - } - - return null; + return GetSample(api, SampleDirection.Response); } /// @@ -252,7 +136,37 @@ namespace MP_MAG.Areas.HelpPage } /// - /// Gets the sample object that will be serialized by the formatters. + /// Search for samples that are provided directly through . + /// + /// Name of the controller. + /// Name of the action. + /// The parameter names. + /// The CLR type. + /// The formatter. + /// The media type. + /// The value indicating whether the sample is for a request or for a response. + /// The sample that matches the parameters. + public virtual object GetActionSample(string controllerName, string actionName, IEnumerable parameterNames, Type type, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType, SampleDirection sampleDirection) + { + object sample; + + // First, try to get the sample provided for the specified mediaType, sampleDirection, controllerName, actionName and parameterNames. + // If not found, try to get the sample provided for the specified mediaType, sampleDirection, controllerName and actionName regardless of the parameterNames. + // If still not found, try to get the sample provided for the specified mediaType and type. + // Finally, try to get the sample provided for the specified mediaType. + if (ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, sampleDirection, controllerName, actionName, parameterNames), out sample) || + ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, sampleDirection, controllerName, actionName, new[] { "*" }), out sample) || + ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, type), out sample) || + ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType), out sample)) + { + return sample; + } + + return null; + } + + /// + /// Gets the sample object that will be serialized by the formatters. /// First, it will look at the . If no sample object is found, it will try to create /// one using (which wraps an ) and other /// factories in . @@ -293,26 +207,6 @@ namespace MP_MAG.Areas.HelpPage return sampleObject; } - /// - /// Gets the request body samples for a given . - /// - /// The . - /// The samples keyed by media type. - public IDictionary GetSampleRequests(ApiDescription api) - { - return GetSample(api, SampleDirection.Request); - } - - /// - /// Gets the response body samples for a given . - /// - /// The . - /// The samples keyed by media type. - public IDictionary GetSampleResponses(ApiDescription api) - { - return GetSample(api, SampleDirection.Response); - } - /// /// Resolves the actual type of passed to the in an action. /// @@ -371,7 +265,6 @@ namespace MP_MAG.Areas.HelpPage type = requestBodyParameter == null ? null : requestBodyParameter.ParameterDescriptor.ParameterType; formatters = api.SupportedRequestBodyFormatters; break; - case SampleDirection.Response: default: type = api.ResponseDescription.ResponseType ?? api.ResponseDescription.DeclaredType; @@ -426,7 +319,6 @@ namespace MP_MAG.Areas.HelpPage } sample = new TextSample(serializedSampleString); - reader.Dispose(); } else { @@ -462,6 +354,91 @@ namespace MP_MAG.Areas.HelpPage return sample; } - #endregion Public Methods + internal static Exception UnwrapException(Exception exception) + { + AggregateException aggregateException = exception as AggregateException; + if (aggregateException != null) + { + return aggregateException.Flatten().InnerException; + } + return exception; + } + + // Default factory for sample objects + private static object DefaultSampleObjectFactory(HelpPageSampleGenerator sampleGenerator, Type type) + { + // Try to create a default sample object + ObjectGenerator objectGenerator = new ObjectGenerator(); + return objectGenerator.GenerateObject(type); + } + + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Handling the failure by returning the original string.")] + private static string TryFormatJson(string str) + { + try + { + object parsedJson = JsonConvert.DeserializeObject(str); + return JsonConvert.SerializeObject(parsedJson, Formatting.Indented); + } + catch + { + // can't parse JSON, return the original string + return str; + } + } + + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Handling the failure by returning the original string.")] + private static string TryFormatXml(string str) + { + try + { + XDocument xml = XDocument.Parse(str); + return xml.ToString(); + } + catch + { + // can't parse XML, return the original string + return str; + } + } + + private static bool IsFormatSupported(SampleDirection sampleDirection, MediaTypeFormatter formatter, Type type) + { + switch (sampleDirection) + { + case SampleDirection.Request: + return formatter.CanReadType(type); + case SampleDirection.Response: + return formatter.CanWriteType(type); + } + return false; + } + + private IEnumerable> GetAllActionSamples(string controllerName, string actionName, IEnumerable parameterNames, SampleDirection sampleDirection) + { + HashSet parameterNamesSet = new HashSet(parameterNames, StringComparer.OrdinalIgnoreCase); + foreach (var sample in ActionSamples) + { + HelpPageSampleKey sampleKey = sample.Key; + if (String.Equals(controllerName, sampleKey.ControllerName, StringComparison.OrdinalIgnoreCase) && + String.Equals(actionName, sampleKey.ActionName, StringComparison.OrdinalIgnoreCase) && + (sampleKey.ParameterNames.SetEquals(new[] { "*" }) || parameterNamesSet.SetEquals(sampleKey.ParameterNames)) && + sampleDirection == sampleKey.SampleDirection) + { + yield return sample; + } + } + } + + private static object WrapSampleIfString(object sample) + { + string stringSample = sample as string; + if (stringSample != null) + { + return new TextSample(stringSample); + } + + return sample; + } } } \ No newline at end of file diff --git a/MP-MAG/Areas/HelpPage/Views/Help/Index.cshtml b/MP-MAG/Areas/HelpPage/Views/Help/Index.cshtml index 583f0f3e..ba100d04 100644 --- a/MP-MAG/Areas/HelpPage/Views/Help/Index.cshtml +++ b/MP-MAG/Areas/HelpPage/Views/Help/Index.cshtml @@ -6,41 +6,33 @@ @model Collection @{ - ViewBag.Title = "ASP.NET Web API Help Page"; + ViewBag.Title = "ASP.NET Web API Help Page"; - // Group APIs by controller - ILookup apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor); + // Group APIs by controller + ILookup apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor); } -
-
-
-
+
+
-

@ViewBag.Title

+

@ViewBag.Title

-
-
-
-
-
-
-
-
+ +
+ -
+
+
@foreach (var group in apiGroups) { - @Html.DisplayFor(m => group, "ApiGroup") + @Html.DisplayFor(m => group, "ApiGroup") } -
-
-
-
\ No newline at end of file + +
diff --git a/MP-MAG/Areas/HelpPage/Views/Web.config b/MP-MAG/Areas/HelpPage/Views/Web.config index e94f4d66..6d4ddaf1 100644 --- a/MP-MAG/Areas/HelpPage/Views/Web.config +++ b/MP-MAG/Areas/HelpPage/Views/Web.config @@ -1,41 +1,41 @@  - - -
-
- - + + +
+
+ + - - - - - - - - - - - + + + + + + + + + + + - - - + + + - - - - - - - + + + + + + + - - - - - - - \ No newline at end of file + + + + + + + diff --git a/MP-MAG/Areas/HelpPage/Views/_ViewStart.cshtml b/MP-MAG/Areas/HelpPage/Views/_ViewStart.cshtml index d735b1cb..a9259508 100644 --- a/MP-MAG/Areas/HelpPage/Views/_ViewStart.cshtml +++ b/MP-MAG/Areas/HelpPage/Views/_ViewStart.cshtml @@ -1,4 +1,4 @@ -@{ - // Change the Layout path below to blend the look and feel of the help page with your existing web pages - Layout = "~/Views/Shared/_Layout.cshtml"; +@{ + // Change the Layout path below to blend the look and feel of the help page with your existing web pages. + Layout = "~/Areas/HelpPage/Views/Shared/_Layout.cshtml"; } \ No newline at end of file diff --git a/MP-MAG/MP-MAG.csproj b/MP-MAG/MP-MAG.csproj index 16ccabea..c9f7f691 100644 --- a/MP-MAG/MP-MAG.csproj +++ b/MP-MAG/MP-MAG.csproj @@ -159,6 +159,9 @@ ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.8\lib\net45\System.Net.Http.Formatting.dll + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll @@ -207,6 +210,12 @@ ..\packages\Microsoft.AspNet.WebPages.3.2.8\lib\net45\System.Web.Helpers.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.8\lib\net45\System.Web.Http.dll + + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.8\lib\net45\System.Web.Http.WebHost.dll + ..\packages\Microsoft.AspNet.Mvc.5.2.8\lib\net45\System.Web.Mvc.dll @@ -234,17 +243,8 @@ True ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll - - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll - - - ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll - ..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll @@ -795,24 +795,7 @@ - - - - - - - - - - - - - - - - - Always @@ -882,6 +865,23 @@ + + + + + + + + + + + + + + + + + diff --git a/MP-MAG/Web.config b/MP-MAG/Web.config index fcc410bd..e3522293 100644 --- a/MP-MAG/Web.config +++ b/MP-MAG/Web.config @@ -92,12 +92,7 @@ - - - - - - + @@ -106,7 +101,12 @@ - + + + + + + diff --git a/MP-MAG/packages.config b/MP-MAG/packages.config index 8de07630..6d2a5cc4 100644 --- a/MP-MAG/packages.config +++ b/MP-MAG/packages.config @@ -24,14 +24,14 @@ - - - - - - - - + + + + + + + +