diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/App.config b/DataCenter_Windows/WindowsDataCenter/CardReaderService/App.config
new file mode 100644
index 0000000..da9bca9
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/App.config
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/CardReaderService.csproj b/DataCenter_Windows/WindowsDataCenter/CardReaderService/CardReaderService.csproj
new file mode 100644
index 0000000..2b37206
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/CardReaderService.csproj
@@ -0,0 +1,79 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {5F30E8E4-5107-4C99-ADFF-38D735DC113D}
+ WinExe
+ Properties
+ CardReaderService
+ CardReaderService
+ v4.5.2
+ 512
+ true
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
+ True
+
+
+ packages\PCSC.3.6.0\lib\net40\pcsc-sharp.dll
+ True
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Component
+
+
+ Service1.cs
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/ConfigureService.cs b/DataCenter_Windows/WindowsDataCenter/CardReaderService/ConfigureService.cs
new file mode 100644
index 0000000..ca79e0b
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/ConfigureService.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CardReaderService
+{
+ internal static class ConfigureService
+ {
+ internal static void Configure()
+ {
+ //try
+ //{
+ // HostFactory.Run(configure =>
+ // {
+ // configure.Service(service =>
+ // {
+ // service.ConstructUsing(s => new Service1());
+ // service.WhenStarted(s => s.Start());
+ // service.WhenStopped(s => s.Stop());
+ // });
+ // //Setup Account that window service use to run.
+ // configure.RunAsLocalSystem();
+ // configure.SetServiceName("MyWindowServiceWithTopshelf");
+ // configure.SetDisplayName("MyWindowServiceWithTopshelf");
+ // configure.SetDescription("My .Net windows service with Topshelf");
+ // });
+ //}
+ //catch (Exception ex)
+ //{
+
+ // throw;
+ //}
+ }
+ }
+}
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/DataCenterHelper.cs b/DataCenter_Windows/WindowsDataCenter/CardReaderService/DataCenterHelper.cs
new file mode 100644
index 0000000..6180064
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/DataCenterHelper.cs
@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+
+namespace CardReaderService
+{
+ static class DataCenterHelper
+ {
+ public static void Post(CardDataPost postObject, string url)
+ {
+ var endpointConfig = ConfigurationManager.AppSettings["DataCenterServiceEndpoint"] ??
+ "http://localhost:8800";
+
+ using (var client = new HttpClient())
+ {
+ var jsonObject = JsonConvert.SerializeObject(postObject);
+ var content = new StringContent(jsonObject, Encoding.UTF8, "application/json");
+ try
+ {
+ Console.WriteLine("Writing");
+ var fullUrl = endpointConfig + url;
+ var response = client.PostAsync(fullUrl, content).Result;
+ Console.WriteLine("Written");
+ }
+ catch (Exception)
+ {
+ Console.WriteLine("exceptioning");
+ //ignore
+ }
+ }
+ }
+
+ public static Task PostAsync(CardDataPost postObject, string url)
+ {
+ return Task.Run(() => Post(postObject, url));
+ }
+ }
+
+ public class CardDataPost
+ {
+ public string CardUId { get; set; }
+ }
+}
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/Program.cs b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Program.cs
new file mode 100644
index 0000000..11b56f1
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Program.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.ServiceProcess;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Xsl;
+
+namespace CardReaderService
+{
+ static class Program
+ {
+ ///
+ /// The main entry point for the application.
+ ///
+ static void Main()
+ {
+ ServiceBase[] ServicesToRun;
+ ServicesToRun = new ServiceBase[]
+ {
+ new Service1()
+ };
+ ServiceBase.Run(ServicesToRun);
+ }
+ }
+}
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/Properties/AssemblyInfo.cs b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..e6f4bb0
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Properties/AssemblyInfo.cs
@@ -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("CardReaderService")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("CardReaderService")]
+[assembly: AssemblyCopyright("Copyright © 2017")]
+[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("5f30e8e4-5107-4c99-adff-38d735dc113d")]
+
+// 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")]
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/Service1.Designer.cs b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Service1.Designer.cs
new file mode 100644
index 0000000..5e4d6a9
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Service1.Designer.cs
@@ -0,0 +1,37 @@
+namespace CardReaderService
+{
+ partial class Service1
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ components = new System.ComponentModel.Container();
+ this.ServiceName = "Service1";
+ }
+
+ #endregion
+ }
+}
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/Service1.cs b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Service1.cs
new file mode 100644
index 0000000..971ea0b
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Service1.cs
@@ -0,0 +1,155 @@
+using PCSC;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.ServiceProcess;
+using System.Text;
+using System.Threading;
+
+namespace CardReaderService
+{
+ public partial class Service1 : ServiceBase
+ {
+ private Thread _mainWorkThread;
+ private bool _stopMainWorkerThread;
+
+ private string _readerName = "";
+ //private SCardReader _reader;
+ private SCardMonitor _cardMonitor;
+
+ public Service1()
+ {
+ InitializeComponent();
+ }
+
+ public void Start()
+ {
+ OnStart(new string[] {});
+ }
+//
+ protected override void OnStart(string[] args)
+ {
+ Console.WriteLine("Starting.. Getting available readers");
+ var ctxFactory = ContextFactory.Instance;
+ using(var context = ctxFactory.Establish(SCardScope.System))
+ {
+ var readerNames = context.GetReaders();
+ if (NoReaderAvailable(readerNames))
+ {
+ Console.WriteLine("No Card Reader is available, Exiting..");
+ return;
+ }
+ Console.WriteLine("Choosing first available reader: " + readerNames.First());
+ _readerName = readerNames.First();
+ _cardMonitor = new SCardMonitor(ctxFactory, SCardScope.System);
+ _cardMonitor.CardInserted += _cardMonitor_CardInserted;
+ _cardMonitor.Start(_readerName);
+
+ StartWorkerThread();
+ }
+ }
+
+ public void Stop()
+ {
+ OnStop();
+ }
+
+ protected override void OnStop()
+ {
+ _stopMainWorkerThread = true;
+ if (_mainWorkThread!= null && _mainWorkThread.IsAlive)
+ {
+ _mainWorkThread.Join(3000);
+ if (_mainWorkThread.IsAlive)
+ {
+ _mainWorkThread.Interrupt();
+ }
+ }
+ if (_cardMonitor != null)
+ {
+ _cardMonitor.Cancel();
+ _cardMonitor.Dispose();
+ _cardMonitor = null;
+ }
+ }
+
+ private void StartWorkerThread()
+ {
+ _stopMainWorkerThread = false;
+ _mainWorkThread = new Thread(MainWorkerThread)
+ {
+ Name = "CardServiceMainThread",
+ IsBackground = false
+ };
+ _mainWorkThread.Start();
+ }
+
+ private void _cardMonitor_CardInserted(object sender, CardStatusEventArgs e)
+ {
+ var ctxFac = ContextFactory.Instance;
+ using (var ctx = ctxFac.Establish(SCardScope.System))
+ {
+ var reader = new SCardReader(ctx);
+ var pioSendPci = new IntPtr();
+ byte[] rcvBuffer = new byte[256];
+
+ if (_readerName == string.Empty)
+ {
+ Console.WriteLine("Reader name is somehow empty... WTF!");
+ _stopMainWorkerThread = true;
+ return;
+ }
+
+ var err = reader.Connect(_readerName, SCardShareMode.Shared, SCardProtocol.T0 | SCardProtocol.T1);
+
+ if (err == SCardError.Success)
+ {
+ var uIdcmd = new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x00 };
+
+ err = reader.Transmit(pioSendPci, uIdcmd, ref rcvBuffer);
+ if (err == SCardError.Success)
+ {
+ var uid = ConvertByteUIDToString(rcvBuffer);
+ var atrString = ConvertByteUIDToString(e.Atr);
+ Console.WriteLine("Card Inserted, ATR: " + atrString + ", and UID is: " + uid);
+
+ CardDataPost postObj = new CardDataPost {CardUId = uid};
+ DataCenterHelper.PostAsync(postObj, "/api/swipedata");
+ Console.WriteLine("Posted to Server");
+ }
+ }
+ else
+ {
+ Console.WriteLine("Reader failed to connect, error: " + Enum.GetName(typeof(SCardError), err));
+ }
+
+ }
+ }
+
+ private void MainWorkerThread()
+ {
+ while (!_stopMainWorkerThread)
+ {
+ //dont actually need to do anything.. but cannot exit right away?
+ Thread.Sleep(3000);
+ }
+ }
+
+ private string ConvertByteUIDToString(byte[] uid)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ foreach(var b in uid)
+ {
+ sb.AppendFormat("{0:X2}", b);
+ }
+
+ return sb.ToString();
+ }
+
+ private bool NoReaderAvailable(ICollection readerNames)
+ {
+ return readerNames == null || readerNames.Count < 1;
+ }
+ }
+}
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/packages.config b/DataCenter_Windows/WindowsDataCenter/CardReaderService/packages.config
new file mode 100644
index 0000000..b8ef0ce
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/packages.config
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/App.config b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/App.config
new file mode 100644
index 0000000..88fa402
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/CardReaderServiceHost.csproj b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/CardReaderServiceHost.csproj
new file mode 100644
index 0000000..44c5609
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/CardReaderServiceHost.csproj
@@ -0,0 +1,72 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {6E48913F-9D8C-4132-93A7-C7B1C6DD5264}
+ Exe
+ Properties
+ CardReaderServiceHost
+ CardReaderServiceHost
+ v4.5.2
+ 512
+ true
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\CardReaderService\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
+ True
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {5f30e8e4-5107-4c99-adff-38d735dc113d}
+ CardReaderService
+
+
+
+
+
\ No newline at end of file
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/Program.cs b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/Program.cs
new file mode 100644
index 0000000..fc8886a
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/Program.cs
@@ -0,0 +1,17 @@
+using System;
+using CardReaderService;
+
+namespace CardReaderServiceHost
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Service1 service1 = new Service1();
+ service1.Start();
+ Console.WriteLine("Service Running...");
+ Console.ReadLine();
+ service1.Stop();
+ }
+ }
+}
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/Properties/AssemblyInfo.cs b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..be4e655
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/Properties/AssemblyInfo.cs
@@ -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("CardReaderServiceHost")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("CardReaderServiceHost")]
+[assembly: AssemblyCopyright("Copyright © 2017")]
+[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("6e48913f-9d8c-4132-93a7-c7b1c6dd5264")]
+
+// 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")]
diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/packages.config b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/packages.config
new file mode 100644
index 0000000..9d64bf3
--- /dev/null
+++ b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceHost/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file