/// <summary>
        /// Adds a reference to this container using the selector data structure to identify it.
        /// </summary>
        /// <param name="selectorData">data describing selected component</param>
        /// <returns>Reference in case of a valid reference node has been created. Otherwise null</returns>
        public ReferenceNode AddReferenceFromSelectorData(VSCOMPONENTSELECTORDATA selectorData)
        {
            //Make sure we can edit the project file
            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            //Create the reference node
            ReferenceNode node = null;

            try
            {
                node = CreateReferenceNode(selectorData);
            }
            catch (ArgumentException)
            {
                // Some selector data was not valid.
            }

            //Add the reference node to the project if we have a valid reference node
            if (node != null)
            {
                // This call will find if the reference is in the project and, in this case
                // will not add it again, so the parent node will not be set.
                node.AddReference();
                if (null == node.Parent)
                {
                    // Remove the partially added (Reference item added to the project file) node.
                    node.Remove(true);

                    // The reference was not added, so we can not return this item because it
                    // is not inside the project.
                    return(null);
                }
            }

            return(node);
        }
        protected virtual ReferenceNode CreateReferenceNode(VSCOMPONENTSELECTORDATA selectorData)
        {
            ReferenceNode node = null;

            switch (selectorData.type)
            {
            case VSCOMPONENTTYPE.VSCOMPONENTTYPE_Project:
                node = this.CreateProjectReferenceNode(selectorData);
                break;

            case VSCOMPONENTTYPE.VSCOMPONENTTYPE_File:
            // This is the case for managed assembly
            case VSCOMPONENTTYPE.VSCOMPONENTTYPE_ComPlus:
                node = this.CreateFileComponent(selectorData);
                break;

            case VSCOMPONENTTYPE.VSCOMPONENTTYPE_Com2:
                node = this.CreateComReferenceNode(selectorData);
                break;
            }

            return(node);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if a reference is already added. The method parses all references and compares the Url.
        /// </summary>
        /// <returns>true if the assembly has already been added.</returns>
        protected virtual bool IsAlreadyAdded(out ReferenceNode existingNode)
        {
            ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;

            Debug.Assert(referencesFolder != null, "Could not find the References node");

            for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
            {
                ReferenceNode referenceNode = n as ReferenceNode;
                if (null != referenceNode)
                {
                    // We check if the Url of the assemblies is the same.
                    if (NativeMethods.IsSamePath(referenceNode.Url, this.Url))
                    {
                        existingNode = referenceNode;
                        return(true);
                    }
                }
            }

            existingNode = null;
            return(false);
        }
Exemplo n.º 4
0
        protected override bool IsAlreadyAdded(out ReferenceNode existingNode)
        {
            ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;

            Debug.Assert(referencesFolder != null, "Could not find the References node");
            bool shouldCheckPath = !string.IsNullOrEmpty(this.Url);

            for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
            {
                ProjectReferenceNode projectReferenceNode = n as ProjectReferenceNode;
                if (null != projectReferenceNode)
                {
                    if (this.ReferencedProjectGuid.Equals(projectReferenceNode.ReferencedProjectGuid) ||
                        (shouldCheckPath && NativeMethods.IsSamePath(projectReferenceNode.Url, this.Url)))
                    {
                        existingNode = projectReferenceNode;
                        return(true);
                    }
                }
            }

            existingNode = null;
            return(false);
        }
        /// <summary>
        /// Checks if a reference is already added. The method parses all references and compares the the FinalItemSpec and the Guid.
        /// </summary>
        /// <returns>true if the assembly has already been added.</returns>
        protected override bool IsAlreadyAdded(out ReferenceNode existingNode)
        {
            ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;

            Debug.Assert(referencesFolder != null, "Could not find the References node");

            for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
            {
                if (n is ComReferenceNode)
                {
                    ComReferenceNode referenceNode = n as ComReferenceNode;

                    // We check if the name and guids are the same
                    if (referenceNode.TypeGuid == this.TypeGuid && String.Compare(referenceNode.Caption, this.Caption, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        existingNode = referenceNode;
                        return(true);
                    }
                }
            }

            existingNode = null;
            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds a reference to this container using the selector data structure to identify it.
        /// </summary>
        public ReferenceNode AddReferenceFromSelectorData(VSCOMPONENTSELECTORDATA selectorData)
        {
            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            ReferenceNode node = CreateReferenceNode(selectorData);

            if (node != null)
            {
                // This call will find if the reference is in the project and, in this case
                // will not add it again, so the parent node will not be set.
                node.AddReference();
                if (null == node.Parent)
                {
                    // The reference was not added, so we can not return this item because it
                    // is not inside the project.
                    return(null);
                }
            }

            return(node);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Checks if a reference is already added. The method parses all references and compares the filename.
        /// </summary>
        /// <returns>true if the extension reference has already been added.</returns>
        protected override bool IsAlreadyAdded(out ReferenceNode existingNode)
        {
            ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;
            Debug.Assert(referencesFolder != null, "Could not find the References node");

            string thisName = Path.GetFileNameWithoutExtension(this.ItemNode.Item.Xml.Include);
            for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
            {
                WixExtensionReferenceNode otherReference = n as WixExtensionReferenceNode;
                if (otherReference != null)
                {
                    string otherName = Path.GetFileNameWithoutExtension(otherReference.Url);
                    if (String.Equals(thisName, otherName, StringComparison.OrdinalIgnoreCase))
                    {
                        existingNode = otherReference;
                        return true;
                    }
                }
            }

            existingNode = null;
            return false;
        }
        /// <summary>
        /// Creates an assemby or com reference node given a selector data.
        /// </summary>
        protected virtual ReferenceNode CreateFileComponent(VSCOMPONENTSELECTORDATA selectorData)
        {
            if (null == selectorData.bstrFile)
            {
                throw new ArgumentNullException("selectordata.bstrFile");
            }

            // We have a path to a file, it could be anything
            // First see if it is a managed assembly
            bool tryToCreateAnAssemblyReference = true;

            if (File.Exists(selectorData.bstrFile))
            {
                try
                {
                    // We should not load the assembly in the current appdomain.
                    // If we do not do it like that and we load the assembly in the current appdomain then the assembly cannot be unloaded again.
                    // The following problems might arose in that case.
                    // 1. Assume that a user is extending the MPF and  his project is creating a managed assembly dll.
                    // 2. The user opens VS and creates a project and builds it.
                    // 3. Then the user opens VS creates another project and adds a reference to the previously built assembly. This will load the assembly in the appdomain had we been using Assembly.ReflectionOnlyLoadFrom.
                    // 4. Then he goes back to the first project modifies it an builds it. A build error is issued that the assembly is used.

                    // GetAssemblyName is assured not to load the assembly.
                    tryToCreateAnAssemblyReference = (AssemblyName.GetAssemblyName(selectorData.bstrFile) != null);
                }
                catch (BadImageFormatException)
                {
                    // We have found the file and it is not a .NET assembly; no need to try to
                    // load it again.
                    tryToCreateAnAssemblyReference = false;
                }
                catch (FileLoadException)
                {
                    // We must still try to load from here because this exception is thrown if we want
                    // to add the same assembly refererence from different locations.
                    tryToCreateAnAssemblyReference = true;
                }
            }

            ReferenceNode node = null;

            if (tryToCreateAnAssemblyReference)
            {
                // This might be a candidate for an assembly reference node. Try to load it.
                // CreateAssemblyReferenceNode will suppress BadImageFormatException if the node cannot be created.
                node = this.CreateAssemblyReferenceNode(selectorData.bstrFile);
            }

            // If no node has been created try to create a com reference node.
            if (node == null)
            {
                if (!File.Exists(selectorData.bstrFile))
                {
                    return(null);
                }
                node = this.CreateComReferenceNode(selectorData);
            }

            return(node);
        }
		protected override bool IsAlreadyAdded(out ReferenceNode existingNode)
		{
			ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;
			Debug.Assert(referencesFolder != null, "Could not find the References node");
			bool shouldCheckPath = !string.IsNullOrEmpty(this.Url);

			for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
			{
				ProjectReferenceNode projectReferenceNode = n as ProjectReferenceNode;
				if (null != projectReferenceNode)
				{
					if (this.ReferencedProjectGuid.Equals(projectReferenceNode.ReferencedProjectGuid) ||
						(shouldCheckPath && NativeMethods.IsSamePath(projectReferenceNode.Url, this.Url)))
					{
						existingNode = projectReferenceNode;
						return true;
					}
				}
			}

			existingNode = null;
			return false;
		}
Exemplo n.º 10
0
		/// <summary>
		/// Checks if a reference is already added. The method parses all references and compares the Url.
		/// </summary>
		/// <returns>true if the assembly has already been added.</returns>
		protected virtual bool IsAlreadyAdded(out ReferenceNode existingNode)
		{
			ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;
			Debug.Assert(referencesFolder != null, "Could not find the References node");

			for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
			{
				ReferenceNode referenceNode = n as ReferenceNode;
				if (null != referenceNode)
				{
					// We check if the Url of the assemblies is the same.
					if (NativeMethods.IsSamePath(referenceNode.Url, this.Url))
					{
						existingNode = referenceNode;
						return true;
					}
				}
			}

			existingNode = null;
			return false;
		}
		/// <summary>
		/// Checks if an assembly is already added. The method parses all references and compares the full assemblynames, or the location of the assemblies to decide whether two assemblies are the same.
		/// </summary>
		/// <returns>true if the assembly has already been added.</returns>
		protected override bool IsAlreadyAdded(out ReferenceNode existingNode)
		{
			ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;
			Debug.Assert(referencesFolder != null, "Could not find the References node");
			bool shouldCheckPath = !String.IsNullOrEmpty(this.Url);

			for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
			{
				AssemblyReferenceNode assemblyRefererenceNode = n as AssemblyReferenceNode;
				if (null != assemblyRefererenceNode)
				{
					// We will check if the full assemblynames are the same or if the Url of the assemblies is the same.
					if (String.Compare(assemblyRefererenceNode.AssemblyName.FullName, this.assemblyName.FullName, StringComparison.OrdinalIgnoreCase) == 0 ||
						(shouldCheckPath && NativeMethods.IsSamePath(assemblyRefererenceNode.Url, this.Url)))
					{
						existingNode = assemblyRefererenceNode;
						return true;
					}
				}
			}

			existingNode = null;
			return false;
		}
Exemplo n.º 12
0
 // =========================================================================================
 // Constructors
 // =========================================================================================
 /// <summary>
 /// Initializes a new instance of the <see cref="WixReferenceNodeProperties"/> class.
 /// </summary>
 /// <param name="node">The node that contains the properties to expose via the Property Browser.</param>
 protected WixReferenceNodeProperties(ReferenceNode node)
     : base(node)
 {
 }
Exemplo n.º 13
0
		/// <summary>
		/// Checks if a reference is already added. The method parses all references and compares the the FinalItemSpec and the Guid.
		/// </summary>
		/// <returns>true if the assembly has already been added.</returns>
		protected override bool IsAlreadyAdded(out ReferenceNode existingNode)
		{
			ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;
			Debug.Assert(referencesFolder != null, "Could not find the References node");

			for (HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
			{
				if (n is ComReferenceNode)
				{
					ComReferenceNode referenceNode = n as ComReferenceNode;

					// We check if the name and guids are the same
					if (referenceNode.TypeGuid == this.TypeGuid && String.Compare(referenceNode.Caption, this.Caption, StringComparison.OrdinalIgnoreCase) == 0)
					{
						existingNode = referenceNode;
						return true;
					}
				}
			}

			existingNode = null;
			return false;
		}