public BotDataSource(DataSourceConnection dataSourceConnection) { this.dataSourceConnection = dataSourceConnection; }
void SetAllEstimatedCounts(ToolBarButton button) { //grab the objects I need before the user has a chance to flip to another active window Project proj = ApplicationObject.ActiveWindow.Project; Window window = ApplicationObject.ActiveWindow; Cube cube = (Cube)this.ApplicationObject.ActiveWindow.ProjectItem.Object; IDesignerHost designer = (IDesignerHost)ApplicationObject.ActiveWindow.Object; if (MessageBox.Show("Updating all estimated counts with exact counts for all partitions and dimensions\r\ncould take an extremely long time.\r\n\r\nAre you sure you want to continue?", "BIDS Helper - Update All Estimated Counts", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } button.ImageIndex = button.Parent.ImageList.Images.IndexOfKey(STOP_ICON_KEY); //change to a stop icon to allow the user to cancel Application.DoEvents(); try { using (WaitCursor cursor1 = new WaitCursor()) { ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationGeneral); IComponentChangeService changesvc = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService)); changesvc.OnComponentChanging(cube, null); System.Collections.Generic.List <string> errors = new System.Collections.Generic.List <string>(); int iProgress = 0; foreach (MeasureGroup mg in cube.MeasureGroups) { ApplicationObject.StatusBar.Progress(true, "Setting Estimated Counts on Measure Group: " + mg.Name, ++iProgress, cube.MeasureGroups.Count + cube.Parent.Dimensions.Count); if (mg.Partitions.Count > 0) { foreach (Partition p in mg.Partitions) { p.EstimatedRows = 0; } foreach (AggregationDesign aggd in mg.AggregationDesigns) { //make sure each measure group dimension and attribute is in each agg design... fixes issue 21220 foreach (MeasureGroupDimension mgd in mg.Dimensions) { if (mgd is RegularMeasureGroupDimension) { if (!aggd.Dimensions.Contains(mgd.CubeDimensionID)) { aggd.Dimensions.Add(mgd.CubeDimensionID); } AggregationDesignDimension aggdd = aggd.Dimensions[mgd.CubeDimensionID]; foreach (DimensionAttribute da in mgd.Dimension.Attributes) { if (da.AttributeHierarchyEnabled && mgd.CubeDimension.Attributes[da.ID].AttributeHierarchyEnabled && !aggdd.Attributes.Contains(da.ID)) { aggdd.Attributes.Add(da.ID); } } } } foreach (AggregationDesignDimension aggdim in aggd.Dimensions) { foreach (AggregationDesignAttribute attr in aggdim.Attributes) { try { attr.EstimatedCount = 0; attr.Attribute.EstimatedCount = 0; } catch { } } } foreach (MeasureGroupDimension mgd in mg.Dimensions) { if (mgd is RegularMeasureGroupDimension) { RegularMeasureGroupDimension dim = (RegularMeasureGroupDimension)mgd; foreach (Partition p in mg.Partitions) { if (p.AggregationDesignID == aggd.ID) { try { SetEstimatedCountsOnPartitionThreadInfo info = new SetEstimatedCountsOnPartitionThreadInfo(); info.instance = this; info.aggDesign = aggd; info.measureGroupDimension = dim; info.partition = p; //run as a separate thread so that the main app stays responsive (so you can click the cancel button) System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(StartSetEstimatedCountsOnPartition), info); while (!info.done) { System.Threading.Thread.Sleep(100); Application.DoEvents(); //keeps main app responsive if (CheckCancelled()) { return; } } errors.AddRange(info.errors); } catch (Exception ex) { errors.Add("BIDS Helper error setting estimated counts on partition " + p.Name + " of measure group " + mg.Name + ": " + ex.Message); } } } } } } //now fill in the count on partitions without agg designs foreach (Partition p in mg.Partitions) { if (p.AggregationDesign == null) { try { SetEstimatedCountsOnPartitionThreadInfo info = new SetEstimatedCountsOnPartitionThreadInfo(); info.instance = this; info.partition = p; //run as a separate thread so that the main app stays responsive (so you can click the cancel button) System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(StartSetEstimatedCountsOnPartition), info); while (!info.done) { System.Threading.Thread.Sleep(100); Application.DoEvents(); //keeps main app responsive if (CheckCancelled()) { return; } } errors.AddRange(info.errors); } catch (Exception ex) { errors.Add("BIDS Helper error setting estimated counts on partition " + p.Name + " of measure group " + mg.Name + ": " + ex.Message); } } } long iMeasureGroupRowsCount = 0; foreach (Partition p in mg.Partitions) { iMeasureGroupRowsCount += p.EstimatedRows; } mg.EstimatedRows = iMeasureGroupRowsCount; } } changesvc.OnComponentChanged(cube, null, null, null); //marks the cube designer as dirty foreach (ProjectItem pi in proj.ProjectItems) { try { if (!(pi.Object is Dimension)) { continue; } } catch { continue; //doing the above seems to blow up on certain objects because of threading? this fixes the problem } Dimension dim = (Dimension)pi.Object; ApplicationObject.StatusBar.Progress(true, "Setting Estimated Counts on Dimension: " + dim.Name, ++iProgress, cube.MeasureGroups.Count + cube.Parent.Dimensions.Count); //open but don't show the dimension designer so you can get at the change service so you can mark it dirty bool bIsOpen = pi.get_IsOpen(EnvDTE.Constants.vsViewKindDesigner); Window win = null; if (bIsOpen) { foreach (Window w in ApplicationObject.Windows) { if (w.ProjectItem != null && w.ProjectItem.Document != null && w.ProjectItem.Document.FullName == pi.Document.FullName) { win = w; break; } } } if (win == null) { win = pi.Open(EnvDTE.Constants.vsViewKindDesigner); if (!bIsOpen) { win.Visible = false; } } designer = (IDesignerHost)win.Object; changesvc = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService)); changesvc.OnComponentChanging(dim, null); if (dim.DataSource != null) { try { DataSourceConnection openedDataSourceConnection = Microsoft.AnalysisServices.Design.DSVUtilities.GetOpenedDataSourceConnection(dim.DataSource); foreach (DimensionAttribute attr in dim.Attributes) { SetEstimatedCountsOnDimensionThreadInfo info = new SetEstimatedCountsOnDimensionThreadInfo(); info.instance = this; info.attribute = attr; info.connection = openedDataSourceConnection; //run as a separate thread so that the main app stays responsive (so you can click the cancel button) System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(StartSetEstimatedCountsOnDimension), info); while (!info.done) { System.Threading.Thread.Sleep(100); Application.DoEvents(); //keeps main app responsive if (CheckCancelled()) { return; } } errors.AddRange(info.errors); } } catch (Exception ex) { errors.Add("BIDS Helper error setting estimated counts on dimension " + dim.Name + ": " + ex.Message); } } changesvc.OnComponentChanged(dim, null, null, null); } AddErrorsToVSErrorList(window, errors.ToArray()); } } finally { try { button.ImageIndex = button.Parent.ImageList.Images.IndexOfKey(SET_ESTIMATED_COUNTS_ICON_KEY); ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationGeneral); ApplicationObject.StatusBar.Progress(false, "", 1, 1); } catch { } } }