示例#1
0
        private void CheckReferences()
        {
            SolutionPackagesContainer container = (SolutionPackagesContainer)GetService(typeof(IHostService));
            IPersistenceService       persist   = (IPersistenceService)container.GetService(typeof(IPersistenceService), true);

            foreach (object obj in container.Components)
            {
                if (obj is VsGuidancePackage)
                {
                    GuidancePackage package = ((VsGuidancePackage)obj).GuidancePackage;

                    if ((package == null) || (package.Configuration == null))
                    {
                        continue;
                    }

                    foreach (IAssetReference reference in persist.LoadReferences(package.Configuration.Name))
                    {
                        if (reference is IBoundAssetReference)
                        {
                            IBoundAssetReference boundReference = (IBoundAssetReference)reference;
                            if (boundReference.Target == null)
                            {
                                referencesToFix.Add(
                                    new FixupReference(package, reference.AssetName, boundReference));
                            }
                        }
                    }
                }
            }
        }
示例#2
0
 public override void Remove(IAssetReference reference)
 {
     if (reference == null)
     {
         throw new ArgumentNullException("reference");
     }
     if (reference is IBoundAssetReference)
     {
         IBoundAssetReference boundref = (IBoundAssetReference)reference;
         if (boundref.Target is EnvDTE.ProjectItem)
         {
             EnvDTE.ProjectItem prItem            = (EnvDTE.ProjectItem)boundref.Target;
             EnvDTE.Project     containingProject = null;
             try
             {
                 containingProject = prItem.ContainingProject;
             }
             catch
             {
                 containingProject = null;
             }
             if (containingProject != null)
             {
                 ArrayList reflist = (ArrayList)references[containingProject];
                 if (reflist != null)
                 {
                     reflist.Remove(reference);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Adds the template reference to the IAssetReferenceService
        /// </summary>
        public override void Execute()
        {
            DTE vs = GetService <DTE>(true);
            IAssetReferenceService referenceService = GetService <IAssetReferenceService>(true);
            object item = DteHelper.GetTarget(vs);

            if (item == null)
            {
                throw new InvalidOperationException("There is no valid target to reference the template.");
            }

            if (item is Project)
            {
                addedReference = new ProjectReference(recipeName, (Project)item);
            }
            else if (item is Solution)
            {
                addedReference = new SolutionReference(recipeName, (Solution)item);
            }
            else if (item is ProjectItem)
            {
                addedReference = new ProjectItemReference(recipeName, (ProjectItem)item);
            }
            else
            {
                throw new NotSupportedException("Current selection is unsupported.");
            }

            referenceService.Add(addedReference);

            MessageBox.Show("The new reference was successfully added.", "New Reference",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#4
0
        /// <summary>
        /// Adds the template reference to the IAssetReferenceService
        /// </summary>
        public override void Execute()
        {
            EnvDTE.DTE             dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
            IAssetReferenceService referenceService = (IAssetReferenceService)GetService(typeof(IAssetReferenceService));
            object item = DteHelper.GetTarget(dte);



            if (item == null)
            {
                MessageBox.Show("There is no valid target to reference the template");
                return;
            }
            templateFilename = new Uri(templateFilename).LocalPath;

            VsBoundReference vsTarget = null;

            if (item is Project)
            {
                vsTarget = new ProjectReference(templateFilename, (Project)item);
            }
            else if (item is Solution)
            {
                vsTarget = new SolutionReference(templateFilename, (Solution)item);
            }
            else if (item is ProjectItem)
            {
                vsTarget = new ProjectItemReference(templateFilename, (ProjectItem)item);
            }
            else if (item is EnvDTE80.SolutionFolder)
            {
                vsTarget = new ProjectReference(templateFilename, ((EnvDTE80.SolutionFolder)item).Parent);
            }
            if (item == null || vsTarget == null)
            {
                MessageBox.Show(string.Format(
                                    CultureInfo.CurrentCulture,
                                    "Target {0} specified for reference to asset {1} doesn't exist.",
                                    "target", templateFilename));
                return;
            }
            if (!File.Exists(templateFilename) || !templateFilename.EndsWith(".vstemplate", StringComparison.InvariantCultureIgnoreCase))
            {
                MessageBox.Show(string.Format(
                                    CultureInfo.CurrentCulture,
                                    "The filename specified for the template \"{0}\" does not exist.",
                                    templateFilename));
                return;
            }
            newReference = new BoundTemplateReference(templateFilename, vsTarget);
            referenceService.Add(newReference);
            MessageBox.Show("The new reference was successfully added", "New Reference",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#5
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();
                }
            }
        }
示例#6
0
 /// <summary>
 /// See <see cref="IAssetReferenceIndexer.Add"/>.
 /// </summary>
 public override void Add(IAssetReference reference)
 {
     if (reference == null)
     {
         throw new ArgumentNullException("reference");
     }
     if (reference is IBoundAssetReference)
     {
         IBoundAssetReference boundref = (IBoundAssetReference)reference;
         ArrayList            reflist  = (ArrayList)references[boundref.AssetName];
         if (reflist == null)
         {
             reflist = new ArrayList();
             references.Add(boundref.AssetName, reflist);
         }
         reflist.Add(reference);
     }
 }
示例#7
0
 /// <summary>
 /// See <see cref="IAssetReferenceIndexer.Add"/>.
 /// </summary>
 public override void Add(IAssetReference reference)
 {
     if (reference == null)
     {
         throw new ArgumentNullException("reference");
     }
     if ((reference is IBoundAssetReference) && (((IBoundAssetReference)reference).Target != null))
     {
         IBoundAssetReference boundref = (IBoundAssetReference)reference;
         IDictionary          targets  = (IDictionary)references[boundref.AssetName];
         if (targets == null)
         {
             targets = new HybridDictionary();
             references.Add(boundref.AssetName, targets);
         }
         targets.Add(boundref.Target, reference);
     }
 }
示例#8
0
 public override void Add(IAssetReference reference)
 {
     if (reference == null)
     {
         throw new ArgumentNullException("reference");
     }
     if (reference is IBoundAssetReference)
     {
         IBoundAssetReference boundref      = (IBoundAssetReference)reference;
         EnvDTE.Project       parentProject = null;
         if (boundref.Target is EnvDTE.ProjectItem)
         {
             EnvDTE.ProjectItem prItem = (EnvDTE.ProjectItem)boundref.Target;
             parentProject = prItem.ContainingProject;
         }
         else if (boundref.Target is EnvDTE.Project)
         {
             EnvDTE.Project project = (EnvDTE.Project)boundref.Target;
             try
             {
                 if (project.ParentProjectItem != null && project.ParentProjectItem.ContainingProject != null)
                 {
                     parentProject = project.ParentProjectItem.ContainingProject;
                 }
             }
             catch
             {
                 parentProject = null;
             }
         }
         if (parentProject != null)
         {
             ArrayList reflist = null;
             if (!references.Contains(parentProject))
             {
                 reflist = new ArrayList();
                 references.Add(parentProject, reflist);
             }
             reflist = (ArrayList)references[parentProject];
             reflist.Add(reference);
         }
     }
 }
示例#9
0
 /// <summary>
 /// See <see cref="IAssetReferenceIndexer.Remove"/>.
 /// </summary>
 public override void Remove(IAssetReference reference)
 {
     if (reference == null)
     {
         throw new ArgumentNullException("reference");
     }
     if (reference is IBoundAssetReference)
     {
         IBoundAssetReference boundRef = (IBoundAssetReference)reference;
         if (boundRef.Target != null)
         {
             ArrayList reflist = (ArrayList)references[boundRef.Target];
             if (reflist != null)
             {
                 reflist.Remove(reference);
             }
         }
     }
 }
示例#10
0
            public FixupReference(GuidancePackage owningPackage,
                                  string asset,
                                  IBoundAssetReference oldReference)
            {
                this.OwningPackage   = owningPackage;
                this.ReferencedAsset = asset;
                VsBoundReference realReference = null;

                if (oldReference is VsBoundReference)
                {
                    realReference = (VsBoundReference)oldReference;
                }
                else if (oldReference is BoundTemplateReference)
                {
                    realReference = (VsBoundReference)((BoundTemplateReference)oldReference).BoundReference;
                }
                this.SavedTarget        = realReference.SubPath;
                this.ExpectedTargetKind = GetTargetKind(realReference);
                this.OldReference       = oldReference;
            }
示例#11
0
 /// <summary>
 /// Determines the kind of target based on the type of the reference.
 /// </summary>
 private TargetKind GetTargetKind(IBoundAssetReference reference)
 {
     if (reference is SolutionReference)
     {
         return(TargetKind.Solution);
     }
     else if (reference is ProjectReference)
     {
         if (((ProjectReference)reference).IsSolutionFolder)
         {
             return(TargetKind.SolutionFolder);
         }
         return(TargetKind.Project);
     }
     else if (reference is ProjectItemReference)
     {
         return(TargetKind.ProjectItem);
     }
     else if (reference is BoundTemplateReference)
     {
         return(TargetKind.SolutionFolder);
     }
     throw new NotSupportedException(reference.ToString());
 }
示例#12
0
        /// <summary>
        /// Adds the template reference to the IAssetReferenceService
        /// </summary>
        public override void Execute()
        {
            EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
            IAssetReferenceService referenceService = (IAssetReferenceService)GetService(typeof(IAssetReferenceService));
            object item = DteHelper.GetTarget(dte);



            if (item == null)
            {
                MessageBox.Show("There is no valid target to reference the template");
                return;
            }
            templateFilename = new Uri(templateFilename).LocalPath;

            VsBoundReference vsTarget = null;
            if (item is Project)
            {
                vsTarget = new ProjectReference(templateFilename, (Project)item);
            }
            else if (item is Solution)
            {
                vsTarget = new SolutionReference(templateFilename, (Solution)item);
            }
            else if (item is ProjectItem)
            {
                vsTarget = new ProjectItemReference(templateFilename, (ProjectItem)item);
            }
            else if (item is EnvDTE80.SolutionFolder)
            {
                vsTarget = new ProjectReference(templateFilename, ((EnvDTE80.SolutionFolder)item).Parent);
            }
            if (item == null || vsTarget == null)
            {
                MessageBox.Show(string.Format(
                    CultureInfo.CurrentCulture,
                    "Target {0} specified for reference to asset {1} doesn't exist.",
                    "target", templateFilename));
                return;
            }
            if (!File.Exists(templateFilename) || !templateFilename.EndsWith(".vstemplate", StringComparison.InvariantCultureIgnoreCase))
            {
                MessageBox.Show(string.Format(
                    CultureInfo.CurrentCulture,
                    "The filename specified for the template \"{0}\" does not exist.",
                    templateFilename));
                return;
            }
            newReference = new BoundTemplateReference(templateFilename, vsTarget);
            referenceService.Add(newReference);
            MessageBox.Show("The new reference was successfully added", "New Reference",
                MessageBoxButtons.OK, MessageBoxIcon.Information);

        }