@@ -716,11 +716,14 @@ public static Blockchain GetChain(string DeviceID)
716
716
return oChain ;
717
717
}
718
718
719
- public static string UploadFull ( string JSON , string DeviceID )
719
+ public static string UploadFull ( string JSON , string DeviceID , string blockType = "" )
720
720
{
721
721
if ( ReadOnly )
722
722
return "" ;
723
723
724
+ if ( string . IsNullOrEmpty ( blockType ) )
725
+ blockType = BlockType ;
726
+
724
727
try
725
728
{
726
729
JObject oObj = JObject . Parse ( JSON ) ;
@@ -894,6 +897,8 @@ public static string UploadFull(string JSON, string DeviceID)
894
897
oStatic . AddFirst ( new JProperty ( "_date" , new DateTime ( oNew . timestamp ) . ToUniversalTime ( ) ) ) ;
895
898
if ( oStatic [ "_index" ] == null )
896
899
oStatic . AddFirst ( new JProperty ( "_index" , oNew . index ) ) ;
900
+ if ( oStatic [ "_type" ] == null )
901
+ oStatic . AddFirst ( new JProperty ( "_type" , blockType ) ) ;
897
902
if ( oStatic [ "#id" ] == null )
898
903
oStatic . AddFirst ( new JProperty ( "#id" , DeviceID ) ) ;
899
904
@@ -903,12 +908,19 @@ public static string UploadFull(string JSON, string DeviceID)
903
908
jTemp . AddFirst ( new JProperty ( "_hash" , oNew . data ) ) ;
904
909
if ( jTemp [ "_date" ] == null )
905
910
jTemp . AddFirst ( new JProperty ( "_date" , new DateTime ( oNew . timestamp ) . ToUniversalTime ( ) ) ) ;
911
+ if ( jTemp [ "_type" ] == null )
912
+ jTemp . AddFirst ( new JProperty ( "_type" , blockType ) ) ;
906
913
if ( jTemp [ "#id" ] == null )
907
914
jTemp . AddFirst ( new JProperty ( "#id" , DeviceID ) ) ;
908
915
909
916
//JSort(jTemp);
910
917
if ( ! UseCosmosDB )
911
- WriteHashAsync ( DeviceID , jTemp . ToString ( Formatting . None ) , "_Full" ) ;
918
+ {
919
+ if ( blockType == BlockType )
920
+ WriteHashAsync ( DeviceID , jTemp . ToString ( Formatting . None ) , "_Full" ) ;
921
+ else
922
+ WriteHashAsync ( DeviceID + "_" + blockType , jTemp . ToString ( Formatting . None ) , "_Full" ) ;
923
+ }
912
924
else
913
925
{
914
926
//No need to save cached document when using CosmosDB
@@ -923,7 +935,12 @@ public static string UploadFull(string JSON, string DeviceID)
923
935
924
936
//JSort(oStatic);
925
937
if ( ! UseCosmosDB )
926
- WriteHashAsync ( sResult , oStatic . ToString ( Newtonsoft . Json . Formatting . None ) , "Assets" ) ;
938
+ {
939
+ if ( blockType == BlockType )
940
+ WriteHashAsync ( sResult , oStatic . ToString ( Newtonsoft . Json . Formatting . None ) , "Assets" ) ;
941
+ else
942
+ WriteHashAsync ( sResult + "_" + blockType , oStatic . ToString ( Newtonsoft . Json . Formatting . None ) , "Assets" ) ;
943
+ }
927
944
else
928
945
{
929
946
//On CosmosDB, store full document as Asset
@@ -943,23 +960,36 @@ public static string UploadFull(string JSON, string DeviceID)
943
960
return "" ;
944
961
}
945
962
946
- public static JObject GetFull ( string DeviceID , int Index = - 1 )
963
+ public static JObject GetFull ( string DeviceID , int Index = - 1 , string blockType = "" )
947
964
{
948
965
try
949
966
{
950
967
JObject oInv = new JObject ( ) ;
951
968
969
+ if ( string . IsNullOrEmpty ( blockType ) )
970
+ blockType = BlockType ;
971
+
952
972
if ( Index == - 1 )
953
973
{
954
- string sFull = ReadHash ( DeviceID , "_Full" ) ;
974
+ string sFull = "" ;
975
+ if ( blockType == BlockType )
976
+ sFull = ReadHash ( DeviceID , "_Full" ) ;
977
+ else
978
+ sFull = ReadHash ( DeviceID + "_" + blockType , "_Full" ) ;
979
+
955
980
if ( ! string . IsNullOrEmpty ( sFull ) )
956
981
{
957
982
return JObject . Parse ( sFull ) ;
958
983
}
959
984
}
960
985
961
- JObject oRaw = GetRawId ( DeviceID , Index ) ;
962
- string sData = ReadHash ( oRaw [ "_hash" ] . ToString ( ) , "Assets" ) ;
986
+ JObject oRaw = GetRawId ( DeviceID , Index , blockType ) ;
987
+
988
+ string sData = "" ;
989
+ if ( blockType == BlockType )
990
+ sData = ReadHash ( oRaw [ "_hash" ] . ToString ( ) , "_Assets" ) ;
991
+ else
992
+ sData = ReadHash ( oRaw [ "_hash" ] . ToString ( ) + "_" + blockType , "_Assets" ) ;
963
993
964
994
if ( ! UseCosmosDB )
965
995
{
@@ -1141,10 +1171,13 @@ public static JObject GetFull(string DeviceID, int Index = -1)
1141
1171
return new JObject ( ) ;
1142
1172
}
1143
1173
1144
- public static JObject GetRawId ( string DeviceID , int Index = - 1 )
1174
+ public static JObject GetRawId ( string DeviceID , int Index = - 1 , string blockType = "" )
1145
1175
{
1146
1176
JObject jResult = new JObject ( ) ;
1147
1177
1178
+ if ( string . IsNullOrEmpty ( blockType ) )
1179
+ blockType = BlockType ;
1180
+
1148
1181
try
1149
1182
{
1150
1183
Blockchain oChain ;
@@ -1154,13 +1187,13 @@ public static JObject GetRawId(string DeviceID, int Index = -1)
1154
1187
if ( Index == - 1 )
1155
1188
{
1156
1189
oChain = GetChain ( DeviceID ) ;
1157
- lBlock = oChain . GetLastBlock ( ) ;
1190
+ lBlock = oChain . GetLastBlock ( blockType ) ;
1158
1191
1159
1192
}
1160
1193
else
1161
1194
{
1162
1195
oChain = GetChain ( DeviceID ) ;
1163
- lBlock = oChain . GetBlock ( Index ) ;
1196
+ lBlock = oChain . GetBlock ( Index , blockType ) ;
1164
1197
}
1165
1198
1166
1199
@@ -1177,15 +1210,19 @@ public static JObject GetRawId(string DeviceID, int Index = -1)
1177
1210
return jResult ;
1178
1211
}
1179
1212
1180
- public static JObject GetHistory ( string DeviceID )
1213
+ public static JObject GetHistory ( string DeviceID , string blockType = "" )
1181
1214
{
1182
1215
JObject jResult = new JObject ( ) ;
1216
+
1217
+ if ( string . IsNullOrEmpty ( blockType ) )
1218
+ blockType = BlockType ;
1219
+
1183
1220
try
1184
1221
{
1185
1222
1186
1223
string sChain = ReadHash ( DeviceID , "Chain" ) ;
1187
1224
var oChain = JsonConvert . DeserializeObject < Blockchain > ( sChain ) ;
1188
- foreach ( block oBlock in oChain . Chain . Where ( t => t . blocktype != "root" ) )
1225
+ foreach ( block oBlock in oChain . Chain . Where ( t => t . blocktype == blockType ) )
1189
1226
{
1190
1227
try
1191
1228
{
@@ -1272,8 +1309,11 @@ public static JObject GetRaw(string RawID, string path = "")
1272
1309
return jResult ;
1273
1310
}
1274
1311
1275
- public static JObject GetDiff ( string DeviceId , int IndexLeft , int mode = - 1 , int IndexRight = - 1 )
1312
+ public static JObject GetDiff ( string DeviceId , int IndexLeft , int mode = - 1 , int IndexRight = - 1 , string blockType = "" )
1276
1313
{
1314
+ if ( string . IsNullOrEmpty ( blockType ) )
1315
+ blockType = BlockType ;
1316
+
1277
1317
try
1278
1318
{
1279
1319
var right = GetFull ( DeviceId , IndexRight ) ;
0 commit comments