Rock U - Lava - Execute Command

Transcribed Video Content

So let's next look at the execute command. Now, is an advanced command. If you don't know c sharp, you probably just wanna turn back now because it relies on an advanced knowledge of c sharp, to do this. What this command allows you to do is actually allows you to run c sharp right within Lava. Okay. So if you're familiar with c sharp, basically return and then the string is gonna return back this string. So the results would just be, hello world. Okay. So not that interesting. But in this case, we're gonna, do the same thing but we're actually gonna note that your c sharp is actually gonna be treated as lava before it's treated as c sharp. So we have the ability to stuff in lava, attributes, lava, properties, lava, filters and even logic into our c sharp before we run it. So it's dynamically creating c sharp and then running it, which is super powerful. So it could be that we have, we wanna reuse the capture which is kinda the assign variable. So we wanna capture a whole bunch of information inside of an execute. So basically, we're taking some c sharp, capturing its return value, putting it into a a Lava variable and then spitting out the Lava variable. So you this is basically showing you you can have lava generate your c sharp which generates lava which then gets put onto the page. So really powerful. In all those cases, we were really looking at a very simple piece of c sharp. Right? It was this return in a string. So not not that interesting. In this case, we're taking a huge chunk of c sharp and we're running it. So basically, what this is doing is it's going out and it's calling a web page or web hook using REST sharp. And so note a few things. One is, yeah, you have a lot more c sharp here. But more importantly, at the top, we're using an import statement to bring in the libraries that are needed. In this case, we needed REST sharp, we needed Newtonsoft JSON and, also NewtonsoftJSON.link. So, when you run your c sharp, you have a couple of packages or a couple of assemblies that you have access to system, system dot text, things that almost every c sharp script would need. But you don't have access to every assembly. That would just be, crazy. So you have to import the ones that you you need specifically. And so in this case, I had to, bring in, newtonsoft dot json, resharp and the link one. Now, in those cases, we are always just running kind of the internal of a method. Right? So we just took the code out of a method of c sharp and we just ran it. What if you had a whole class that you wanted to run? And you can do that. So in this case, we've basically, we're using our own using clauses. We've we've told the execute that this is of type class, so don't treat it a little method. This is a full c sharp class. Now, your class has to have a method called execute. Okay? So that's that is the one limitation. That's how we know what to do. So when we run this, in Lava, we're gonna recall your execute method and then it's gonna do whatever it needs to do. Now, it could be that your class has, , other methods that are helper methods inside of it and as long as your execute calls those helper methods, you're you're you're set. But this is basically running a whole c c sharp class. But the entry point is the execute method. So as usual, check out the Lava page for more information on how to use that command.