Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
New Tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerioms committed Aug 26, 2015
1 parent 6ad3de2 commit 45ad0ce
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Intelipost/Intelipost.API/Intelipost.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="Business\ShipmentOrder.cs" />
<Compile Include="Configure.cs" />
<Compile Include="AutoComplete.cs" />
<Compile Include="Tracking.cs" />
<Compile Include="Info.cs" />
<Compile Include="GetShipmentOder.cs" />
<Compile Include="Infrastructure\CustomConverter\TimestampToDateTime.cs" />
Expand Down Expand Up @@ -86,6 +87,8 @@
<Compile Include="Model\ShipmentOrder\ShipmentOrderVolumeArray.cs" />
<Compile Include="Model\ShipmentOrder\ShipmentOrderVolumeInvoice.cs" />
<Compile Include="Model\Quote\Volume.cs" />
<Compile Include="Model\Tracking\History.cs" />
<Compile Include="Model\Tracking\Tracking.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GetLabel.cs" />
<Compile Include="QuoteByProduct.cs" />
Expand All @@ -98,6 +101,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<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.
Expand Down
67 changes: 67 additions & 0 deletions Intelipost/Intelipost.API/Model/Tracking/History.cs
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; }

}
}
51 changes: 51 additions & 0 deletions Intelipost/Intelipost.API/Model/Tracking/Tracking.cs
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();
}
}
}
86 changes: 86 additions & 0 deletions Intelipost/Intelipost.API/Tracking.cs
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ C:\Users\user\Documents\GitHub\Intelipost\api-dotnet\Intelipost\Intelipost.API\b
C:\Users\user\Documents\GitHub\Intelipost\api-dotnet\Intelipost\Intelipost.API\bin\Debug\Newtonsoft.Json.xml
C:\Users\user\Documents\GitHub\Intelipost\api-dotnet\Intelipost\Intelipost.API\obj\Debug\Intelipost.API.dll
C:\Users\user\Documents\GitHub\Intelipost\api-dotnet\Intelipost\Intelipost.API\obj\Debug\Intelipost.API.pdb
C:\Users\user\Documents\GitHub\Intelipost\api-dotnet\Intelipost\Intelipost.API\obj\Debug\Intelipost.API.csprojResolveAssemblyReference.cache
7 changes: 7 additions & 0 deletions Intelipost/Intelipost.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1 - Test Layer", "1 - Test
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intelipost.UnitTest", "Intelipost.UnitTest\Intelipost.UnitTest.csproj", "{4991225A-6CF9-4768-B066-16EA00DA60A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTracking", "TestTracking\TestTracking.csproj", "{46C72389-3486-4A7B-A6DB-28520C3C81F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -26,13 +28,18 @@ Global
{4991225A-6CF9-4768-B066-16EA00DA60A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4991225A-6CF9-4768-B066-16EA00DA60A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4991225A-6CF9-4768-B066-16EA00DA60A4}.Release|Any CPU.Build.0 = Release|Any CPU
{46C72389-3486-4A7B-A6DB-28520C3C81F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46C72389-3486-4A7B-A6DB-28520C3C81F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46C72389-3486-4A7B-A6DB-28520C3C81F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46C72389-3486-4A7B-A6DB-28520C3C81F1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D27837BD-5067-4C8B-ACBF-51BD8B956737} = {7F7CC6AD-A8F1-4BEF-AFFA-BB07A492A398}
{4991225A-6CF9-4768-B066-16EA00DA60A4} = {21751A4A-1B09-46E4-9923-DE6455B854BB}
{46C72389-3486-4A7B-A6DB-28520C3C81F1} = {21751A4A-1B09-46E4-9923-DE6455B854BB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
BuildVersion_BuildVersioningStyle = DeltaBaseYear.DayStamp.Increment.Increment
Expand Down
6 changes: 6 additions & 0 deletions Intelipost/TestTracking/App.config
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>
18 changes: 18 additions & 0 deletions Intelipost/TestTracking/Program.cs
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/");
}
}
}
36 changes: 36 additions & 0 deletions Intelipost/TestTracking/Properties/AssemblyInfo.cs
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")]
66 changes: 66 additions & 0 deletions Intelipost/TestTracking/TestTracking.csproj
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>

0 comments on commit 45ad0ce

Please sign in to comment.