Example #1
0
        private void ExecDimension(ProjectItem pi)
        {
            try
            {
                Dimension dim = pi.Object as Dimension;
                Program.ASFlattener     = new frmASFlattener();
                Program.ASFlattener.dim = dim;
                frmASFlattenerOptions Options = new frmASFlattenerOptions();
                Options.lbHierarchies.Items.Clear();
                Options.lbAttributes.Items.Clear();
                if (dim != null)
                {
                    foreach (Hierarchy hier in dim.Hierarchies)
                    {
                        Options.lbHierarchies.Items.Add(new ctlFancyCheckedListBoxItem(hier.Name, true));
                    }
                    foreach (DimensionAttribute attr in dim.Attributes)
                    {
                        if (attr.Usage == AttributeUsage.Regular)
                        {
                            if (ASPCDimNaturalizer.IsAttributeRelated(attr, dim.KeyAttribute))
                            {
                                Options.lbAttributes.Items.Add(attr.Name);
                            }
                            Options.lbHierarchies.Items.Add(new ctlFancyCheckedListBoxItem(attr.Name, false));
                        }
                    }
                }

                for (int i = 0; i < Options.lbAttributes.Items.Count; i++)
                {
                    Options.lbAttributes.SetItemChecked(i, true);
                }
                for (int i = 0; i < Options.lbHierarchies.Items.Count; i++)
                {
                    Options.lbHierarchies.SetItemChecked(i, true);
                }
                Options.tabControl1.SelectedIndex = 0;
                Options.numMinLevels.Value        = 0;
                Options.trkActionLevel.Value      = 4;

                if (Options.ShowDialog() == DialogResult.OK)
                {
                    ProjectItem piDsv = null;
                    foreach (ProjectItem piTemp in pi.ContainingProject.ProjectItems)
                    {
                        if (piTemp.Object == dim.DataSourceView)
                        {
                            piDsv = piTemp;
                            break;
                        }
                    }

                    //close all project windows
                    foreach (ProjectItem piTemp in pi.ContainingProject.ProjectItems)
                    {
                        bool bIsOpen = piTemp.get_IsOpen(BIDSViewKinds.Designer);
                        if (bIsOpen)
                        {
                            Window win = piTemp.Open(BIDSViewKinds.Designer);
                            win.Close(vsSaveChanges.vsSaveChangesYes);
                        }
                    }

                    Microsoft.DataWarehouse.Design.DataSourceConnection openedDataSourceConnection = GetOpenedDataSourceConnection(dim.DataSource);
                    Program.ASFlattener.db = Program.ASFlattener.dim.Parent;
                    Program.ASFlattener.DataSourceConnection = openedDataSourceConnection;

                    Program.SQLFlattener = null;

                    asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectHierarchy       projectService = (asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectHierarchy)((System.IServiceProvider)pi.ContainingProject).GetService(typeof(asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectHierarchy));
                    sharedDataWarehouseInterfaces::Microsoft.DataWarehouse.Interfaces.IConfigurationSettings settings       = (sharedDataWarehouseInterfaces::Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)((System.IServiceProvider)pi.ContainingProject).GetService(typeof(sharedDataWarehouseInterfaces::Microsoft.DataWarehouse.Interfaces.IConfigurationSettings));
                    asAlias::Microsoft.DataWarehouse.Project.DataWarehouseProjectManager projectManager = (asAlias::Microsoft.DataWarehouse.Project.DataWarehouseProjectManager)settings.GetType().InvokeMember("ProjectManager", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy, null, settings, null);

                    Dimension dimNew = dim.Clone();
                    dimNew.Name = dim.Name + "_Naturalized";
                    dimNew.ID   = dimNew.Name;

                    string sNewDimProjectItemName = dimNew.Name + ".dim";
                    if (dim.ParentServer != null)
                    {
                        sNewDimProjectItemName = dimNew.Name;
                    }
                    if (dim.Parent.Dimensions.ContainsName(dimNew.Name))
                    {
                        projectManager.GetProjectItemFromName(sNewDimProjectItemName).Delete(); //deletes the project item and the dimension from the AMO dimensions collection
                    }

                    if (dim.ParentServer == null)
                    {
                        string sFullPath = pi.get_FileNames(0);
                        sFullPath = sFullPath.Substring(0, sFullPath.Length - System.IO.Path.GetFileName(sFullPath).Length) + sNewDimProjectItemName;
                        XmlWriter writer = new System.Xml.XmlTextWriter(sFullPath, Encoding.UTF8);
                        Microsoft.AnalysisServices.Utils.Serialize(writer, dimNew, false);
                        writer.Close();

                        asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectNode parentNode = null;
                        asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectNode projNode   = projectManager.CreateFileProjectNode(ref parentNode, 1, sNewDimProjectItemName, sFullPath, 0, 0);

                        projectService.Add(projNode, parentNode);
                        ((asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.ComponentModel.IFileProjectComponentManager)projectManager).UpdateComponentModel(asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.ComponentModel.UpdateOperationType.AddObject, projNode);
                    }
                    else
                    {
                        dim.Parent.Dimensions.Add(dimNew);
                    }

                    Program.Progress = new frmProgress();
                    Program.Progress.ShowDialog(); // The Progress form actually launches the naturalizer...

                    if (piDsv != null && dim.ParentServer == null)
                    {
                        Window winDesigner = piDsv.Open(BIDSViewKinds.Designer);
                        winDesigner.Activate();
                        System.ComponentModel.Design.IDesignerHost host = (System.ComponentModel.Design.IDesignerHost)(winDesigner.Object);
                        asAlias::Microsoft.AnalysisServices.Design.DataSourceDesigner designer = (asAlias::Microsoft.AnalysisServices.Design.DataSourceDesigner)host.GetDesigner(dim.DataSourceView);
                        designer.MakeDesignerDirty();
                    }

                    ProjectItem piNew = projectManager.GetProjectItemFromName(sNewDimProjectItemName);
                    if (dim.ParentServer == null)
                    {
                        piNew.Save(null);
                        //piNew.ContainingProject.Save(null); //didn't work
                    }
                    else
                    {
                        //already processed inside the ASPCDimNaturalizer code
                    }

                    Window winNew = piNew.Open(BIDSViewKinds.Designer);
                    winNew.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
Example #2
0
 private void frmASFlattener_Load(object sender, EventArgs e)
 {
     cmbDatabase.SelectedIndex = 0;
     cmbDimension.SelectedIndex = 0;
     Options = new frmASFlattenerOptions();
 }
        private void ExecDimension(ProjectItem pi)
        {
            try
            {
                Dimension dim = pi.Object as Dimension;
                Program.ASFlattener = new frmASFlattener();
                Program.ASFlattener.dim = dim;
                frmASFlattenerOptions Options = new frmASFlattenerOptions();
                Options.lbHierarchies.Items.Clear();
                Options.lbAttributes.Items.Clear();
                if (dim != null)
                {
                    foreach (Hierarchy hier in dim.Hierarchies)
                        Options.lbHierarchies.Items.Add(new ctlFancyCheckedListBoxItem(hier.Name, true));
                    foreach (DimensionAttribute attr in dim.Attributes)
                    {
                        if (attr.Usage == AttributeUsage.Regular)
                        {
                            if (ASPCDimNaturalizer.IsAttributeRelated(attr, dim.KeyAttribute))
                                Options.lbAttributes.Items.Add(attr.Name);
                            Options.lbHierarchies.Items.Add(new ctlFancyCheckedListBoxItem(attr.Name, false));
                        }
                    }
                }

                for (int i = 0; i < Options.lbAttributes.Items.Count; i++)
                    Options.lbAttributes.SetItemChecked(i, true);
                for (int i = 0; i < Options.lbHierarchies.Items.Count; i++)
                    Options.lbHierarchies.SetItemChecked(i, true);
                Options.tabControl1.SelectedIndex = 0;
                Options.numMinLevels.Value = 0;
                Options.trkActionLevel.Value = 4;

                if (Options.ShowDialog() == DialogResult.OK)
                {
                    ProjectItem piDsv = null;
                    foreach (ProjectItem piTemp in pi.ContainingProject.ProjectItems)
                    {
                        if (piTemp.Object == dim.DataSourceView)
                        {
                            piDsv = piTemp;
                            break;
                        }
                    }

                    //close all project windows
                    foreach (ProjectItem piTemp in pi.ContainingProject.ProjectItems)
                    {
                        bool bIsOpen = piTemp.get_IsOpen(BIDSViewKinds.Designer);
                        if (bIsOpen)
                        {
                            Window win = piTemp.Open(BIDSViewKinds.Designer);
                            win.Close(vsSaveChanges.vsSaveChangesYes);
                        }
                    }

                    Microsoft.DataWarehouse.Design.DataSourceConnection openedDataSourceConnection = GetOpenedDataSourceConnection(dim.DataSource);
                    Program.ASFlattener.db = Program.ASFlattener.dim.Parent;
                    Program.ASFlattener.DataSourceConnection = openedDataSourceConnection;

                    Program.SQLFlattener = null;

                    Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectHierarchy projectService = (Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectHierarchy)((System.IServiceProvider)pi.ContainingProject).GetService(typeof(Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectHierarchy));
                    Microsoft.DataWarehouse.Interfaces.IConfigurationSettings settings = (Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)((System.IServiceProvider)pi.ContainingProject).GetService(typeof(Microsoft.DataWarehouse.Interfaces.IConfigurationSettings));
                    Microsoft.DataWarehouse.Project.DataWarehouseProjectManager projectManager = (Microsoft.DataWarehouse.Project.DataWarehouseProjectManager)settings.GetType().InvokeMember("ProjectManager", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy, null, settings, null);

                    Dimension dimNew = dim.Clone();
                    dimNew.Name = dim.Name + "_Naturalized";
                    dimNew.ID = dimNew.Name;

                    string sNewDimProjectItemName = dimNew.Name + ".dim";
                    if (dim.ParentServer != null)
                    {
                        sNewDimProjectItemName = dimNew.Name;
                    }
                    if (dim.Parent.Dimensions.ContainsName(dimNew.Name))
                    {
                        projectManager.GetProjectItemFromName(sNewDimProjectItemName).Delete(); //deletes the project item and the dimension from the AMO dimensions collection
                    }

                    if (dim.ParentServer == null)
                    {
                        string sFullPath = pi.get_FileNames(0);
                        sFullPath = sFullPath.Substring(0, sFullPath.Length - System.IO.Path.GetFileName(sFullPath).Length) + sNewDimProjectItemName;
                        XmlWriter writer = new System.Xml.XmlTextWriter(sFullPath, Encoding.UTF8);
                        Microsoft.AnalysisServices.Utils.Serialize(writer, dimNew, false);
                        writer.Close();

                        Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectNode parentNode = null;
                        Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectNode projNode = projectManager.CreateFileProjectNode(ref parentNode, 1, sNewDimProjectItemName, sFullPath, 0, 0);

                        projectService.Add(projNode, parentNode);
                        ((Microsoft.DataWarehouse.VsIntegration.Shell.Project.ComponentModel.IFileProjectComponentManager)projectManager).UpdateComponentModel(Microsoft.DataWarehouse.VsIntegration.Shell.Project.ComponentModel.UpdateOperationType.AddObject, projNode);
                    }
                    else
                    {
                        dim.Parent.Dimensions.Add(dimNew);
                    }

                    Program.Progress = new frmProgress();
                    Program.Progress.ShowDialog(); // The Progress form actually launches the naturalizer...

                    if (piDsv != null && dim.ParentServer == null)
                    {
                        Window winDesigner = piDsv.Open(BIDSViewKinds.Designer);
                        winDesigner.Activate();
                        System.ComponentModel.Design.IDesignerHost host = (System.ComponentModel.Design.IDesignerHost)(winDesigner.Object);
                        Microsoft.AnalysisServices.Design.DataSourceDesigner designer = (Microsoft.AnalysisServices.Design.DataSourceDesigner)host.GetDesigner(dim.DataSourceView);
                        designer.MakeDesignerDirty();
                    }

                    ProjectItem piNew = projectManager.GetProjectItemFromName(sNewDimProjectItemName);
                    if (dim.ParentServer == null)
                    {
                        piNew.Save(null);
                        //piNew.ContainingProject.Save(null); //didn't work
                    }
                    else
                    {
                        //already processed inside the ASPCDimNaturalizer code
                    }

                    Window winNew = piNew.Open(BIDSViewKinds.Designer);
                    winNew.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
Example #4
0
 private void frmASFlattener_Load(object sender, EventArgs e)
 {
     cmbDatabase.SelectedIndex  = 0;
     cmbDimension.SelectedIndex = 0;
     Options = new frmASFlattenerOptions();
 }