Exemple #1
0
        public override int DebugLaunch(uint grfLaunch)
        {
            CCITracing.TraceCall();

            try
            {
                if (grfLaunch == 0)
                    grfLaunch = (uint) __VSDBGLAUNCHFLAGS.DBGLAUNCH_Silent;
                VsDebugTargetInfo info = new VsDebugTargetInfo();
                info.cbSize = (uint)Marshal.SizeOf(info);
                info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

                // On first call, reset the cache, following calls will use the cached values
                string property = GetConfigurationProperty("DebuggerCommand", true);
                if (string.IsNullOrEmpty(property))
                {
                    property = this._project.GetOutputAssembly(this.ConfigCanonicalName);
                }
                info.bstrExe = property;

                property = GetConfigurationProperty("DebuggerWorkingDirectory", false);
                if (string.IsNullOrEmpty(property))
                {
                    property = Path.GetDirectoryName(info.bstrExe);
                }
                info.bstrCurDir = property;

                property = GetConfigurationProperty("DebuggerCommandArguments", false);
                if (!string.IsNullOrEmpty(property))
                {
                    info.bstrArg = property;
                }

                property = GetConfigurationProperty("RemoteDebugMachine", false);
                if (property != null && property.Length > 0)
                {
                    info.bstrRemoteMachine = property;
                }

                property = GetConfigurationProperty("RedirectToOutputWindow", false);
                if (property != null && string.Compare(property, "true", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    info.fSendStdoutToOutputWindow = 1;
                }
                else
                {
                    info.fSendStdoutToOutputWindow = 0;
                }


                property = GetConfigurationProperty("EnableUnmanagedDebugging", false);
                if (property != null && string.Compare(property, "true", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    info.clsidCustom = VSConstants.DebugEnginesGuids.ManagedAndNative_guid; // {92EF0900-2251-11D2-B72E-0000F87572EF}
                }
                else
                {
                    info.clsidCustom = VSConstants.DebugEnginesGuids.ManagedOnly_guid;      // {449EC4CC-30D2-4032-9256-EE18EB41B62B}
                }
                info.grfLaunch = grfLaunch;
                VsShellUtilities.LaunchDebugger(this._project.Site, info);
            }
            catch (Exception e)
            {
                XSharpProjectPackage.Instance.DisplayException(e);

                return Marshal.GetHRForException(e);
            }

            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);
        }
Exemple #3
0
        /// <summary>
        /// Override AddProjectReference to hide the .NET and COM tabs.
        ///
        /// This is copied from the base project - just removed some of
        /// the elements in the tabInitList to remove the .NET and COM
        /// tabs from the dialog.
        /// </summary>
        /// <returns>Success message</returns>
        public override int AddProjectReference()
        {
            CCITracing.TraceCall();

            IVsComponentSelectorDlg4 componentDialog;
            string strBrowseLocations = Path.GetDirectoryName(this.BaseURI.Uri.LocalPath);
            var    tabInitList        = new List <VSCOMPONENTSELECTORTABINIT>()
            {
                new VSCOMPONENTSELECTORTABINIT {
                    // Tell the Add Reference dialog to call hierarchies GetProperty with the following
                    // propID to enablefiltering out ourself from the Project to Project reference
                    varTabInitInfo = (int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage,
                    guidTab        = VSConstants.GUID_SolutionPage,
                },
                // Add the Browse for file page
                new VSCOMPONENTSELECTORTABINIT {
                    varTabInitInfo = 0,
                    guidTab        = VSConstants.GUID_BrowseFilePage,
                },
            };

            tabInitList.ForEach(tab => tab.dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)));

            componentDialog = this.GetService(typeof(IVsComponentSelectorDlg)) as IVsComponentSelectorDlg4;
            try
            {
                // call the container to open the add reference dialog.
                if (componentDialog != null)
                {
                    // Let the project know not to show itself in the Add Project Reference Dialog page
                    this.ShowProjectInSolutionPage = false;
                    // call the container to open the add reference dialog.
                    string browseFilters = "M-Files Application Packages (*.zip)\0*.zip\0";
                    ErrorHandler.ThrowOnFailure(componentDialog.ComponentSelectorDlg5(
                                                    (System.UInt32)(__VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode | __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName),
                                                    (IVsComponentUser)this,
                                                    0,
                                                    null,
                                                    SR.GetString(SR.AddReferenceDialogTitle, CultureInfo.CurrentUICulture), // Title
                                                    "VS.AddReference",                                                      // Help topic
                                                    0, 0,
                                                    (uint)tabInitList.Count,
                                                    tabInitList.ToArray(),
                                                    ref addComponentLastActiveTab,
                                                    browseFilters,
                                                    ref strBrowseLocations,
                                                    this.TargetFrameworkMoniker.FullName));
                }
            }
            catch (COMException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
                return(e.ErrorCode);
            }
            finally
            {
                // Let the project know it can show itself in the Add Project Reference Dialog page
                this.ShowProjectInSolutionPage = true;
            }
            return(VSConstants.S_OK);
        }
Exemple #4
0
        /// <summary>
        /// Called by the vs shell to start debugging (managed or unmanaged).
        /// Override this method to support other debug engines.
        /// </summary>
        /// <param name="grfLaunch">A flag that determines the conditions under which to start the debugger. For valid grfLaunch values, see __VSDBGLAUNCHFLAGS</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code</returns>
        public override int DebugLaunch(uint grfLaunch)
        {
            CCITracing.TraceCall();

            try
            {
                VsDebugTargetInfo info = new VsDebugTargetInfo();
                info.cbSize = (uint)Marshal.SizeOf(info);
                info.dlo    = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

                // On first call, reset the cache, following calls will use the cached values
                string property = GetConfigurationProperty("StartProgram", true);

                if (string.IsNullOrEmpty(property))
                {
                    info.bstrExe = ProjectMgr.GetOutputAssembly(this.ConfigKey);
                }
                else
                {
                    info.bstrExe = property;
                }

                property = GetConfigurationProperty("WorkingDirectory", false);

                if (string.IsNullOrEmpty(property))
                {
                    info.bstrCurDir = Path.GetDirectoryName(info.bstrExe);
                }
                else
                {
                    if (Path.IsPathRooted(property))
                    {
                        info.bstrCurDir = property;
                    }
                    else
                    {
                        var path = Path.Combine(ProjectMgr.BaseURI.AbsoluteUrl, property);

                        if (Directory.Exists(path))
                        {
                            info.bstrCurDir = path;
                        }
                        else
                        {
                            info.bstrCurDir = property;
                        }
                    }
                }

                property = GetConfigurationProperty("CmdArgs", false);

                if (!string.IsNullOrEmpty(property))
                {
                    info.bstrArg = property;
                }

                property = GetConfigurationProperty("RemoteDebugMachine", false);

                if (property != null && property.Length > 0)
                {
                    info.bstrRemoteMachine = property;
                }

                info.fSendStdoutToOutputWindow = 0;

                property = GetConfigurationProperty("EnableUnmanagedDebugging", false);

                if (property != null && string.Compare(property, "true", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    //Set the unmanged debugger
                    //TODO change to vsconstant when it is available in VsConstants (guidNativeOnlyEng was the old name, maybe it has got a new name)
                    info.clsidCustom = new Guid("{3B476D35-A401-11D2-AAD4-00C04F990171}");
                }
                else
                {
                    //Set the managed debugger
                    info.clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine;
                }

                info.grfLaunch = grfLaunch;
                LaunchDebugger(this.ProjectMgr.Site, info);
            }
            catch (Exception e)
            {
                var proj = ((NemerleProjectNode)ProjectMgr).ProjectInfo;
                proj.ShowMessage(e.Message, Nemerle.Completion2.MessageType.Error);

                return(Marshal.GetHRForException(e));
            }

            return(VSConstants.S_OK);
        }
Exemple #5
0
        // =========================================================================================
        // Methods
        // =========================================================================================

        /// <summary>
        /// Hides all of the tabs in the Add Reference dialog except for the browse tab, which will search for wixlibs.
        /// </summary>
        /// <returns></returns>
        public override int AddProjectReference()
        {
            CCITracing.TraceCall();

            Guid   emptyGuid           = Guid.Empty;
            Guid   showOnlyThisTabGuid = Guid.Empty;
            Guid   startOnThisTabGuid  = VSConstants.GUID_BrowseFilePage;
            string helpTopic           = "VS.AddReference";
            string machineName         = String.Empty;
            string browseFilters       = this.AddReferenceDialogFilter;
            string browseLocation      = this.AddReferenceDialogInitialDirectory;

            // initialize the structure that we have to pass into the dialog call
            VSCOMPONENTSELECTORTABINIT[] tabInitializers = new VSCOMPONENTSELECTORTABINIT[2];

            // tab 1 is the Project References tab: passing VSHPROPID_ShowProjInSolutionPage will tell the Add Reference
            // dialog to call into our GetProperty to determine if we should show ourself in the dialog
            tabInitializers[0].dwSize         = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT));
            tabInitializers[0].guidTab        = VSConstants.GUID_SolutionPage;
            tabInitializers[0].varTabInitInfo = (int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage;

            // tab 2 is the Browse tab
            tabInitializers[1].dwSize         = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT));
            tabInitializers[1].guidTab        = VSConstants.GUID_BrowseFilePage;
            tabInitializers[1].varTabInitInfo = 0;

            // initialize the flags to control the dialog
            __VSCOMPSELFLAGS flags = __VSCOMPSELFLAGS.VSCOMSEL_HideCOMClassicTab |
                                     __VSCOMPSELFLAGS.VSCOMSEL_HideCOMPlusTab |
                                     __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName |
                                     __VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode;

            // get the dialog service from the environment
            IVsComponentSelectorDlg dialog = WixHelperMethods.GetService <IVsComponentSelectorDlg, SVsComponentSelectorDlg>(this.Site);

            try
            {
                // tell ourself not to show our project in the Add Reference dialog
                this.ShowProjectInSolutionPage = false;

                // show the dialog
                ErrorHandler.ThrowOnFailure(dialog.ComponentSelectorDlg(
                                                (uint)flags,
                                                (IVsComponentUser)this,
                                                this.AddReferenceDialogTitle,
                                                helpTopic,
                                                ref showOnlyThisTabGuid,
                                                ref startOnThisTabGuid,
                                                machineName,
                                                (uint)tabInitializers.Length,
                                                tabInitializers,
                                                browseFilters,
                                                ref browseLocation));
            }
            catch (COMException e)
            {
                CCITracing.Trace(e);
                return(e.ErrorCode);
            }
            finally
            {
                // we can show ourself in the Add Reference dialog if somebody else invokes it
                this.ShowProjectInSolutionPage = true;
            }

            return(VSConstants.S_OK);
        }