Open gerry100 opened 7 years ago
My workaround:
public static bool CallSaveCommand(this ICommandService service)
{
try
{
var command = service.GetCommand(Gemini.Modules.Shell.ToolBarDefinitions.SaveFileToolBarItem.CommandDefinition);
var target = service.GetTargetableCommand(command);
target.Execute(null);
return true;
}
catch (Exception ex)
{
Logger.Error("Error saving", ex.Unwrap());
System.Windows.MessageBox.Show(ex.Unwrap().Message, "WDG Automation", MessageBoxButton.OK, MessageBoxImage.Error);
}
return false;
}
I've created an extension method for ICommandService
.
However, I also had to change TargetableCommand.Execute
to wait the task, like so:
public void Execute(object parameter)
{
var commandHandler = _commandRouter.GetCommandHandler(_command.CommandDefinition);
if (commandHandler == null)
return;
commandHandler.Run(_command).Wait(); //NOTE: had to call .Wait() otherwise this method is async, which is fine, except when we call commandService.CallSaveCommand()
}
Hi
i search a solution to send a save command to a document.
Thanks