Hi,
I navigate a new page to load the cubes. When I navigate to new page I connect to my cube database but it not seems to load the Cubes. So I have add a listener after connected.
this.PivotGrid.DataSource.LoadSchemaAsync(); this.PivotGrid.DataSource.LoadCubesCompleted += new EventHandler<LoadCubesCompletedEventArgs>(DataSource_LoadCubesCompleted);
private void DataSource_LoadCubesCompleted(object sender, LoadCubesCompletedEventArgs e) { if (this.PivotGrid.DataSource.Cubes.Count > 0) {
this.dataProvider.LoadDimensionsAsync("CubeName");
this.PivotGrid.DataSource.LoadDimensionsCompleted +=
new EventHandler<AsyncCompletedEventArgs>(DataSource_LoadDimensionsCompleted);
}
After loading all cubes I call the Dimensions Load. And Fetch the Xml data to pivot grid. But DataSource_LoadDimensionsCompleted is fired more than once. So the Fill method add only row to grid. And fire the Fill () method secondly. Second time it add row again and failes.
public void DataSource_LoadDimensionsCompleted(object sender, AsyncCompletedEventArgs e)
{
XMLSerializedView.Fill();
I call after the Fill() method that:
this.PivotGrid.DataSource.LoadDimensionsCompleted -= new EventHandler(DataSource_LoadDimensionsCompleted);
But it does not solve my problem.How can I control the cube and dimensions loading ?
Hello,
If your point is to have specific cube selected then you need:
1. Get subscribed for LoadCubesCompleted and Initialized events first.
2. Call LoadSchemaAsync() method.
3. When LoadCubesCompleted is fired look at the Cubes collection for the cube you are interested in.
4. Set dataSource.Cube = cube;
5. Wait for Initialized event. At this point you have all dimensions, hierarchies and their levels loaded (the metadata tree). You can access this data through dataSource.Metadata property and can continue with adding an items to Rows, Columns and ect.
Plamen.
I follow these steps firstly but it continue to call LoadDimensionsAsync. So I add
this.pivotGrid.DataSource.LoadDimensionsCompleted -= new EventHandler<AsyncCompletedEventArgs>(DataSource_LoadDimensionsCompleted);
in the LoadDimensionsCompleted method.
The problem seems to solve the problem. But Now, cube dimension loaded twice. DataSource.Cube.Dimensions.Count and dim.Hierarchies.Count are duplicated.
Would it be possible for you to provide us with a sample of your code?
Thanks,Plamen.
public partial class FixedQuery : Page { XmlaDataProvider dataProvider; SavedPivotGridView XMLSerializedView = new SavedPivotGridView();
string QueryResult = string.Empty;
public FixedQuery() { InitializeComponent(); dataProvider = Connection.GetDataSource(this.FixedQueryPivotGrid); } protected override void OnNavigatedTo(NavigationEventArgs e) { if (this.NavigationContext.QueryString.ContainsKey("QueryXml")) { QueryResult = this.NavigationContext.QueryString["QueryXml"]; if (this.FixedQueryPivotGrid.DataSource != null) { this.FixedQueryPivotGrid.DataSource.LoadSchemaAsync(); this.FixedQueryPivotGrid.DataSource.LoadCubesCompleted += new EventHandler<LoadCubesCompletedEventArgs>(DataSource_LoadCubesCompleted); } } }
void DataSource_LoadCubesCompleted(object sender, LoadCubesCompletedEventArgs e) { try { XmlSerializer serializer = new XmlSerializer(typeof(SavedPivotGridView)); StringReader stringReader = new StringReader(QueryResult); XMLSerializedView = (SavedPivotGridView)serializer.Deserialize(stringReader);
this.FixedQueryPivotGrid.DataSource.Cube = XMLSerializedView.SetCube(this.FixedQueryPivotGrid, this.dataProvider); this.FixedQueryPivotGrid.DataSource.LoadDimensionsCompleted += new EventHandler<AsyncCompletedEventArgs>(DataSource_LoadDimensionsCompleted); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
void DataSource_LoadDimensionsCompleted(object sender, AsyncCompletedEventArgs e) { this.FixedQueryPivotGrid.DataSource.LoadDimensionsCompleted -= new EventHandler<AsyncCompletedEventArgs>(DataSource_LoadDimensionsCompleted); XMLSerializedView.Fill(this.FixedQueryPivotGrid); } }
And methods of SavedPivotGridView ,SetCube and Fill methods like these
public ICube SetCube(XamPivotGrid pivotGrid, XmlaDataProvider dataProvider) { StateLoadComplete = false; pivotGrid.DataSource.Cube = pivotGrid.DataSource.Cubes[this.SelectedCubeIndex]; pivotGrid.DataSource.DeferredLayoutUpdate = true;
pivotGrid.DataSource.Rows.Clear(); pivotGrid.DataSource.Columns.Clear(); pivotGrid.DataSource.Measures.Clear(); pivotGrid.DataSource.Filters.Clear();
dataProvider.LoadDimensionsAsync(pivotGrid.DataSource.Cube); return pivotGrid.DataSource.Cube; }
public void Fill(XamPivotGrid pg) { IFilterViewModel fvm;
foreach (IDimension dim in pg.DataSource.Cube.Dimensions) { foreach (IHierarchy hierarchy in dim.Hierarchies) { if (this.RowHierarchies.Contains(hierarchy.UniqueName)) { fvm = pg.DataSource.CreateFilterViewModel(hierarchy); pg.DataSource.Rows.Add(fvm); } else if (this.ColumnHierarchies.Contains(hierarchy.UniqueName)) { fvm = pg.DataSource.CreateFilterViewModel(hierarchy); pg.DataSource.Columns.Add(fvm); } else if (this.FilterHierarchies.Contains(hierarchy.UniqueName)) { fvm = pg.DataSource.CreateFilterViewModel(hierarchy); pg.DataSource.Filters.Add(fvm); } } } foreach (IMeasure measure in pg.DataSource.Cube.Measures) { if (this.Measures.Contains(measure.UniqueName)) { IMeasureViewModel mvm = pg.DataSource.CreateMeasureViewModel(measure); pg.DataSource.Measures.Add(mvm); } } if (!eventAttached) pg.LayoutLoaded += pivotGrid_LayoutLoaded;
pg.DataSource.DeferredLayoutUpdate = false; }