コード例 #1
0
ファイル: VSIPHelper.cs プロジェクト: vijumn/open-wssf-2015
        public static void AddSolutionItem(IVsSolution solution, string fileName)
        {
            uint itemId = DteHelper2.FindItemByName(
                solution as IVsHierarchy, "Solution Items");

            IntPtr ptr = IntPtr.Zero;
            Guid   solutionFolderGuid = new Guid("2150E333-8FDC-42a3-9474-1A3956D46DE8");
            Guid   iidProject         = typeof(IVsHierarchy).GUID;

            int res = solution.CreateProject(
                ref solutionFolderGuid,
                null,
                null,
                "Solution Items",
                0,
                ref iidProject,
                out ptr);

            if (ptr != IntPtr.Zero)
            {
                IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetObjectForIUnknown(ptr);

                Guid projGuid;

                hierarchy.GetGuidProperty(
                    VSConstants.VSITEMID_ROOT,
                    (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
                    out projGuid);

                ProjectNode node = new ProjectNode(solution, projGuid);

                node.AddItem(fileName);
            }
        }
コード例 #2
0
ファイル: HierarchyListener.cs プロジェクト: ugurak/nemerle
        bool IsNemerleFile(uint itemId, out string canonicalName)
        {
            canonicalName = null;

            // Find out if this item is a physical file.
            //
            Guid typeGuid;
            int  hr = _hierarchy.GetGuidProperty(itemId, (int)__VSHPROPID.VSHPROPID_TypeGuid, out typeGuid);

            if (ErrorHandler.Failed(hr) || VSConstants.GUID_ItemType_PhysicalFile != typeGuid)
            {
                // It is not a file, we can exit now.
                return(false);
            }

            // This item is a file; find if it is a nemerle file.
            //
            hr = _hierarchy.GetCanonicalName(itemId, out canonicalName);

            if (ErrorHandler.Failed(hr))
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
 public static Guid GetKind(this IVsHierarchy hierarchy)
 {
     hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT,
                               (int)__VSHPROPID.VSHPROPID_TypeGuid,
                               out Guid guid);
     return(guid);
 }
コード例 #4
0
        /// <summary>
        ///     Returns the GUID of the specified property.
        /// </summary>
        public static Guid GetGuidProperty(this IVsHierarchy hierarchy, VsHierarchyPropID property)
        {
            Requires.NotNull(hierarchy, nameof(hierarchy));
            Verify.HResult(hierarchy.GetGuidProperty(HierarchyId.Root, (int)property, out Guid result));

            return(result);
        }
コード例 #5
0
 private bool ShouldIncludeInFilter(IVsHierarchyItem hierarchyItem)
 {
     try
     {
         if (hierarchyItem == null)
         {
             return(false);
         }
         IVsHierarchy hierarchy = hierarchyItem.HierarchyIdentity.Hierarchy;
         Guid         pguid;
         hierarchy.GetGuidProperty(4294967294U, (int)__VSHPROPID.VSHPROPID_TypeGuid, out pguid);
         if (hierarchyItem.HierarchyIdentity.IsNestedItem && (pguid == VSConstants.GUID_ItemType_VirtualFolder || pguid == Guid.Empty && hierarchyItem.Children.Any()) || !hierarchyItem.HierarchyIdentity.IsRoot && pguid == Guid.Empty)
         {
             return(false);
         }
         object pvar1;
         hierarchy.GetProperty(hierarchyItem.HierarchyIdentity.ItemID, (int)__VSHPROPID.VSHPROPID_ProjectType, out pvar1);
         object pvar2;
         hierarchy.GetProperty(hierarchyItem.HierarchyIdentity.ItemID, (int)__VSHPROPID.VSHPROPID_ProjectDir, out pvar2);
         object pvar3;
         bool   didSucceed = !ErrorHandler.Succeeded(hierarchy.GetProperty(
                                                         hierarchyItem.HierarchyIdentity.ItemID, (int)__VSHPROPID5.VSHPROPID_ProjectUnloadStatus,
                                                         out pvar3));
         return(didSucceed || pvar3 != null && (uint)pvar3 != 0U);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #6
0
        private IVsProject TryGetProjectOfHierarchy(IVsHierarchy hierarchyOpt)
        {
            // The invisible editor manager will fail in cases where the IVsProject passed to it is not consistent with
            // the IVsProject known to IVsSolution (e.g. if the object is a wrapper like AbstractHostObject created by
            // the CPS-based project system). This method returns an IVsProject instance known to the solution, or null
            // if the project could not be determined.
            if (hierarchyOpt == null)
            {
                return(null);
            }

            if (!ErrorHandler.Succeeded(hierarchyOpt.GetGuidProperty(
                                            (uint)VSConstants.VSITEMID.Root,
                                            (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
                                            out var projectId)))
            {
                return(null);
            }

            var solution = (IVsSolution)_serviceProvider.GetService(typeof(SVsSolution));

            if (!ErrorHandler.Succeeded(solution.GetProjectOfGuid(projectId, out var projectHierarchy)))
            {
                return(null);
            }

            return(projectHierarchy as IVsProject);
        }
コード例 #7
0
ファイル: HierarchyVisitor.cs プロジェクト: menees/VsTools
            private static TResult GetProperty <TPropId, TResult>(
                IVsHierarchy hierarchy,
                uint itemId,
                TPropId propertyId,
                TResult defaultValue = default)
                where TPropId : struct
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                int propId = Convert.ToInt32(propertyId);

                TResult result;
                int     hr;

                if (typeof(TResult) == typeof(Guid) || Nullable.GetUnderlyingType(typeof(TResult)) == typeof(Guid))
                {
                    hr     = hierarchy.GetGuidProperty(itemId, propId, out Guid guid);
                    result = hr == VSConstants.S_OK ? (TResult)(object)guid : defaultValue;
                }
                else
                {
                    hr     = hierarchy.GetProperty(itemId, propId, out object value);
                    result = hr == VSConstants.S_OK ? (TResult)value : defaultValue;
                }

                return(result);
            }
        private static ProjectReferenceNode GetProjectReferenceOnNodeForHierarchy(IList <ReferenceNode> references, IVsHierarchy inputHierarchy)
        {
            if (references == null)
            {
                return(null);
            }

            Guid projectGuid;

            ErrorHandler.ThrowOnFailure(inputHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid));

            string canonicalName;

            ErrorHandler.ThrowOnFailure(inputHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out canonicalName));
            foreach (ReferenceNode refNode in references)
            {
                ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode;
                if (projRefNode != null)
                {
                    if (projRefNode.ReferencedProjectGuid == projectGuid)
                    {
                        return(projRefNode);
                    }

                    // Try with canonical names, if the project that is removed is an unloaded project than the above criteria will not pass.
                    if (!String.IsNullOrEmpty(projRefNode.Url) && NativeMethods.IsSamePath(projRefNode.Url, canonicalName))
                    {
                        return(projRefNode);
                    }
                }
            }

            return(null);
        }
コード例 #9
0
        private bool IsFoxProFile(uint itemId, out string canonicalName)
        {
            // Find out if this item is a physical file.
            Guid typeGuid = Guid.Empty;

            canonicalName = null;
            int hr = VSConstants.S_OK;

            try
            {
                hr = hierarchy.GetGuidProperty(itemId, (int)__VSHPROPID.VSHPROPID_TypeGuid, out typeGuid);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                //For WPF Projects, they will throw an exception when trying to access this property if the
                //guid is empty. These are caught and ignored here.
            }

            if (Microsoft.VisualStudio.ErrorHandler.Failed(hr) ||
                VSConstants.GUID_ItemType_PhysicalFile != typeGuid)
            {
                // It is not a file, we can exit now.
                return(false);
            }

            // This item is a file; find if it is a pyhon file.
            hr = hierarchy.GetCanonicalName(itemId, out canonicalName);
            if (Microsoft.VisualStudio.ErrorHandler.Failed(hr))
            {
                return(false);
            }
            string extension = System.IO.Path.GetExtension(canonicalName);

            return(0 == string.Compare(extension, FoxProConstants.FoxProFileExtension, StringComparison.OrdinalIgnoreCase));
        }
コード例 #10
0
        /// <include file='doc\FlavoredProject.uex' path='docs/doc[@for="FlavoredProject.GetGuidProperty"]/*' />
        protected virtual Guid GetGuidProperty(uint itemId, int propId)
        {
            Guid property;

            NativeMethods.ThrowOnFailure(innerVsHierarchy.GetGuidProperty(itemId, propId, out property));
            return(property);
        }
コード例 #11
0
        public static bool GetIsFolder(IVsHierarchy h, uint id = RootID)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var e = h.GetGuidProperty(
                id, (int)__VSHPROPID.VSHPROPID_TypeGuid,
                out var type);

            if (e != VSConstants.S_OK || type == null)
            {
                Main.Instance.Logger.ErrorCode(e, "can't get TypeGuid");
                return(false);
            }

            // ignore anything but folders
            if (type == VSConstants.ItemTypeGuid.PhysicalFolder_guid)
            {
                return(true);
            }

            if (type == VSConstants.ItemTypeGuid.VirtualFolder_guid)
            {
                return(true);
            }

            return(false);
        }
コード例 #12
0
        private static ISolutionHierarchyItem CreateSolutionHierarchyItemDirect(IVsHierarchy hierarchy, uint itemId)
        {
            Dispatcher.CurrentDispatcher.VerifyAccess();

            object pVar;
            Guid   id;

            ErrorHandler.ThrowOnFailure(hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_Name, out pVar));
            string projectName = (string)pVar;

            int hr = hierarchy.GetGuidProperty(itemId, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out id);

            hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out pVar);
            if (pVar == null)
            {
                try
                {
                    if (ErrorHandler.Succeeded(hierarchy.GetProperty(itemId, (int)__VSHPROPID5.VSHPROPID_ProjectUnloadStatus, out pVar)))
                    {
                        return(new SolutionHierarchyItem(hierarchy, itemId, SolutionHierarchyItemType.UnloadedProject));
                    }
                }
                catch
                {
                }

                return(null);
            }
            else
            {
                Project pr = pVar as Project;
                if (pr != null)
                {
                    Guid projectKind;
                    if (Guid.TryParse(pr.Kind, out projectKind) && projectKind == m_solutionFolderId)
                    {
                        return(new SolutionHierarchyContainerItem(hierarchy, itemId, SolutionHierarchyItemType.SolutionFolder));
                    }
                    else
                    {
                        return(new SolutionHierarchyItem(hierarchy, itemId, SolutionHierarchyItemType.Project));
                    }
                }
                else
                {
                    Solution sol = pVar as Solution;
                    if (sol == null)
                    {
                        // Unknown item
                        return(null);
                    }
                    else
                    {
                        // Solution
                        return(new SolutionHierarchyContainerItem(hierarchy, itemId, SolutionHierarchyItemType.Solution));
                    }
                }
            }
        }
コード例 #13
0
 public static bool TryGetGuidProperty(
     this IVsHierarchy hierarchy,
     __VSHPROPID propertyId,
     out Guid guid
     ) =>
 ErrorHandler.Succeeded(
     hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)propertyId, out guid)
     );
コード例 #14
0
        public static Guid GetKind(this IVsHierarchy hierarchy)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT,
                                      (int)__VSHPROPID.VSHPROPID_TypeGuid,
                                      out Guid guid);
            return(guid);
        }
コード例 #15
0
    public static Guid GetProjectGuid(IVsHierarchy projectHierarchy)
    {
        int hr;

        hr = projectHierarchy.GetGuidProperty(VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out Guid projectGuid);
        ErrorHandler.ThrowOnFailure(hr);

        return(projectGuid);
    }
コード例 #16
0
        internal bool TryGetProjectId(out Guid projectId)
        {
            var result = _hierarchy.GetGuidProperty(
                VSConstants.VSITEMID_ROOT,
                (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
                out projectId);

            return(result == VSConstants.S_OK);
        }
コード例 #17
0
        static public Guid GetProjectType(IVsHierarchy hierarchy)
        {
            Guid projectType = Guid.Empty;

            if (hierarchy != null)
            {
                hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_TypeGuid, out projectType);
            }
            return(projectType);
        }
コード例 #18
0
        public static Guid GetProjectGuid(this IVsHierarchy hierarchy)
        {
            Debug.Assert(hierarchy != null);
            ErrorHandler.ThrowOnFailure(
                hierarchy.GetGuidProperty(
                    VSConstants.VSITEMID_ROOT,
                    (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
                    out Guid projectGuid));

            return(projectGuid);
        }
コード例 #19
0
        public Guid GetProjectGuid(IVsHierarchy projectHierarchy)
        {
            var VSITEMID_ROOT = 0xFFFFFFFE;
            Guid projectGuid;
            int hr;

            hr = projectHierarchy.GetGuidProperty(VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid);
            ErrorHandler.ThrowOnFailure(hr);

            return projectGuid;
        }
コード例 #20
0
ファイル: Utility.cs プロジェクト: yovannyr/scsf2019
 internal static Guid GetProjectGuid(IServiceProvider serviceProvider, Project project)
 {
     if (project != null)
     {
         IVsHierarchy vsHier      = Microsoft.Practices.RecipeFramework.Library.DteHelper.GetVsHierarchy(serviceProvider, project);
         Guid         projectGuid = Guid.Empty;
         vsHier.GetGuidProperty(ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid);
         return(projectGuid);
     }
     return(Guid.Empty);
 }
コード例 #21
0
        internal static Guid GetProjectIDGuidProperty(this IVsHierarchy project)
        {
            Guid guid;

            ErrorHandler.ThrowOnFailure(project.GetGuidProperty(
                                            (uint)VSConstants.VSITEMID.Root,
                                            (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
                                            out guid
                                            ));
            return(guid);
        }
コード例 #22
0
        public bool TryGetProjectId(out Guid projectId)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var result = _hierarchy.GetGuidProperty(
                VSConstants.VSITEMID_ROOT,
                (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
                out projectId);

            return(result == VSConstants.S_OK);
        }
コード例 #23
0
        // --------------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the specified GUID hierarchy property.
        /// </summary>
        /// <param name="propId">Property identifier.</param>
        /// <returns>Property value ofthe specified property.</returns>
        // --------------------------------------------------------------------------------------------
        protected object GetGuidProperty(int propId)
        {
            if (propId == (int)__VSHPROPID.VSHPROPID_NIL)
            {
                return(null);
            }
            Guid propValue;

            _Hierarchy.GetGuidProperty(_ItemId, propId, out propValue);
            return(propValue);
        }
コード例 #24
0
        /// <summary>
        ///     Returns the GUID of the specified property.
        /// </summary>
        public static Guid GetGuidProperty(this IVsHierarchy hierarchy, VsHierarchyPropID property)
        {
            Requires.NotNull(hierarchy, nameof(hierarchy));
            HResult hr = hierarchy.GetGuidProperty(HierarchyId.Root, (int)property, out Guid result);

            if (hr.Failed)
            {
                throw hr.Exception;
            }

            return(result);
        }
コード例 #25
0
        private Guid GetGuidProperty(__VSHPROPID propId, uint itemid = VSConstants.VSITEMID_ROOT)
        {
            int hr = _hierarchy.GetGuidProperty(itemid, (int)propId, out Guid guid);

            // in case of failure, we simply trace the error and return silently with an empty guid
            // so the caller can resolve what to do without blowing out execution with an exception
            if (hr != 0)
            {
                Trace.TraceError(Marshal.GetExceptionForHR(hr).ToString());
            }
            return(guid);
        }
コード例 #26
0
        public static bool IsSupportedByGuid(IVsHierarchy hierarchy)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            ErrorHandler.ThrowOnFailure(hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_TypeGuid, out Guid pguid));
            var guid = pguid.ToString("B");

            if (ProjectType.IsUnsupported(guid) || !ProjectType.IsSupported(guid))
            {
                return(false);
            }
            return(true);
        }
コード例 #27
0
        public static Guid GetProjectGuid(Project project)
        {
            if (project != null)
            {
                IVsHierarchy vsHier      = DteConverter.ToHierarchy(project);
                Guid         projectGuid = Guid.Empty;
                vsHier.GetGuidProperty(ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid);
                return(projectGuid);
            }

            return(Guid.Empty);
        }
コード例 #28
0
ファイル: Utils.cs プロジェクト: rick111111/CpsPlugin
        /// <summary>
        /// Get project Guid from IVsProject
        /// </summary>
        public static Guid GetProjectGuid(IVsHierarchy project)
        {
            if (project is IVsProject)
            {
                int result = project.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out Guid guid);
                if (result == VSConstants.S_OK)
                {
                    return(guid);
                }
            }

            return(Guid.Empty);
        }
コード例 #29
0
 //--------------------------------------------------------------------------------------------
 /// <summary>
 /// Calls IVsHIerachy::GetGuidProperty
 /// </summary>
 //--------------------------------------------------------------------------------------------
 internal Guid GetGuidPropHelper(Microsoft.VisualStudio.Shell.Interop.__VSHPROPID propid)
 {
     Guid guid;
     try
     {
         _hier.GetGuidProperty(_vsitemid, (int)propid, out guid);
     }
     catch(Exception)
     {
         guid = Guid.Empty;
     }
     return guid;
 }
コード例 #30
0
        public static Guid?GetGuidProperty(this IVsHierarchy hierarchy, uint itemId, int propId)
        {
            if (hierarchy == null)
            {
                return(null);
            }

            if (hierarchy.GetGuidProperty(itemId, propId, out Guid guid) != 0)
            {
                return(null);
            }

            return(guid);
        }
コード例 #31
0
 /// <summary>
 /// Create a ProjectTargetView with values from an EnvDTE.Project.
 /// </summary>
 public ProjectTargetView(IVsHierarchy project) {
     object value;
     ErrorHandler.ThrowOnFailure(project.GetProperty(
         (uint)VSConstants.VSITEMID.Root,
         (int)__VSHPROPID.VSHPROPID_Name,
         out value
     ));
     _name = value as string ?? "(Unknown name)";
     ErrorHandler.ThrowOnFailure(project.GetGuidProperty(
         (uint)VSConstants.VSITEMID.Root,
         (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
         out _guid
     )); 
 }
コード例 #32
0
        private Constants.ItemNodeType get_node_type(uint itemId)
        {
            Guid type;

            try
            {
                ErrorHandler.ThrowOnFailure(root_hierarchy.GetGuidProperty(itemId, (int)__VSHPROPID.VSHPROPID_TypeGuid, out type));
            }
            catch (COMException e)
            {
                // FSharp project returns Guid.Empty as the type guid for reference nodes, which causes the WAP to throw an exception
                //var pinfo = e.GetType().GetProperty("HResult", BindingFlags.Instance | BindingFlags.NonPublic);
                var pinfo = e.GetType().GetProperty("HResult");
                if ((int)pinfo.GetValue(e, new object[] { }) == VSConstants.DISP_E_MEMBERNOTFOUND)
                {
                    type = Guid.Empty;
                }
                else
                {
                    throw;
                }
            }

            // set the sort order based on the item type
            if (type == Guid.Empty)
            {
                return(Constants.ItemNodeType.Reference);
            }
            else if (type == VSConstants.GUID_ItemType_PhysicalFile)
            {
                return(Constants.ItemNodeType.PhysicalFile);
            }
            else if (type == VSConstants.GUID_ItemType_PhysicalFolder)
            {
                return(Constants.ItemNodeType.PhysicalFolder);
            }
            else if (type == VSConstants.GUID_ItemType_SubProject)
            {
                return(Constants.ItemNodeType.SubProject);
            }
            else if (type == VSConstants.GUID_ItemType_VirtualFolder)
            {
                return(Constants.ItemNodeType.VirtualFolder);
            }
            else if (type == Constants.guidFSharpProject)
            {
                return(Constants.ItemNodeType.Root);
            }
            return(Constants.ItemNodeType.Unknown);
        }
コード例 #33
0
        /// <param name="pHierProj"></param>
        /// <param name="force">Load in global collection with __VSHPROPID.VSHPROPID_ExtObject if true value</param>
        /// <returns>project name from Microsoft.Build.Evaluation rules or null value if project not found in GlobalProjectCollection and force value is false</returns>
        public string getProjectNameFrom(IVsHierarchy pHierProj, bool force = false)
        {
            Guid id;
            pHierProj.GetGuidProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out id);

            foreach(Project eProject in ProjectCollection.GlobalProjectCollection.LoadedProjects)
            {
                string guidString = eProject.GetPropertyValue("ProjectGuid");
                if(!String.IsNullOrEmpty(guidString) && id == (new Guid(guidString))) {
                    return getProjectNameFrom(eProject);
                }
            }

            if(!force) {
                return null;
            }
            object dteProject;
            pHierProj.GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ExtObject, out dteProject);
            return getProjectNameFrom(tryLoadPCollection((EnvDTE.Project)dteProject));
        }
コード例 #34
0
        private void ProcessHierarchyNode(IVsHierarchy hierarchy, uint itemid)
        {
            int hr;

            // Canonical Name
            string canonicalName;
            hr = hierarchy.GetCanonicalName(itemid, out canonicalName);

            // Project Name
            object projectName;
            ErrorHandler.ThrowOnFailure(hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Name, out projectName));

            // Project GUID
            Guid projectGuid;
            hr = hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid);
            if (Guid.Empty == projectGuid) // in case when project is unloaded
                _projectNames.TryGetValue(canonicalName, out projectGuid);

            // Project Icon
            var icon = RetrieveProjectIcon(hierarchy);

            // Load Priority
            var loadPriority = RetrieveProjectLoadPriority(projectGuid);

            if (null == _rootProject)
            {
                _rootProject = _lastProject = new ProjectInfo((String)projectName, projectGuid, loadPriority, null) { Icon = icon };
            }
            else
            {
                _lastProject = new ProjectInfo((String)projectName, projectGuid, loadPriority, _currentProject) { Icon = icon };
                _currentProject.Children.Add(_lastProject);
            }
        }
コード例 #35
0
ファイル: Common.cs プロジェクト: dbremner/specsharp
 static public Guid GetProjectType(IVsHierarchy hierarchy)
 {
   Guid projectType = Guid.Empty;
   if (hierarchy != null) {
     hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_TypeGuid, out projectType);
   }
   return projectType;
 }
コード例 #36
0
        private static ProjectReferenceNode GetProjectReferenceOnNodeForHierarchy(IList<ReferenceNode> references, IVsHierarchy inputHierarchy)
        {
            if(references == null)
                return null;

            Guid projectGuid;

            // !EFW - This is an odd one.  Open a file not contained within a project in the active solution and
            // then close it.  When you do, this method is called and it fails here.  The file is hosted in the
            // Miscellaneous Files hierarchy.  In such cases, we'll just ignore it and return null.
            if(inputHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT,
              (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid) != VSConstants.S_OK)
                return null;

            string canonicalName;
            ErrorHandler.ThrowOnFailure(inputHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out canonicalName));

            foreach(ReferenceNode refNode in references)
            {
                ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode;

                if(projRefNode != null)
                {
                    if(projRefNode.ReferencedProjectGuid == projectGuid)
                        return projRefNode;

                    // Try with canonical names, if the project that is removed is an unloaded project that the
                    // above criteria will not pass.
                    if(!String.IsNullOrEmpty(projRefNode.Url) && NativeMethods.IsSamePath(projRefNode.Url, canonicalName))
                        return projRefNode;
                }
            }

            return null;
        }
コード例 #37
0
        private static ProjectReferenceNode GetProjectReferenceOnNodeForHierarchy(IList<ReferenceNode> references,
            IVsHierarchy inputHierarchy)
        {
            if (references == null)
            {
                return null;
            }

            Guid projectGuid;
            ErrorHandler.ThrowOnFailure(inputHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT,
                (int) __VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid));

            string canonicalName;
            ErrorHandler.ThrowOnFailure(inputHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out canonicalName));
            foreach (var refNode in references)
            {
                var projRefNode = refNode as ProjectReferenceNode;
                if (projRefNode != null)
                {
                    if (projRefNode.ReferencedProjectGuid == projectGuid)
                    {
                        return projRefNode;
                    }

                    // Try with canonical names, if the project that is removed is an unloaded project than the above criteria will not pass.
                    if (!string.IsNullOrEmpty(projRefNode.Url) &&
                        NativeMethods.IsSamePath(projRefNode.Url, canonicalName))
                    {
                        return projRefNode;
                    }
                }
            }

            return null;
        }
コード例 #38
0
            /// <summary>
            /// Recursive method that walk a hierarchy and add items it find to our project.
            /// Note that this is meant as an helper to the Copy&Paste/Drag&Drop functionality.
            /// </summary>
            /// <param name="sourceHierarchy">Hierarchy to walk</param>
            /// <param name="itemId">Item ID where to start walking the hierarchy</param>
            /// <param name="targetNode">Node to start adding to</param>
            /// <param name="addSibblings">Typically false on first call and true after that</param>
            private bool WalkSourceProjectAndAdd(IVsHierarchy sourceHierarchy, uint itemId, string targetPath, bool addSiblings, List<Addition> additions, string name = null) {
                Utilities.ArgumentNotNull("sourceHierarchy", sourceHierarchy);

                if (itemId != VSConstants.VSITEMID_NIL) {
                    // Before we start the walk, add the current node
                    object variant = null;

                    // Calculate the corresponding path in our project
                    string source;
                    ErrorHandler.ThrowOnFailure(((IVsProject)sourceHierarchy).GetMkDocument(itemId, out source));
                    if (name == null) {
                        name = CommonUtils.GetFileOrDirectoryName(source);
                    }

                    Guid guidType;
                    ErrorHandler.ThrowOnFailure(sourceHierarchy.GetGuidProperty(itemId, (int)__VSHPROPID.VSHPROPID_TypeGuid, out guidType));

                    IVsSolution solution = Project.GetService(typeof(IVsSolution)) as IVsSolution;
                    if (solution != null) {
                        if (guidType == VSConstants.GUID_ItemType_PhysicalFile) {
                            string projRef;
                            ErrorHandler.ThrowOnFailure(solution.GetProjrefOfItem(sourceHierarchy, itemId, out projRef));
                            var addition = CanAddFileFromProjectReference(projRef, targetPath);
                            if (addition == null) {
                                // cancelled
                                return false;
                            }
                            additions.Add(addition);
                        }
                    }

                    // Start with child nodes (depth first)
                    if (guidType == VSConstants.GUID_ItemType_PhysicalFolder) {
                        variant = null;
                        ErrorHandler.ThrowOnFailure(sourceHierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out variant));
                        uint currentItemID = (uint)(int)variant;

                        List<Addition> nestedAdditions = new List<Addition>();

                        string newPath = Path.Combine(targetPath, name);

                        if (!WalkSourceProjectAndAdd(sourceHierarchy, currentItemID, newPath, true, nestedAdditions)) {
                            // cancelled
                            return false;
                        }

                        if (!Project.Tracker.CanRenameItem(
                            source,
                            newPath,
                            VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_Directory)) {
                            return false;
                        }

                        additions.Add(new FolderAddition(Project, Path.Combine(targetPath, name), source, DropEffect, nestedAdditions.ToArray()));
                    }

                    if (addSiblings) {
                        // Then look at siblings
                        uint currentItemID = itemId;
                        while (currentItemID != VSConstants.VSITEMID_NIL) {
                            variant = null;
                            // http://mpfproj10.codeplex.com/workitem/11618 - pass currentItemID instead of itemId
                            ErrorHandler.ThrowOnFailure(sourceHierarchy.GetProperty(currentItemID, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out variant));
                            currentItemID = (uint)(int)variant;
                            if (!WalkSourceProjectAndAdd(sourceHierarchy, currentItemID, targetPath, false, additions)) {
                                // cancelled
                                return false;
                            }
                        }
                    }
                }
                return true;
            }
コード例 #39
0
        /// <summary>
        /// Updates the ServiceDefinition.csdef file in
        /// <paramref name="project"/> to include the default startup and
        /// runtime tasks for Python projects.
        /// </summary>
        /// <param name="project">
        /// The Cloud Service project to update.
        /// </param>
        /// <param name="roleType">
        /// The type of role being added, either "Web" or "Worker".
        /// </param>
        /// <param name="projectName">
        /// The name of the role. This typically matches the Caption property.
        /// </param>
        /// <param name="site">
        /// VS service provider.
        /// </param>
        internal static void UpdateServiceDefinition(
            IVsHierarchy project,
            string roleType,
            string projectName,
            System.IServiceProvider site
        ) {
            Utilities.ArgumentNotNull("project", project);

            object obj;
            ErrorHandler.ThrowOnFailure(project.GetProperty(
                (uint)VSConstants.VSITEMID.Root,
                (int)__VSHPROPID.VSHPROPID_FirstChild,
                out obj
            ));

            uint id;
            while (TryGetItemId(obj, out id)) {
                Guid itemType;
                string mkDoc;

                if (ErrorHandler.Succeeded(project.GetGuidProperty(id, (int)__VSHPROPID.VSHPROPID_TypeGuid, out itemType)) &&
                    itemType == VSConstants.GUID_ItemType_PhysicalFile &&
                    ErrorHandler.Succeeded(project.GetProperty(id, (int)__VSHPROPID.VSHPROPID_Name, out obj)) &&
                    "ServiceDefinition.csdef".Equals(obj as string, StringComparison.InvariantCultureIgnoreCase) &&
                    ErrorHandler.Succeeded(project.GetCanonicalName(id, out mkDoc)) &&
                    !string.IsNullOrEmpty(mkDoc)
                ) {
                    // We have found the file
                    var rdt = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

                    IVsHierarchy docHier;
                    uint docId, docCookie;
                    IntPtr pDocData;

                    bool updateFileOnDisk = true;

                    if (ErrorHandler.Succeeded(rdt.FindAndLockDocument(
                        (uint)_VSRDTFLAGS.RDT_EditLock,
                        mkDoc,
                        out docHier,
                        out docId,
                        out pDocData,
                        out docCookie
                    ))) {
                        try {
                            if (pDocData != IntPtr.Zero) {
                                try {
                                    // File is open, so edit it through the document
                                    UpdateServiceDefinition(
                                        Marshal.GetObjectForIUnknown(pDocData) as IVsTextLines,
                                        roleType,
                                        projectName
                                    );

                                    ErrorHandler.ThrowOnFailure(rdt.SaveDocuments(
                                        (uint)__VSRDTSAVEOPTIONS.RDTSAVEOPT_ForceSave,
                                        docHier,
                                        docId,
                                        docCookie
                                    ));

                                    updateFileOnDisk = false;
                                } catch (ArgumentException) {
                                } catch (InvalidOperationException) {
                                } catch (COMException) {
                                } finally {
                                    Marshal.Release(pDocData);
                                }
                            }
                        } finally {
                            ErrorHandler.ThrowOnFailure(rdt.UnlockDocument(
                                (uint)_VSRDTFLAGS.RDT_Unlock_SaveIfDirty | (uint)_VSRDTFLAGS.RDT_RequestUnlock,
                                docCookie
                            ));
                        }
                    }

                    if (updateFileOnDisk) {
                        // File is not open, so edit it on disk
                        FileStream stream = null;
                        try {
                            UpdateServiceDefinition(mkDoc, roleType, projectName);
                        } finally {
                            if (stream != null) {
                                stream.Close();
                            }
                        }
                    }

                    break;
                }

                if (ErrorHandler.Failed(project.GetProperty(id, (int)__VSHPROPID.VSHPROPID_NextSibling, out obj))) {
                    break;
                }
            }
        }