public void LoadDuplicateReferencesThrow()
        {
            IAssetReferenceService service = (IAssetReferenceService)package.GetService(typeof(IAssetReferenceService), true);

            service.Add(new MockObjects.MockReference("AddService", "/Solution/Services"), true);
            service.Add(new MockObjects.MockReference("AddService", "/Solution/Services"), true);
        }
Пример #2
0
            public override void Execute()
            {
                IAssetReferenceService refsvc = (IAssetReferenceService)
                                                GetService(typeof(IAssetReferenceService));

                refsvc.Add(new MockObjects.MockReference("ValidateSolution", "/"));
                refsvc.Add(new MockObjects.MockReference("PublishServices", "/Services/Accounting"));
                refsvc.Add(new MyUnboundRecipeReference("AddXmlSerializationClass"));

                Flags[0] = true;
            }
        public void IndexedByItem()
        {
            IAssetReferenceService service = (IAssetReferenceService)package.GetService(typeof(IAssetReferenceService), true);

            service.Add(new MockObjects.MockReference("AddService", "/Solution/Services"));
            service.Add(new MockObjects.MockReference("AddService", "/Solution/Services/Accounting"));
            service.Add(new MockObjects.MockReference("AddService", "/Solution/BusinessLayer"));
            service.Add(new MockObjects.MockReference("AddBusinessAction", "/Solution/BusinessLayer"));

            Assert.AreEqual(service.Find(typeof(IndexerBoundTarget), "/Solution/Services/Accounting").Length, 1);
            Assert.AreEqual(service.Find(typeof(IndexerBoundTarget), "/Solution/BusinessLayer").Length, 2);
        }
Пример #4
0
        /// <summary>
        /// Creates the unbound reference and registers
        /// the reference with the Recipe Framework
        /// </summary>
        public override void Execute()
        {
            ITypeResolutionService typeLoader = GetService <ITypeResolutionService>(true);
            Type assetType = typeLoader.GetType(this.referenceType, true);

            if (!typeof(IUnboundAssetReference).IsAssignableFrom(assetType))
            {
                throw new ArgumentException(String.Format(
                                                System.Globalization.CultureInfo.CurrentCulture,
                                                Properties.Resources.CreateUnboundReferenceAction_WrongType,
                                                assetType));
            }

            ConstructorInfo ctor = assetType.GetConstructor(new Type[] { typeof(string) });

            if (ctor == null)
            {
                throw new NotSupportedException(String.Format(
                                                    System.Globalization.CultureInfo.CurrentCulture,
                                                    Properties.Resources.CreateUnboundReferenceAction_UnsupportedConstructor,
                                                    assetType));
            }

            reference = (IAssetReference)ctor.Invoke(new object[] { this.assetName });
            if (reference is IAttributesConfigurable)
            {
                ((IAttributesConfigurable)reference).Configure(this.attributes);
            }
            IAssetReferenceService service = GetService <IAssetReferenceService>(true);

            service.Add(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);
        }
Пример #6
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);
        }
Пример #7
0
            public override void Execute()
            {
                if (OldReference == null)
                {
                    return;
                }
                IRecipeManagerService manager = (IRecipeManagerService)
                                                ServiceHelper.GetService(this, typeof(IRecipeManagerService));
                // Add the references to the target package.
                GuidancePackage        package          = manager.GetPackage(targetPackage);
                IAssetReferenceService referenceService = (IAssetReferenceService)
                                                          ServiceHelper.GetService(package, typeof(IAssetReferenceService), this);
                IPersistenceService persist = (IPersistenceService)
                                              ServiceHelper.GetService(this, typeof(IPersistenceService));

                try
                {
                    IDictionary state = persist.LoadState(package.Configuration.Name, OldReference);
                    if ((target != null) && !(target is DummyDTE.EmptyDteElement))
                    {
                        //We have to get the real object Project for case of Solution Folder
                        object realTarget = target;
                        if (target is SolutionFolder)
                        {
                            realTarget = ((SolutionFolder)target).Parent;
                        }

                        if (OldReference is VsBoundReference)
                        {
                            ((VsBoundReference)OldReference).SetTarget(realTarget);
                        }
                        else if (OldReference is BoundTemplateReference)
                        {
                            ((BoundTemplateReference)OldReference).BoundReference.SetTarget(realTarget);
                        }
                        referenceService.Add(OldReference, state);
                    }
                }
                catch (Exception ex)
                {
                    if (OldReference != null)
                    {
                        referenceService.Remove(OldReference);
                    }
                    ErrorHelper.Show(this.Site, ex);
                }
            }
        /// <summary>
        /// <seealso cref="IAction.Execute"/>
        /// </summary>
        public override void Execute()
        {
            if (Template.ExtensionData.References == null)
            {
                return;
            }
            int length = 0;

            if (Template.ExtensionData.References.RecipeReference != null)
            {
                length = Template.ExtensionData.References.RecipeReference.Length;
            }
            if (Template.ExtensionData.References.TemplateReference != null)
            {
                length += Template.ExtensionData.References.TemplateReference.Length;
            }

            referencesAdded = new ArrayList(length);

            IAssetReferenceService referenceService = GetService <IAssetReferenceService>(true);
            StringBuilder          errorList        = new StringBuilder();

            if (this.Template.ExtensionData.References.RecipeReference != null)
            {
                foreach (Microsoft.Practices.RecipeFramework.VisualStudio.VsTemplate.AssetReference reference in Template.ExtensionData.References.RecipeReference)
                {
                    Hashtable hashInitialState;
                    try
                    {
                        hashInitialState = ReadReferenceState(reference.InitialState);
                    }
                    catch (Exception ex)
                    {
                        errorList.AppendFormat(
                            CultureInfo.CurrentCulture,
                            Properties.Resources.Templates_InitialStateError,
                            reference.Name,
                            DteHelper.ReplaceParameters(reference.Target, this.ReplacementDictionary),
                            ex);
                        // Don't add the offending reference.
                        continue;
                    }
                    VsBoundReference vsTarget = this.GetReferenceTarget(reference.Target, reference.Name);
                    if (vsTarget != null)
                    {
                        try
                        {
                            referenceService.Add(vsTarget, hashInitialState);
                            referencesAdded.Add(vsTarget);
                        }
                        catch (Exception ex)
                        {
                            errorList.AppendFormat(ex.Message).AppendLine();
                        }
                    }
                    else
                    {
                        errorList.AppendFormat(
                            CultureInfo.CurrentCulture,
                            Properties.Resources.Templates_CantFindTarget,
                            DteHelper.ReplaceParameters(reference.Target, this.ReplacementDictionary),
                            reference.Name).AppendLine();
                    }
                }
            }
            if (this.Item != null && this.Template.ExtensionData.References.TemplateReference != null)
            {
                throw new ArgumentException(String.Format(
                                                CultureInfo.CurrentCulture,
                                                Properties.Resources.Templates_ItemCantHaveTemplates,
                                                Path.GetFileName(this.Template.FileName)),
                                            "TemplateReference");
            }
            if (this.Template.ExtensionData.References.TemplateReference != null)
            {
                string basePath = this.Package.BasePath;
                foreach (VsTemplate.AssetReference reference in this.Template.ExtensionData.References.TemplateReference)
                {
                    Hashtable hashInitialState;
                    try
                    {
                        hashInitialState = ReadReferenceState(reference.InitialState);
                    }
                    catch (Exception ex)
                    {
                        errorList.AppendFormat(
                            CultureInfo.CurrentCulture,
                            Properties.Resources.Templates_InitialStateError,
                            reference.Name, reference.Target, ex);
                        continue;
                    }
                    string templateFileName = basePath + @"\Templates\" + reference.Name;
                    templateFileName = new CompatibleUri(templateFileName).LocalPath;
                    // Normalize path as it may contain double back slashes which usually shouldn't hurt but will break some of the checkings GAX does against registry keys
                    // this is necessary due to Uri.LocalPath behaving differently under Vista -- reported as VS bug #
                    //templateFileName = WinXpUriLocalPathBehavior(
                    //templateFileName = templateFileName.Replace(@"\\", @"\");
                    VsBoundReference vsTarget = this.GetReferenceTarget(reference.Target, templateFileName);
                    if (File.Exists(templateFileName) && templateFileName.EndsWith(".vstemplate", StringComparison.InvariantCultureIgnoreCase) && vsTarget != null)
                    {
                        BoundTemplateReference tmpref = new BoundTemplateReference(templateFileName, vsTarget);
                        referencesAdded.Add(tmpref);
                        referenceService.Add(tmpref, hashInitialState);
                    }
                    else if (vsTarget == null)
                    {
                        errorList.Append(String.Format(
                                             CultureInfo.CurrentCulture,
                                             Properties.Resources.Templates_CantFindTarget,
                                             DteHelper.ReplaceParameters(reference.Target, this.ReplacementDictionary),
                                             reference.Name));
                        errorList.Append(Environment.NewLine);
                    }
                    else
                    {
                        errorList.Append(String.Format(
                                             CultureInfo.CurrentCulture,
                                             Properties.Resources.Template_DoesntExist,
                                             reference.Name));
                        errorList.Append(Environment.NewLine);
                    }
                }
            }
            if (errorList.Length > 0)
            {
                // Enclose full list of errors in a simpler message for display in the dialog.
                throw new RecipeFrameworkException(string.Format(CultureInfo.CurrentCulture,
                                                                 Properties.Resources.Templates_ErrorsProcessingReferences,
                                                                 this.Template.Name),
                                                   new ArgumentException(errorList.ToString()));
            }
        }