cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Thingworx and Visual Studio Code with any Source Control, CI / CD

wposner-2
12-Amethyst

Thingworx and Visual Studio Code with any Source Control, CI / CD

@htran-21 This is great!  I've been searching around to try to figure out how you're extracting the JS from the XML, but not having much luck.  Could you please share your process to extract and create the corresponding .js/.sql files?

6 REPLIES 6
htran-21
15-Moonstone
(To:wposner-2)

Hi @wposner-2 

 

Here is the code that i use to extract JS code and SQL code from the XML

 

docNew.XPathSelectElements($"//ThingShape/ServiceImplementations/ServiceImplementation").ForEach(codeElement =>
{
	var handler = codeElement.Attribute("handlerName").Value;
	var name = codeElement.Attribute("name").Value;
	if (string.Equals("Script", handler))
	{
		// Javascript
		codeElement.XPathSelectElement("*//Rows/Row/code").WriteJS($"{entityFolderPath}/{name}.js", merge);
	}
	else
	{
		// SQLCommand, SQLQuery
		codeElement.XPathSelectElement("*//Rows/Row/sql").WriteSQL($"{entityFolderPath}/{name}.sql", merge);
	}
});

 

You may need to extract mashup code, so that you would be able to track/merge UI changes 

// Mashups
docNew.XPathSelectElements($"//{entityCollection}/{entityType}/Things").Where(_ => _.HasElements)
.ForEach(codeElement => codeElement.WriteXML($"{entityGroupFolderPath}/{entityName}.xml", merge)); docNew.XPathSelectElements($"//{entityCollection}/{entityType}/mashupContent") .ForEach(codeElement => codeElement.WriteJSON($"{entityGroupFolderPath}/{entityName}.json", merge));

 

Hope this helps!

 

My Bests,

Hung Tran

wposner-2
12-Amethyst
(To:htran-21)

@htran-21 Thank you!  One final question.  How are you merging your JS/SQL back in to to the XML so that it can be re-imported to TWX?  I'm really hoping this is not a copy/paste operation :)

htran-21
15-Moonstone
(To:wposner-2)

Hi @wposner-2 

 

No, everything is automatic, just perform merge task, and the final XML would be merged with the latest local/remote changes

 

Screenshot_1.png

 

My Bests,

Hung Tran

 

cbrandy-2
6-Contributor
(To:htran-21)

Hi @htran-21 ,

I'm really interested with you tools. Based on your original post, I guess you wrote a bunch of tasks.

Would you share the source code ?

 

Thanks in advance,

 

Cyril

htran-21
15-Moonstone
(To:cbrandy-2)

Hi Cyril,

 

Thank you for your interest. I think of packaging the solution in a Docket and deploy it as a cloud solution, a something similar to https://stackblitz.com/, but allow us to work with Thingworx projects.

 

My Bests,

Hung Tran

cbrandy-2
6-Contributor
(To:htran-21)

That sounds great !

 

Unfortunately, we just need this kind of functionality to ease GIT process and review code changes in services before committing.

 

We are developing on customer premises.

 

Cyril

Top Tags