Azure logic app use a variable inside inline_code action - azure

I have a logic app that looks something like this:
In the js code action, I just wanted to check if the name of the file (that had triggered the workflow) match some pattern. So my Inline code action has something like:
var input = workflowContext.trigger.outputs.headers.x-ms-file-name;
if(input.match(/^([0-9]){3}_Hello/))
return true;
else
return false;
However, it seems that the action can't get the file name because the x-ms-file-name is splitted by a '-'.
So, I tried to solve this problem by creating a variable called fileName in an the action before it
and then use it in the inline code action. But I don't know how to call the variable inside inline code action.
What should I write here:
var input = ????;
if(input.match(/^([0-9]){3}_Hello/))
return true;
else
return false;
Any suggestion to how to solve this problem?
Note (I am not sure if it is relevant but in case it helps): I am using the standard logic app so I amp supposed to not have/use Integration account

It seems that I can just simply write the following in the inline action:
var input = workflowContext.trigger.outputs.headers['x-ms-file-name'];
if(input.match(/^([0-9]){3}_Hello/))
return true;
else
return false;

Related

Azure Functions - run code block before function execution

I have a series of Node based HTTP Azure Functions each of which needs to undertake some checks before the function can be executed. The checks are based on the contents of some HTTP headers.
I've implemented the checks in a helper and can add that to the head of each function e.g.
if (myHelper.doChecksPass()) {
// Execute the main body of the function code
context.res.status = 200;
}
else {
context.res.status = 403;
}
Does anyone know if there is a slicker way to do this rather than duplicating the above code into each function? I'm thinking along the lines of something which runs on function execution and before the main function body which can stop the execution of the function and return the 403.
I've checked the MS docs and I can't see anything but I might just be missing it.
Thanks in advance

how to move to other section in script

I'm building a bot using gupshup.io using the scripting way ... but handling some things in default.js file as mentioned in the docs
I'm trying in a handler function to check if the event.message equals specific string to go to another section in the script
can anybody please help ?
thanks a lot
So to achieve that you can create a child state to go another section and just set options.next_state to that state. I mean suppose you have a script like this
[main]
inputParser:Welcome to New Bot.
thisFlow:
This is a output of this flow.
callAnotherFlow:
:call default.anotherFlow
[anotherFlow]
This is another flow.[[Wow, No]]
Wow
Thanks
No
Oh!
So in case if the message is 'another flow' you want the second flow to begin. So in the input parser you can create something like.
module.exports.main = {
inputParser: (options, event, context, callback)=>{
if(event.message.toLowerCase() === "another flow"){
options.next_state = 'callAnotherFlow';
}else{
options.next_state = 'thisFlow';
}
callback(options, event, context);
}
}
I think this is what you are looking for.

How to enable user to re-entry(or) reuse the same dialog in MFC

I'm currently doing a FTP download using MFC. Is a very simple program which takes 2 inputs from user and click a download button in order to download from server. Everything is fine and im able to download it from. But i realized this program can only be executed once. Either successful or fail user has to open the .exe again to download another file. I'm a beginner in C&C++ with a simple knowledge i put OnInitDialog() at the last line of the download function hopping it will loop back and initialize again. Of course it doesn't work. Below are my current codes for the download button
BOOL CFTPDOWNLOADDlg::Log_In(char* path, char* ID, char* password {
m_pFtpConnection = NULL;
try{
// path
// ID
// password
m_pFtpConnection = m_Session.GetFtpConnection(path,
ID,password,INTERNET_INVALID_PORT_NUMBER);
}
catch(CInternetException *pEx){
pEx->ReportError(MB_ICONEXCLAMATION);
m_pFtpConnection = NULL;
pEx->Delete();
return FALSE;
}
return TRUE;
}
BOOL CFTPDOWNLOADDlg::Download(){
m_Edit3.SetWindowText("Downloading..");
m_Session.EnableStatusCallback(TRUE);
if(m_pFtpConnection->GetFile(serv_Loc,host_Loc,
FALSE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_BINARY,1) != 0){
MessageBox("Download Complete");
m_Edit3.SetWindowText("");}
else{
MessageBox("Download Fail");
return FALSE;
}
// Log_out Session
m_Session.Close();
m_pFtpConnection->Close();
if(m_pFtpConnection!=NULL) delete m_pFtpConnection;
else MessageBox("Download Complete");
return TRUE;
}
BOOL CFTPDOWNLOADDlg::get_Path(){
...
...
...
sprintf(serv_Loc,"soft\\%s\\%d\\%s.zip",s_No,r_Number,r_No);
sprintf(host_Loc,"%s\\%s.zip",buff2,r_No);
return TRUE;
}
void CFTPDOWNLOADDlg::OnCancel() {
// Log_out Session
m_Session.Close();
m_pFtpConnection->Close();
if(m_pFtpConnection!=NULL)
delete m_pFtpConnection;
CDialog::OnCancel();
}
void CFTPDOWNLOADDlg::OnDLButton() {
//get path from user input
get_Path();
// start download
Download();
}
I've tried to search online, i couldn't find anything which is close. Sorry for my poor explanation.
Thank you in advance for your kindness in replying
Here is what you need to do:
You should make CInternetSession m_Session; a member of your CWinApp-derived class.
You should call m_Session.Close() in ExitInstance() method of your CWinApp-derived class.
In your CDialog-derived class you should only deal with CFtpConnection related stuff. So when user clicks on Download button you should call GetFtpConnection() and initialize your m_pFtpConnection and do the rest. When download/upload is done call m_pFtpConnection->Close(); and delete m_pFtpConnection;
Please also use CString instead of char*. There are lots of benefits like automatic UNICODE support, etc.
Please also consider using CString::Format() method instead of sprintf().
You should also consider using threads to perform upload/download tasks in a separate worker thread. Use AfxBeginThread() to start the thread. This way you'll not affect Windows message pump that is a part of main application (GUI) thread. So your GUI wont lock up while you uploading/downloading files.

NodeJS: Run module method within sandbox

I need one simple thing:
var Base = function(module){
this.outsideMethod = function(arg1)
{
// run method in new context - sandbox
return vm.runInNewContext(module.insideMethod, arg1);
}
}
is something like this possible in nodejs? thx very much
If the insideMethod function does not call or use functions/vlues from outside the context it shall run in, yes.
You can convert any function in Javascript to a string.
Doing vm.runInNewContext('('+module.insideMethod+')('+JSON.stringify(arg1)+"); could be what you want.

how to define functions in redis \ lua?

I'm using Node.js, and the 'redis-scripto' module, and I'm trying to define a function in Lua:
var redis = require("redis");
var redisClient = redis.createClient("6379","127.0.0.1");
var Scripto = require('redis-scripto');
var scriptManager = new Scripto(redisClient);
var scripts = {'add_script':'function add(i,j) return (i+j) end add(i,j)'};
scriptManager.load(scripts);
scriptManager.run('add_script', [], [1,1], function(err, result){
console.log(err || result);
});
so I'm getting this error:
[Error: ERR Error running script (call to .... #enable_strict_lua:7: user_script:1: Script attempted to create global variable 'add']
so I've found that it's a protection, as explained in this thread:
"The doc-string of scriptingEnableGlobalsProtection indicates that intent is to notify script authors of common mistake (not using local)."
but I still didn't understand - where is this scripting.c ? and the solution of changing global tables seems risky to me.
Is there no simple way of setting functions to redis - using lua ?
It looks like the script runner is running your code in a function. So when you create function add(), it thinks you're doing it inside a function by accident. It'll also, likely, have a similar issue with the arguments to the call to add(i,j).
If this is correct then this should work:
local function add(i,j) return (i+j) end return add(1,1)
and if THAT works then hopefully this will too with your arguments passed from the js:
local function add(i,j) return (i+j) end return add(...)
You have to assign an anonymous function to a variable (using local).
local just_return_it = function(value)
return value
end
--// result contains the string "hello world"
local result = just_return_it("hello world")
Alternately, you can create a table and add functions as fields on the table. This allows a more object oriented style.
local obj = {}
function obj.name()
return "my name is Tom"
end
--// result contains "my name is Tom"
local result = obj.name()
Redis requires this to prevent access to the global scope. The entire scripting mechanism is designed to keep persistence out of the scripting layer. Allowing things in the global scope would create an easy way to subvert this, making it much more difficult to track and manage state on the server.
Note: this means you'll have to add the same functions to every script that uses them. They aren't persistent on the server.
This worked for me: (change line 5 from the question above):
var scripts = {
'add_script':'local function add(i,j) return (i+j) end return(add(ARGV[1],ARGV[2]))'};
to pass variables to the script use KEYS[] and ARGV[], as explained in the redis-scripto guide
and also there's a good example in here: "Lua: A Guide for Redis Users"

Resources