diff --git a/.gitignore b/.gitignore index e75bc5e..7e73f9e 100644 --- a/.gitignore +++ b/.gitignore @@ -215,3 +215,5 @@ pip-log.txt #Mr Developer .mr.developer.cfg + +.idea diff --git a/samples/WebApiConsole/Controllers/FooController.cs b/samples/WebApiConsole/Controllers/FooController.cs index a790c91..d31e7c0 100644 --- a/samples/WebApiConsole/Controllers/FooController.cs +++ b/samples/WebApiConsole/Controllers/FooController.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using System.Web.Http; +using System.Net.Http; +using Microsoft.AspNetCore.Mvc; namespace WebApiConsole.Controllers { - public class FooController : ApiController + public class FooController : Controller { - [EntryPointRelation("http://example.org/rels/foo")] public HttpResponseMessage Get(int id) { @@ -21,12 +15,11 @@ public HttpResponseMessage Get(int id) public HttpResponseMessage Post(int id) { return null; - } + } } - public class BarController : ApiController + public class BarController : Controller { - [EntryPointRelation("http://example.org/rels/bar")] public HttpResponseMessage Get(HttpRequestMessage request) { @@ -38,4 +31,4 @@ public HttpResponseMessage Get(HttpRequestMessage request) // return null; //} } -} +} \ No newline at end of file diff --git a/samples/WebApiConsole/Controllers/HomeController.cs b/samples/WebApiConsole/Controllers/HomeController.cs index 22d0b16..3f69c2f 100644 --- a/samples/WebApiConsole/Controllers/HomeController.cs +++ b/samples/WebApiConsole/Controllers/HomeController.cs @@ -1,33 +1,27 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net.Http; -using System.Net.Http.Headers; -using System.Reflection; -using System.Text; using System.Threading.Tasks; -using System.Web.Http; -using System.Web.Http.Description; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ApiExplorer; using Tavis; using Tavis.Home; using Tavis.IANA; namespace WebApiConsole.Controllers { - public class HomeController : ApiController + public class HomeController : Controller { - - public HttpResponseMessage Get(HttpRequestMessage requestMessage) + public async Task Index() { var homeDocument = new HomeDocument(); var fooLink = new Link() - { - Relation = "http://example.org/rels/foo", - Target = new Uri("foo", UriKind.Relative) - }; + { + Relation = "http://example.org/rels/foo", + Target = new Uri("foo", UriKind.Relative) + }; var allowHint = new AllowHint(); allowHint.AddMethod(HttpMethod.Get); allowHint.AddMethod(HttpMethod.Post); @@ -51,28 +45,26 @@ public HttpResponseMessage Get(HttpRequestMessage requestMessage) Relation = "http://example.org/rels/bar2", Target = new Uri("bar/{id}", UriKind.Relative) }; - // bar2Link.SetParameter("id","",new Uri("template/params/id", UriKind.Relative)); + // bar2Link.SetParameter("id","",new Uri("template/params/id", UriKind.Relative)); homeDocument.AddResource(bar2Link); var ms = new MemoryStream(); homeDocument.Save(ms); ms.Position = 0; - var streamContent = new StreamContent(ms); - return new HttpResponseMessage() - { - Content = streamContent - }; + + + await ms.CopyToAsync(this.Response.Body); } //public HttpResponseMessage Get2(HttpRequestMessage requestMessage) //{ - + // var homeDocument = new HomeDocument(); - + // IApiExplorer apiExplorer = Configuration.Services.GetApiExplorer(); // var resources = from ad in apiExplorer.ApiDescriptions @@ -85,7 +77,7 @@ public HttpResponseMessage Get(HttpRequestMessage requestMessage) // { // var apiDescription = res.First(); // var atts = apiDescription.ActionDescriptor.GetCustomAttributes(); - + // // Get EntryPoint Link relation name // var epr = atts.FirstOrDefault(); // if (epr != null) @@ -125,9 +117,9 @@ public HttpResponseMessage Get(HttpRequestMessage requestMessage) // var streamContent = new StreamContent(stream); // streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // var responseMessage = new HttpResponseMessage() {Content = streamContent}; - + // return responseMessage; - + //} private string MakeQueryString(ApiDescription ad) @@ -135,6 +127,4 @@ private string MakeQueryString(ApiDescription ad) return String.Empty; } } - - -} +} \ No newline at end of file diff --git a/samples/WebApiConsole/EntryPointRelationAttribute.cs b/samples/WebApiConsole/EntryPointRelationAttribute.cs index f9123ee..14a21b3 100644 --- a/samples/WebApiConsole/EntryPointRelationAttribute.cs +++ b/samples/WebApiConsole/EntryPointRelationAttribute.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace WebApiConsole { @@ -20,4 +16,4 @@ public string Name get { return _name; } } } -} +} \ No newline at end of file diff --git a/samples/WebApiConsole/Program.cs b/samples/WebApiConsole/Program.cs index 14db93b..9eaaa6e 100644 --- a/samples/WebApiConsole/Program.cs +++ b/samples/WebApiConsole/Program.cs @@ -1,40 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using System.Web.Http; -using System.Web.Http.Description; -using System.Web.Http.SelfHost; -using Tavis; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; namespace WebApiConsole { class Program { - static void Main(string[] args) + static async Task Main(string[] args) { - - - var baseAddress = "http://localhost:8080"; - var config = new HttpSelfHostConfiguration(baseAddress); - - config.Routes.MapHttpRoute("defaultWithId", "api/{controller}/{id}"); - config.Routes.MapHttpRoute("default", "api/{controller}"); - //config.Routes.MapHttpRoute("default", "api/{controller}/{id}", new {id= RouteParameter.Optional}); - - - var server = new HttpSelfHostServer(config); - - - Console.WriteLine("Opening server at " + baseAddress); - server.OpenAsync().Wait(); - - Console.WriteLine("Press enter to shutdown server"); - Console.ReadLine(); - server.CloseAsync().Wait(); + await WebHost.CreateDefaultBuilder(args).Build().RunAsync(); + } + } + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + app.UseMvcWithDefaultRoute(); } } -} +} \ No newline at end of file diff --git a/samples/WebApiConsole/Properties/AssemblyInfo.cs b/samples/WebApiConsole/Properties/AssemblyInfo.cs deleted file mode 100644 index daf1fc4..0000000 --- a/samples/WebApiConsole/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("WebApiConsole")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("WebApiConsole")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("71487c42-b0fd-4d81-8269-4fefd0e52ffc")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/samples/WebApiConsole/WebApiConsole.csproj b/samples/WebApiConsole/WebApiConsole.csproj index dd44d8d..de03ca0 100644 --- a/samples/WebApiConsole/WebApiConsole.csproj +++ b/samples/WebApiConsole/WebApiConsole.csproj @@ -1,109 +1,14 @@ - - - + - Debug - AnyCPU - {40BCCD0F-FAF7-4E11-8C7C-072020362FDF} Exe - Properties - WebApiConsole - WebApiConsole - v4.5 - 512 - ..\..\src\ - true - - - + netcoreapp2.2 + latest - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - ..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - True - - - - - - - ..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - True - - - - ..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll - True - - - ..\..\packages\Microsoft.AspNet.WebApi.SelfHost.5.2.3\lib\net45\System.Web.Http.SelfHost.dll - True - - - - - - - - ..\..\packages\Tavis.Link.2.5\lib\portable-net45+sl5+wp8+win8+wpa81+MonoTouch1+MonoAndroid1\Tavis.Link.dll - True - - - ..\..\packages\Tavis.UriTemplates.1.0.0\lib\Net45\Tavis.UriTemplates.dll - True - - - - - - - - - - - + + - - {151aef3f-322e-4968-9642-25857a4d2ed9} - Home - + - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/samples/WebApiConsole/app.config b/samples/WebApiConsole/app.config deleted file mode 100644 index 7f8b1df..0000000 --- a/samples/WebApiConsole/app.config +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/WebApiConsole/packages.config b/samples/WebApiConsole/packages.config deleted file mode 100644 index 972bdbe..0000000 --- a/samples/WebApiConsole/packages.config +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/Home/Home.csproj b/src/Home/Home.csproj index b92719d..2d6e35d 100644 --- a/src/Home/Home.csproj +++ b/src/Home/Home.csproj @@ -1,83 +1,25 @@  - - + - 10.0 - Debug - AnyCPU - {151AEF3F-322E-4968-9642-25857A4D2ED9} - Library - Properties - Tavis.Home - Tavis.Home - v4.5 - Profile111 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - .\ - true - - - - - 4.0 - 71667d90 + json-home + netstandard2.0 + 1.0.0 + 1.0.0 + Darrel Miller + .NET Support for application/json-home + asp.net core;.net core;hypermedia;rest;application/json-home + https://github.com/tavis-software/Tavis.home + Apache-2.0 + latest + true + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - bin\Debug\Tavis.Home.XML - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\Tavis.Home.XML - - - - - - - - - - ..\..\packages\Newtonsoft.Json.7.0.1\lib\portable-net45+wp80+win8+wpa81+dnxcore50\Newtonsoft.Json.dll - - - ..\..\packages\Tavis.Link.2.5\lib\portable-net45+sl5+wp8+win8+wpa81+MonoTouch1+MonoAndroid1\Tavis.Link.dll - True - - - ..\..\packages\Tavis.UriTemplates.1.0.0\lib\portable-net45+netcore45+wpa81+wp8\Tavis.UriTemplates.dll - True - - + - - + + - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - + + \ No newline at end of file diff --git a/src/Home/Properties/AssemblyInfo.cs b/src/Home/Properties/AssemblyInfo.cs deleted file mode 100644 index 32b02fc..0000000 --- a/src/Home/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("json-home")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("json-home")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Home/app.config b/src/Home/app.config deleted file mode 100644 index 195db1f..0000000 --- a/src/Home/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/src/Home/packages.config b/src/Home/packages.config deleted file mode 100644 index 372809a..0000000 --- a/src/Home/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/HomeTests/BasicHomeTests.cs b/src/HomeTests/BasicHomeTests.cs index 097ed9f..cab1d4d 100644 --- a/src/HomeTests/BasicHomeTests.cs +++ b/src/HomeTests/BasicHomeTests.cs @@ -1,12 +1,7 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using Tavis; using Tavis.IANA; using Tavis.UriTemplates; @@ -17,13 +12,12 @@ namespace HomeTests { public class BasicHomeTests { - [Fact] public void ParseEmptyHomeDoc() { // Doc needs to be at least an object var doc = HomeDocument.Parse("{}"); - + Assert.NotNull(doc); } @@ -45,7 +39,7 @@ public void ParseHomeDocWithOneResource() var resource = doc.GetResource("http://example.org/rels/test"); Assert.NotNull(resource); - Assert.Equal(resource.Target, new Uri("/test",UriKind.Relative)); + Assert.Equal(resource.Target, new Uri("/test", UriKind.Relative)); } [Fact] @@ -62,15 +56,14 @@ public void ParseHomeDocWithMultipleResources() Assert.NotNull(resource2); Assert.Equal(resource2.Target, new Uri("/test2", UriKind.Relative)); - Assert.Equal(2,doc.Resources.Count()); - + Assert.Equal(2, doc.Resources.Count()); } [Fact] public void RoundTripHomeDocument() { var doc = new HomeDocument(); - doc.AddResource(new AboutLink() {Target = new Uri("about",UriKind.Relative)}); + doc.AddResource(new AboutLink() {Target = new Uri("about", UriKind.Relative)}); var ms = new MemoryStream(); doc.Save(ms); @@ -109,7 +102,7 @@ public void RoundTripHomeDocumentWithHint() public void CreateHomeDocumentWithFormatsHints() { var doc = new HomeDocument(); - var aboutLink = new AboutLink() { Target = new Uri("about", UriKind.Relative) }; + var aboutLink = new AboutLink() {Target = new Uri("about", UriKind.Relative)}; aboutLink.AddHint(h => h.AddMethod(HttpMethod.Get)); aboutLink.AddHint(h => h.AddMediaType("application/json")); @@ -149,9 +142,8 @@ public void CreateHomeDocumentWithLotsOfHints() var st = new StreamReader(ms); var s = st.ReadToEnd(); - + Assert.NotNull(s); - } [Fact] @@ -159,15 +151,9 @@ public void CreateResourceWithPathParameter() { var doc = new HomeDocument(); - doc.AddResource(l => - { - l.Target = new Uri("http://example.org:1001/about/{id}"); - }); + doc.AddResource(l => { l.Target = new Uri("http://example.org:1001/about/{id}"); }); - doc.AddResource(l => - { - l.Target = new Uri("http://example.org:1001/help/{id}"); - }); + doc.AddResource(l => { l.Target = new Uri("http://example.org:1001/help/{id}"); }); var ms = new MemoryStream(); doc.Save(ms); @@ -175,9 +161,7 @@ public void CreateResourceWithPathParameter() var st = new StreamReader(ms); var s = st.ReadToEnd(); - Assert.True(s.Contains("href-template")); - - + Assert.True(s.Contains("href-template")); } [Fact] @@ -191,10 +175,7 @@ public void CreateResourceWithPathParameterAndRelWithDots() l.Target = new Uri("http://example.org:1001/about/{id}"); }); - doc.AddResource(l => - { - l.Target = new Uri("http://example.org:1001/help/{id}"); - }); + doc.AddResource(l => { l.Target = new Uri("http://example.org:1001/help/{id}"); }); var ms = new MemoryStream(); doc.Save(ms); @@ -203,8 +184,6 @@ public void CreateResourceWithPathParameterAndRelWithDots() var st = new StreamReader(ms); var s = st.ReadToEnd(); Assert.True(s.Contains("href-template")); - - } @@ -227,11 +206,9 @@ public void CreateResource_with_extension_rel_and_template() var st = new StreamReader(ms); var s = st.ReadToEnd(); Assert.True(s.Contains("href-template")); - - } - - [Fact] + + [Fact] public void CreateResourceWithMultipleQueryParameters() { var doc = new HomeDocument(); @@ -241,7 +218,7 @@ public void CreateResourceWithMultipleQueryParameters() l.Relation = "vnd.foo.about"; l.Template = new UriTemplate("http://example.org:1001/about{?id,name}"); }); - + var ms = new MemoryStream(); doc.Save(ms); @@ -250,8 +227,6 @@ public void CreateResourceWithMultipleQueryParameters() var st = new StreamReader(ms); var s = st.ReadToEnd(); Assert.True(s.Contains("href-template")); - - } //[Fact] //public async Task LiveParse() @@ -264,20 +239,17 @@ public void CreateResourceWithMultipleQueryParameters() //} - } - //[Fact] - //public async Task LiveParse() - //{ - // var httpClient = new HttpClient(); - - // var response = await httpClient.GetAsync("http://birch:1001"); - - // var homedocument = HomeDocument.Parse(await response.Content.ReadAsStreamAsync()); + //[Fact] + //public async Task LiveParse() + //{ + // var httpClient = new HttpClient(); + // var response = await httpClient.GetAsync("http://birch:1001"); - //} + // var homedocument = HomeDocument.Parse(await response.Content.ReadAsStreamAsync()); - } + //} +} \ No newline at end of file diff --git a/src/HomeTests/HomeTests.csproj b/src/HomeTests/HomeTests.csproj index 8a2d746..c55adac 100644 --- a/src/HomeTests/HomeTests.csproj +++ b/src/HomeTests/HomeTests.csproj @@ -1,97 +1,17 @@  - - + - Debug - AnyCPU - {59746D39-B2B9-420E-B609-4CA301F9CFBB} - Library - Properties - HomeTests - HomeTests - v4.5 - 512 - ..\ - true - - 5e495116 + netcoreapp2.2 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - False - ..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - - - - - - - - - - - - - ..\..\packages\Tavis.Link.2.5\lib\portable-net45+sl5+wp8+win8+wpa81+MonoTouch1+MonoAndroid1\Tavis.Link.dll - True - - - ..\..\packages\Tavis.UriTemplates.1.0.0\lib\Net45\Tavis.UriTemplates.dll - True - - - ..\..\packages\xunit.1.9.2\lib\net20\xunit.dll - - - - - - - - - - + - - {151aef3f-322e-4968-9642-25857a4d2ed9} - Home - + + + + - + - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - + \ No newline at end of file diff --git a/src/HomeTests/Properties/AssemblyInfo.cs b/src/HomeTests/Properties/AssemblyInfo.cs deleted file mode 100644 index e73aa86..0000000 --- a/src/HomeTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("HomeTests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("HomeTests")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("50c32623-a8f8-431e-a79d-e22f6a21be12")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/HomeTests/app.config b/src/HomeTests/app.config deleted file mode 100644 index d94ddfd..0000000 --- a/src/HomeTests/app.config +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/HomeTests/packages.config b/src/HomeTests/packages.config deleted file mode 100644 index 72e389c..0000000 --- a/src/HomeTests/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file