How to execute "org.eclipse.ui.file.closeAll" command? - eclipse

I tried
IHandlerService handlerService = PlatformUI.getWorkbench().getService( IHandlerService.class ) ;
ICommandService commandService = PlatformUI.getWorkbench().getService( ICommandService.class ) ;
Command command = commandService.getCommand( "org.eclipse.ui.file.closeAll" ) ;
command.executeWithChecks( handlerService.createExecutionEvent( command, new Event() ) ) ;
but it throws org.eclipse.core.commands.NotEnabledException.
There is a method org.eclipse.core.commands.Command.setEnabled(Object), I tried
command.setEnabled( null ) ;
but it still didn't work. If the parameter is not passed null, what is passed ?
In addition, I tried
IHandlerService handlerService = PlatformUI.getWorkbench().getService( IHandlerService.class ) ;
handlerService.executeCommand( "org.eclipse.ui.file.closeAll", new Event() ) ;
It didn't work out either.

Related

Symfony 4 Component Process pass arguments for command

Symfony Component Process
/**
* #param array $command The command to run and its arguments listed as separate entries
* #param string|null $cwd The working directory or null to use the working dir of the current PHP process
* #param array|null $env The environment variables or null to use the same environment as the current PHP process
* #param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
* #param int|float|null $timeout The timeout in seconds or null to disable
*
* #throws LogicException When proc_open is not installed
*/
public function __construct($command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
{ .. }
I have created a command and I use the component Process in my controller.
When I try to run Process I get a ProcessFailException
The command "app:load-file foo bar foobar" failed
Exit Code: 1(General error)
.. ErrorOutput: The filename, directory name, or volume label syntax is incorrect
use Symfony\Component\Process\Process;
..
public function loadFile(KernelInterface $kernel)
{
$argument1 = 'foo';
$argument2 = 'bar';
$argument3 = 'foobar';
$rootDir = $kernel->getProjectDir();
$process = new Process(array(
$rootDir . '/bin/console app:load-file',
$argument1,
$argument2,
$argument3
));
$process->mustRun();
}
What is the correct syntax to run the command from the controller ?
/* *#param array $command The command to run and its arguments listed as separate entries
public function __construct($command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
{ .. }
$cwd is the second parameter of the constructor.
$argument1 = 'foo';
$argument2 = 'bar';
$argument3 = 'foobar';
$rootDir = $kernel->getProjectDir();
$process = new Process(
"bin/console app:load-file $argument1 $argument2 $argument3",
$rootDir
);
try {
$process->mustRun();
} catch(ProcessFailedException $e) {
echo $e->getMessage();
}
$argument1 = 'foo';
$argument2 = 'bar';
$argument3 = 'foobar';
$rootDir = $kernel->getProjectDir();
$process = new Process(
[
$_SERVER['_'],
'bin/console'
'app:load-file',
$argument1,
$argument2,
$argument3,
],
$rootDir
);
$process->mustRun();
$_SERVER['_'] contains path to PHP interpreter executable. Use it if you have several php versions on the server

Skip step if file input resource does not exist

I have 12 Steps in a single job in which steps are reading from csv and txt files. I'm trying to add the functionality of skipping the step if the file corresponding to the step doesn't exist in the directory using JobExecutionDecider following this https://docs.spring.io/spring-batch/docs/current/reference/html/step.html#programmaticFlowDecisions. It'is working fine when the files are not present in the directory. Instead if the files are present it stops at the first from.
jobBuilderFactory.get("importFileJob")
.listener( new ImportFileJobListener() )
.incrementer( new RunIdIncrementer() )
.start( truncateAnagraficheTableStep( QUERY_TRUNCATE_INTERFACE_IN_ANAGRAFICHE ) )
.next( new Decider( directory, file01Prefix ) ).on( "FAILED" ).to( truncateContrattiTableStep( QUERY_TRUNCATE_INTERFACE_IN_CONTRATTI ) )
.from( new Decider( directory, file01Prefix ) ).on( "COMPLETED" ).to( anagraficheStep( QUERY_INSERT_INTERFACE_IN_ANAGRAFICHE ) )
.next( anagraficheStep( QUERY_INSERT_INTERFACE_IN_ANAGRAFICHE ) )
.next( truncateContrattiTableStep( QUERY_TRUNCATE_INTERFACE_IN_CONTRATTI ) )
.next( new Decider( directory, file02Prefix ) ).on( "FAILED" ).to( truncateCapitalLimitTableStep( QUERY_TRUNCATE_INTERFACE_IN_CAPITAL_LIMIT ) )
.from( new Decider( directory, file02Prefix ) ).on( "COMPLETED" ).to( contrattiStep( QUERY_INSERT_INTERFACE_IN_CONTRATTI ) )
.next( contrattiStep( QUERY_INSERT_INTERFACE_IN_CONTRATTI ) )
.next( truncateCapitalLimitTableStep( QUERY_TRUNCATE_INTERFACE_IN_CAPITAL_LIMIT ))
.next( new Decider( directory, file03Prefix ) ).on( "FAILED" ).to( truncateEsitiPefTableStep( QUERY_TRUNCATE_INTERFACE_IN_ESITI_PEF ) )
.from( new Decider( directory, file03Prefix ) ).on( "COMPLETED" ).to( capitalLimitStep( QUERY_INSERT_INTERFACE_IN_CAPITAL_LIMIT ) )
.next( capitalLimitStep( QUERY_INSERT_INTERFACE_IN_CAPITAL_LIMIT ))
.next( moveTextFilesStep() )
.next( truncateEsitiPefTableStep( QUERY_TRUNCATE_INTERFACE_IN_ESITI_PEF ) )
.next( new Decider( directory, file04Prefix ) ).on( "FAILED" ).to( truncateStatoOperazioniTableStep( QUERY_TRUNCATE_INTERFACE_IN_STATO_OPERAZIONI ) )
.from( new Decider( directory, file04Prefix ) ).on( "COMPLETED" ).to( esitiPefStep() )
.next(esitiPefStep())
.next( truncateStatoOperazioniTableStep( QUERY_TRUNCATE_INTERFACE_IN_STATO_OPERAZIONI ) )
.next( new Decider( directory, file05Prefix ) ).on( "FAILED" ).fail()
.from( new Decider( directory, file05Prefix ) ).on( "COMPLETED" ).to( statoOperazioniStep() )
.next( statoOperazioniStep() )
.next( moveExcelFilesStep() )
.end()
.build();
Here is the code of the decider
public class Decider implements JobExecutionDecider {
private static Logger logger = Logger.getLogger("techLog");
private File directory;
private String filePrefix;
public Decider(File directory, String filePrefix) {
super();
this.directory = directory;
this.filePrefix = filePrefix;
}
#Override
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
// TODO Auto-generated method stub
String status;
File[] inputFiles = directory.listFiles((dir, name) -> name.startsWith(filePrefix) );
if ( inputFiles.length == 0 ) {
logger.error( "Input resource does not exist file " + directory + "\\" + filePrefix );
status = "FAILED";
}
else {
status = "COMPLETED";
}
return new FlowExecutionStatus(status);
}
}
That's an issue with your decider implementation. It is up to you to specify the FlowExecutionStatus to return according to the presence/absence of the file.

How to use Create Command in yii2?

i want to create a new table and then insert value into it using create command. This is the code which i tried
if ( $model->save() )
{
$first_val = $model->num_start - 1;
$connection = \Yii::$app()->db;
$transaction = $connection->beginTransaction();
try
{
$q = "CREATE TABLE range_{$model->id}( id INT(11) NOT NULL AUTO_INCREMENT,PRIMARY KEY (id) ); " ;
$connection->createCommand($q)->execute(); // new table created
$transaction->commit();
if ( $model->num_start > 1 )
{
$r = "INSERT INTO range_{$model->id}( id ) VALUES ({$first_val});" ;
$connection->createCommand($r)->execute(); // new value inserted
$transaction->commit();
}
}
catch (Exception $e)
{
// react on exception
$transaction->rollback();
}
return $this->redirect( [ 'index' ] );
}
when i try to run this code i get an error Call to undefined method Yii::app() How can i use the create command in Yii2?
You have mixed both yii and yii2:
Use:
\Yii::$app->db;
Instead of
\Yii::$app()->db;

Command Line Program - Sending 'Enter' commands

I have command line program that has a menu with multiple choice. I can pass the parameter via program.exe < input.txt but I am having problems sending the 'Enter' command (the program crashes if I attempt to send anything else; such as a ' ' character).
I enter 'All' as Proc name. It then prints 'enter proc name' again and I have to hit Enter for the code to continue. What I cannot work out is how to send this Enter to the program. I have tried a black line in input.txt but that did not work.
while( !end )
{
for( legal=0; !legal; )
{
printf("\tEnter Proc Name: ");
if( fgets( str, 70, stdin ) == NULL )
{
printf("Bye.\n");
exit(0);
}
ret = sscanf(str, "%s", p.name );
if( ret > 0 || str[0] == '\n' ) legal = 1;
else printf("Please enter a legal proc name, none, or all\n");
}
if( str[0] == '\n' ) {
end = 1;
} else if( !strcmp( p.name, "all" )) {
for( i=0; i < Conf_num_procs( &Cn ); i++ )
Status_vector[i] = 1;
} else if( !strcmp( p.name, "none" )) {
for( i=0; i < Conf_num_procs( &Cn ); i++ )
Status_vector[i] = 0;
} else {
proc_index = Conf_proc_by_name( p.name, &p );
if( proc_index != -1 ) {
Status_vector[proc_index] = 1;
} else printf("Please! enter a legal proc name, none, or all\n");
}
}

How do I return a value if the prepare statement fails in the below code?

sub loadFileRecon {
my $self = shift;
my $days = shift;
if($days eq '') {
$days = 1;
}
my $insert = $self->{rba}->rbdb->prepare(q{
insert into rba.filerecon (
filename,
records,
start_dtm,
file_type,
managed_file_id,
mf_dtm,
processed_tidemark,
mm_records,
mm_dropped,
mm_erred,
mm_duplicate,
file_source
)
select
i.filename,
i.records,
i.file_dtm start_dtm,
i.file_type,
mf.managed_file_id,
mf.created_dtm mf_dtm,
NULL,
i.orig_records,
i.dropped,
i.erred,
i.duplicate,
i.file_source
from rba.mmfilestats i, managedfile mf, filelog fl
where
i.filename = fl.file_name and
trunc(i.file_dtm) = trunc(sysdate - ?) and
mf.managed_file_id = fl.managed_file_id
}) or die $DBI::errstr;
$insert->execute($days);
$insert->finish;
$self->{rba}->rbdb->commit;
my $update = $self->{rba}->rbdb->prepare(q{
update rba.filerecon fr
set processed_tidemark = (
select processed_tidemark
from jobhasfile j
where j.managed_file_id = fr.managed_file_id
)
where
trunc(start_dtm) = trunc(sysdate - ?) and
processed_tidemark is null
});
$update->execute($days);
$insert->finish;
$self->{rba}->rbdb->commit;
}
If the prepare statement above fails due to table or view not existing, then it should return a value to perl module
you are telling your program to die if the prepare returns false:
}) or die $DBI::errstr;
replace that with what you're looking for:
}) or return $somevalue;
or remove the or entirely and check the value of your statement handle;
my $insert = $self->{rba}->rbdb->prepare(q{
...
});
return $somevalue if ( !$insert );
What you need to do is return the DBI::errstr. Do not die on error.
So do something like this (starting at your prepare and ending with your where but getting rid of the "or die"):
...prepare( ......
where
i.filename = fl.file_name and
trunc(i.file_dtm) = trunc(sysdate - ?) and
mf.managed_file_id = fl.managed_file_id
});
if ($DBI::errstr) {
# oops something is wrong
print $DBI::errstr;
call_error($DBI::errstr);
}
Good luck
Your post of the errorlog shows that your error is raised at point of execute not at the point of prepare.
So this what you do AFTER the execute:
#your execute statement first
$insert->execute($days);
#Now the check on the execute
if ($DBI::errstr) {
# oops something is wrong
return -1;
}
Please let me know if this works