I wrote a command and run it by pressing a button. How can I run it from OnLogOn?
Solved! Go to Solution.
I wrote a command and run it by pressing a button. How can I run it from OnLogOn?
Solved! Go to Solution.
Solved by Nick_Hall. Go to Solution.
Hi
From your brief description, it sounds like you need to use the OnLogOn method
Here's a screenshot from the Vault API help
The HelloWorld sample in the SDK contains the template for the method (but no actual code in it)
Hope that helps
Nick
Hi
From your brief description, it sounds like you need to use the OnLogOn method
Here's a screenshot from the Vault API help
The HelloWorld sample in the SDK contains the template for the method (but no actual code in it)
Hope that helps
Nick
Yes, thanks, I know that. But I don't understand how to call the command specifically from OnLogOn. I could run the written CommandHandler(CommandItem, CommandItemEventArgs). But I don't know how to receive CommandItemEventArgs at the moment of OnLogOn to pass it to CommandHandler.
Yes, thanks, I know that. But I don't understand how to call the command specifically from OnLogOn. I could run the written CommandHandler(CommandItem, CommandItemEventArgs). But I don't know how to receive CommandItemEventArgs at the moment of OnLogOn to pass it to CommandHandler.
Hi
Now I understand your question better
You can't use CommandItemEventArgs because the OnLogOn event doesn't have one
This is due to when the event occurs, immediately after the user has logged in, but before the UI is initialised
Because the UI has not initialised, there's no Context to pass into the event - all you have is the iApplication, which is the same as CommandItemEventArgs.Context.Application
If your command only uses CommandItemEventArgs.Context.Application, you can replace it directly, but if you use any other members of CommandItemEventArgs.Context, you'll need to look at another way of calling it
If you can tell me roughly what your command does, I might be able to suggest something
Hope that helps
Nick
Hi
Now I understand your question better
You can't use CommandItemEventArgs because the OnLogOn event doesn't have one
This is due to when the event occurs, immediately after the user has logged in, but before the UI is initialised
Because the UI has not initialised, there's no Context to pass into the event - all you have is the iApplication, which is the same as CommandItemEventArgs.Context.Application
If your command only uses CommandItemEventArgs.Context.Application, you can replace it directly, but if you use any other members of CommandItemEventArgs.Context, you'll need to look at another way of calling it
If you can tell me roughly what your command does, I might be able to suggest something
Hope that helps
Nick
Hello! My command runs AcquireFiles. The user has a configuration file that specifies which files and where to upload them. I rewrote this command based on Hello World. Also, the command only becomes available if the user selects a file, although it is not used in the command. This is probably wrong
Hello! My command runs AcquireFiles. The user has a configuration file that specifies which files and where to upload them. I rewrote this command based on Hello World. Also, the command only becomes available if the user selects a file, although it is not used in the command. This is probably wrong
Here is my code:
public IEnumerable<CommandSite> CommandSites()
{
CommandItem helloWorldCmdItem = new CommandItem("HelloWorldCommand", "BackUp files")
{
NavigationTypes = new SelectionTypeId[] { SelectionTypeId.File, SelectionTypeId.FileVersion, SelectionTypeId.Folder },
MultiSelectEnabled = false
};
helloWorldCmdItem.Execute += FileDownloadCommandhandler;
CommandSite toolbarCmdSite = new CommandSite("HelloWorldCommand.Toolbar", "Hello World Menu")
{
Location = CommandSiteLocation.AdvancedToolbar,
DeployAsPulldownMenu = false
};
toolbarCmdSite.AddCommand(helloWorldCmdItem);
List<CommandSite> sites = new List<CommandSite>();
sites.Add(toolbarCmdSite);
return sites;
}
public IEnumerable<DetailPaneTab> DetailTabs()
{
List<DetailPaneTab> fileTabs = new List<DetailPaneTab>();
DetailPaneTab filePropertyTab = new DetailPaneTab("File.Tab.PropertyGrid", "Selection Info", SelectionTypeId.File,
typeof(VaultFileCopyOfSheduleTabControl));
filePropertyTab.SelectionChanged += propertyTab_SelectionChanged;
fileTabs.Add(filePropertyTab);
DetailPaneTab folderPropertyTab = new DetailPaneTab("Folder.Tab.PropertyGrid", "Selection Info",
SelectionTypeId.Folder, typeof(VaultFileCopyOfSheduleTabControl));
folderPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
fileTabs.Add(folderPropertyTab);
DetailPaneTab itemPropertyTab = new DetailPaneTab("Item.Tab.PropertyGrid", "Selection Info",
SelectionTypeId.Item,
typeof(VaultFileCopyOfSheduleTabControl));
itemPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
fileTabs.Add(itemPropertyTab);
DetailPaneTab coPropertyTab = new DetailPaneTab("Co.Tab.PropertyGrid", "Selection Info",
SelectionTypeId.ChangeOrder,
typeof(VaultFileCopyOfSheduleTabControl));
coPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
fileTabs.Add(coPropertyTab);
return fileTabs;
}
void FileDownloadCommandhandler(object s, CommandItemEventArgs e)
{
Connection connection = e.Context.Application.Connection;
try
{
if (startFromButton == true && backupFileOfExplorer == false)
{
AnalyzeTXTFile(connection);
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
void AnalyzeTXTFile(Connection connection)
{
//read config txt file
GetTheFile(connection, file);
}
public void GetTheFile(Connection connection, File file)
{
var acquireSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection);
if (pathToCopy != null)
{
acquireSettings.LocalPath = new VDF.Currency.FolderPathAbsolute(pathToCopy);
}
else
{
acquireSettings.LocalPath = new VDF.Currency.FolderPathAbsolute(@"C:\TestBackUp");
}
acquireSettings.AddFileToAcquire(new VDF.Vault.Currency.Entities.FileIteration(connection, file),
VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);
VDF.Vault.Results.AcquireFilesResults results = connection.FileManager.AcquireFiles(acquireSettings);
}
Here is my code:
public IEnumerable<CommandSite> CommandSites()
{
CommandItem helloWorldCmdItem = new CommandItem("HelloWorldCommand", "BackUp files")
{
NavigationTypes = new SelectionTypeId[] { SelectionTypeId.File, SelectionTypeId.FileVersion, SelectionTypeId.Folder },
MultiSelectEnabled = false
};
helloWorldCmdItem.Execute += FileDownloadCommandhandler;
CommandSite toolbarCmdSite = new CommandSite("HelloWorldCommand.Toolbar", "Hello World Menu")
{
Location = CommandSiteLocation.AdvancedToolbar,
DeployAsPulldownMenu = false
};
toolbarCmdSite.AddCommand(helloWorldCmdItem);
List<CommandSite> sites = new List<CommandSite>();
sites.Add(toolbarCmdSite);
return sites;
}
public IEnumerable<DetailPaneTab> DetailTabs()
{
List<DetailPaneTab> fileTabs = new List<DetailPaneTab>();
DetailPaneTab filePropertyTab = new DetailPaneTab("File.Tab.PropertyGrid", "Selection Info", SelectionTypeId.File,
typeof(VaultFileCopyOfSheduleTabControl));
filePropertyTab.SelectionChanged += propertyTab_SelectionChanged;
fileTabs.Add(filePropertyTab);
DetailPaneTab folderPropertyTab = new DetailPaneTab("Folder.Tab.PropertyGrid", "Selection Info",
SelectionTypeId.Folder, typeof(VaultFileCopyOfSheduleTabControl));
folderPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
fileTabs.Add(folderPropertyTab);
DetailPaneTab itemPropertyTab = new DetailPaneTab("Item.Tab.PropertyGrid", "Selection Info",
SelectionTypeId.Item,
typeof(VaultFileCopyOfSheduleTabControl));
itemPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
fileTabs.Add(itemPropertyTab);
DetailPaneTab coPropertyTab = new DetailPaneTab("Co.Tab.PropertyGrid", "Selection Info",
SelectionTypeId.ChangeOrder,
typeof(VaultFileCopyOfSheduleTabControl));
coPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
fileTabs.Add(coPropertyTab);
return fileTabs;
}
void FileDownloadCommandhandler(object s, CommandItemEventArgs e)
{
Connection connection = e.Context.Application.Connection;
try
{
if (startFromButton == true && backupFileOfExplorer == false)
{
AnalyzeTXTFile(connection);
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
void AnalyzeTXTFile(Connection connection)
{
//read config txt file
GetTheFile(connection, file);
}
public void GetTheFile(Connection connection, File file)
{
var acquireSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection);
if (pathToCopy != null)
{
acquireSettings.LocalPath = new VDF.Currency.FolderPathAbsolute(pathToCopy);
}
else
{
acquireSettings.LocalPath = new VDF.Currency.FolderPathAbsolute(@"C:\TestBackUp");
}
acquireSettings.AddFileToAcquire(new VDF.Vault.Currency.Entities.FileIteration(connection, file),
VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);
VDF.Vault.Results.AcquireFilesResults results = connection.FileManager.AcquireFiles(acquireSettings);
}
Hi
In your command handler (FileDownloadCommandhandler), your code is essentially this
void FileDownloadCommandhandler(object s, CommandItemEventArgs e)
{
Connection connection = e.Context.Application.Connection;
AnalyzeTXTFile(connection);
}
To achieve the same thing in the OnLogOn method you would need this code
public void OnLogOn(IApplication application)
{
Connection connection = application.Connection;
AnalyzeTXTFile(connection);
}
That should get your AnalyzeTXTFile function running at the right point, and it should be relatively smooth from there
Nick
Hi
In your command handler (FileDownloadCommandhandler), your code is essentially this
void FileDownloadCommandhandler(object s, CommandItemEventArgs e)
{
Connection connection = e.Context.Application.Connection;
AnalyzeTXTFile(connection);
}
To achieve the same thing in the OnLogOn method you would need this code
public void OnLogOn(IApplication application)
{
Connection connection = application.Connection;
AnalyzeTXTFile(connection);
}
That should get your AnalyzeTXTFile function running at the right point, and it should be relatively smooth from there
Nick
Yes it works, thanks!
Yes it works, thanks!
Can't find what you're looking for? Ask the community or share your knowledge.