Browse Source

loading in docker

the IP for the catalog service is wrong, but other than that, it's
working.
pull/182/head
BillWagner 7 years ago
committed by Bill Wagner
parent
commit
9f01790d4d
8 changed files with 226 additions and 14 deletions
  1. +3
    -0
      src/Web/Catalog.WebForms/Catalog.WebForms/Catalog.WebForms.csproj
  2. +5
    -1
      src/Web/Catalog.WebForms/Catalog.WebForms/Modules/AutoFacHttpModule.cs
  3. +7
    -7
      src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs
  4. +174
    -0
      src/Web/Catalog.WebForms/Catalog.WebForms/Services/RequestProvider.cs
  5. +31
    -0
      src/Web/Catalog.WebForms/Catalog.WebForms/Web.Debug.config
  6. +1
    -1
      src/Web/Catalog.WebForms/Catalog.WebForms/Web.config
  7. +0
    -5
      src/Web/Catalog.WebForms/docker-compose.override.yml
  8. +5
    -0
      src/Web/Catalog.WebForms/docker-compose.yml

+ 3
- 0
src/Web/Catalog.WebForms/Catalog.WebForms/Catalog.WebForms.csproj View File

@ -57,6 +57,8 @@
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data.Entity" /> <Reference Include="System.Data.Entity" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web.Extensions" /> <Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
@ -415,6 +417,7 @@
<Compile Include="Services\Common.cs" /> <Compile Include="Services\Common.cs" />
<Compile Include="Services\ICatalogService.cs" /> <Compile Include="Services\ICatalogService.cs" />
<Compile Include="Services\IRouteProvider.cs" /> <Compile Include="Services\IRouteProvider.cs" />
<Compile Include="Services\RequestProvider.cs" />
<Compile Include="Site.Master.cs"> <Compile Include="Site.Master.cs">
<DependentUpon>Site.Master</DependentUpon> <DependentUpon>Site.Master</DependentUpon>
<SubType>ASPXCodeBehind</SubType> <SubType>ASPXCodeBehind</SubType>


+ 5
- 1
src/Web/Catalog.WebForms/Catalog.WebForms/Modules/AutoFacHttpModule.cs View File

@ -1,5 +1,6 @@
using Autofac; using Autofac;
using eShopOnContainers.Core.Services.Catalog; using eShopOnContainers.Core.Services.Catalog;
using eShopOnContainers.Core.Services.RequestProvider;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -34,8 +35,11 @@ namespace eShopOnContainers.Catalog.WebForms.Modules
} }
else else
{ {
builder.RegisterType<CatalogMockService>()
builder.RegisterType<CatalogService>()
.As<ICatalogService>(); .As<ICatalogService>();
builder.RegisterType<RequestProvider>()
.As<IRequestProvider>();
} }
var container = builder.Build(); var container = builder.Build();
return container; return container;


+ 7
- 7
src/Web/Catalog.WebForms/Catalog.WebForms/Services/CatalogService.cs View File

@ -24,7 +24,7 @@ namespace eShopOnContainers.Core.Services.Catalog
try try
{ {
// TODO: // TODO:
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
UriBuilder builder = new UriBuilder("http://catalog.api:5101");
builder.Path = string.Format("api/v1/catalog/items/type/{0}/brand/{1}", catalogTypeId, catalogBrandId); builder.Path = string.Format("api/v1/catalog/items/type/{0}/brand/{1}", catalogTypeId, catalogBrandId);
@ -49,7 +49,7 @@ namespace eShopOnContainers.Core.Services.Catalog
try try
{ {
// TODO: // TODO:
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
UriBuilder builder = new UriBuilder("http://catalog.api:5101");
builder.Path = "api/v1/catalog/items"; builder.Path = "api/v1/catalog/items";
@ -83,7 +83,7 @@ namespace eShopOnContainers.Core.Services.Catalog
try try
{ {
// TODO: // TODO:
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
UriBuilder builder = new UriBuilder("http://catalog.api:5101");
builder.Path = "api/v1/catalog/catalogbrands"; builder.Path = "api/v1/catalog/catalogbrands";
@ -108,7 +108,7 @@ namespace eShopOnContainers.Core.Services.Catalog
try try
{ {
// TODO: // TODO:
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
UriBuilder builder = new UriBuilder("http://catalog.api:5101");
builder.Path = "api/v1/catalog/catalogtypes"; builder.Path = "api/v1/catalog/catalogtypes";
@ -131,7 +131,7 @@ namespace eShopOnContainers.Core.Services.Catalog
public Task DeleteCatalogItemAsync(string catalogItemId) public Task DeleteCatalogItemAsync(string catalogItemId)
{ {
// TODO: // TODO:
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
UriBuilder builder = new UriBuilder("http://catalog.api:5101");
builder.Path = $"api/v1/catalog/{catalogItemId}"; builder.Path = $"api/v1/catalog/{catalogItemId}";
@ -143,7 +143,7 @@ namespace eShopOnContainers.Core.Services.Catalog
public Task<CatalogItem> UpdateCatalogItemAsync(CatalogItem item) public Task<CatalogItem> UpdateCatalogItemAsync(CatalogItem item)
{ {
// TODO: // TODO:
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
UriBuilder builder = new UriBuilder("http://catalog.api:5101");
builder.Path = "api/v1/catalog/edit"; builder.Path = "api/v1/catalog/edit";
@ -155,7 +155,7 @@ namespace eShopOnContainers.Core.Services.Catalog
public Task<CatalogItem> CreateCatalogItemAsync(CatalogItem item) public Task<CatalogItem> CreateCatalogItemAsync(CatalogItem item)
{ {
// TODO: // TODO:
UriBuilder builder = new UriBuilder("" /* GlobalSetting.Instance.CatalogEndpoint */);
UriBuilder builder = new UriBuilder("http://catalog.api:5101");
builder.Path = "api/v1/catalog/create"; builder.Path = "api/v1/catalog/create";


+ 174
- 0
src/Web/Catalog.WebForms/Catalog.WebForms/Services/RequestProvider.cs View File

@ -0,0 +1,174 @@
using eShopOnContainers.Core.Exceptions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System;
// Taken from https://raw.githubusercontent.com/dotnet/eShopOnContainers/dev/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/RequestProvider/RequestProvider.cs
// TODO: DRY This
namespace eShopOnContainers.Core.Services.RequestProvider
{
public class RequestProvider : IRequestProvider
{
private readonly JsonSerializerSettings _serializerSettings;
public RequestProvider()
{
_serializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
NullValueHandling = NullValueHandling.Ignore
};
_serializerSettings.Converters.Add(new StringEnumConverter());
}
public async Task<TResult> GetAsync<TResult>(string uri, string token = "")
{
HttpClient httpClient = CreateHttpClient(token);
HttpResponseMessage response = await httpClient.GetAsync(uri);
await HandleResponse(response);
string serialized = await response.Content.ReadAsStringAsync();
TResult result = await Task.Run(() =>
JsonConvert.DeserializeObject<TResult>(serialized, _serializerSettings));
return result;
}
public async Task<TResult> PostAsync<TResult>(string uri, TResult data, string token = "", string header = "")
{
HttpClient httpClient = CreateHttpClient(token);
if (!string.IsNullOrEmpty(header))
{
AddHeaderParameter(httpClient, header);
}
var content = new StringContent(JsonConvert.SerializeObject(data));
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = await httpClient.PostAsync(uri, content);
await HandleResponse(response);
string serialized = await response.Content.ReadAsStringAsync();
TResult result = await Task.Run(() =>
JsonConvert.DeserializeObject<TResult>(serialized, _serializerSettings));
return result;
}
public Task<TResult> PostAsync<TResult>(string uri, TResult data, string token = "")
{
return PostAsync<TResult, TResult>(uri, data, token);
}
public async Task<TResult> PostAsync<TRequest, TResult>(string uri, TRequest data, string token = "")
{
HttpClient httpClient = CreateHttpClient(token);
string serialized = await Task.Run(() => JsonConvert.SerializeObject(data, _serializerSettings));
var content = new StringContent(serialized, Encoding.UTF8, "application/json");
HttpResponseMessage response = await httpClient.PostAsync(uri, content);
await HandleResponse(response);
string responseData = await response.Content.ReadAsStringAsync();
return await Task.Run(() => JsonConvert.DeserializeObject<TResult>(responseData, _serializerSettings));
}
public Task<TResult> PutAsync<TResult>(string uri, TResult data, string token = "")
{
return PutAsync<TResult, TResult>(uri, data, token);
}
public async Task<TResult> PutAsync<TRequest, TResult>(string uri, TRequest data, string token = "")
{
HttpClient httpClient = CreateHttpClient(token);
string serialized = await Task.Run(() => JsonConvert.SerializeObject(data, _serializerSettings));
HttpResponseMessage response = await httpClient.PutAsync(uri, new StringContent(serialized, Encoding.UTF8, "application/json"));
await HandleResponse(response);
string responseData = await response.Content.ReadAsStringAsync();
return await Task.Run(() => JsonConvert.DeserializeObject<TResult>(responseData, _serializerSettings));
}
public async Task DeleteAsync(string uri, string token = "")
{
HttpClient httpClient = CreateHttpClient(token);
await httpClient.DeleteAsync(uri);
}
private HttpClient CreateHttpClient(string token = "")
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (!string.IsNullOrEmpty(token))
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
}
return httpClient;
}
private void AddHeaderParameter(HttpClient httpClient, string parameter)
{
if (httpClient == null)
return;
if (string.IsNullOrEmpty(parameter))
return;
httpClient.DefaultRequestHeaders.Add(parameter, Guid.NewGuid().ToString());
}
private async Task HandleResponse(HttpResponseMessage response)
{
if (!response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
if (response.StatusCode == HttpStatusCode.Forbidden
|| response.StatusCode == HttpStatusCode.Unauthorized)
{
throw new ServiceAuthenticationException(content);
}
throw new HttpRequestException(content);
}
}
}
}
// Taken from: https://raw.githubusercontent.com/dotnet/eShopOnContainers/dev/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Exceptions/ServiceAuthenticationException.cs
namespace eShopOnContainers.Core.Exceptions
{
public class ServiceAuthenticationException : Exception
{
public string Content { get; }
public ServiceAuthenticationException()
{
}
public ServiceAuthenticationException(string content)
{
Content = content;
}
}
}

+ 31
- 0
src/Web/Catalog.WebForms/Catalog.WebForms/Web.Debug.config View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
<customErrors mode="Off"/>
</system.web>
</configuration>

+ 1
- 1
src/Web/Catalog.WebForms/Catalog.WebForms/Web.config View File

@ -9,7 +9,7 @@
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections> </configSections>
<appSettings> <appSettings>
<add key="usefake" value="true" />
<add key="usefake" value="false" />
</appSettings> </appSettings>
<connectionStrings> <connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Catalog.WebForms-20170322110716.mdf;Initial Catalog=aspnet-Catalog.WebForms-20170322110716;Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Catalog.WebForms-20170322110716.mdf;Initial Catalog=aspnet-Catalog.WebForms-20170322110716;Integrated Security=True" providerName="System.Data.SqlClient" />


+ 0
- 5
src/Web/Catalog.WebForms/docker-compose.override.yml View File

@ -20,8 +20,3 @@ services:
catalog.webforms: catalog.webforms:
ports: ports:
- "80:80" - "80:80"
networks:
default:
external:
name: nat

+ 5
- 0
src/Web/Catalog.WebForms/docker-compose.yml View File

@ -19,3 +19,8 @@ services:
sql.data: sql.data:
image: microsoft/mssql-server-windows image: microsoft/mssql-server-windows
networks:
default:
external:
name: nat

Loading…
Cancel
Save