Esempio n. 1
0
        private void BuildEvents_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
        {
            if (!this.Enabled)
            {
                return;
            }
            if (Action == vsBuildAction.vsBuildActionClean)
            {
                return;
            }

            foreach (UIHierarchyItem hierItem in VisualStudioHelpers.GetAllItemsFromSolutionExplorer(this.ApplicationObject.ToolWindows.SolutionExplorer))
            {
                if (hierItem.Name != null && hierItem.Name.ToLower().EndsWith(".bim"))
                {
                    Microsoft.AnalysisServices.BackEnd.DataModelingSandbox sandbox = TabularHelpers.GetTabularSandboxFromBimFile(hierItem, false);
                    if (sandbox != null)
                    {
                        List <BIDSHelperPluginBase> checks = new List <BIDSHelperPluginBase>();
                        foreach (BIDSHelperPluginBase plugin in Connect.Plugins.Values)
                        {
                            Type t = plugin.GetType();
                            if (plugin is ITabularOnPreBuildAnnotationCheck &&
                                !t.IsInterface &&
                                !t.IsAbstract)
                            {
                                ITabularOnPreBuildAnnotationCheck check = (ITabularOnPreBuildAnnotationCheck)plugin;
                                if (check.TabularOnPreBuildAnnotationCheckPriority == TabularOnPreBuildAnnotationCheckPriority.HighPriority)
                                {
                                    checks.Insert(0, plugin); //insert the high priority checks at the front of the list so they get run first
                                }
                                else
                                {
                                    checks.Add(plugin);
                                }
                            }
                        }

                        foreach (BIDSHelperPluginBase plugin in checks)
                        {
                            ITabularOnPreBuildAnnotationCheck check = (ITabularOnPreBuildAnnotationCheck)plugin;
                            string sWarning = check.GetPreBuildWarning(sandbox);
                            if (sWarning != null)
                            {
                                if (MessageBox.Show(sWarning, "BIDS Helper Pre-Build Warning - " + plugin.FeatureName, MessageBoxButtons.OKCancel) == DialogResult.OK)
                                {
                                    Microsoft.VisualStudio.Project.Automation.OAFileItem project = hierItem.Object as Microsoft.VisualStudio.Project.Automation.OAFileItem;
                                    Window win = project.Open(EnvDTE.Constants.vsViewKindPrimary);
                                    win.Activate();
                                    check.FixPreBuildWarning(sandbox);
                                    project.Save(hierItem.Name);
                                }
                            }
                        }
                    }
                }
            }
        }
        //#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);
        }
        internal override void OnUpdateConfigBegin(IVsHierarchy pHierProj, VSSOLNBUILDUPDATEFLAGS dwAction, ref int pfCancel)
        {
            if (!this.Enabled)
            {
                return;
            }
            if (dwAction == VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_CLEAN)
            {
                return;
            }

            foreach (UIHierarchyItem hierItem in VisualStudioHelpers.GetAllItemsFromSolutionExplorer(this.ApplicationObject.ToolWindows.SolutionExplorer))
            {
                if (hierItem.Name != null && hierItem.Name.ToLower().EndsWith(".bim"))
                {
                    Microsoft.AnalysisServices.BackEnd.DataModelingSandbox sandbox = TabularHelpers.GetTabularSandboxFromBimFile(this, false);
                    if (sandbox == null)
                    {
                        var sandboxEditor = TabularHelpers.GetTabularSandboxEditorFromBimFile(hierItem, true);
                        if (sandboxEditor != null)
                        {
                            sandbox = sandboxEditor.Sandbox;
                        }
                    }
                    if (sandbox != null)
                    {
#if !DENALI && !SQL2014
                        if (sandbox.IsTabularMetadata)
                        {
                            return;
                        }
#endif
                        List <BIDSHelperPluginBase> checks = new List <BIDSHelperPluginBase>();
                        foreach (BIDSHelperPluginBase plugin in BIDSHelperPackage.Plugins.Values)
                        {
                            Type t = plugin.GetType();
                            if (plugin is ITabularOnPreBuildAnnotationCheck &&
                                !t.IsInterface &&
                                !t.IsAbstract)
                            {
                                ITabularOnPreBuildAnnotationCheck check = (ITabularOnPreBuildAnnotationCheck)plugin;
                                if (check.TabularOnPreBuildAnnotationCheckPriority == TabularOnPreBuildAnnotationCheckPriority.HighPriority)
                                {
                                    checks.Insert(0, plugin); //insert the high priority checks at the front of the list so they get run first
                                }
                                else
                                {
                                    checks.Add(plugin);
                                }
                            }
                        }

                        foreach (BIDSHelperPluginBase plugin in checks)
                        {
                            ITabularOnPreBuildAnnotationCheck check = (ITabularOnPreBuildAnnotationCheck)plugin;
                            string sWarning = check.GetPreBuildWarning(sandbox);
                            if (sWarning != null)
                            {
                                if (MessageBox.Show(sWarning, "BIDS Helper Pre-Build Warning - " + plugin.FeatureName, MessageBoxButtons.OKCancel) == DialogResult.OK)
                                {
                                    Microsoft.VisualStudio.Project.Automation.OAFileItem project = hierItem.Object as Microsoft.VisualStudio.Project.Automation.OAFileItem;
                                    Window win = project.Open(EnvDTE.Constants.vsViewKindPrimary);
                                    win.Activate();
                                    check.FixPreBuildWarning(sandbox);
                                    project.Save(hierItem.Name);
                                }
                            }
                        }
                    }
                }
            }
        }