Initial commit
This commit is contained in:
29
PartSource/App.config
Normal file
29
PartSource/App.config
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</configSections>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
|
||||
<parameters>
|
||||
<parameter value="mssqllocaldb" />
|
||||
</parameters>
|
||||
</defaultConnectionFactory>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
</providers>
|
||||
</entityFramework>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.3.4.0" newVersion="3.3.4.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
12
PartSource/App_Start/FilterConfig.cs
Normal file
12
PartSource/App_Start/FilterConfig.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace PartSource
|
||||
{
|
||||
public class FilterConfig
|
||||
{
|
||||
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
|
||||
{
|
||||
filters.Add(new HandleErrorAttribute());
|
||||
}
|
||||
}
|
||||
}
|
||||
56
PartSource/App_Start/NinjectWebCommon.cs
Normal file
56
PartSource/App_Start/NinjectWebCommon.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
|
||||
using Ninject;
|
||||
using Ninject.Activation;
|
||||
using Ninject.Modules;
|
||||
using Ninject.Web.Common;
|
||||
using Ninject.Web.Common.WebHost;
|
||||
using PartSource.Entities;
|
||||
using PartSource.Entities.Nexpart;
|
||||
using PartSource.Services;
|
||||
using System;
|
||||
using System.Web;
|
||||
|
||||
namespace PartSource
|
||||
{
|
||||
public static class NinjectWebCommon
|
||||
{
|
||||
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
|
||||
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
|
||||
NinjectWebCommon.bootstrapper.Initialize(new Func<IKernel>(NinjectWebCommon.CreateKernel));
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
NinjectWebCommon.bootstrapper.ShutDown();
|
||||
}
|
||||
|
||||
private static IKernel CreateKernel()
|
||||
{
|
||||
StandardKernel standardKernel = new StandardKernel(Array.Empty<INinjectModule>());
|
||||
try
|
||||
{
|
||||
standardKernel.Bind<Func<IKernel>>().ToMethod((Func<IContext, Func<IKernel>>)(ctx => (Func<IKernel>)(() => new Bootstrapper().Kernel)));
|
||||
standardKernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
|
||||
NinjectWebCommon.RegisterServices((IKernel)standardKernel);
|
||||
return (IKernel)standardKernel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
standardKernel.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private static void RegisterServices(IKernel kernel)
|
||||
{
|
||||
kernel.Bind<PartSourceContext>().To<PartSourceContext>();
|
||||
kernel.Bind<SecurityService>().To<SecurityService>();
|
||||
kernel.Bind<NexpartService>().To<NexpartService>();
|
||||
kernel.Bind<PSRequestHeader>().To<PSRequestHeader>();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
PartSource/App_Start/WebApiConfig.cs
Normal file
27
PartSource/App_Start/WebApiConfig.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: PartSource.WebApiConfig
|
||||
// Assembly: PartSource, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 9C95A003-DAA7-4079-9F59-D1FC80E1666C
|
||||
// Assembly location: C:\Users\Tommy\Desktop\PS temp\PartSource.dll
|
||||
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace PartSource
|
||||
{
|
||||
public static class WebApiConfig
|
||||
{
|
||||
public static void Register(HttpConfiguration config)
|
||||
{
|
||||
HttpConfigurationExtensions.MapHttpAttributeRoutes(config);
|
||||
HttpRouteCollectionExtensions.MapHttpRoute(config.Routes, "DefaultApi", "{controller}/{id}", new
|
||||
{
|
||||
id = RouteParameter.Optional
|
||||
});
|
||||
|
||||
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
|
||||
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
|
||||
}
|
||||
}
|
||||
}
|
||||
18
PartSource/AssemblyInfo.cs
Normal file
18
PartSource/AssemblyInfo.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using PartSource;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using WebActivatorEx;
|
||||
|
||||
[assembly: PreApplicationStartMethod(typeof (NinjectWebCommon), "Start")]
|
||||
[assembly: ApplicationShutdownMethod(typeof (NinjectWebCommon), "Stop")]
|
||||
[assembly: AssemblyTitle("CanadianTire")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("CanadianTire")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("ab430735-adfd-42b5-bce1-55f18897a618")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
47
PartSource/Controllers/BaseNexpartController.cs
Normal file
47
PartSource/Controllers/BaseNexpartController.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: PartSource.Controllers.BaseNexpartController
|
||||
// Assembly: PartSource, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 9C95A003-DAA7-4079-9F59-D1FC80E1666C
|
||||
// Assembly location: C:\Users\Tommy\Desktop\PS temp\PartSource.dll
|
||||
|
||||
using PartSource.Entities.Nexpart;
|
||||
using PartSource.Entities.Nexpart.Interfaces;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace PartSource.Controllers
|
||||
{
|
||||
public class BaseNexpartController : ApiController
|
||||
{
|
||||
public IHttpActionResult NexpartResponse<T, U>(T response) where T : IResponseElement<U>
|
||||
{
|
||||
try
|
||||
{
|
||||
Exceptions[] exceptions = response.PSResponseHeader.Exceptions;
|
||||
if ((exceptions != null ? ((uint)exceptions.Length > 0U ? 1 : 0) : 0) == 0)
|
||||
return Ok(new
|
||||
{
|
||||
Data = response.ResponseBody
|
||||
});
|
||||
string empty = string.Empty;
|
||||
foreach (Exceptions exception in response.PSResponseHeader.Exceptions)
|
||||
empty += string.Format("{0}\n", (object)exception.Value);
|
||||
return (IHttpActionResult)this.Content(HttpStatusCode.BadRequest, new
|
||||
{
|
||||
Data = response.ResponseBody
|
||||
});
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
return (IHttpActionResult)this.Content(HttpStatusCode.InternalServerError, new
|
||||
{
|
||||
Message = ex.Message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
38
PartSource/Controllers/InventoryController.cs
Normal file
38
PartSource/Controllers/InventoryController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using PartSource.Entities.Models;
|
||||
using PartSource.Services;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace PartSource.Controllers
|
||||
{
|
||||
[RoutePrefix("inventory")]
|
||||
public class InventoryController : BaseNexpartController
|
||||
{
|
||||
private readonly InventoryService _inventoryService;
|
||||
|
||||
public InventoryController(InventoryService inventoryService)
|
||||
{
|
||||
_inventoryService = inventoryService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("sku/{sku}/storeNumber/{storeNumber}")]
|
||||
public async Task<IHttpActionResult> GetInventory(int sku, int storeNumber)
|
||||
{
|
||||
ps_parts_availability inventory = _inventoryService.GetInventory(sku, storeNumber);
|
||||
|
||||
return inventory == null
|
||||
? Content(HttpStatusCode.NotFound, $"No part matching SKU {sku} was found.")
|
||||
: (IHttpActionResult)Ok(new
|
||||
{
|
||||
data = new
|
||||
{
|
||||
StoreNumber = inventory.Store,
|
||||
Sku = sku,
|
||||
Quantity = inventory.QTY
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
71
PartSource/Controllers/PartsController.cs
Normal file
71
PartSource/Controllers/PartsController.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using PartSource.Entities.Nexpart;
|
||||
using PartSource.Services;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace PartSource.Controllers
|
||||
{
|
||||
[RoutePrefix("parts")]
|
||||
public class PartsController : BaseNexpartController
|
||||
{
|
||||
private readonly NexpartService _nexpartService;
|
||||
|
||||
public PartsController(NexpartService nexpartService)
|
||||
{
|
||||
this._nexpartService = nexpartService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("PartNumber/{partNumber}/LineCode/{lineCode}")]
|
||||
public IHttpActionResult GetPart(string partNumber, string lineCode)
|
||||
{
|
||||
new SmartPageDataSearch().Items = new Item[1]
|
||||
{
|
||||
new Item()
|
||||
{
|
||||
PartNumber = partNumber.ToUpperInvariant(),
|
||||
MfrCode = lineCode.ToUpperInvariant()
|
||||
}
|
||||
};
|
||||
return (IHttpActionResult)this.Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("search/basevehicleid/{baseVehicleId}")]
|
||||
public async Task<IHttpActionResult> Search(uint baseVehicleId, [FromUri] string query)
|
||||
{
|
||||
PartsController partsController = this;
|
||||
PartTypeSearch requestContent = new PartTypeSearch()
|
||||
{
|
||||
SearchString = query,
|
||||
SearchType = "ALL",
|
||||
SearchOptions = "PARTIAL_MATCH",
|
||||
VehicleIdentifier = new VehicleIdentifier()
|
||||
{
|
||||
BaseVehicleId = baseVehicleId
|
||||
}
|
||||
};
|
||||
PartTypeSearchResponse response = await partsController._nexpartService.SendRequest<PartTypeSearch, PartTypeSearchResponse>(requestContent);
|
||||
return partsController.NexpartResponse<PartTypeSearchResponse, PartTypes>(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("validate/partTypeId/{partTypeId}/baseVehicleId/{baseVehicleId}")]
|
||||
public async Task<IHttpActionResult> ValidatePartFitment(uint partTypeId, uint baseVehicleId)
|
||||
{
|
||||
PartsController partsController = this;
|
||||
PartTypesValidateLookup typesValidateLookup = new PartTypesValidateLookup();
|
||||
typesValidateLookup.PartTypes = new PartType[1]
|
||||
{
|
||||
new PartType() { Id = partTypeId }
|
||||
};
|
||||
typesValidateLookup.VehicleIdentifier = new VehicleIdentifier()
|
||||
{
|
||||
BaseVehicleId = baseVehicleId
|
||||
};
|
||||
PartTypesValidateLookup requestContent = typesValidateLookup;
|
||||
PartTypesValidateLookupResponse response = await partsController._nexpartService.SendRequest<PartTypesValidateLookup, PartTypesValidateLookupResponse>(requestContent);
|
||||
return partsController.NexpartResponse<PartTypesValidateLookupResponse, PartTypes>(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
PartSource/Controllers/SearchController.cs
Normal file
31
PartSource/Controllers/SearchController.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using PartSource.Entities.Nexpart;
|
||||
using PartSource.Services;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace PartSource.Controllers
|
||||
{
|
||||
[RoutePrefix("search")]
|
||||
public class SearchController : BaseNexpartController
|
||||
{
|
||||
private readonly NexpartService _nexpartService;
|
||||
|
||||
public SearchController()
|
||||
{
|
||||
this._nexpartService = new NexpartService();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("makes/vehicletypeid/{vehicleTypeId}")]
|
||||
public async Task<IHttpActionResult> GetMakes(uint vehicleTypeId)
|
||||
{
|
||||
SearchController searchController = this;
|
||||
MakeSearch requestContent = new MakeSearch()
|
||||
{
|
||||
VehicleTypeId = new uint[1] { vehicleTypeId }
|
||||
};
|
||||
MakeSearchResponse response = await searchController._nexpartService.SendRequest<MakeSearch, MakeSearchResponse>(requestContent);
|
||||
return searchController.NexpartResponse<MakeSearchResponse, Makes>(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
PartSource/Controllers/StoresController.cs
Normal file
46
PartSource/Controllers/StoresController.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using PartSource.Entities.Models;
|
||||
using PartSource.Services;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace PartSource.Controllers
|
||||
{
|
||||
[RoutePrefix("stores")]
|
||||
public class StoresController : ApiController
|
||||
{
|
||||
private const int Count = 5;
|
||||
private const int Page = 1;
|
||||
private readonly LocationService _service;
|
||||
|
||||
public StoresController(LocationService service)
|
||||
{
|
||||
this._service = service;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("nearest/{postal}")]
|
||||
[Route("nearest/{postal}/count/{count}")]
|
||||
[Route("nearest/{postal}/count/{count}/page/{page}")]
|
||||
public IHttpActionResult GetNearestStores(string postal, int count = 5, int page = 1)
|
||||
{
|
||||
PostalCode postalCodeData = this._service.GetPostalCodeData(postal);
|
||||
if (postalCodeData == null)
|
||||
return (IHttpActionResult)this.BadRequest("Invalid postal code");
|
||||
return (IHttpActionResult)this.Ok(new
|
||||
{
|
||||
Data = this._service.GetClosestLocations(postalCodeData, count, page)
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("nearest/{postal}/radius/{radius}")]
|
||||
[Route("nearest/{postal}/radius/{radius}/count/{count}")]
|
||||
[Route("nearest/{postal}/radius/{radius}/count/{count}/page/{page}")]
|
||||
public IHttpActionResult GetNearestStores(string postal, double radius, int count = 5, int page = 1)
|
||||
{
|
||||
return (IHttpActionResult)this.Ok(new
|
||||
{
|
||||
Data = this._service.GetClosestLocations(this._service.GetPostalCodeData(postal), count, page, radius)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
114
PartSource/Controllers/VehiclesController.cs
Normal file
114
PartSource/Controllers/VehiclesController.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using PartSource.Entities.Nexpart;
|
||||
using PartSource.Services;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace PartSource.Controllers
|
||||
{
|
||||
[RoutePrefix("vehicles")]
|
||||
public class VehiclesController : BaseNexpartController
|
||||
{
|
||||
private readonly NexpartService _nexpartService;
|
||||
|
||||
public VehiclesController(NexpartService nexpartService)
|
||||
{
|
||||
this._nexpartService = nexpartService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("types")]
|
||||
public async Task<IHttpActionResult> GetVehicleTypes()
|
||||
{
|
||||
VehiclesController vehiclesController = this;
|
||||
VehicleTypesGetResponse response = await vehiclesController._nexpartService.SendRequest<VehicleTypesGet, VehicleTypesGetResponse>(new VehicleTypesGet());
|
||||
return vehiclesController.NexpartResponse<VehicleTypesGetResponse, VehicleTypes>(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("makes")]
|
||||
public async Task<IHttpActionResult> GetMakes()
|
||||
{
|
||||
VehiclesController vehiclesController = this;
|
||||
MakeSearch requestContent = new MakeSearch()
|
||||
{
|
||||
VehicleTypeId = new uint[3] { 5U, 6U, 7U }
|
||||
};
|
||||
MakeSearchResponse response = await vehiclesController._nexpartService.SendRequest<MakeSearch, MakeSearchResponse>(requestContent);
|
||||
return vehiclesController.NexpartResponse<MakeSearchResponse, Makes>(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("makes/vehicletypeid/{vehicleTypeId}")]
|
||||
public async Task<IHttpActionResult> GetMakes(uint vehicleTypeId)
|
||||
{
|
||||
VehiclesController vehiclesController = this;
|
||||
MakeSearch requestContent = new MakeSearch()
|
||||
{
|
||||
VehicleTypeId = new uint[1] { vehicleTypeId }
|
||||
};
|
||||
MakeSearchResponse response = await vehiclesController._nexpartService.SendRequest<MakeSearch, MakeSearchResponse>(requestContent);
|
||||
return vehiclesController.NexpartResponse<MakeSearchResponse, Makes>(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("models/makeid/{makeId}/modelyear/{year}")]
|
||||
public async Task<IHttpActionResult> GetModels(uint makeId, uint year)
|
||||
{
|
||||
VehiclesController vehiclesController = this;
|
||||
ModelSearch requestContent = new ModelSearch()
|
||||
{
|
||||
MakeId = makeId,
|
||||
Year = year,
|
||||
VehicleTypeId = new uint[3] { 5U, 6U, 7U }
|
||||
};
|
||||
ModelSearchResponse response = await vehiclesController._nexpartService.SendRequest<ModelSearch, ModelSearchResponse>(requestContent);
|
||||
return vehiclesController.NexpartResponse<ModelSearchResponse, Models[]>(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("models/makeid/{makeId}/modelyear/{year}/vehicletypeid/{vehicleTypeId}")]
|
||||
public async Task<IHttpActionResult> GetModels(uint makeId, uint year, uint vehicleTypeId)
|
||||
{
|
||||
VehiclesController vehiclesController = this;
|
||||
ModelSearch requestContent = new ModelSearch()
|
||||
{
|
||||
MakeId = makeId,
|
||||
Year = year,
|
||||
VehicleTypeId = new uint[1] { vehicleTypeId }
|
||||
};
|
||||
ModelSearchResponse response = await vehiclesController._nexpartService.SendRequest<ModelSearch, ModelSearchResponse>(requestContent);
|
||||
return vehiclesController.NexpartResponse<ModelSearchResponse, Models[]>(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("basevehicle/makeid/{makeId}/modelid/{modelId}/modelyear/{year}")]
|
||||
public async Task<IHttpActionResult> GetBaseVehicle(uint makeId, uint modelId, uint year)
|
||||
{
|
||||
VehiclesController vehiclesController = this;
|
||||
BaseVehicleDetailLookup requestContent = new BaseVehicleDetailLookup()
|
||||
{
|
||||
MakeId = makeId,
|
||||
ModelId = modelId,
|
||||
Year = year
|
||||
};
|
||||
BaseVehicleDetailLookupResponse response = await vehiclesController._nexpartService.SendRequest<BaseVehicleDetailLookup, BaseVehicleDetailLookupResponse>(requestContent);
|
||||
return vehiclesController.NexpartResponse<BaseVehicleDetailLookupResponse, BaseVehicleDetail>(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("engines/basevehicleid/{baseVehicleId}")]
|
||||
public async Task<IHttpActionResult> GetEngines(uint baseVehicleId)
|
||||
{
|
||||
VehiclesController vehiclesController = this;
|
||||
EngineSearch requestContent = new EngineSearch()
|
||||
{
|
||||
VehicleIdentifier = new VehicleIdentifier()
|
||||
{
|
||||
BaseVehicleId = baseVehicleId
|
||||
}
|
||||
};
|
||||
EngineSearchResponse response = await vehiclesController._nexpartService.SendRequest<EngineSearch, EngineSearchResponse>(requestContent);
|
||||
return vehiclesController.NexpartResponse<EngineSearchResponse, Engines>(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
100
PartSource/Filters/HmacAuthenticationAttribute.cs
Normal file
100
PartSource/Filters/HmacAuthenticationAttribute.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using Ninject;
|
||||
using Ninject.Modules;
|
||||
using Ninject.Parameters;
|
||||
using PartSource.Entities.Models;
|
||||
using PartSource.Services;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Filters;
|
||||
|
||||
namespace PartSource.Filters
|
||||
{
|
||||
public class HmacAuthenticationAttribute : Attribute, IAuthenticationFilter, IFilter
|
||||
{
|
||||
private readonly SecurityService _securityService;
|
||||
|
||||
public bool AllowMultiple { get { return false; } }
|
||||
|
||||
public HmacAuthenticationAttribute()
|
||||
{
|
||||
_securityService = new StandardKernel().Get<SecurityService>();
|
||||
}
|
||||
|
||||
public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (context.Request.Headers.Date.HasValue)
|
||||
{
|
||||
DateTimeOffset? date = context.Request.Headers.Date;
|
||||
DateTimeOffset timestamp = date.Value;
|
||||
if (ValidateTimestamp(timestamp))
|
||||
{
|
||||
if (context.Request.Headers.Authorization == null)
|
||||
{
|
||||
context.ErrorResult = new HmacErrorResult(HttpStatusCode.Unauthorized);
|
||||
return;
|
||||
}
|
||||
|
||||
string[] authParams = context.Request.Headers.Authorization.Parameter.Split(':');
|
||||
ApiClient client = await _securityService.GetApiClientByKeyAsync(authParams[0]);
|
||||
if (client == null || !client.Active)
|
||||
{
|
||||
context.ErrorResult = (IHttpActionResult)new HmacErrorResult(HttpStatusCode.Unauthorized);
|
||||
return;
|
||||
}
|
||||
byte[] secret = Encoding.UTF8.GetBytes(client.Secret);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append((object)secret);
|
||||
builder.Append((object)context.Request.Method);
|
||||
StringBuilder stringBuilder = builder;
|
||||
date = context.Request.Headers.Date;
|
||||
string str = date.Value.ToString("r");
|
||||
stringBuilder.Append(str);
|
||||
if (context.Request.Method != HttpMethod.Get)
|
||||
{
|
||||
using (MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider())
|
||||
builder.Append((object)md5Provider.ComputeHash(Encoding.UTF8.GetBytes(await context.Request.Content.ReadAsStringAsync())));
|
||||
}
|
||||
byte[] numArray;
|
||||
using (HMACSHA1 hmacshA1 = new HMACSHA1(secret))
|
||||
{
|
||||
numArray = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
numArray = hmacshA1.ComputeHash(numArray);
|
||||
}
|
||||
if (Convert.ToBase64String(numArray) == authParams[1])
|
||||
{
|
||||
string[] roles = new string[1] { "ValidUser" };
|
||||
context.Principal = (IPrincipal)new GenericPrincipal((IIdentity)new GenericIdentity(client.AppName), roles);
|
||||
return;
|
||||
}
|
||||
context.ErrorResult = (IHttpActionResult)new HmacErrorResult(HttpStatusCode.Unauthorized);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
context.ErrorResult = (IHttpActionResult)new HmacErrorResult(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
|
||||
public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
return new Task(null);
|
||||
}
|
||||
|
||||
private bool ValidateTimestamp(DateTimeOffset timestamp)
|
||||
{
|
||||
if (int.TryParse(ConfigurationManager.AppSettings["ClockDriftThresholdMinutes"], out int result) && DateTimeOffset.UtcNow.AddMinutes((double)(result * -1)) < timestamp)
|
||||
{
|
||||
return timestamp < DateTimeOffset.UtcNow.AddMinutes((double)result);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
PartSource/Filters/HmacErrorResult.cs
Normal file
33
PartSource/Filters/HmacErrorResult.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace PartSource.Filters
|
||||
{
|
||||
public class HmacErrorResult : IHttpActionResult
|
||||
{
|
||||
private HttpStatusCode _statusCode;
|
||||
private string _content;
|
||||
|
||||
public HmacErrorResult(HttpStatusCode statusCode)
|
||||
{
|
||||
this._statusCode = statusCode;
|
||||
}
|
||||
|
||||
public HmacErrorResult(HttpStatusCode statusCode, string content)
|
||||
{
|
||||
this._statusCode = statusCode;
|
||||
this._content = content;
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return new HttpResponseMessage(this._statusCode)
|
||||
{
|
||||
Content = !string.IsNullOrEmpty(this._content) ? (HttpContent)new StringContent(this._content) : (HttpContent)new StringContent(this._statusCode.ToString())
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
30
PartSource/Filters/LocalizationAttribute.cs
Normal file
30
PartSource/Filters/LocalizationAttribute.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
|
||||
namespace PartSource.Filters
|
||||
{
|
||||
public class LocalizationAttribute : Attribute, IActionFilter, IFilter
|
||||
{
|
||||
public bool AllowMultiple
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> ExecuteActionFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func<Task<HttpResponseMessage>> continuation)
|
||||
{
|
||||
foreach (StringWithQualityHeaderValue qualityHeaderValue in (IEnumerable<StringWithQualityHeaderValue>) ((IEnumerable<string>) actionContext.Request.Headers.AcceptLanguage.ToString().Split(',')).Select<string, StringWithQualityHeaderValue>(new Func<string, StringWithQualityHeaderValue>(StringWithQualityHeaderValue.Parse)).OrderByDescending<StringWithQualityHeaderValue, double>((Func<StringWithQualityHeaderValue, double>) (s => s.Quality.GetValueOrDefault(1.0))))
|
||||
;
|
||||
return await continuation();
|
||||
}
|
||||
}
|
||||
}
|
||||
17
PartSource/Global.asax.cs
Normal file
17
PartSource/Global.asax.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace PartSource
|
||||
{
|
||||
public class WebApiApplication : HttpApplication
|
||||
{
|
||||
protected void Application_Start()
|
||||
{
|
||||
AreaRegistration.RegisterAllAreas();
|
||||
GlobalConfiguration.Configure(new Action<HttpConfiguration>(WebApiConfig.Register));
|
||||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
||||
}
|
||||
}
|
||||
}
|
||||
114
PartSource/PartSource.csproj
Normal file
114
PartSource/PartSource.csproj
Normal file
@@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<!--Project was exported from assembly: C:\Users\Tommy\Desktop\PS temp\PartSource.dll-->
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{68F2C48E-87D6-4BD3-9259-136E5DA2BE2E}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AssemblyName>PartSource</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<ApplicationVersion>1.0.0.0</ApplicationVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<RootNamespace>PartSource</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Ninject, Version=3.3.4.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.3.3.4\lib\net45\Ninject.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Ninject.Web.Common, Version=3.3.1.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.Web.Common.3.3.1\lib\net45\Ninject.Web.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Ninject.Web.Common.WebHost, Version=3.3.1.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.Web.Common.WebHost.3.3.1\lib\net45\Ninject.Web.Common.WebHost.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.WebHost, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WebActivatorEx, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7b26dc2a43f6a0d4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\WebActivatorEx.2.2.0\lib\net40\WebActivatorEx.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App_Start\FilterConfig.cs" />
|
||||
<Compile Include="App_Start\NinjectWebCommon.cs" />
|
||||
<Compile Include="App_Start\WebApiConfig.cs" />
|
||||
<Compile Include="Global.asax.cs" />
|
||||
<Compile Include="Filters\LocalizationAttribute.cs" />
|
||||
<Compile Include="Filters\HmacAuthenticationAttribute.cs" />
|
||||
<Compile Include="Filters\HmacErrorResult.cs" />
|
||||
<Compile Include="Controllers\BaseNexpartController.cs" />
|
||||
<Compile Include="Controllers\InventoryController.cs" />
|
||||
<Compile Include="Controllers\StoresController.cs" />
|
||||
<Compile Include="Controllers\PartsController.cs" />
|
||||
<Compile Include="Controllers\SearchController.cs" />
|
||||
<Compile Include="Controllers\VehiclesController.cs" />
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
BIN
PartSource/lib/PartSource.Entities.dll
Normal file
BIN
PartSource/lib/PartSource.Entities.dll
Normal file
Binary file not shown.
BIN
PartSource/lib/PartSource.Services.dll
Normal file
BIN
PartSource/lib/PartSource.Services.dll
Normal file
Binary file not shown.
17
PartSource/packages.config
Normal file
17
PartSource/packages.config
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi" version="5.2.7" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net461" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net461" />
|
||||
<package id="Ninject" version="3.3.4" targetFramework="net461" />
|
||||
<package id="Ninject.Web.Common" version="3.3.1" targetFramework="net461" />
|
||||
<package id="Ninject.Web.Common.WebHost" version="3.3.1" targetFramework="net461" />
|
||||
<package id="WebActivatorEx" version="2.2.0" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user