#917 Haystack Rest API & SkySpark Arc

Mr. Samuel Nelson Wed 12 May

Hi all,

Working with a colleague, I am integrating SkySpark with an ASP .NET/C# application. Recently, I have written Axon queries to take advantage of the Arc system and all that functionality. The queries work in the shell and are now being brought over to the application to be called through the API. At this point, we are experiencing an error when trying to call this function that lists all the arcs for a given site.

(siteId) => do
  readAll(arc and workorder and workorderState!="cancelled" 
  and workorderState!="resolved").findAll(r=>readById(r->arcOn) 
  ->siteRef==siteId)
end

It gave the error, "Span is not a valid type". After updating the Project Haystack client, it now returns an HGrid of results, but trying to convert it to JSON, it says, "method not implemented".

With a workaround we were able to parse out the HGrid manually and got the output that follows. It appears that the ViewLink portion is where the problem arises.

Please let me know how to proceed. Thank you much!

Samuel

[{"Id":"p:synergyDemo:r:27f6383d-44cd26b1","Arc":"marker","ArcHvac":"marker","ArcInspection":"marker","ArcOn":"p:synergyDemo:r:27ce9dfe-446971b9","ArcPriority":"medium","AssignedTo":"u:johns","By":"u:johns","Created":"2021-03-30T19:27:57.277Z UTC","Dis":"AHU_CSB_003_001","DueDate":"2021-04-30","ViewLink":"{view:\"sparkEquip\" state:{span:Span(\"2021-03-21,2021-03-28\") equip:@p:synergyDemo:r:27ce9dfe-446971b9 \"AHU_CSB_003_001\" targets:[@nav:equip.site.aWQ6QHA6c3luZXJneURlbW86cjoyN2NlOWQ0OS0zMTZlMGQ5OQ]}}","Workorder":"marker","WorkorderState":"open","Mod":"2021-05-08T19:04:01.77Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:2824fe4f-76316b5f","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-3ec8f463","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-05-05T06:57:19.731Z UTC","Dis":"Worn Tread","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-05-05T06:57:19.732Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:281e46c5-c2c3046b","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-446971b9","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-04-30T04:40:37.141Z UTC","Dis":"New note","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-04-30T04:40:37.207Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:282503db-a6b8fcec","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-3ec8f463","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-05-05T07:20:59.106Z UTC","Dis":"Running slow","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-05-05T07:20:59.123Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:2824f1ca-25de467b","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-3ec8f463","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-05-05T06:03:54.825Z UTC","Dis":"Broken Pipe","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-05-05T06:03:54.835Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:28250321-6ee67b3f","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-3ec8f463","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-05-05T07:17:53.752Z UTC","Dis":"Another Screw loose","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-05-09T02:04:20.792Z UTC","ArcMaintenance":"marker","ArcPlumbing":"marker","ArcSupport":"marker","ArcWish":"marker","ArcSafety":null},{"Id":"p:synergyDemo:r:27f63a64-80fcbd55","Arc":"marker","ArcHvac":"marker","ArcInspection":"marker","ArcOn":"p:synergyDemo:r:27ce9dfe-a62db66b","ArcPriority":"critical","AssignedTo":"u:johns","By":"u:johns","Created":"2021-03-30T19:37:08.436Z UTC","Dis":"TU_CSB_004_004","DueDate":"2021-03-30","ViewLink":"{view:\"sparkEquip\" state:{span:Span(\"2021-03-21,2021-03-28\") equip:@p:synergyDemo:r:27ce9dfe-a62db66b \"TU_CSB_004_004\" targets:[@nav:equip.site.aWQ6QHA6c3luZXJneURlbW86cjoyN2NlOWQ0OS0zMTZlMGQ5OQ]}}","Workorder":"marker","WorkorderState":"new","Mod":"2021-03-30T19:37:08.451Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":"marker"},{"Id":"p:synergyDemo:r:2825018c-10a88d66","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-3ec8f463","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-05-05T07:11:08.989Z UTC","Dis":"Screw loose","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-05-05T07:11:08.998Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:2825004e-77fbe55b","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-3ec8f463","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-05-05T07:05:50.797Z UTC","Dis":"Sensor Bad Again","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-05-05T07:05:50.805Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:281e4c91-b0804a72","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-446971b9","ArcPriority":"low","AssignedTo":"u:johns","By":"u:samueln","Created":"2021-04-30T05:05:21.725Z UTC","Dis":"New note 2","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-04-30T05:05:21.789Z UTC","ArcMaintenance":"marker","ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:27f636fb-36cfc190","Arc":"marker","ArcHvac":"marker","ArcInspection":"marker","ArcOn":"p:synergyDemo:r:27ce9dfe-446971b9","ArcPriority":"low","AssignedTo":"u:samueln","By":"u:johns","Created":"2021-03-30T19:22:35.801Z UTC","Dis":"AHU_CSB_003_001","DueDate":"2021-04-30","ViewLink":"{view:\"sparkEquip\" state:{span:Span(\"2021-03-21,2021-03-28\") equip:@p:synergyDemo:r:27ce9dfe-446971b9 \"AHU_CSB_003_001\" targets:[@nav:equip.site.aWQ6QHA6c3luZXJneURlbW86cjoyN2NlOWQ0OS0zMTZlMGQ5OQ]}}","Workorder":"marker","WorkorderState":"open","Mod":"2021-05-08T22:38:42.673Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:27f63a89-65cb1a28","Arc":"marker","ArcHvac":"marker","ArcInspection":"marker","ArcOn":"p:synergyDemo:r:27ce9dfe-3ec8f463","ArcPriority":"low","AssignedTo":"u:johns","By":"u:johns","Created":"2021-03-30T19:37:45.457Z UTC","Dis":"AHU_CSB_004_001","DueDate":"2021-04-09","ViewLink":"{view:\"sparkEquip\" state:{span:Span(\"2021-03-21,2021-03-28\") equip:@p:synergyDemo:r:27ce9dfe-3ec8f463 \"AHU_CSB_004_001\" targets:[@nav:equip.site.aWQ6QHA6c3luZXJneURlbW86cjoyN2NlOWQ0OS0zMTZlMGQ5OQ]}}","Workorder":"marker","WorkorderState":"new","Mod":"2021-05-11T03:38:48.733Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:2824ffab-26767c85","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-3ec8f463","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-05-05T07:03:07.528Z UTC","Dis":"Sensor Bad","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-05-05T07:03:07.538Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:2824fade-f3c55d94","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9dfe-3ec8f463","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-05-05T06:42:38.721Z UTC","Dis":"Old Gasket","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-05-05T06:42:38.749Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null},{"Id":"p:synergyDemo:r:282d985e-8762ab61","Arc":"marker","ArcHvac":null,"ArcInspection":null,"ArcOn":"p:synergyDemo:r:27ce9e00-114d55a5","ArcPriority":null,"AssignedTo":null,"By":"u:samueln","Created":"2021-05-11T19:32:46.29Z UTC","Dis":"Our Issue","DueDate":null,"ViewLink":null,"Workorder":"marker","WorkorderState":"new","Mod":"2021-05-11T19:32:46.313Z UTC","ArcMaintenance":null,"ArcPlumbing":null,"ArcSupport":null,"ArcWish":null,"ArcSafety":null}]

Chris Breederveld Wed 12 May

Hi Samuel,

As one of the maintainers of the C# library I'm sorry to hear you are having problems with it.

I see you or a colleague have added an issue to the GitHub repository, this is indeed the best next step.

To prevent duplicate communication I will respond in more detail in that issue.

Chris Breederveld Wed 12 May

Hi Samuel,

One thing I forgot to mention is some new functionality that you might be interested in: The standard json serilization is not the nicest to use in most cases, which is why the Hayson (or JSON v4) standard was introduced.

The C# library has the possibility to convert any object to this standard using the HaysonWriter class.

If you intend to use the json format for communicating with a UI for example I would highly advice using that standard instead!

Chris Breederveld Wed 12 May

Oh, and also an option for SkySpark users: There is the option to get the response directly in json format, for example this will result in a json string without requiring you to do any additional parsing:

await client.OpenAsync();
var builder = new HGridBuilder();
builder.addCol("expr");
builder.addRow(new[] { HStr.make("readAll(view)") });
var result = await client.PostStringAsync("eval", builder.toGrid().toZinc(), "text/zinc", "application/json");

Note that this will result in JSON V3 in SkySpark < 3.0.28, but will result in JSON V4 in SkySpark 3.0.28.

Brian Frank Wed 12 May

It gave the error, "Span is not a valid type".

Spans are encoded as an XStr as:

Span("2021-03-21,2021-03-28")

Although taking a quick look at the C# code they look fully supported. But perhaps that was the problem fixed by the upgrade and you have now moved onto a JSON issue

Chris Breederveld Wed 12 May

Hi Brian,

I can confirm the XStr was fleshed out more very recently when we were reading views from SkySpark, that is why upgrading helped in this regard. A nice example of eating your own dogfood ;)

The JSON issue is just some missing implementation for which a PR has been created pending the verification by the reporter.

Mr. Samuel Nelson Wed 12 May

Hey thanks for all the attention and feedback we've gotten on this. I will circle back around with my colleague, Whitey.

Samuel

Chris Breederveld Fri 14 May

Hi, for anyone interested: The NuGet package 1.8.1 has been released containing the XStr.toJson() logic.

This release also contains a fix in the HaysonWriter class (numbers are now marked as "number" instead of "Num" as per the latest specs) and I would highly advice you to use this class over the .toJson() functions in all cases.

Login or Signup to reply.