Ejemplo n.º 1
0
        /// <summary>
        /// Executes the reference.
        /// </summary>
        /// <param name="reference">The IAssetReference that will be execute.</param>
        private void ExecuteReference(IAssetReference reference)
        {
            if (reference == null)
            {
                return;
            }

            try
            {
                IHostService host = (IHostService)ServiceHelper.GetService(this, typeof(IHostService));

                bool execute = false;
                if (reference is IBoundAssetReference)
                {
                    IBoundAssetReference boundReferece = reference as IBoundAssetReference;
                    if (boundReferece.Target == null)
                    {
                        // this is a stale bound reference: tell the user and refresh the list of available guidance
                        MessageBox.Show(Properties.Resources.Navigator_StaleReference, Properties.Resources.Navigator_StaleReferenceTitle);
                        // invalidate the cache to remove stale references
                        this.UpdateAvailableGuidance(true);
                        return;
                    }
                    execute = host.SelectTarget(((IBoundAssetReference)reference).Target);
                }
                else if (reference is IUnboundAssetReference)
                {
                    execute = host.SelectTarget(this, (IUnboundAssetReference)reference);
                }

                if (execute)
                {
                    selectedGuidancePackage.TurnOnOutput();
                    reference.Execute();
                }
            }
            catch (Exception ex)
            {
                ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), ex);
            }
            finally
            {
                if (selectedGuidancePackage != null)
                {
                    selectedGuidancePackage.TurnOffOutput();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs selection of the target item before executing the recipe
        /// if it's not the same as the target.
        /// </summary>
        protected override ExecutionResult OnExecute()
        {
            DTE    vs        = (DTE)ServiceHelper.GetService(this, typeof(DTE));
            object selection = null;

            if (vs.SelectedItems != null && vs.SelectedItems.Count > 0)
            {
                IEnumerator enumerator = vs.SelectedItems.GetEnumerator();
                enumerator.MoveNext();
                SelectedItem item = (SelectedItem)enumerator.Current;
                // Determine current target selection.
                if (item.Project != null)
                {
                    selection = item.Project;
                }
                else if (item.ProjectItem != null)
                {
                    selection = item.ProjectItem;
                }
                else
                {
                    selection = vs.Solution;
                }
            }
            if (this.target != selection)
            {
                IHostService host = (IHostService)ServiceHelper.GetService(this, typeof(IHostService));
                // Perform selection of reference target.
                host.SelectTarget(this.target);
            }
            return(base.OnExecute());
        }
Ejemplo n.º 3
0
        private void OnExecuteRecipe(object sender, System.EventArgs e)
        {
            GuidancePackage Package = null;

            try
            {
                if (lstRecipes.SelectedItems.Count == 0)
                {
                    MessageBox.Show(this, Configuration.Resources.PackageManager_MustSelectRecipe,
                                    this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                IHostService    host      = (IHostService)ServiceHelper.GetService(this, typeof(IHostService));
                IAssetReference reference = ((ReferenceInfo)lstRecipes.SelectedItems[0].Tag).Reference;
                bool            execute   = false;
                if (reference is IBoundAssetReference)
                {
                    execute = host.SelectTarget(((IBoundAssetReference)reference).Target);
                }
                else if (reference is IUnboundAssetReference)
                {
                    execute = host.SelectTarget(this, (IUnboundAssetReference)reference);
                }

                if (execute)
                {
                    Package = (GuidancePackage)ServiceHelper.GetService(reference, typeof(IExecutionService));
                    Package.TurnOnOutput();
                    reference.Execute();
                    LoadReferences();
                }
            }
            catch (Exception ex)
            {
                ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), ex);
            }
            finally
            {
                if (Package != null)
                {
                    Package.TurnOffOutput();
                }
            }
        }