//#endif

#if !DENALI && !SQL2014
        public static Microsoft.AnalysisServices.BackEnd.DataModelingSandboxAmo GetTabularSandboxAmoFromBimFile(Core.BIDSHelperPluginBase plugin, bool openIfNotOpen)
        {
            UIHierarchy solExplorer = plugin.ApplicationObject.ToolWindows.SolutionExplorer;

            if (((System.Array)solExplorer.SelectedItems).Length != 1)
            {
                return(null);
            }

            UIHierarchyItem hierItem = ((UIHierarchyItem)((System.Array)solExplorer.SelectedItems).GetValue(0));

            if (!(hierItem.Object is ProjectItem))
            {
                return(null);
            }
            string sFileName = ((ProjectItem)hierItem.Object).Name.ToLower();

            if (sFileName.EndsWith(".bim"))
            {
                Microsoft.AnalysisServices.VSHost.VSHostManager host = GetVSHostManager(hierItem, openIfNotOpen);
                if (host == null)
                {
                    return(null);
                }
                if (!host.Sandbox.IsTabularMetadata)
                {
                    return((Microsoft.AnalysisServices.BackEnd.DataModelingSandboxAmo)host.Sandbox.Impl);
                }
            }
            return(null);
        }
 public static Microsoft.AnalysisServices.Common.SandboxEditor GetTabularSandboxEditorFromBimFile(UIHierarchyItem hierItem, bool openIfNotOpen)
 {
     Microsoft.AnalysisServices.VSHost.VSHostManager host = GetVSHostManager(hierItem, openIfNotOpen);
     if (host == null)
     {
         return(null);
     }
     return(host.Editor);
 }
 public static Microsoft.AnalysisServices.BackEnd.DataModelingSandbox GetTabularSandboxFromBimFile(UIHierarchyItem hierItem, bool openIfNotOpen)
 {
     Microsoft.AnalysisServices.VSHost.VSHostManager host = GetVSHostManager(hierItem, openIfNotOpen);
     if (host == null)
     {
         return(null);
     }
     return(host.Sandbox);
 }
        //public static Microsoft.AnalysisServices.Common.SandboxEditor GetTabularSandboxEditorFromActiveWindow()
        //{
        //    return GetTabularSandboxEditorFromProjectItem(Connect.Application.ActiveWindow.ProjectItem, false);
        //}

        public static Microsoft.AnalysisServices.Common.SandboxEditor GetTabularSandboxEditorFromProjectItem(ProjectItem projectItem, bool openIfNotOpen)
        {
            Microsoft.VisualStudio.Project.Automation.OAFileItem project = projectItem as Microsoft.VisualStudio.Project.Automation.OAFileItem;
            Microsoft.AnalysisServices.VSHost.VSHostManager      host    = GetVSHostManager(project, openIfNotOpen);
            if (host == null)
            {
                return(null);
            }
            return(host.Editor);
        }
 public static Microsoft.AnalysisServices.BackEnd.DataModelingSandbox GetTabularSandboxFromProjectItem(ProjectItem projectItem, bool openIfNotOpen)
 {
     Microsoft.VisualStudio.Project.Automation.OAFileItem project = projectItem as Microsoft.VisualStudio.Project.Automation.OAFileItem;
     Microsoft.AnalysisServices.VSHost.VSHostManager      host    = GetVSHostManager(project, openIfNotOpen);
     if (host == null)
     {
         return(null);
     }
     return(host.Sandbox);
 }
        //#if DENALI || SQL2014
        public static Microsoft.AnalysisServices.BackEnd.DataModelingSandbox GetTabularSandboxFromBimFile(Core.BIDSHelperPluginBase plugin, bool openIfNotOpen)
        {
            UIHierarchy solExplorer = plugin.ApplicationObject.ToolWindows.SolutionExplorer;

            if (((System.Array)solExplorer.SelectedItems).Length != 1)
            {
                return(null);
            }

            UIHierarchyItem hierItem  = ((UIHierarchyItem)((System.Array)solExplorer.SelectedItems).GetValue(0));
            string          sFileName = "";

            if (hierItem.Object is ProjectItem)
            {
                sFileName = ((ProjectItem)hierItem.Object).Name.ToLower();
            }

            if (sFileName.EndsWith(".bim"))
            {
                Microsoft.AnalysisServices.VSHost.VSHostManager host = GetVSHostManager(hierItem, openIfNotOpen);
                if (host == null)
                {
                    return(null);
                }

                return(host.Sandbox);
            }
            else
            {
                foreach (UIHierarchyItem hierItem2 in VisualStudioHelpers.GetAllItemsFromSolutionExplorer(plugin.ApplicationObject.ToolWindows.SolutionExplorer))
                {
                    if (hierItem2.Name != null && hierItem2.Name.ToLower().EndsWith(".bim"))
                    {
                        Microsoft.AnalysisServices.VSHost.VSHostManager host = GetVSHostManager(hierItem2, openIfNotOpen);
                        if (host == null)
                        {
                            return(null);
                        }

                        return(host.Sandbox);
                    }
                }
            }
            return(null);
        }
        private static Microsoft.AnalysisServices.VSHost.VSHostManager GetVSHostManager(Microsoft.VisualStudio.Project.Automation.OAFileItem project, bool openIfNotOpen)
        {
            if (project == null)
            {
                return(null);
            }
            if (openIfNotOpen && (!project.get_IsOpen(EnvDTE.Constants.vsViewKindPrimary) || project.get_IsOpen(EnvDTE.Constants.vsViewKindCode))) //having the code view open was passing this test previously
            {
                Window win = project.Open(EnvDTE.Constants.vsViewKindPrimary);
                if (win == null)
                {
                    throw new Exception("BIDS Helper was unable to open designer window.");
                }
                win.Activate();
            }

            Microsoft.AnalysisServices.VSHost.Integration.BISMFileNode bim = project.Object as Microsoft.AnalysisServices.VSHost.Integration.BISMFileNode;
            if (bim == null)
            {
                return(null);
            }
            Microsoft.AnalysisServices.VSHost.VSHostManager host = (Microsoft.AnalysisServices.VSHost.VSHostManager)bim.GetType().InvokeMember("VSHostManager", System.Reflection.BindingFlags.ExactBinding | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, bim, null); //bim.VSHostManager;
            return(host);
        }