Microsoft.VisualStudio.Project.ProjectContainerNode.OpenChildren C# (CSharp) Method

OpenChildren() public method

public OpenChildren ( ) : int
return int
        public virtual int OpenChildren()
        {
            IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;

            Debug.Assert(solution != null, "Could not retrieve the solution from the services provided by this project");
            if(solution == null)
            {
                return VSConstants.E_FAIL;
            }

            IntPtr iUnKnownForSolution = IntPtr.Zero;
            int returnValue = VSConstants.S_OK; // be optimistic.

            try
            {
                this.DisableQueryEdit = true;
                this.EventTriggeringFlag = SuppressEvents.Hierarchy | SuppressEvents.Tracker;
                iUnKnownForSolution = Marshal.GetIUnknownForObject(solution);

                // notify SolutionEvents listeners that we are about to add children
                IVsFireSolutionEvents fireSolutionEvents = Marshal.GetTypedObjectForIUnknown(iUnKnownForSolution, typeof(IVsFireSolutionEvents)) as IVsFireSolutionEvents;
                ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnBeforeOpeningChildren(this));

                this.AddVirtualProjects();

                ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnAfterOpeningChildren(this));
            }
            catch(Exception e)
            {
                // Exceptions are digested by the caller but we want then to be shown if not a ComException and if not in automation.
                if(!(e is COMException) && !Utilities.IsInAutomationFunction(this.Site))
                {
                    string title = null;
                    OLEMSGICON icon = OLEMSGICON.OLEMSGICON_CRITICAL;
                    OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                    OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                    VsShellUtilities.ShowMessageBox(this.Site, title, e.Message, icon, buttons, defaultButton);
                }

                Trace.WriteLine("Exception : " + e.Message);
                throw;
            }
            finally
            {
                this.DisableQueryEdit = false;

                if(iUnKnownForSolution != IntPtr.Zero)
                {
                    Marshal.Release(iUnKnownForSolution);
                }

                this.EventTriggeringFlag = SuppressEvents.None;
            }

            return returnValue;
        }