aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-16 18:32:04 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-16 18:32:04 +0200
commit6f0f2a7908884deab8aca33ec967d03c5e564060 (patch)
treeb9d3e7efa91e8b3ac597dc1a824dd3a6175e16d4 /Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore
parentc39d31f1095bda6bda2755100f9f8df3da1eb93d (diff)
downloadTango-6f0f2a7908884deab8aca33ec967d03c5e564060.tar.gz
Tango-6f0f2a7908884deab8aca33ec967d03c5e564060.zip
Working on DataStore WebAPI.
Modified data store bytes parsing to Base64.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs33
1 files changed, 33 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs
index ce8e42e35..41fb21498 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs
@@ -68,6 +68,7 @@ namespace Tango.PPC.Common.DataStore
[ExternalBridgeRequestHandlerMethod(typeof(RemoteDataStorePutRequest), RequestHandlerLoggingMode.LogRequestName)]
public async Task OnRemoteDataStorePutRequest(RemoteDataStorePutRequest request, String token, ExternalBridgeReceiver receiver)
{
+ ValidateCollectionAndKey(request.Collection, request.Key);
GetManager().GetCollection(request.Collection).Put(request.Key, request.Value);
await receiver.SendGenericResponse(new RemoteDataStorePutResponse(), token);
}
@@ -75,6 +76,8 @@ namespace Tango.PPC.Common.DataStore
[ExternalBridgeRequestHandlerMethod(typeof(RemoteDataStoreGetRequest), RequestHandlerLoggingMode.LogRequestName)]
public async Task OnRemoteDataStoreGetRequest(RemoteDataStoreGetRequest request, String token, ExternalBridgeReceiver receiver)
{
+ ValidateCollectionAndKey(request.Collection, request.Key);
+
if (request.DefaultValue is JObject obj)
{
request.DefaultValue = DataStoreProtoObject.FromJObject(obj);
@@ -91,6 +94,8 @@ namespace Tango.PPC.Common.DataStore
[ExternalBridgeRequestHandlerMethod(typeof(RemoteDataStoreGetItemRequest), RequestHandlerLoggingMode.LogRequestName)]
public async Task OnRemoteDataStoreGetItemRequest(RemoteDataStoreGetItemRequest request, String token, ExternalBridgeReceiver receiver)
{
+ ValidateCollectionAndKey(request.Collection, request.Key);
+
if (request.DefaultValue is JObject obj)
{
request.DefaultValue = DataStoreProtoObject.FromJObject(obj);
@@ -195,6 +200,11 @@ namespace Tango.PPC.Common.DataStore
foreach (var item in request.ToUpsert)
{
+ ValidateCollectionAndKey(item.CollectionName, item.Key);
+ }
+
+ foreach (var item in request.ToUpsert)
+ {
var itemDb = allItems.FirstOrDefault(x => x.CollectionName == item.CollectionName && x.Key == item.Key);
if (itemDb == null)
@@ -270,6 +280,8 @@ namespace Tango.PPC.Common.DataStore
{
try
{
+ ValidateCollectionAndKey(request.Collection, request.Key);
+
GetManager().GetCollection(request.Collection).Put(request.Key, GetPMRValue(request.Item));
await transporter.SendResponse(new PutDataStoreItemResponse(), token);
@@ -324,6 +336,8 @@ namespace Tango.PPC.Common.DataStore
{
try
{
+ ValidateCollectionAndKey(request.Collection, request.Key);
+
var item = GetManager().GetCollection(request.Collection).GetItem(request.Key, GetPMRValue(request.DefaultItem));
await transporter.SendResponse(new GetDataStoreItemResponse()
{
@@ -429,6 +443,25 @@ namespace Tango.PPC.Common.DataStore
#endregion
+ private void ValidateCollectionAndKey(String collection = null, String key = null)
+ {
+ if (collection != null)
+ {
+ if (!DataStoreHelper.ValidateCollectionOrKeyName(collection))
+ {
+ throw new ArgumentException("Collection name contains invalid characters.");
+ }
+ }
+
+ if (key != null)
+ {
+ if (!DataStoreHelper.ValidateCollectionOrKeyName(key))
+ {
+ throw new ArgumentException("Item key contains invalid characters.");
+ }
+ }
+ }
+
public void OnReceiverDisconnected(ExternalBridgeReceiver receiver)
{
//Do nothing.