示例#1
0
 private void lbAttributes_ItemCheck(object sender, ItemCheckEventArgs e)
 {
     try
     {
         lbAttributes.ItemCheck -= lbAttributes_ItemCheck;
         bool   Announced      = false;
         string attCheckedName = lbAttributes.Items[e.Index].ToString();
         if (e.NewValue != CheckState.Checked)
         {
             foreach (string attName in AnyAttsOrHiersDependOnAtt(Program.ASFlattener.dim.Attributes.FindByName((string)lbAttributes.Items[e.Index])))
             {
                 if (lbAttributes.CheckedItems.Contains(attName))
                 {
                     if (!Announced && lbAttributes.Visible)
                     {
                         MessageBox.Show("One or more attribute is related to the dimension key indirectly by way of this one, so all related attributes will also be unselected.", "Indirect Key Attribute Relationship Detected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     }
                     Announced = true;
                 }
                 lbAttributes.SetItemChecked(lbAttributes.FindStringExact(attName), false);
             }
         }
         else
         if (!Program.ASFlattener.dim.KeyAttribute.AttributeRelationships.ContainsName(attCheckedName))
         {
             List <DimensionAttribute> atList = ASPCDimNaturalizer.GetAttrRelOwnerChainToKey(Program.ASFlattener.dim.Attributes.GetByName(attCheckedName));
             foreach (DimensionAttribute attr in atList)
             {
                 if (lbAttributes.Items.Contains(attr.Name) && !lbAttributes.CheckedItems.Contains(attr.Name) && attCheckedName != attr.Name)
                 {
                     if (!Announced && lbAttributes.Visible)
                     {
                         MessageBox.Show("The selected attribute is related only indirectly to the key attribute for the dimension, so all its related attributes will also be selected.", "Indirect Key Attribute Relationship Detected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     }
                     if (lbAttributes.Visible)
                     {
                         Announced = true;
                     }
                     lbAttributes.SetItemChecked(lbAttributes.FindStringExact(attr.Name), true);
                 }
             }
         }
         lbAttributes.ItemCheck += lbAttributes_ItemCheck;
     }
     catch (Exception exc)
     {
         throw exc;
     }
 }
示例#2
0
        private void btnOptions_Click(object sender, EventArgs e)
        {
            Options.lbHierarchies.Items.Clear();
            Options.lbAttributes.Items.Clear();
            if (VerifySelections())
            {
                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++)
            {
                if (PCAttributesToInclude.Contains((string)Options.lbAttributes.Items[i]) || AddAllPCAttributes)
                {
                    Options.lbAttributes.SetItemChecked(i, true);
                }
            }
            for (int i = 0; i < Options.lbHierarchies.Items.Count; i++)
            {
                if (NonPCHierarchiesToInclude.Contains(((ctlFancyCheckedListBoxItem)Options.lbHierarchies.Items[i]).Text) || AddAllNonPCHierarchies)
                {
                    Options.lbHierarchies.SetItemChecked(i, true);
                }
            }
            Options.tabControl1.SelectedIndex = 0;
            Options.numMinLevels.Value        = MinLevels;
            Options.trkActionLevel.Value      = ActionLevel;
            Options.ShowDialog();
        }
示例#3
0
        private List <string> AnyAttsOrHiersDependOnAtt(DimensionAttribute attr)
        {
            List <string> dependants = new List <string>();

            foreach (Hierarchy hier in Program.ASFlattener.dim.Hierarchies)
            {
                foreach (Level lvl in hier.Levels)
                {
                    if (lvl.SourceAttribute.Name == attr.Name)
                    {
                        dependants.Add(hier.Name);
                    }
                }
            }
            for (int i = 0; i < lbAttributes.Items.Count; i++)
            {
                if (ASPCDimNaturalizer.IsAttributeRelated((Program.ASFlattener.dim.Attributes.FindByName((string)lbAttributes.Items[i])), attr))
                {
                    dependants.Add((string)lbAttributes.Items[i]);
                }
            }
            return(dependants);
        }
示例#4
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);
            }
        }
示例#5
0
        private void frmProgress_Load(object sender, EventArgs e)
        {
            try
            {
                hdlCloseButton = btnClose.Handle; // for processing update messages to change the close button's text from the async callback of the naturalization function
                waitImage      = BIDSHelper.Resources.Common.ProcessProgress as Bitmap;
                ImageAnimator.Animate(waitImage, new EventHandler(OnFrameChanged));
                pictureBox1.BackColor = this.BackColor;
                txtStatus.Text        = "Starting...";
                int MinLevels;

                PCDimNaturalizer nat = null;
                if (Program.ASFlattener != null)
                {
                    nat       = new ASPCDimNaturalizer(Program.ASFlattener.srv, Program.ASFlattener.db, Program.ASFlattener.dim, Program.ASFlattener.ActionLevel);
                    MinLevels = Program.ASFlattener.MinLevels;
                    if (Program.ASFlattener.AddAllNonPCHierarchies)
                    {
                        foreach (Hierarchy hier in Program.ASFlattener.dim.Hierarchies)
                        {
                            ((ASPCDimNaturalizer)nat).NonPCHierarchiesToInclude.Add(hier.Name);
                        }
                        foreach (DimensionAttribute attr in Program.ASFlattener.dim.Attributes)
                        {
                            ((ASPCDimNaturalizer)nat).NonPCHierarchiesToInclude.Add(attr.Name);
                        }
                    }
                    else
                    {
                        ((ASPCDimNaturalizer)nat).NonPCHierarchiesToInclude = Program.ASFlattener.NonPCHierarchiesToInclude;
                    }
                    if (Program.ASFlattener.AddAllPCAttributes)
                    {
                        foreach (DimensionAttribute attr in Program.ASFlattener.dim.Attributes)
                        {
                            if (attr.Usage == AttributeUsage.Regular)
                            {
                                ((ASPCDimNaturalizer)nat).PCAttributesToInclude.Add(attr.Name);
                            }
                        }
                    }
                    else
                    {
                        ((ASPCDimNaturalizer)nat).PCAttributesToInclude = Program.ASFlattener.PCAttributesToInclude;
                    }
                }
                else // if it is frmSQLFlattener, since there are only two types of calling forms for this
                {
                    nat       = new SQLPCDimNaturalizer(Program.SQLFlattener.Conn, Program.SQLFlattener.cmbTable.Text, Program.SQLFlattener.cmbID.Text, Program.SQLFlattener.cmbPID.Text, Program.SQLFlattener.MinLevels);
                    MinLevels = Program.SQLFlattener.MinLevels;
                    if (Program.SQLFlattener.AddAllAttributesPC)
                    {
                        foreach (DataRow dr in Program.SQLFlattener.Columns)
                        {
                            if (Program.SQLFlattener.cmbID.Text.Trim() != dr.ItemArray[dr.Table.Columns.IndexOf("COLUMN_NAME")].ToString().Trim() &&
                                Program.SQLFlattener.cmbPID.Text.Trim() != dr.ItemArray[dr.Table.Columns.IndexOf("COLUMN_NAME")].ToString().Trim())
                            {
                                ((SQLPCDimNaturalizer)nat).SQLColsASPCAttributes.Add(dr.ItemArray[dr.Table.Columns.IndexOf("COLUMN_NAME")].ToString());
                            }
                        }
                    }
                    else
                    {
                        ((SQLPCDimNaturalizer)nat).SQLColsASPCAttributes = Program.SQLFlattener.AttributesPC;
                    }
                    if (Program.SQLFlattener.AddAllAttributesNatural)
                    {
                        foreach (DataRow dr in Program.SQLFlattener.Columns)
                        {
                            if (Program.SQLFlattener.cmbID.Text.Trim() != dr.ItemArray[dr.Table.Columns.IndexOf("COLUMN_NAME")].ToString().Trim() &&
                                Program.SQLFlattener.cmbPID.Text.Trim() != dr.ItemArray[dr.Table.Columns.IndexOf("COLUMN_NAME")].ToString().Trim())
                            {
                                ((SQLPCDimNaturalizer)nat).SQLColsAsNonPCAttributes.Add(dr.ItemArray[dr.Table.Columns.IndexOf("COLUMN_NAME")].ToString());
                            }
                        }
                    }
                    else
                    {
                        ((SQLPCDimNaturalizer)nat).SQLColsAsNonPCAttributes = Program.SQLFlattener.AttributesNatural;
                    }
                }
                nat.SourceWindowHandle = this.Handle;
                NaturalizeThreadFunc natThreadFunc = new NaturalizeThreadFunc(nat.Naturalize);
                AsyncCallback        cbNat         = new AsyncCallback(NaturalizeCompletion);
                IAsyncResult         ar            = natThreadFunc.BeginInvoke(MinLevels, cbNat, null);
            }
            catch (Exception exc)
            {
                pictureBox1.Paint -= pictureBox1_Paint;
                ImageAnimator.StopAnimate(waitImage, OnFrameChanged);
                pictureBox1.Image = BIDSHelper.Resources.Common.ProcessError;
                pictureBox1.Refresh();
                pictureBox1.Invalidate();
                txtStatus.Text = "Error initializing naturalizer:  " + exc.ToString();
            }
        }