public override void Exec()
        {
            ProjectItem piCurrent = null;

            try
            {
                listNonDefaultProperties = new List <NonDefaultProperty>();

                UIHierarchy     solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer;
                UIHierarchyItem hierItem    = ((UIHierarchyItem)((System.Array)solExplorer.SelectedItems).GetValue(0));
                SolutionClass   solution    = hierItem.Object as SolutionClass;
                EnvDTE.Project  p           = GetSelectedProjectReference();

                if (p != null)
                {
                    Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt projExt = (Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt)p;
                    if (projExt.Kind == BIDSProjectKinds.SSAS)
                    {
                        Database db = (Database)p.Object;
                        ScanAnalysisServicesProperties(db);
                    }
                    else
                    {
                        this.DatabaseName = "Project: " + p.Name;
                        this.SSASProject  = false;

                        try
                        {
                            using (WaitCursor cursor1 = new WaitCursor())
                            {
                                int iProgress = 0;
                                ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationGeneral);
                                Microsoft.SqlServer.Dts.Runtime.Application app = SSIS.PackageHelper.Application; //sets the proper TargetServerVersion
                                foreach (ProjectItem pi in p.ProjectItems)
                                {
                                    ApplicationObject.StatusBar.Progress(true, "Scanning package " + pi.Name, iProgress++, p.ProjectItems.Count);
                                    string sFileName = pi.Name.ToLower();
                                    if (!sFileName.EndsWith(".dtsx"))
                                    {
                                        continue;
                                    }
                                    piCurrent = pi;
                                    this.PackagePathPrefix = pi.Name;
                                    Package package = GetPackageFromIntegrationServicesProjectItem(pi);
                                    ScanIntegrationServicesProperties(package);
                                }
                            }
                        }
                        finally
                        {
                            try
                            {
                                ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationGeneral);
                                ApplicationObject.StatusBar.Progress(false, "", 1, 1);
                            }
                            catch { }
                        }
                    }
                }
                else if (solution != null)
                {
                    this.DatabaseName = "Solution: " + System.IO.Path.GetFileNameWithoutExtension(solution.FullName);
                    try
                    {
                        this.DatabaseName = "Solution: " + solution.Properties.Item("Name").Value;
                    }
                    catch { }

                    this.SSASProject = false;

                    try
                    {
                        using (WaitCursor cursor1 = new WaitCursor())
                        {
                            ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationGeneral);
                            foreach (EnvDTE.Project proj in solution.Projects)
                            {
                                Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt projExt = (Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt)proj;
                                if (projExt.Kind == BIDSProjectKinds.SSIS)
                                {
                                    int iProgress = 0;
                                    Microsoft.SqlServer.Dts.Runtime.Application app = SSIS.PackageHelper.Application; //sets the proper TargetServerVersion;
                                    foreach (ProjectItem pi in proj.ProjectItems)
                                    {
                                        ApplicationObject.StatusBar.Progress(true, "Scanning project " + proj.Name + " package " + pi.Name, iProgress++, proj.ProjectItems.Count);
                                        string sFileName = pi.Name.ToLower();
                                        if (!sFileName.EndsWith(".dtsx"))
                                        {
                                            continue;
                                        }
                                        piCurrent = pi;
                                        this.PackagePathPrefix = proj.Name + "\\" + pi.Name;
                                        Package package = GetPackageFromIntegrationServicesProjectItem(pi);
                                        ScanIntegrationServicesProperties(package);
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        try
                        {
                            ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationGeneral);
                            ApplicationObject.StatusBar.Progress(false, "", 1, 1);
                        }
                        catch { }
                    }
                }
                else
                {
                    ProjectItem pi = (ProjectItem)hierItem.Object;
                    piCurrent = pi;
                    Package package = GetPackageFromIntegrationServicesProjectItem(pi);

                    this.DatabaseName      = "Package: " + package.Name;
                    this.SSASProject       = false;
                    this.PackagePathPrefix = string.Empty;

                    ScanIntegrationServicesProperties(package);
                }

                //clear the cache
                this.packageDefault = null;
                this.dictCachedDtsObjects.Clear();

                if (listNonDefaultProperties.Count == 0)
                {
                    MessageBox.Show("No properties set to non-default values were found.", "BIDS Helper - Non-Default Properties Report");
                    return;
                }

                //pop up the form to let the user exclude properties from showing on the report
                List <string> listExcludedProperties = new List <string>(this.ExcludedProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                BIDSHelper.SSAS.NonDefaultPropertiesSelectionForm selector = new BIDSHelper.SSAS.NonDefaultPropertiesSelectionForm();
                foreach (NonDefaultProperty prop in listNonDefaultProperties)
                {
                    if (!selector.listProperties.Items.Contains(prop.PropertyName))
                    {
                        bool bChecked = !listExcludedProperties.Contains(prop.PropertyName);
                        selector.listProperties.Items.Add(prop.PropertyName, bChecked);
                    }
                }

                DialogResult selectorResult = selector.ShowDialog();
                if (selectorResult == DialogResult.OK)
                {
                    //remove the the report rows they unchecked
                    for (int i = 0; i < listNonDefaultProperties.Count; i++)
                    {
                        if (!selector.listProperties.CheckedItems.Contains(listNonDefaultProperties[i].PropertyName))
                        {
                            listNonDefaultProperties.RemoveAt(i--);
                        }
                    }

                    //save their prefs... keep previously prefs which haven't been changes (because an excluded property may not show up in the possible properties list each time you run the report)
                    foreach (object item in selector.listProperties.Items)
                    {
                        if (!selector.listProperties.CheckedItems.Contains(item)) //if excluded, then add to the excluded list
                        {
                            if (!listExcludedProperties.Contains(item.ToString()))
                            {
                                listExcludedProperties.Add(item.ToString());
                            }
                        }
                        else //if included, then remove from the excluded list
                        {
                            if (listExcludedProperties.Contains(item.ToString()))
                            {
                                listExcludedProperties.Remove(item.ToString());
                            }
                        }
                    }
                    this.ExcludedProperties = string.Join(",", listExcludedProperties.ToArray());

                    ReportViewerForm frm = new ReportViewerForm();
                    frm.ReportBindingSource.DataSource = this.listNonDefaultProperties;
                    frm.Report = "SSAS.NonDefaultProperties.rdlc";
                    Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
                    reportDataSource1.Name  = "BIDSHelper_NonDefaultProperty";
                    reportDataSource1.Value = frm.ReportBindingSource;
                    frm.ReportViewerControl.LocalReport.DataSources.Add(reportDataSource1);
                    frm.ReportViewerControl.LocalReport.ReportEmbeddedResource = frm.Report;

                    frm.Caption     = "Non-Default Properties Report";
                    frm.WindowState = FormWindowState.Maximized;
                    frm.Show();
                }
            }
            catch (DtsRuntimeException ex)
            {
                if (ex.ErrorCode == -1073659849L)
                {
                    MessageBox.Show((piCurrent == null ? "This package" : piCurrent.Name) + " has a package password. Please open the package designer, specify the password when the dialog prompts you, then rerun the Non-Default Properties report.\r\n\r\nDetailed error was:\r\n" + ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Password Not Specified");
                }
                else
                {
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Error" + (piCurrent == null ? string.Empty : " scanning " + piCurrent.Name));
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Error" + (piCurrent == null ? string.Empty : " scanning " + piCurrent.Name));
            }
        }
Пример #2
0
        public override void Exec()
        {
            ProjectItem piCurrent = null;
            try
            {
                listNonDefaultProperties = new List<NonDefaultProperty>();

                UIHierarchy solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer;
                UIHierarchyItem hierItem = ((UIHierarchyItem)((System.Array)solExplorer.SelectedItems).GetValue(0));
                SolutionClass solution = hierItem.Object as SolutionClass;
                EnvDTE.Project p = GetSelectedProjectReference();

                if (p != null)
                {
                    Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt projExt = (Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt)p;
                    if (projExt.Kind == BIDSProjectKinds.SSAS)
                    {
                        Database db = (Database)p.Object;
                        ScanAnalysisServicesProperties(db);
                    }
                    else
                    {
                        this.DatabaseName = "Project: " + p.Name;
                        this.SSASProject = false;

                        try
                        {
                            using (WaitCursor cursor1 = new WaitCursor())
                            {
                                int iProgress = 0;
                                ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationGeneral);
                                Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
                                foreach (ProjectItem pi in p.ProjectItems)
                                {
                                    ApplicationObject.StatusBar.Progress(true, "Scanning package " + pi.Name, iProgress++, p.ProjectItems.Count);
                                    string sFileName = pi.Name.ToLower();
                                    if (!sFileName.EndsWith(".dtsx")) continue;
                                    piCurrent = pi;
                                    this.PackagePathPrefix = pi.Name;
                                    Package package = GetPackageFromIntegrationServicesProjectItem(pi);
                                    ScanIntegrationServicesProperties(package);
                                }
                            }

                        }
                        finally
                        {
                            try
                            {
                                ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationGeneral);
                                ApplicationObject.StatusBar.Progress(false, "", 1, 1);
                            }
                            catch { }
                        }
                    }
                }
                else if (solution != null)
                {
                    this.DatabaseName = "Solution: " + System.IO.Path.GetFileNameWithoutExtension(solution.FullName);
                    try
                    {
                        this.DatabaseName = "Solution: " + solution.Properties.Item("Name").Value;
                    }
                    catch { }

                    this.SSASProject = false;

                    try
                    {
                        using (WaitCursor cursor1 = new WaitCursor())
                        {
                            ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationGeneral);
                            foreach (EnvDTE.Project proj in solution.Projects)
                            {
                                Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt projExt = (Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt)proj;
                                if (projExt.Kind == BIDSProjectKinds.SSIS)
                                {
                                    int iProgress = 0;
                                    Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
                                    foreach (ProjectItem pi in proj.ProjectItems)
                                    {
                                        ApplicationObject.StatusBar.Progress(true, "Scanning project " + proj.Name + " package " + pi.Name, iProgress++, proj.ProjectItems.Count);
                                        string sFileName = pi.Name.ToLower();
                                        if (!sFileName.EndsWith(".dtsx")) continue;
                                        piCurrent = pi;
                                        this.PackagePathPrefix = proj.Name + "\\" + pi.Name;
                                        Package package = GetPackageFromIntegrationServicesProjectItem(pi);
                                        ScanIntegrationServicesProperties(package);
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        try
                        {
                            ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationGeneral);
                            ApplicationObject.StatusBar.Progress(false, "", 1, 1);
                        }
                        catch { }
                    }
                }
                else
                {
                    ProjectItem pi = (ProjectItem)hierItem.Object;
                    piCurrent = pi;
                    Package package = GetPackageFromIntegrationServicesProjectItem(pi);

                    this.DatabaseName = "Package: " + package.Name;
                    this.SSASProject = false;
                    this.PackagePathPrefix = string.Empty;

                    ScanIntegrationServicesProperties(package);
                }

                //clear the cache
                this.packageDefault = null;
                this.dictCachedDtsObjects.Clear();

                if (listNonDefaultProperties.Count == 0)
                {
                    MessageBox.Show("No properties set to non-default values were found.", "BIDS Helper - Non-Default Properties Report");
                    return;
                }

                //pop up the form to let the user exclude properties from showing on the report
                List<string> listExcludedProperties = new List<string>(this.ExcludedProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                BIDSHelper.SSAS.NonDefaultPropertiesSelectionForm selector = new BIDSHelper.SSAS.NonDefaultPropertiesSelectionForm();
                foreach (NonDefaultProperty prop in listNonDefaultProperties)
                {
                    if (!selector.listProperties.Items.Contains(prop.PropertyName))
                    {
                        bool bChecked = !listExcludedProperties.Contains(prop.PropertyName);
                        selector.listProperties.Items.Add(prop.PropertyName, bChecked);
                    }
                }

                DialogResult selectorResult = selector.ShowDialog();
                if (selectorResult == DialogResult.OK)
                {
                    //remove the the report rows they unchecked
                    for (int i = 0; i < listNonDefaultProperties.Count; i++)
                    {
                        if (!selector.listProperties.CheckedItems.Contains(listNonDefaultProperties[i].PropertyName))
                        {
                            listNonDefaultProperties.RemoveAt(i--);
                        }
                    }

                    //save their prefs... keep previously prefs which haven't been changes (because an excluded property may not show up in the possible properties list each time you run the report)
                    foreach (object item in selector.listProperties.Items)
                    {
                        if (!selector.listProperties.CheckedItems.Contains(item)) //if excluded, then add to the excluded list
                        {
                            if (!listExcludedProperties.Contains(item.ToString()))
                                listExcludedProperties.Add(item.ToString());
                        }
                        else //if included, then remove from the excluded list
                        {
                            if (listExcludedProperties.Contains(item.ToString()))
                                listExcludedProperties.Remove(item.ToString());
                        }
                    }
                    this.ExcludedProperties = string.Join(",", listExcludedProperties.ToArray());

                    ReportViewerForm frm = new ReportViewerForm();
                    frm.ReportBindingSource.DataSource = this.listNonDefaultProperties;
                    frm.Report = "SSAS.NonDefaultProperties.rdlc";
                    Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
                    reportDataSource1.Name = "BIDSHelper_NonDefaultProperty";
                    reportDataSource1.Value = frm.ReportBindingSource;
                    frm.ReportViewerControl.LocalReport.DataSources.Add(reportDataSource1);
                    frm.ReportViewerControl.LocalReport.ReportEmbeddedResource = frm.Report;

                    frm.Caption = "Non-Default Properties Report";
                    frm.WindowState = FormWindowState.Maximized;
                    frm.Show();
                }
            }
            catch (DtsRuntimeException ex)
            {
                if (ex.ErrorCode == -1073659849L)
                {
                    MessageBox.Show((piCurrent == null ? "This package" : piCurrent.Name) + " has a package password. Please open the package designer, specify the password when the dialog prompts you, then rerun the Non-Default Properties report.\r\n\r\nDetailed error was:\r\n" + ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Password Not Specified");
                }
                else
                {
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Error" + (piCurrent == null ? string.Empty : " scanning " + piCurrent.Name));
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Error" + (piCurrent == null ? string.Empty : " scanning " + piCurrent.Name));
            }
        }