-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
a68e341
commit 8dcec4b
Showing
10 changed files
with
437 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeGuardServerAPI", "SafeGuardServerAPI\SafeGuardServerAPI.csproj", "{26473D92-174E-4252-82E0-1CCF7D63F3DB}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{26473D92-174E-4252-82E0-1CCF7D63F3DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{26473D92-174E-4252-82E0-1CCF7D63F3DB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{26473D92-174E-4252-82E0-1CCF7D63F3DB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{26473D92-174E-4252-82E0-1CCF7D63F3DB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
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,3 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue"><data><IncludeFilters /><ExcludeFilters /></data></s:String> | ||
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue"><data /></s:String></wpf:ResourceDictionary> |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<configSections> | ||
</configSections> | ||
<appSettings> | ||
<add key="SafeGuardURL" value="http://stagingsafeguard.herokuapp.com" /> | ||
<add key="ClientSettingsProvider.ServiceUri" value="" /> | ||
</appSettings> | ||
<system.web> | ||
<membership defaultProvider="ClientAuthenticationMembershipProvider"> | ||
<providers> | ||
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" /> | ||
</providers> | ||
</membership> | ||
<roleManager defaultProvider="ClientRoleProvider" enabled="true"> | ||
<providers> | ||
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" /> | ||
</providers> | ||
</roleManager> | ||
</system.web> | ||
</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,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Runtime.Serialization; | ||
|
||
namespace SafeGuardServerAPI | ||
{ | ||
[DataContract(Name = "locator")] | ||
public class Locator | ||
{ | ||
public Locator(String locator, String source, String destination, String origin, DateTime departureAt, DateTime arrivalAt, Boolean isInternational, List<Ticket> tickets) | ||
{ | ||
this.Loc = locator; | ||
this.Source = source; | ||
this.Destination = destination; | ||
this.Origin = origin; | ||
this.DepartureAt = departureAt; | ||
this.ArrivalAt = arrivalAt; | ||
this.IsInternational = isInternational; | ||
this.Tickets = tickets; | ||
} | ||
|
||
[DataMember(Name = "loc")] | ||
String Loc{set; get;} | ||
|
||
[DataMember(Name = "source")] | ||
String Source{set; get;} | ||
|
||
[DataMember(Name = "destination")] | ||
String Destination { set; get; } | ||
|
||
[DataMember(Name = "origin")] | ||
String Origin { set; get; } | ||
|
||
[DataMember(Name = "departure_at")] | ||
private String DepartureAtSerializable { set; get; } | ||
|
||
DateTime DepartureAt { set; get; } | ||
|
||
[DataMember(Name = "arrival_at")] | ||
private String ArrivalAtSerializable { set; get; } | ||
|
||
DateTime ArrivalAt { set; get; } | ||
|
||
[DataMember(Name = "is_international")] | ||
Boolean IsInternational { set; get; } | ||
|
||
[DataMember(Name = "tickets_attributes")] | ||
List<Ticket> Tickets { set; get; } | ||
|
||
[OnSerializing] | ||
void OnSerializing(StreamingContext context) | ||
{ | ||
this.DepartureAtSerializable = this.DepartureAt.ToString("yyyy/MM/dd HH:mm:ss zzz"); | ||
this.ArrivalAtSerializable = this.ArrivalAt.ToString("yyyy/MM/dd HH:mm:ss zzz"); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
SafeGuardServer.NetAPI/SafeGuardServerAPI/Properties/AssemblyInfo.cs
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("SafeGuardServerAPI")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("SafeGuardServerAPI")] | ||
[assembly: AssemblyCopyright("Copyright © 2013")] | ||
[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("bd0c7766-64f2-4604-bb50-f3d02d03cffa")] | ||
|
||
// 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.1.0.0")] | ||
[assembly: AssemblyFileVersion("1.1.0.0")] |
26 changes: 26 additions & 0 deletions
26
SafeGuardServer.NetAPI/SafeGuardServerAPI/Properties/Settings.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
SafeGuardServer.NetAPI/SafeGuardServerAPI/Properties/Settings.settings
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,5 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)"> | ||
<Profiles /> | ||
<Settings /> | ||
</SettingsFile> |
151 changes: 151 additions & 0 deletions
151
SafeGuardServer.NetAPI/SafeGuardServerAPI/SafeGuardClient.cs
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,151 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Net; | ||
using System.Web.Script.Serialization; | ||
using System.IO; | ||
using System.Configuration; | ||
using System.Runtime.Serialization.Json; | ||
|
||
namespace SafeGuardServerAPI | ||
{ | ||
public class SafeGuardClient | ||
{ | ||
private String Application; | ||
private String ApplicationToken; | ||
private String Url; | ||
|
||
private void SetParams(String application, String applicationToken, String serverURL) | ||
{ | ||
if (String.IsNullOrEmpty(application) || String.IsNullOrEmpty(applicationToken)) | ||
throw new Exception("It's manadtory to pass a valid application name, and application token"); | ||
this.Application = application; | ||
this.ApplicationToken = applicationToken; | ||
this.Url = serverURL; | ||
} | ||
|
||
public SafeGuardClient(String application, String applicationToken, String serverURL) | ||
{ | ||
SetParams(application, applicationToken, serverURL); | ||
} | ||
|
||
public SafeGuardClient(String application, String applicationToken) | ||
{ | ||
string url = ConfigurationManager.AppSettings["SafeGuardURL"]; | ||
SetParams(application, applicationToken, url); | ||
} | ||
|
||
public Boolean ContextMustUsehardwareToken(string context, string user) | ||
{ | ||
try | ||
{ | ||
string json = "{\"context\": \"" + context + "\", \"user\": \"" + user + "\"}"; | ||
return executePost("/context_must_use_hw_token.json", json); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw e; | ||
} | ||
} | ||
public Boolean ValidateTransactionToken(string token, string otp, string context, string user) | ||
{ | ||
try | ||
{ | ||
string json = "{\"token\": \"" + token + "\", \"otp\": \"" + otp + "\", \"context\": \"" + context + "\", \"user\": \"" + user + "\"}"; | ||
return executePost("/validate_transaction_token.json", json); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw e; | ||
} | ||
} | ||
|
||
public Boolean LogTicketsIssued(List<Locator> locators, String token) | ||
{ | ||
string json = ""; | ||
try | ||
{ | ||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(locators.GetType()); | ||
using (MemoryStream ms = new MemoryStream()) | ||
{ | ||
serializer.WriteObject(ms, locators); | ||
json = Encoding.Default.GetString(ms.ToArray()); | ||
} | ||
json = "{\"token\":\"" + token + "\", \"locators\":" + json + "}"; | ||
return executePost("/insert_issue_log_in_transaction_token.json", json); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw e; | ||
} | ||
} | ||
|
||
private Boolean executePost(String relativeURL, String body) | ||
{ | ||
var webRequest = GenerateWebRequest(relativeURL); | ||
webRequest.Method = "POST"; | ||
webRequest.ContentType = "application/json"; | ||
using (var writer = new StreamWriter(webRequest.GetRequestStream())) | ||
{ | ||
writer.Write(body); | ||
} | ||
|
||
try | ||
{ | ||
var webResponse = (HttpWebResponse)webRequest.GetResponse(); | ||
|
||
if (webResponse.StatusCode == HttpStatusCode.OK) | ||
return true; | ||
else | ||
return false; | ||
} | ||
catch (WebException we) | ||
{ | ||
if (((HttpWebResponse)we.Response).StatusCode == HttpStatusCode.NotFound) | ||
return false; | ||
else if (((HttpWebResponse)we.Response).StatusCode == HttpStatusCode.Forbidden) | ||
return false; | ||
else | ||
throw we; | ||
} | ||
|
||
} | ||
|
||
private Boolean executeGet(String relativeURL) | ||
{ | ||
var webRequest = GenerateWebRequest(relativeURL); | ||
|
||
webRequest.Method = "GET"; | ||
try | ||
{ | ||
var webResponse = (HttpWebResponse)webRequest.GetResponse(); | ||
|
||
if (webResponse.StatusCode == HttpStatusCode.OK) | ||
return true; | ||
else | ||
return false; | ||
} | ||
catch (WebException we) | ||
{ | ||
if (((HttpWebResponse)we.Response).StatusCode == HttpStatusCode.NotFound) | ||
return false; | ||
else if (((HttpWebResponse)we.Response).StatusCode == HttpStatusCode.Forbidden) | ||
return false; | ||
else | ||
throw we; | ||
} | ||
} | ||
|
||
private HttpWebRequest GenerateWebRequest(String relativeURL) | ||
{ | ||
System.Net.ServicePointManager.Expect100Continue = false; | ||
var webRequest = (HttpWebRequest)WebRequest.Create(Url + relativeURL); | ||
webRequest.Accept = "*/*"; | ||
webRequest.Headers.Add("Accept-Encoding", "gzip,deflate,sdch"); | ||
webRequest.Headers.Add("Accept-Language", "pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4"); | ||
webRequest.UserAgent = this.Application + "(" + this.ApplicationToken + ")"; | ||
return webRequest; | ||
} | ||
} | ||
} |
Oops, something went wrong.