diff --git a/.vscode/launch.json b/.vscode/launch.json index 4dc08fbbe..bbb0d3a44 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -142,7 +142,7 @@ "name": "Excel Launch", "type": "clr", "request": "launch", - "program": "C:/Program Files/Microsoft Office/Office14/EXCEL.EXE", + "program": "C:/Program Files/Microsoft Office/Office16/EXCEL.EXE", "args": [ "${workspaceRoot}/build/Debug/bin/net471/spark_excel-addin64-packed.xll" ], diff --git a/src/client/spark_excel/historical_query.xlsm b/src/client/spark_excel/historical_query.xlsm index 4de72045d..78e1edb49 100644 Binary files a/src/client/spark_excel/historical_query.xlsm and b/src/client/spark_excel/historical_query.xlsm differ diff --git a/src/client/spark_excel/utils/APIDispatch.cs b/src/client/spark_excel/utils/APIDispatch.cs index 0ee92b3a1..6b584d8ba 100644 --- a/src/client/spark_excel/utils/APIDispatch.cs +++ b/src/client/spark_excel/utils/APIDispatch.cs @@ -90,7 +90,14 @@ namespace bts.excel { if(string.IsNullOrEmpty(json)) json = "{}"; - request = JsonParser.Default.Parse(json, desc); + try + { + request = JsonParser.Default.Parse(json, desc); + } + catch(InvalidProtocolBufferException) + { + request = (IMessage) Newtonsoft.Json.JsonConvert.DeserializeObject(json, desc.ClrType); + } } } return request; diff --git a/src/client/spark_excel/utils/Utilities.cs b/src/client/spark_excel/utils/Utilities.cs index 99d0d7925..4e109d006 100644 --- a/src/client/spark_excel/utils/Utilities.cs +++ b/src/client/spark_excel/utils/Utilities.cs @@ -25,7 +25,68 @@ namespace bts.excel else if (!string.IsNullOrEmpty(key1)) val = jo[key1]; return val.ToString(); - } + } + + static Google.Protobuf.JsonFormatter _formatter = + new Google.Protobuf.JsonFormatter(new Google.Protobuf.JsonFormatter.Settings(true)); + [ExcelFunction] + public static object bts_json_create(string type) + { + System.Type t = find_full_type_in_all_assemblies(type); + object obj = Activator.CreateInstance(t); + foreach(var pr in t.GetProperties()) + { + object val = null; + try + { + val = Activator.CreateInstance(pr.PropertyType); + } + catch {} + try + { + pr.SetValue(obj, val); + } + catch {} + } + string s = "{}"; + if(obj is Google.Protobuf.IMessage imsg) + s = _formatter.Format(imsg); + else + s = JsonConvert.SerializeObject(obj, Formatting.Indented); + return s; + } + [ExcelFunction] + public static object bts_json_fill(string root, string key, string value) + { + var jo = JObject.Parse(root); + jo[key] = value; + var s = jo.ToString(); + return s; + } + + [ExcelFunction] + public static object bts_date_to_json(object dt, bool is_duration = false) + { + string s = "{}"; + if(is_duration) + { + var span = TimeSpan.FromDays((double)dt); + var ts = Google.Protobuf.WellKnownTypes.Duration.FromTimeSpan(span); + s = JsonConvert.SerializeObject(ts, Formatting.None); + s = _formatter.Format(ts); + s = s.Replace(@"""", ""); + } + else + { + var dd = DateTime.FromOADate((double)dt); + var utc = dd.ToUniversalTime(); + var ts = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(utc); + s = JsonConvert.SerializeObject(ts, Formatting.None); + s = _formatter.Format(ts); + s = s.Replace(@"""", ""); + } + return s; + } public static bool parse_venue(string exch, out Venue ven) { diff --git a/src/lib/api/services/HistoricalDataService.proto b/src/lib/api/services/HistoricalDataService.proto index 765594a38..0156f08d9 100644 --- a/src/lib/api/services/HistoricalDataService.proto +++ b/src/lib/api/services/HistoricalDataService.proto @@ -3,6 +3,7 @@ package bts.history; option csharp_namespace="bts.history"; option cc_enable_arenas=true; import "lib/api/Apioptions.proto"; +import "google/protobuf/wrappers.proto"; import "google/protobuf/timestamp.proto"; import "google/protobuf/duration.proto"; import "lib/domain_model/Security.proto"; diff --git a/tools/spark_vm_shell.cmd b/tools/spark_vm_shell.cmd index b6e45e83b..5d406a675 100644 --- a/tools/spark_vm_shell.cmd +++ b/tools/spark_vm_shell.cmd @@ -43,7 +43,7 @@ REM can't share externals because of symlinks REM docker exec spark_sdk ln -s /home/bts/spark_host/externals /home/bts/spark/externals echo installing protobuf pybars3 markdown, remove this line if we fixed docker docker exec spark_sdk pip install protobuf pybars3 markdown -echo now run git clone git@bitbucket.org:bluetradesys/externals.git in /home/bts/sparknm +echo now run git clone git@bitbucket.org:bluetradesys/externals.git in /home/bts/spark echo also remove node_modules directories because they can't be shared between windows and linux, echo remove src/web/ui/node_modules and src/web/api/node_modules