private void SelectVaultDialog_Load( object sender, EventArgs e ) { var app = new MFilesAPI.MFilesClientApplication(); var vaults = app.GetVaultConnections(); foreach( MFilesAPI.VaultConnection vault in vaults ) { vaultList.Items.Add( vault.Name ); } vaultList.SelectedIndex = 0; }
private void SelectVaultDialog_Load(object sender, EventArgs e) { var app = new MFilesAPI.MFilesClientApplication(); var vaults = app.GetVaultConnections(); foreach (MFilesAPI.VaultConnection vault in vaults) { vaultList.Items.Add(vault.Name); } vaultList.SelectedIndex = 0; }
public override bool Execute() { MFilesAPI.MFilesClientApplication app = new MFilesAPI.MFilesClientApplication(); try { var vault = app.BindToVault( VaultName, IntPtr.Zero, false, true ); if( vault != null ) vault.LogOutWithDialogs( IntPtr.Zero ); } catch { // This is most likely caused by logged out vault which is what we wanted anyway. } return true; }
public override bool Execute() { MFilesAPI.MFilesClientApplication app = new MFilesAPI.MFilesClientApplication(); try { var vault = app.BindToVault(VaultName, IntPtr.Zero, false, true); if (vault != null) { vault.LogOutWithDialogs(IntPtr.Zero); } } catch { // This is most likely caused by logged out vault which is what we wanted anyway. } return(true); }
public ApplicationDebugPropertyPageUI( ApplicationDebugPropertyPage page ) { InitializeComponent(); this.Page = page; // If values change mark this as dirty. outputPath.TextChanged += ( s, a ) => this.IsDirty = true; vaultInput.SelectedIndexChanged += ( s, a ) => this.IsDirty = true; launchMFilesInput.CheckedChanged += ( s, a ) => this.IsDirty = true; launchPowerShellInput.CheckedChanged += ( s, a ) => this.IsDirty = true; mfilesPathInput.TextChanged += ( s, a ) => this.IsDirty = true; powerShellScriptInput.TextChanged += ( s, a ) => this.IsDirty = true; launchMFilesInput.CheckedChanged += ( s, a ) => UpdateControlStates(); launchPowerShellInput.CheckedChanged += ( s, a ) => UpdateControlStates(); UpdateControlStates(); // Resolve the current API version and display it in the label. clientApp = new MFilesAPI.MFilesClientApplication(); apiVersion = clientApp.GetAPIVersion().Display; apiLabel.Text = string.Format( apiLabel.Text, apiVersion ); }
public ApplicationDebugPropertyPageUI(ApplicationDebugPropertyPage page) { InitializeComponent(); this.Page = page; // If values change mark this as dirty. outputPath.TextChanged += (s, a) => this.IsDirty = true; vaultInput.SelectedIndexChanged += (s, a) => this.IsDirty = true; launchMFilesInput.CheckedChanged += (s, a) => this.IsDirty = true; launchPowerShellInput.CheckedChanged += (s, a) => this.IsDirty = true; mfilesPathInput.TextChanged += (s, a) => this.IsDirty = true; powerShellScriptInput.TextChanged += (s, a) => this.IsDirty = true; // Update control enabled state when radio buttons change. launchMFilesInput.CheckedChanged += (s, a) => UpdateControlStates(); launchPowerShellInput.CheckedChanged += (s, a) => UpdateControlStates(); UpdateControlStates(); // Resolve the current API version and display it in the label. clientApp = new MFilesAPI.MFilesClientApplication(); apiVersion = clientApp.GetAPIVersion().Display; apiLabel.Text = string.Format(apiLabel.Text, apiVersion); }
public override int DebugLaunch( uint grfLaunch ) { CCITracing.TraceCall(); var clientApp = new MFilesAPI.MFilesClientApplication(); var apiVersion = clientApp.GetAPIVersion().Display; MFilesAPI.Vault vault = null; var vaultName = GetConfigurationProperty( "TestVault", true ); MFilesAPI.VaultConnection vaultConnection; try { vaultConnection = clientApp.GetVaultConnection( vaultName ); } catch { throw new Exception( "The document vault '" + vaultName + "' was not found." ); } string vaultGuid = vaultConnection.GetGUID(); // Get the M-Files install directory from the registry. var hklm64 = RegistryKey.OpenBaseKey( RegistryHive.LocalMachine, RegistryView.Registry64 ); var mfKey = hklm64.OpenSubKey( @"Software\Motive\M-Files\" + apiVersion ); var installDir = (string)mfKey.GetValue( "InstallDir" ); mfKey.Close(); hklm64.Close(); // Log out to free the current application. try { vault = clientApp.BindToVault( vaultName, IntPtr.Zero, false, true ); if( vault != null ) vault.LogOutWithDialogs( IntPtr.Zero ); } catch { } // Deploy the application. var relativePath = string.Format( @"Client\Apps\{0}\sysapps\{1}", vaultGuid, this.project.GetProjectProperty( "Name" ) ?? "unnamed" ); var targetDir = Path.Combine( installDir, relativePath ); // If the directory exists, remove it so there's no residue files left. if( Directory.Exists( targetDir ) ) { Directory.Delete( targetDir, true ); } Directory.CreateDirectory( targetDir ); // Extract the Zip contents to the target directory. var outputZip = this.project.GetOutputAssembly( this.ConfigName ); // MPF is lazy and hardcodes ".exe" to the output assembly. We hardcode it to zip instead. outputZip = outputZip.Substring( 0, outputZip.Length - 4 ) + ".zip"; var file = new Ionic.Zip.ZipFile( outputZip ); file.ExtractAll( targetDir, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently ); var launchMode = ( GetConfigurationProperty( "LaunchMode", false ) ?? "" ).ToLowerInvariant(); vault = clientApp.BindToVault( vaultName, IntPtr.Zero, true, false ); if( launchMode == "powershell" ) { var builtInState = InitialSessionState.CreateDefault(); builtInState.Variables.Add( new SessionStateVariableEntry( "vaultName", vaultName, "Name of the vault used for testing." ) ); builtInState.Variables.Add( new SessionStateVariableEntry( "vault", vault, "M-Files Vault" ) ); Runspace runspace = RunspaceFactory.CreateRunspace( builtInState ); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript( GetConfigurationProperty( "LaunchPSScript", false ) ?? "" ); pipeline.Invoke(); runspace.Close(); } else { var mfilesPath = clientApp.GetDriveLetter() + ":\\" + vaultName + "\\" + GetConfigurationProperty( "LaunchMFilesPath", false ); try { // We need to log in first - otherwise explorer.exe can't find the folders. Process.Start( "explorer.exe", string.Format( "\"{0}\"", mfilesPath ) ); } catch { } } return VSConstants.S_OK; }
/// <summary> /// Deploys the M-Files Application to a client and launches it. /// </summary> /// <param name="grfLaunch">Launch flags</param> /// <returns>Success code</returns> public override int DebugLaunch( uint grfLaunch ) { // TODO: For debugging, check the grfLaunch flags. // The flags differ for "Launch" and "Launch with debugging". CCITracing.TraceCall(); // Resolve the test vault. var clientApp = new MFilesAPI.MFilesClientApplication(); var vaultName = GetConfigurationProperty( "TestVault", true ); MFilesAPI.VaultConnection vaultConnection; try { // Try to get the connection. vaultConnection = clientApp.GetVaultConnection( vaultName ); } catch { // Vault wasn't found, ask the user for a new one. var selectVaultDialog = new SelectVaultDialog(); selectVaultDialog.ShowDialog(); if( selectVaultDialog.Result == System.Windows.Forms.DialogResult.Cancel ) return VSConstants.S_FALSE; // Get the user answer. vaultName = selectVaultDialog.VaultName; vaultConnection = clientApp.GetVaultConnection( selectVaultDialog.VaultName ); // If the user defined this as the default vault, save it in the project file. if( selectVaultDialog.SetDefault ) this.SetConfigurationProperty( "TestVault", selectVaultDialog.VaultName ); } // Get the M-Files install directory from the registry. var apiVersion = clientApp.GetAPIVersion().Display; var hklm64 = RegistryKey.OpenBaseKey( RegistryHive.LocalMachine, RegistryView.Registry64 ); var mfKey = hklm64.OpenSubKey( @"Software\Motive\M-Files\" + apiVersion ); var installDir = (string)mfKey.GetValue( "InstallDir" ); mfKey.Close(); hklm64.Close(); // Log out to free the current application. MFilesAPI.Vault vault = null; try { vault = clientApp.BindToVault( vaultName, IntPtr.Zero, false, true ); if( vault != null ) vault.LogOutWithDialogs( IntPtr.Zero ); } catch { // We most likely weren't logged in so everything is okay. } // Deploy the application. string vaultGuid = vaultConnection.GetGUID(); var relativePath = string.Format( @"Client\Apps\{0}\sysapps\{1}", vaultGuid, this.project.GetProjectProperty( "Name" ) ?? "unnamed" ); var targetDir = Path.Combine( installDir, relativePath ); // If the directory exists, remove it so there's no residue files left. if( Directory.Exists( targetDir ) ) { Directory.Delete( targetDir, true ); } Directory.CreateDirectory( targetDir ); // Extract the Zip contents to the target directory. DeployPackage( targetDir ); // Log back into the application. vault = clientApp.BindToVault( vaultName, IntPtr.Zero, true, true ); // If vault is null, the user cancelled the login -> Exit if( vault == null ) return VSConstants.S_FALSE; // Figure out the launch mode. var launchMode = ( GetConfigurationProperty( "LaunchMode", false ) ?? "" ).ToLowerInvariant(); if( launchMode == "powershell" ) { // Create a powershell window to launch the application. // Create the initial state with the app and vault references. var builtInState = InitialSessionState.CreateDefault(); builtInState.Variables.Add( new SessionStateVariableEntry( "app", clientApp, "M-Files Application" ) ); builtInState.Variables.Add( new SessionStateVariableEntry( "vault", vault, "M-Files Vault" ) ); Runspace runspace = RunspaceFactory.CreateRunspace( builtInState ); // Run the script. runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript( GetConfigurationProperty( "LaunchPSScript", false ) ?? "" ); pipeline.Invoke(); runspace.Close(); } else { // Launch the application by navigating to a path in the vault. var mfilesPath = clientApp.GetDriveLetter() + ":\\" + vaultName + "\\" + GetConfigurationProperty( "LaunchMFilesPath", false ); Process.Start( "explorer.exe", string.Format( "\"{0}\"", mfilesPath ) ); } return VSConstants.S_OK; }
/// <summary> /// Deploys the M-Files Application to a client and launches it. /// </summary> /// <param name="grfLaunch">Launch flags</param> /// <returns>Success code</returns> public override int DebugLaunch(uint grfLaunch) { // TODO: For debugging, check the grfLaunch flags. // The flags differ for "Launch" and "Launch with debugging". CCITracing.TraceCall(); // Resolve the test vault. var clientApp = new MFilesAPI.MFilesClientApplication(); var vaultName = GetConfigurationProperty("TestVault", true); MFilesAPI.VaultConnection vaultConnection; try { // Try to get the connection. vaultConnection = clientApp.GetVaultConnection(vaultName); } catch { // Vault wasn't found, ask the user for a new one. var selectVaultDialog = new SelectVaultDialog(); selectVaultDialog.ShowDialog(); if (selectVaultDialog.Result == System.Windows.Forms.DialogResult.Cancel) { return(VSConstants.S_FALSE); } // Get the user answer. vaultName = selectVaultDialog.VaultName; vaultConnection = clientApp.GetVaultConnection(selectVaultDialog.VaultName); // If the user defined this as the default vault, save it in the project file. if (selectVaultDialog.SetDefault) { this.SetConfigurationProperty("TestVault", selectVaultDialog.VaultName); } } // Get the M-Files install directory from the registry. var apiVersion = clientApp.GetAPIVersion().Display; var hklm64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); var mfKey = hklm64.OpenSubKey(@"Software\Motive\M-Files\" + apiVersion); var installDir = (string)mfKey.GetValue("InstallDir"); mfKey.Close(); hklm64.Close(); // Log out to free the current application. MFilesAPI.Vault vault = null; try { vault = clientApp.BindToVault(vaultName, IntPtr.Zero, false, true); if (vault != null) { vault.LogOutWithDialogs(IntPtr.Zero); } } catch { // We most likely weren't logged in so everything is okay. } // Deploy the application. string vaultGuid = vaultConnection.GetGUID(); var relativePath = string.Format(@"Client\Apps\{0}\sysapps\{1}", vaultGuid, this.project.GetProjectProperty("Name") ?? "unnamed"); var targetDir = Path.Combine(installDir, relativePath); // If the directory exists, remove it so there's no residue files left. if (Directory.Exists(targetDir)) { Directory.Delete(targetDir, true); } Directory.CreateDirectory(targetDir); // Extract the Zip contents to the target directory. DeployPackage(targetDir); // Log back into the application. vault = clientApp.BindToVault(vaultName, IntPtr.Zero, true, true); // If vault is null, the user cancelled the login -> Exit if (vault == null) { return(VSConstants.S_FALSE); } // Figure out the launch mode. var launchMode = (GetConfigurationProperty("LaunchMode", false) ?? "").ToLowerInvariant(); if (launchMode == "powershell") { // Create a powershell window to launch the application. // Create the initial state with the app and vault references. var builtInState = InitialSessionState.CreateDefault(); builtInState.Variables.Add(new SessionStateVariableEntry( "app", clientApp, "M-Files Application")); builtInState.Variables.Add(new SessionStateVariableEntry( "vault", vault, "M-Files Vault")); Runspace runspace = RunspaceFactory.CreateRunspace(builtInState); // Run the script. runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript(GetConfigurationProperty("LaunchPSScript", false) ?? ""); pipeline.Invoke(); runspace.Close(); } else { // Launch the application by navigating to a path in the vault. var mfilesPath = clientApp.GetDriveLetter() + ":\\" + vaultName + "\\" + GetConfigurationProperty("LaunchMFilesPath", false); Process.Start("explorer.exe", string.Format("\"{0}\"", mfilesPath)); } return(VSConstants.S_OK); }