diff --git a/sources/RoboforkApp.AWS/App.config b/sources/RoboforkApp.AWS/App.config new file mode 100644 index 0000000..a70df3f --- /dev/null +++ b/sources/RoboforkApp.AWS/App.config @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/sources/RoboforkApp.AWS/Contracts/ITableDataService.cs b/sources/RoboforkApp.AWS/Contracts/ITableDataService.cs new file mode 100644 index 0000000..571f2fb --- /dev/null +++ b/sources/RoboforkApp.AWS/Contracts/ITableDataService.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoboforkApp.AWS.Contracts +{ + public interface ITableDataService + { + void Store(T item) where T : new(); + void BatchStore(IEnumerable items) where T : class; + IEnumerable GetAll() where T : class; + T GetItem(string key) where T : class; + } +} diff --git a/sources/RoboforkApp.AWS/DynamoDb/DynamoService.cs b/sources/RoboforkApp.AWS/DynamoDb/DynamoService.cs new file mode 100644 index 0000000..92a2bc8 --- /dev/null +++ b/sources/RoboforkApp.AWS/DynamoDb/DynamoService.cs @@ -0,0 +1,109 @@ +using System.Collections.Generic; +using Amazon.DynamoDBv2; +using Amazon.DynamoDBv2.DataModel; +using RoboforkApp.AWS.Contracts; + +namespace RoboforkApp.AWS.DynamoDb +{ + public class DynamoService : ITableDataService + { + public readonly DynamoDBContext DbContext; + public AmazonDynamoDBClient DynamoClient; + + public DynamoService() + { + DynamoClient = new AmazonDynamoDBClient(); + + DbContext = new DynamoDBContext(DynamoClient, new DynamoDBContextConfig + { + //Setting the Consistent property to true ensures that you'll always get the latest + ConsistentRead = true, + SkipVersionCheck = true + }); + } + + /// + /// The Store method allows you to save a POCO to DynamoDb + /// + /// + /// + public void Store(T item) where T : new() + { + DbContext.Save(item); + } + + /// + /// The BatchStore Method allows you to store a list of items of type T to dynamoDb + /// + /// + /// + public void BatchStore(IEnumerable items) where T : class + { + var itemBatch = DbContext.CreateBatchWrite(); + + foreach (var item in items) + { + itemBatch.AddPutItem(item); + } + + itemBatch.Execute(); + } + /// + /// Uses the scan operator to retrieve all items in a table + /// [CAUTION] This operation can be very expensive if your table is large + /// + /// + /// + public IEnumerable GetAll() where T : class + { + IEnumerable items = DbContext.Scan(); + return items; + } + + /// + /// Retrieves an item based on a search key + /// + /// + /// + /// + public T GetItem(string key) where T : class + { + return DbContext.Load(key); + } + + /// + /// Method Updates and existing item in the table + /// + /// + /// + public void UpdateItem(T item) where T : class + { + T savedItem = DbContext.Load(item); + + if (savedItem == null) + { + throw new AmazonDynamoDBException("The item does not exist in the Table"); + } + + DbContext.Save(item); + } + + /// + /// Deletes an Item from the table. + /// + /// + /// + public void DeleteItem(T item) + { + var savedItem = DbContext.Load(item); + + if (savedItem == null) + { + throw new AmazonDynamoDBException("The item does not exist in the Table"); + } + + DbContext.Delete(item); + } + + } +} diff --git a/sources/RoboforkApp.AWS/Entities/DynamoTable.cs b/sources/RoboforkApp.AWS/Entities/DynamoTable.cs new file mode 100644 index 0000000..83e41cf --- /dev/null +++ b/sources/RoboforkApp.AWS/Entities/DynamoTable.cs @@ -0,0 +1,9 @@ +namespace RoboforkApp.AWS.Entities +{ + public class DynamoTable + { + public string PrimaryKey { get; set; } + public string HashKey { get; set; } + public string RangeKey { get; set; } + } +} diff --git a/sources/RoboforkApp.AWS/Properties/AssemblyInfo.cs b/sources/RoboforkApp.AWS/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e5facba --- /dev/null +++ b/sources/RoboforkApp.AWS/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("RoboforkApp.AWS")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("RoboforkApp.AWS")] +[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("9dfd12bf-548c-4489-8b66-5d7717541002")] + +// 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/sources/RoboforkApp.AWS/RoboforkApp.AWS.csproj b/sources/RoboforkApp.AWS/RoboforkApp.AWS.csproj new file mode 100644 index 0000000..c2a71fe --- /dev/null +++ b/sources/RoboforkApp.AWS/RoboforkApp.AWS.csproj @@ -0,0 +1,135 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {A4DB3A6A-7959-4517-844B-4D00AE09436C} + Library + Properties + RoboforkApp.AWS + RoboforkApp.AWS + v4.5 + 512 + false + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AllRules.ruleset + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + AllRules.ruleset + + + + + + + + + + + False + True + C:\Program Files (x86)\AWS SDK for .NET\bin\Net35\AWSSDK.Core.dll + + + False + True + C:\Program Files (x86)\AWS SDK for .NET\bin\Net35\AWSSDK.S3.dll + + + + + + + + C:\Program Files (x86)\AWS SDK for .NET\past-releases\Version-2\Net45\AWSSDK.dll + + + + + + + + + + + + + + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 2.0 %28x86%29 + true + + + False + .NET Framework 3.0 %28x86%29 + false + + + False + .NET Framework 3.5 + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + \ No newline at end of file diff --git a/sources/RoboforkApp/Entities/Fork2PC.cs b/sources/RoboforkApp/Entities/Fork2PC.cs new file mode 100644 index 0000000..644df77 --- /dev/null +++ b/sources/RoboforkApp/Entities/Fork2PC.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic; +using Amazon.DynamoDBv2.DataModel; + +namespace RoboforkApp.Entities +{ + [DynamoDBTable("Fork2PCTable")] + public class Fork2PC + { + // フォークリフトそれぞれの ID ※ID は”1”固定 + [DynamoDBHashKey] + public int ForkID { get; set; } + // 実舵角 ※10 進数 LSB 0.1 + public byte ang_str { get; set; } + // 駆動コントローラフェールフラグ + public byte fail_con1 { get; set; } + // ステアコントローラフェールフラグ + public byte fail_con2 { get; set; } + // ハンディコントローラのフェールフラグ + public byte fail_hand { get; set; } + // リフト高さセンサのフェールフラグ + public byte fail_high { get; set; } + // 走行モータのフェールフラグ + public byte fail_mot1 { get; set; } + // ステアモータのフェールフラグ + public byte fail_mot2 { get; set; } + // リフト油圧モータのフェールフラグ + public byte fail_mot3 { get; set; } + // 車速センサのフェールフラグ + public byte fail_spd { get; set; } + // 舵角センサのフェールフラグ + public byte fail_str { get; set; } + // 重度バッテリ低下フラグ + public byte flag_bat_hi { get; set; } + // 軽度バッテリ低下フラグ + public byte flag_bat_lo { get; set; } + // 緊急停止フラグ + public byte flag_emestp { get; set; } + // 軽度エラーフラグ + public byte flag_err1 { get; set; } + // 重度エラーフラグ + public byte flag_err2 { get; set; } + // ハンディ操作中フラグ + public byte flag_handy { get; set; } + // READY フラグ + public byte flag_ready { get; set; } + // スキャナによる停止中フラグ + public byte flag_stop { get; set; } + // 出発時点からの x 変位※10 進数 LSB 0.001 m ←GPS 使用 + public double ForkPos_x { get; set; } + // 出発地点からの y 変位 ※10 進数 LSB 0.001 m ←GPS 使用 + public double ForkPos_y { get; set; } + // 実リフト高さ ※10 進数 LSB 0.001 m + public double height_lift { get; set; } + // 実速度 ※10 進数 LSB 0.001m + public double spd_veh { get; set; } + // GPS データ ※GPRMC 方式 このデータのみ String + public string GPS_data { get; set; } + + //public override string ToString() + //{ + // return string.Format(@"{0} – {1} Actors: {2}", Title, ReleaseYear, string.Join(", ", ActorNames.ToArray())); + //} + } +} diff --git a/sources/RoboforkApp/Entities/Robofork15Demo.cs b/sources/RoboforkApp/Entities/Robofork15Demo.cs new file mode 100644 index 0000000..605dd35 --- /dev/null +++ b/sources/RoboforkApp/Entities/Robofork15Demo.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using Amazon.DynamoDBv2.DataModel; + +namespace RoboforkApp.Entities +{ + [DynamoDBTable("Robofork15Demo")] + public class Robofork15Demo + { + // フォークリフト毎の ID(No.)今回は"1"固定 + [DynamoDBHashKey] + public int ForkID { get; set; } + // ラストノードフラグ 最後のノードでは”1” + public byte LastNodeFlag { get; set; } + // スタート位置からのノードの ID + public int NodeID { get; set; } + // ノードの目標リフト高さ ※10 進数 LSB 0.001 m + public double NodeLftHeight { get; set; } + // スタート位置からの x 差分 ※10 進数 LSB 0.001 m + public double NodePos_x { get; set; } + // スタート位置からの y 差分 ※10 進数 LSB 0.001 m + public double NodePos_y { get; set; } + // ノードの目標速度 ※10 進数 LSB 0.001m + public double NodeVehSpd { get; set; } + // ノードの車両角度(前ノードとの差分) + public double NodeVehAng { get; set; } + } +} diff --git a/sources/RoboforkApp/Services/Fork2PCTableService.cs b/sources/RoboforkApp/Services/Fork2PCTableService.cs new file mode 100644 index 0000000..28f4f47 --- /dev/null +++ b/sources/RoboforkApp/Services/Fork2PCTableService.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using Amazon.DynamoDBv2; +using Amazon.DynamoDBv2.DocumentModel; +using Amazon.DynamoDBv2.Model; +using RoboforkApp.AWS.DynamoDb; +using RoboforkApp.Entities; + +namespace RoboforkApp.Services +{ + public class Fork2PCTableService + { + private readonly DynamoService _dynamoService; + + public Fork2PCTableService() + { + _dynamoService = new DynamoService(); + } + + /// + /// AddFork2PC will accept a Fork2PC object and creates an Item on Amazon DynamoDB + /// + /// + public void AddFork2PC(Fork2PC fork2PC) + { + _dynamoService.Store(fork2PC); + } + + /// + /// ModifyFork2PC tries to load an existing Fork2PC, modifies and saves it back. If the Item doesn’t exist, it raises an exception + /// + /// + public void ModifyFork2PC(Fork2PC fork2PC) + { + _dynamoService.UpdateItem(fork2PC); + } + + /// + /// GetALllFork2PCs will perform a Table Scan operation to return all the Fork2PCs + /// + /// + public IEnumerable GetAllFork2PCs() + { + return _dynamoService.GetAll(); + } + + /// + /// SearchFork2PCs will search all data Fork2PCs with id + /// + /// + /// + /// + public IEnumerable SearchFork2PCs(int forkId) + { + IEnumerable filteredFork2PCs = _dynamoService.DbContext.Query(forkId, QueryOperator.Equal); + + return filteredFork2PCs; + } + + /// + /// Delete Fork2PC will remove an item from DynamoDb + /// + /// + public void DeleteFork2PC(Fork2PC fork2PC) + { + _dynamoService.DeleteItem(fork2PC); + } + } +} diff --git a/sources/RoboforkApp/Services/Robofork15DemoService.cs b/sources/RoboforkApp/Services/Robofork15DemoService.cs new file mode 100644 index 0000000..8c032d5 --- /dev/null +++ b/sources/RoboforkApp/Services/Robofork15DemoService.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using Amazon.DynamoDBv2; +using Amazon.DynamoDBv2.DocumentModel; +using Amazon.DynamoDBv2.Model; +using RoboforkApp.AWS.DynamoDb; +using RoboforkApp.Entities; + +namespace RoboforkApp.Services +{ + public class Robofork15DemoService + { + private readonly DynamoService _dynamoService; + + public Robofork15DemoService() + { + _dynamoService = new DynamoService(); + } + + /// + /// AddRobofork15Demo will accept a Robofork15Demo object and creates an Item on Amazon DynamoDB + /// + /// + public void AddRobofork15Demo(Robofork15Demo robofork15Demo) + { + _dynamoService.Store(robofork15Demo); + } + + /// + /// ModifyRobofork15Demo tries to load an existing Robofork15Demo, modifies and saves it back. If the Item doesn’t exist, it raises an exception + /// + /// + public void ModifyRobofork15Demo(Robofork15Demo robofork15Demo) + { + _dynamoService.UpdateItem(robofork15Demo); + } + + /// + /// GetALllRobofork15Demos will perform a Table Scan operation to return all the Robofork15Demos + /// + /// + public IEnumerable GetAllRobofork15Demos() + { + return _dynamoService.GetAll(); + } + + /// + /// SearchRobofork15Demos will search all data Robofork15Demos with id + /// + /// Fork Id + /// + public IEnumerable SearchRobofork15Demos(int forkId) + { + IEnumerable filteredRobofork15Demos = _dynamoService.DbContext.Query(forkId, QueryOperator.Equal); + + return filteredRobofork15Demos; + } + + /// + /// Delete Robofork15Demo will remove an item from DynamoDb + /// + /// + public void DeleteRobofork15Demo(Robofork15Demo robofork15Demo) + { + _dynamoService.DeleteItem(robofork15Demo); + } + } +}