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

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

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

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

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

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

@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 :)

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

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

 

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

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

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

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

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

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

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________