loading in docker
the IP for the catalog service is wrong, but other than that, it's working.
This commit is contained in:
parent
3f01246404
commit
b455624909
@ -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>
|
||||||
|
@ -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;
|
||||||
|
@ -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";
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,5 +26,6 @@
|
|||||||
<error statusCode="500" redirect="InternalError.htm"/>
|
<error statusCode="500" redirect="InternalError.htm"/>
|
||||||
</customErrors>
|
</customErrors>
|
||||||
-->
|
-->
|
||||||
|
<customErrors mode="Off"/>
|
||||||
</system.web>
|
</system.web>
|
||||||
</configuration>
|
</configuration>
|
@ -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" />
|
||||||
|
@ -20,8 +20,3 @@ services:
|
|||||||
catalog.webforms:
|
catalog.webforms:
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
|
|
||||||
networks:
|
|
||||||
default:
|
|
||||||
external:
|
|
||||||
name: nat
|
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user