diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter.sln b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter.sln new file mode 100644 index 0000000..131620a --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsDataCenter", "WindowsDataCenter\WindowsDataCenter.csproj", "{A5FEE048-17A6-4966-9B6B-BF073592A470}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsDataServiceHost", "WindowsDataServiceHost\WindowsDataServiceHost.csproj", "{5A4E2CF2-FA51-413E-82C7-14A19A50766D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A5FEE048-17A6-4966-9B6B-BF073592A470}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A5FEE048-17A6-4966-9B6B-BF073592A470}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A5FEE048-17A6-4966-9B6B-BF073592A470}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A5FEE048-17A6-4966-9B6B-BF073592A470}.Release|Any CPU.Build.0 = Release|Any CPU + {5A4E2CF2-FA51-413E-82C7-14A19A50766D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A4E2CF2-FA51-413E-82C7-14A19A50766D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5A4E2CF2-FA51-413E-82C7-14A19A50766D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5A4E2CF2-FA51-413E-82C7-14A19A50766D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Program.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Program.cs new file mode 100644 index 0000000..122b841 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Program.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.ServiceProcess; +using System.Text; +using System.Threading.Tasks; + +namespace WindowsDataCenter +{ + 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/WindowsDataCenter/Properties/AssemblyInfo.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4172feb --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/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("WindowsDataCenter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WindowsDataCenter")] +[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("a5fee048-17a6-4966-9b6b-bf073592a470")] + +// 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/WindowsDataCenter/RestService_Get.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/RestService_Get.cs new file mode 100644 index 0000000..3d34e9d --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/RestService_Get.cs @@ -0,0 +1,56 @@ +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; +//using Devkoes.Restup.WebServer.Attributes; +//using Devkoes.Restup.WebServer.Models.Schemas; + +//namespace WebSocketService +//{ +// internal partial class RestService +// { +// [UriFormat("/users")] +// public GetResponse GetAllUsers() +// { +// var query = _conn.Table(); +// if (query.Any()) +// { +// return new GetResponse(GetResponse.ResponseStatus.OK, query.ToArray()); +// } +// return new GetResponse(GetResponse.ResponseStatus.NotFound); +// } + +// [UriFormat("/users?userid={id}")] +// public GetResponse GetUserById(int id) +// { +// var userQuery = _conn.Query( +// "select * from UserIdentity where Id = ?", +// id); +// if (userQuery.Any()) +// { +// return new GetResponse(GetResponse.ResponseStatus.OK, userQuery.First()); +// } +// return new GetResponse(GetResponse.ResponseStatus.NotFound); +// } + +// [UriFormat("/timelogs?userid={id}")] +// public GetResponse GetTimeLogsByUserId(int id) +// { +// var timeLogQuery = _conn.Query( +// "select * from TimeLog where UserId_FK = ?", +// id); +// if (timeLogQuery.Any()) +// { +// return new GetResponse(GetResponse.ResponseStatus.OK, timeLogQuery.ToArray()); +// } +// return new GetResponse(GetResponse.ResponseStatus.NotFound); +// } + +// [UriFormat("/stats")] +// public GetResponse GetTimeLogStatistics() +// { +// return new GetResponse(GetResponse.ResponseStatus.NotFound); +// } +// } +//} diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/RestService_Post.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/RestService_Post.cs new file mode 100644 index 0000000..8eccbe9 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/RestService_Post.cs @@ -0,0 +1,83 @@ +//using System; +//using System.Linq; +//using Devkoes.Restup.WebServer.Models.Schemas; +//using Devkoes.Restup.WebServer.Attributes; +//using System.IO; + +//namespace WebSocketService +//{ +// [RestController(InstanceCreationType.Singleton)] +// internal partial class RestService +// { +// private static SQLite.Net.SQLiteConnection _conn; +// private static string _path; + +// public RestService() +// { +// if (string.IsNullOrEmpty(_path)) +// _path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite"); +// if (_conn == null) +// { +// _conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), _path); +// _conn.CreateTable(); +// _conn.CreateTable(); +// } +// } + +// /// +// /// Make sure the number of parameters in your UriFormat match the parameters in your method and +// /// the names (case sensitive) and order are respected. +// /// +// [UriFormat("/simpleparameter/{id}/property/{propName}")] +// public GetResponse GetWithSimpleParameters(int id, string propName) +// { +// return new GetResponse( +// GetResponse.ResponseStatus.OK, +// new DataReceived() +// { +// ID = id, +// PropName = propName +// }); +// } + +// [UriFormat("/postTest")] +// public PostResponse Post([FromContent] DataReceived rcv) +// { +// return new PostResponse(PostResponse.ResponseStatus.Created, $"/simpleparameter/{rcv.ID}/property/{rcv.PropName}"); +// } + +// //This is the method you need. +// [UriFormat("/postSwipeData")] +// public PostResponse PostWeather([FromContent] CardDataPostDto cardData) +// { +// var userQuery = _conn.Query( +// "select * from UserIdentity where CardUId = ?", +// cardData.CardUId); + +// var userId = 0; +// if (!userQuery.Any()) +// { +// userId = _conn.Insert(new UserIdentity +// { +// CardUId = cardData.CardUId, +// FirstName = "?", +// LastName = "?", +// HoursPerWeek = 37.0f +// }); +// } +// else +// { +// userId = userQuery.First().Id; +// } + +// var timeLog = new TimeLog +// { +// SwipeEventDateTime = DateTime.UtcNow, +// UserId_FK = userId +// }; + +// var tLogId = _conn.Insert(timeLog); +// return new PostResponse(PostResponse.ResponseStatus.Created); +// } +// } +//} diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Service1.Designer.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Service1.Designer.cs new file mode 100644 index 0000000..264072a --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Service1.Designer.cs @@ -0,0 +1,37 @@ +namespace WindowsDataCenter +{ + 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/WindowsDataCenter/Service1.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Service1.cs new file mode 100644 index 0000000..6c74fff --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Service1.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.ServiceProcess; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Web.Http; +using Microsoft.Owin.Hosting; +using Owin; + +namespace WindowsDataCenter +{ + public partial class Service1: ServiceBase + { + public Service1() + { + InitializeComponent(); + } + + private IDisposable _webApp; + private bool _stopMainWorkerThread; + private Thread _mainWorkerThread; + + public void Start() + { + OnStart(new string[] {}); + } + + public void Stop() + { + OnStop(); + } + + protected override void OnStart(string[] args) + { + _mainWorkerThread = new Thread(MainWorkerThread) + { + IsBackground = false, + Name = "OWIN SELF HOST MAIN THREAD" + }; + _webApp = WebApp.Start("http://localhost:8800"); + } + + protected override void OnStop() + { + _webApp.Dispose(); + _stopMainWorkerThread = true; + if (_mainWorkerThread != null && _mainWorkerThread.IsAlive) + { + _mainWorkerThread.Join(2000); + if (_mainWorkerThread.IsAlive) + { + _mainWorkerThread.Interrupt(); + } + } + } + + private void MainWorkerThread() + { + while (!_stopMainWorkerThread) + { + Thread.Sleep(2000); + } + } + } + public class StartOwin + { + public void Configuration(IAppBuilder appBuilder) + { + var config = new HttpConfiguration(); + config.Routes.MapHttpRoute( + name: "DefaultApi", + routeTemplate: "api/{controller}/{id}", + defaults: new { id = RouteParameter.Optional } + ); + + appBuilder.UseWebApi(config); + } + } + + public class SwipeDataController : ApiController + { + [HttpPost] + //[Route("postSwipeData")] + public IHttpActionResult PostData([FromBody] CardData cData) + { + Console.WriteLine(cData.CardUId); + var respMsg = new HttpResponseMessage(HttpStatusCode.OK); + return ResponseMessage(respMsg); + } + } + + public class ValuesController : ApiController + { + public IEnumerable Get() + { + return new List { "ASP.NET", "Docker", "Windows Containers" }; + } + } + + public class UsersController : ApiController + { + public IHttpActionResult GetUsers() + { + throw new NotImplementedException(); + } + } + public class CardData + { + public string CardUId { get; set; } + } +} diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj new file mode 100644 index 0000000..e3aad17 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj @@ -0,0 +1,102 @@ + + + + + Debug + AnyCPU + {A5FEE048-17A6-4966-9B6B-BF073592A470} + WinExe + Properties + WindowsDataCenter + WindowsDataCenter + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll + True + + + ..\packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll + True + + + ..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll + True + + + ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll + True + + + ..\packages\Owin.1.0\lib\net40\Owin.dll + True + + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll + True + + + ..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll + True + + + + + + + + + + + + + + Component + + + Service1.cs + + + + + + + + + + + \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj.user b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj.user new file mode 100644 index 0000000..ca1d04b --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj.user @@ -0,0 +1,6 @@ + + + + ProjectFiles + + \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/packages.config b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/packages.config new file mode 100644 index 0000000..3de2560 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/Program.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/Program.cs new file mode 100644 index 0000000..3f57db9 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WindowsDataCenter; + +namespace WindowsDataServiceHost +{ + class Program + { + static void Main(string[] args) + { + var service = new Service1(); + service.Start(); + Console.WriteLine("Running DataService.."); + Console.ReadLine(); + service.Stop(); + } + } +} diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/Properties/AssemblyInfo.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..303630b --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/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("WindowsDataServiceHost")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WindowsDataServiceHost")] +[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("5a4e2cf2-fa51-413e-82c7-14a19a50766d")] + +// 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/WindowsDataServiceHost/WindowsDataServiceHost.csproj b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/WindowsDataServiceHost.csproj new file mode 100644 index 0000000..726578d --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/WindowsDataServiceHost.csproj @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {5A4E2CF2-FA51-413E-82C7-14A19A50766D} + Exe + Properties + WindowsDataServiceHost + WindowsDataServiceHost + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Owin.Host.HttpListener.3.0.1\lib\net45\Microsoft.Owin.Host.HttpListener.dll + True + + + + + + + + + + + + + + + + + + + + + + {A5FEE048-17A6-4966-9B6B-BF073592A470} + WindowsDataCenter + + + + + \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/packages.config b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/packages.config new file mode 100644 index 0000000..375a96f --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file