This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using Intelipost.API.Utilities; | ||
using Newtonsoft.Json; | ||
using Intelipost.API.Model; | ||
using Intelipost.API.Infrastructure; | ||
using Intelipost.API.Infrastructure.TimestampToDateTime; | ||
using System.Collections.Generic; | ||
|
||
namespace Intelipost.API.Model | ||
{ | ||
/// <summary> | ||
/// Entidade respectiva ao volume da encomenda. | ||
/// </summary> | ||
public class History | ||
{ | ||
/// <summary> | ||
/// Data de criação do Volume (UTC) | ||
/// </summary> | ||
[JsonProperty("created")] | ||
[JsonConverter(typeof(TimestampToDateTime))] | ||
public DateTime? Created { get; set; } | ||
|
||
/// <summary> | ||
/// Data do evento. (UTC) | ||
/// </summary> | ||
[JsonProperty("event_date")] | ||
[JsonConverter(typeof(TimestampToDateTime))] | ||
public DateTime? EventDate { get; set; } | ||
|
||
/// <summary> | ||
/// Mensagem da transportadora. | ||
/// </summary> | ||
[JsonProperty("provider_message")] | ||
public string ProviderMessage { get; set; } | ||
|
||
/// <summary> | ||
/// Estado do volume para a transportadora. | ||
/// </summary> | ||
[JsonProperty("provider_state")] | ||
public string ProviderState { get; set; } | ||
|
||
/// <summary> | ||
/// Id do volume. | ||
/// </summary> | ||
[JsonProperty("shipment_order_volume_id")] | ||
public int ShipmentOrderVolumeId { get; set; } | ||
|
||
/// <summary> | ||
/// Estado do volume. | ||
/// </summary> | ||
[JsonProperty("shipment_order_volume_state")] | ||
public string ShipmentOrderVolumeState { get; set; } | ||
|
||
/// <summary> | ||
/// ID do history. | ||
/// </summary> | ||
[JsonProperty("shipment_order_volume_state_history")] | ||
public int ShipmentOrderVolumeStateHistory { get; set; } | ||
|
||
/// <summary> | ||
/// Estado atual do volume. | ||
/// </summary> | ||
[JsonProperty("shipment_order_volume_state_localized")] | ||
public string ShipmentOrderVolumeStateLocalized { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Intelipost.API.Utilities; | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
using Intelipost.API.Infrastructure.TimestampToDateTime; | ||
using Newtonsoft.Json.Converters; | ||
namespace Intelipost.API.Model | ||
{ | ||
/// <summary> | ||
/// Entidade respectiva ao Pedido. | ||
/// </summary> | ||
|
||
public class Tracking | ||
{ | ||
/// <summary> | ||
/// Numero do Pedido. | ||
/// </summary> | ||
[JsonProperty("order_number")] | ||
public string OrderNumber { get; set; } | ||
|
||
/// <summary> | ||
/// Código de rastreio. | ||
/// </summary> | ||
[JsonProperty("tracking_code")] | ||
public string TrackingCode { get; set; } | ||
|
||
/// <summary> | ||
/// Número do volume. | ||
/// </summary> | ||
[JsonProperty("volume_number")] | ||
public string VolumeNumber { get; set; } | ||
|
||
/// <summary> | ||
/// Informações da nota fiscal | ||
/// </summary> | ||
[JsonProperty("invoice")] | ||
public ShipmentOrderVolumeInvoice Invoice { get; set; } | ||
|
||
/// <summary> | ||
/// Informações da nota fiscal | ||
/// </summary> | ||
[JsonProperty("history")] | ||
public History History { get; set; } | ||
|
||
public Tracking() | ||
{ | ||
History = new History(); | ||
Invoice = new ShipmentOrderVolumeInvoice(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using Intelipost.API.Model; | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading; | ||
using Newtonsoft.Json; | ||
|
||
namespace Intelipost.API | ||
{ | ||
/// <summary> | ||
/// Classe destinada a expor as informações da etiqueta. | ||
/// </summary> | ||
public class Tracking | ||
{ | ||
private HttpListener listener; | ||
|
||
/// <summary> | ||
/// Método que ativará um listener para receber as requisições do webhook | ||
/// </summary> | ||
/// <param name="url">Url definida para receber as requisições do webhook.</param> | ||
/// <returns>Retorna um objeto com as informações da requisição.</returns> | ||
|
||
public Tracking(string url) | ||
{ | ||
ThreadPool.SetMaxThreads(50, 1000); | ||
ThreadPool.SetMinThreads(50, 50); | ||
listener = new HttpListener(); | ||
listener.Prefixes.Add(url); | ||
listener.Start(); | ||
while (true) | ||
try | ||
{ | ||
HttpListenerContext request = listener.GetContext(); | ||
ThreadPool.QueueUserWorkItem(ProcessRequest, request); | ||
} | ||
catch (HttpListenerException) | ||
{ | ||
break; | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
|
||
public void Stop() { listener.Stop(); } | ||
|
||
void ProcessRequest(object listenerContext) | ||
{ | ||
try | ||
{ | ||
//Reading request | ||
var context = (HttpListenerContext)listenerContext; | ||
var postContent = new StreamReader(context.Request.InputStream).ReadToEnd(); | ||
context.Response.KeepAlive = false; | ||
|
||
//Response | ||
byte[] response = Encoding.UTF8.GetBytes(postContent); | ||
var output = context.Response.OutputStream; | ||
|
||
var objTrck = new Model.Tracking(); | ||
//Deserealizing request to object | ||
objTrck = JsonConvert.DeserializeObject<Model.Tracking>(postContent); | ||
|
||
if (objTrck != new Model.Tracking() && objTrck != null) | ||
{ | ||
output.Write(Encoding.UTF8.GetBytes("OK"), 0, Encoding.UTF8.GetBytes("OK").Length); | ||
context.Response.StatusCode = 200; | ||
} | ||
else | ||
{ | ||
output.Write(Encoding.UTF8.GetBytes("BAD REQUEST"), 0, Encoding.UTF8.GetBytes("BAD REQUEST").Length); | ||
context.Response.StatusCode = 400; | ||
} | ||
|
||
context.Response.Close(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine("Request error: " + ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Intelipost.API; | ||
|
||
|
||
namespace TestTracking | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Tracking tr = new Tracking("http://localhost:7777/"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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("TestTracking")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("TestTracking")] | ||
[assembly: AssemblyCopyright("Copyright © 2015")] | ||
[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("46c72389-3486-4a7b-a6db-28520c3c81f1")] | ||
|
||
// 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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{46C72389-3486-4A7B-A6DB-28520C3C81F1}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>TestTracking</RootNamespace> | ||
<AssemblyName>TestTracking</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</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="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Intelipost.API\Intelipost.API.csproj"> | ||
<Project>{d27837bd-5067-4c8b-acbf-51bd8b956737}</Project> | ||
<Name>Intelipost.API</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |