Beispiel #1
0
 public CubeMetadata Clone()
 {
     var m = new CubeMetadata();
     foreach (var p in Perspectives)
         m.Perspectives.Add(p.Key, p.Value.Clone());
     return m;
 }
        private CubeMetadata BuildFakeMetadata()
        {
            var metadata = new CubeMetadata();

            var p = new Perspective("p");

            var mg = new MeasureGroup("mg");

            var h1 = new Hierarchy("[h1]", "h1", "df");
            var h2 = new Hierarchy("[h2]", "h2", "df");

            var hs = new HierarchyCollection();
            hs.Add(h1);
            hs.Add(h2);

            var d = new Dimension("[d]", "d", hs);
            mg.LinkedDimensions.Add(d);

            var m1 = new Measure("[m1]", "m1", "df");
            var m2 = new Measure("[m2]", "m2", "df");
            mg.Measures.Add(m1);
            mg.Measures.Add(m2);

            p.MeasureGroups.Add(mg);

            metadata.Perspectives.Add(p);
            return metadata;
        }
Beispiel #3
0
        public CubeMetadata FindMeasures(string pattern)
        {
            var result = new CubeMetadata();

            foreach (var p in this.Perspectives)
            {
                foreach (var mg in p.Value.MeasureGroups)
                {
                    foreach (var mea in mg.Value.Measures)
                    {
                        // Here we call Regex.Match.
                        var match = Regex.Match(mea.Value.Caption, pattern, RegexOptions.IgnoreCase);

                        // Here we check the Match instance.
                        if (match.Success)
                        {
                            result.Perspectives.AddOrIgnore(p.Key);
                            result.Perspectives[p.Key].MeasureGroups.AddOrIgnore(mg.Key);
                            result.Perspectives[p.Key].MeasureGroups[mg.Key].Measures.Add(mea.Value.Clone());
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #4
0
        public void Write_OneElementAtEachStep_FileIsCorrectlyBuilt()
        {
            var header = GetHeader();
            var expectedContent = header + "\"p\";\"mg\";\"m1\";\"[m1]\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n";
            var expectedFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), "ExpectedCSV-" + MethodBase.GetCurrentMethod() + ".csv");
            if (File.Exists(expectedFilename))
                File.Delete(expectedFilename);
            File.AppendAllText(expectedFilename, expectedContent, Encoding.UTF8);

            var filename = Path.Combine(DiskOnFile.GetDirectoryPath(), @"ActualCSV-" + MethodBase.GetCurrentMethod() + ".csv");

            var metadata = new CubeMetadata();
            var p = new Perspective("p");
            metadata.Perspectives.Add(p);
            var mg = new MeasureGroup("mg");
            p.MeasureGroups.Add(mg);
            var m1 = new Measure("[m1]", "m1", "df");
            mg.Measures.Add(m1);
            var d = new Dimension("[d]", "d");
            mg.LinkedDimensions.Add(d);
            var h1 = new Hierarchy("[h1]", "h1", "df");
            d.Hierarchies.Add(h1);
            var l1 = new Level("[l1]", "l1", 0);
            h1.Levels.Add(l1);
            var p1 = new Property("[p1]", "p1");
            l1.Properties.Add(p1);

            //set the object to test
            var mcw = new MetadataCsvWriter(filename);
            mcw.Write(metadata);

            //Assertion
            FileAssert.AreEqual(expectedFilename, filename);
        }
Beispiel #5
0
        public CubeMetadata Read()
        {
            CubeMetadata metadata = new CubeMetadata();

            RaiseProgressStatus("Processing CSV file");
            int i = 0;

            int count = 0;
            using (StreamReader r = new StreamReader(Filename))
            {
                while (r.ReadLine() != null)
                    count++;
            }

            using (StreamReader sr = new StreamReader(Filename, Encoding.UTF8))
            {
                while (sr.Peek() >= 0)
                {
                    var row = sr.ReadLine();
                    if (i>0)
                    {
                        RaiseProgressStatus("Loading row {0} of {1}", i, count);
                        var meta = GetMetadataBasic(SplitLine(row));
                        LoadMetadata(meta, false, ref metadata);
                    }
                    i++;

                }
            }

            RaiseProgressStatus("CSV file processed");

            return metadata;
        }
Beispiel #6
0
        public CubeMetadata Clone()
        {
            var m = new CubeMetadata();

            foreach (var p in Perspectives)
            {
                m.Perspectives.Add(p.Key, p.Value.Clone());
            }
            return(m);
        }
Beispiel #7
0
        public void Write(CubeMetadata metadata)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException();
            }

            GetSheets();
            if (_sheets.IndexOf(SheetName + "$") == -1)
            {
                CreateNewSheet(SheetName);
            }

            RaiseProgressStatus("Opening Xls file");

            DataTable dataTable = MetadataFileFormat.WriteInDataTable(metadata);

            dataTable.TableName = SheetName + "$";
            _rowTotal           = dataTable.Rows.Count;

            using (var conn = new OleDbConnection(GetConnectionString(Filename)))
            {
                using (var da = new OleDbDataAdapter())
                {
                    var sb = new StringBuilder();
                    sb.AppendFormat("INSERT INTO [{0}$] (", SheetName);

                    foreach (DataColumn col in dataTable.Columns)
                    {
                        sb.AppendFormat(" {0},", col.ColumnName);
                    }
                    sb.Remove(sb.Length - 1, 1); //Remove the last comma
                    sb.Append(") VALUES (");
                    for (int i = 0; i < dataTable.Columns.Count; i++)
                    {
                        sb.Append(" ?,");
                    }
                    sb.Remove(sb.Length - 1, 1); //Remove the last comma
                    sb.Append(")");
                    da.InsertCommand = new OleDbCommand(sb.ToString(), conn);
                    foreach (DataColumn col in dataTable.Columns)
                    {
                        da.InsertCommand.Parameters.Add(string.Format("@{0}", col.ColumnName), OleDbType.VarChar, 255, col.ColumnName);
                    }

                    da.RowUpdated += new OleDbRowUpdatedEventHandler(OnRowUpdated);
                    conn.Open();
                    da.Update(dataTable);
                    da.RowUpdated -= new OleDbRowUpdatedEventHandler(OnRowUpdated);
                }
            }
            RaiseProgressStatus("Xls file written");
        }
Beispiel #8
0
        internal static DataTable WriteInDataTable(CubeMetadata metadata, string sheetName)
        {
            var dt = CreateDataTable(sheetName);

            foreach (var perspective in metadata.Perspectives)
            {
                foreach (var mg in perspective.Value.MeasureGroups)
                {
                    foreach (var m in mg.Value.Measures)
                    {
                        foreach (var dim in mg.Value.LinkedDimensions)
                        {
                            foreach (var h in dim.Value.Hierarchies)
                            {
                                foreach (var l in h.Value.Levels)
                                {
                                    var p = l.Value.Properties.GetEnumerator();
                                    if (l.Value.Properties.Count > 0)
                                    {
                                        p.MoveNext();
                                    }
                                    do
                                    {
                                        var row = dt.NewRow();
                                        row[0]  = perspective.Value.Name;
                                        row[1]  = mg.Value.Name;
                                        row[2]  = m.Value.Caption;
                                        row[3]  = m.Value.UniqueName;
                                        row[4]  = dim.Value.Caption;
                                        row[5]  = dim.Value.UniqueName;
                                        row[6]  = h.Value.Caption;
                                        row[7]  = h.Value.UniqueName;
                                        row[8]  = l.Value.Caption;
                                        row[9]  = l.Value.UniqueName;
                                        row[10] = l.Value.Number;
                                        row[11] = l.Value.Properties.Count > 0 ? p.Current.Value.Caption : string.Empty;
                                        row[12] = l.Value.Properties.Count > 0 ? p.Current.Value.UniqueName : string.Empty;
                                        dt.Rows.Add(row);
                                    } while (p.MoveNext());
                                }
                            }
                        }
                    }
                }
            }
            return(dt);
        }
Beispiel #9
0
        internal static DataTable WriteInDataTable(CubeMetadata metadata, string sheetName)
        {
            var dt = CreateDataTable(sheetName);

            foreach (var perspective in metadata.Perspectives)
            {
                foreach (var mg in perspective.Value.MeasureGroups)
                {
                    foreach (var m in mg.Value.Measures)
                    {
                        foreach (var dim in mg.Value.LinkedDimensions)
                        {
                            foreach (var h in dim.Value.Hierarchies)
                            {
                                foreach (var l in h.Value.Levels)
                                {
                                    var p = l.Value.Properties.GetEnumerator();
                                    if (l.Value.Properties.Count > 0)
                                        p.MoveNext();
                                    do
                                    {
                                        var row = dt.NewRow();
                                        row[0] = perspective.Value.Name;
                                        row[1] = mg.Value.Name;
                                        row[2] = m.Value.Caption;
                                        row[3] = m.Value.UniqueName;
                                        row[4] = dim.Value.Caption;
                                        row[5] = dim.Value.UniqueName;
                                        row[6] = h.Value.Caption;
                                        row[7] = h.Value.UniqueName;
                                        row[8] = l.Value.Caption;
                                        row[9] = l.Value.UniqueName;
                                        row[10] = l.Value.Number;
                                        row[11] = l.Value.Properties.Count > 0 ? p.Current.Value.Caption : string.Empty;
                                        row[12] = l.Value.Properties.Count > 0 ? p.Current.Value.UniqueName : string.Empty;
                                        dt.Rows.Add(row);
                                    } while (p.MoveNext());

                                }
                            }
                        }
                    }

                }
            }
            return dt;
        }
Beispiel #10
0
        public void FindMeasures_OneLetterExistingInNoCaptions_ZeroMatches()
        {
            //Buiding object used during test
            var cm = new CubeMetadata();
            cm.Perspectives.Add(new Perspective("p"));
            cm.Perspectives["p"].MeasureGroups.Add(new MeasureGroup("mg"));
            cm.Perspectives["p"].MeasureGroups["mg"].Measures.Add(new Measure("[m1]", "m1", "df"));
            cm.Perspectives["p"].MeasureGroups["mg"].Measures.Add(new Measure("[m2]", "m2", "df"));
            cm.Perspectives["p"].MeasureGroups["mg"].Measures.Add(new Measure("[m3]", "xm3x", "df"));
            cm.Perspectives["p"].MeasureGroups["mg"].Measures.Add(new Measure("[m4]", "4", "df"));

            //Call the method to test
            var res = cm.FindMeasures("z");

            //Assertion
            Assert.That(res.Perspectives.Count, Is.EqualTo(0));
        }
Beispiel #11
0
        public void Write(CubeMetadata metadata)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException();
            }

            RaiseProgressStatus("Building Csv file content");

            DataTable dataTable = MetadataFileFormat.WriteInDataTable(metadata);

            _rowTotal = dataTable.Rows.Count;

            var sb = new StringBuilder();

            foreach (DataColumn col in dataTable.Columns)
            {
                sb.AppendFormat("\"{0}\"{1}", col.ColumnName, Definition.FieldSeparator);
            }
            sb.Remove(sb.Length - 1, 1); //Remove the last comma
            sb.AppendLine();             //goto next line

            foreach (DataRow row in dataTable.Rows)
            {
                _rowCount++;
                foreach (string item in row.ItemArray)
                {
                    var str = (item).Replace(Definition.TextQualifier.ToString(), Definition.TextQualifier.ToString() + Definition.TextQualifier.ToString());
                    sb.AppendFormat("\"{0}\"{1}", str, Definition.FieldSeparator);
                }
                sb.Remove(sb.Length - 1, 1); //Remove the last comma
                sb.AppendLine();             //goto next line
                RaiseProgressStatus("Creating row {0} of {1}", _rowCount, _rowTotal);
            }

            RaiseProgressStatus("Csv file content built");

            RaiseProgressStatus("Writing Csv file content");

            using (StreamWriter outfile = new StreamWriter(Filename, false, Encoding.UTF8))
            {
                outfile.Write(sb);
            }

            RaiseProgressStatus("Csv file written");
        }
Beispiel #12
0
        public CubeMetadata Read()
        {
            CubeMetadata metadata = new CubeMetadata();

            RaiseProgressStatus("Processing Xls file");
            int i = 0;

            foreach (DataRow row in DataTable.Rows)
            {
                i++;
                RaiseProgressStatus("Loading row {0} of {1}", i, DataTable.Rows.Count);
                var r = GetMetadata(row);

                LoadMetadata(r, false, ref metadata);
            }
            RaiseProgressStatus("Xls file processed");

            return(metadata);
        }
Beispiel #13
0
        public void FindMeasures_ComplexRegexMatchingTwoCaptions_TwoMatches()
        {
            //Buiding object used during test
            var cm = new CubeMetadata();
            cm.Perspectives.Add(new Perspective("p"));
            cm.Perspectives["p"].MeasureGroups.Add(new MeasureGroup("mg"));
            cm.Perspectives["p"].MeasureGroups["mg"].Measures.Add(new Measure("[m1]", "m1", "df"));
            cm.Perspectives["p"].MeasureGroups["mg"].Measures.Add(new Measure("[m2]", "m2", "df"));
            cm.Perspectives["p"].MeasureGroups["mg"].Measures.Add(new Measure("[m3]", "xm3x", "df"));
            cm.Perspectives["p"].MeasureGroups["mg"].Measures.Add(new Measure("[m4]", "4", "df"));

            //Call the method to test
            var res = cm.FindMeasures("m[0-9]$");

            //Assertion
            Assert.That(res.Perspectives.Count, Is.EqualTo(1));
            Assert.That(res.Perspectives["p"].MeasureGroups.Count, Is.EqualTo(1));
            Assert.That(res.Perspectives["p"].MeasureGroups["mg"].Measures.Count, Is.EqualTo(2));
        }
Beispiel #14
0
        public void Write(CubeMetadata metadata)
        {
            if (metadata == null)
                throw new ArgumentNullException();

            GetSheets();
            if (_sheets.IndexOf(SheetName + "$") == -1)
                CreateNewSheet(SheetName);

            RaiseProgressStatus("Opening Xls file");

            DataTable dataTable = MetadataFileFormat.WriteInDataTable(metadata);
            dataTable.TableName = SheetName + "$";
            _rowTotal = dataTable.Rows.Count;

            using (var conn = new OleDbConnection(GetConnectionString(Filename)))
            {
                using (var da = new OleDbDataAdapter())
                {
                    var sb = new StringBuilder();
                    sb.AppendFormat("INSERT INTO [{0}$] (", SheetName);

                    foreach (DataColumn col in dataTable.Columns)
                        sb.AppendFormat(" {0},", col.ColumnName);
                    sb.Remove(sb.Length - 1, 1); //Remove the last comma
                    sb.Append(") VALUES (");
                    for (int i = 0; i < dataTable.Columns.Count; i++)
                        sb.Append(" ?,");
                    sb.Remove(sb.Length - 1, 1); //Remove the last comma
                    sb.Append(")");
                    da.InsertCommand = new OleDbCommand(sb.ToString(), conn);
                    foreach (DataColumn col in dataTable.Columns)
                        da.InsertCommand.Parameters.Add(string.Format("@{0}", col.ColumnName), OleDbType.VarChar, 255, col.ColumnName);

                    da.RowUpdated += new OleDbRowUpdatedEventHandler(OnRowUpdated);
                    conn.Open();
                    da.Update(dataTable);
                    da.RowUpdated -= new OleDbRowUpdatedEventHandler(OnRowUpdated);
                }
            }
            RaiseProgressStatus("Xls file written");
        }
Beispiel #15
0
        public void Write(CubeMetadata metadata)
        {
            if (metadata == null)
                throw new ArgumentNullException();

            RaiseProgressStatus("Building Csv file content");

            DataTable dataTable = MetadataFileFormat.WriteInDataTable(metadata);
            _rowTotal = dataTable.Rows.Count;

            var sb = new StringBuilder();

            foreach (DataColumn col in dataTable.Columns)
                sb.AppendFormat("\"{0}\"{1}", col.ColumnName, Definition.FieldSeparator);
            sb.Remove(sb.Length - 1, 1); //Remove the last comma
            sb.AppendLine(); //goto next line

            foreach (DataRow row in dataTable.Rows)
            {
                _rowCount++;
                foreach (string item in row.ItemArray)
                {
                    var str = (item).Replace(Definition.TextQualifier.ToString(), Definition.TextQualifier.ToString() + Definition.TextQualifier.ToString());
                    sb.AppendFormat("\"{0}\"{1}", str, Definition.FieldSeparator);
                }
                sb.Remove(sb.Length - 1, 1); //Remove the last comma
                sb.AppendLine(); //goto next line
                RaiseProgressStatus("Creating row {0} of {1}", _rowCount, _rowTotal);
            }

            RaiseProgressStatus("Csv file content built");

            RaiseProgressStatus("Writing Csv file content");

            using (StreamWriter outfile = new StreamWriter(Filename, false, Encoding.UTF8))
            {
                outfile.Write(sb);
            }

            RaiseProgressStatus("Csv file written");
        }
Beispiel #16
0
        public CubeMetadata GetFullMetadata()
        {
            var cube = new CubeMetadata();

            if (ProgressStatusChanged != null)
            {
                ProgressStatusChanged(this, new ProgressStatusEventArgs("Starting investigation ..."));
            }

            using (var cmd = new PerspectiveDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new DimensionDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new HierarchyDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new LevelDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new PropertyDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new MeasureGroupDiscoveryCommand(ConnectionString))
            {
                var rows = cmd.Discover(null);
                cube.Import(rows);
                //cube.Link(rows);
            }
            using (var cmd = new MeasureDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            if (ProgressStatusChanged != null)
            {
                ProgressStatusChanged(this, new ProgressStatusEventArgs("Cube investigated"));
            }

            return(cube);
        }
Beispiel #17
0
        public CubeMetadata Read(string track)
        {
            CubeMetadata metadata = new CubeMetadata();

            RaiseProgressStatus((string.Format("Processing Xls file for track {0}", track)));

            int i = 0;

            foreach (DataRow row in DataTable.Rows)
            {
                i++;
                RaiseProgressStatus("Loading row {0} of {1}", i, DataTable.Rows.Count);
                var trackPos = _tracks.IndexOf(track) + _reservedColumnsCount;
                var r        = GetMetadata(row, trackPos);

                LoadMetadata(r, true, ref metadata);
            }

            RaiseProgressStatus("Xls file processed");

            return(metadata);
        }
Beispiel #18
0
        public string[] Build(CubeMetadata metadata, string hierarchyFunction, string slicer, bool notEmpty)
        {
            var i = 0;
            var total = metadata.GetItemsCount();

            if (ProgressStatusChanged != null)
                ProgressStatusChanged(this, new ProgressStatusEventArgs(string.Format("Creating query set")));
            var res = new List<string>();
            foreach (var p in metadata.Perspectives)
            {
                foreach (var mg in p.Value.MeasureGroups)
                {
                    foreach (var dim in mg.Value.LinkedDimensions)
                    {
                        foreach (var hierarchy in dim.Value.Hierarchies)
                        {
                            foreach (var m in mg.Value.Measures)
                            {
                                var mdx = BuildMdx(p.Value.Name, m.Value.UniqueName, hierarchy.Value.UniqueName, hierarchyFunction, slicer, notEmpty);
                                if (!string.IsNullOrEmpty(PersistancePath))
                                {
                                    i++;
                                    var filename = BuildFilename(p.Value.Name, mg.Value.Name, m.Value.Caption, dim.Value.Caption, hierarchy.Value.Caption);
                                    Persist(mdx, filename);
                                    if (ProgressStatusChanged != null)
                                        ProgressStatusChanged(this, new ProgressStatusEventArgs(String.Format("Persisting query set {0} of {1}", i, total), i, total));
                                }
                               res.Add(mdx);
                            }

                        }
                    }

                }
            }
            if (ProgressStatusChanged != null)
                ProgressStatusChanged(this, new ProgressStatusEventArgs(string.Format("Query set created")));
            return res.ToArray();
        }
Beispiel #19
0
        public CubeMetadata FindMeasures(string pattern)
        {
            var result = new CubeMetadata();

            foreach (var p in this.Perspectives)
                foreach (var mg in p.Value.MeasureGroups)
                    foreach (var mea in mg.Value.Measures)
                    {
                        // Here we call Regex.Match.
                        var match = Regex.Match(mea.Value.Caption, pattern, RegexOptions.IgnoreCase);

                        // Here we check the Match instance.
                        if (match.Success)
                        {
                            result.Perspectives.AddOrIgnore(p.Key);
                            result.Perspectives[p.Key].MeasureGroups.AddOrIgnore(mg.Key);
                            result.Perspectives[p.Key].MeasureGroups[mg.Key].Measures.Add(mea.Value.Clone());
                        }
                    }

            return result;
        }
Beispiel #20
0
        public CubeMetadata GetFullMetadata()
        {
            var cube = new CubeMetadata();

            if (ProgressStatusChanged != null)
                ProgressStatusChanged(this, new ProgressStatusEventArgs("Starting investigation ..."));

            using (var cmd = new PerspectiveDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new DimensionDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new HierarchyDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new LevelDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new PropertyDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            using (var cmd = new MeasureGroupDiscoveryCommand(ConnectionString))
            {
                var rows = cmd.Discover(null);
                cube.Import(rows);
                //cube.Link(rows);
            }
            using (var cmd = new MeasureDiscoveryCommand(ConnectionString))
                cube.Import(cmd.Discover(null));

            if (ProgressStatusChanged != null)
                ProgressStatusChanged(this, new ProgressStatusEventArgs("Cube investigated"));

            return cube;
        }
Beispiel #21
0
        public CubeMetadata Read()
        {
            CubeMetadata metadata = new CubeMetadata();

            RaiseProgressStatus("Processing CSV file");
            int i = 0;

            int count = 0;

            using (StreamReader r = new StreamReader(Filename))
            {
                while (r.ReadLine() != null)
                {
                    count++;
                }
            }

            using (StreamReader sr = new StreamReader(Filename, Encoding.UTF8))
            {
                while (sr.Peek() >= 0)
                {
                    var row = sr.ReadLine();
                    if (i > 0)
                    {
                        RaiseProgressStatus("Loading row {0} of {1}", i, count);
                        var meta = GetMetadataBasic(SplitLine(row));
                        LoadMetadata(meta, false, ref metadata);
                    }
                    i++;
                }
            }

            RaiseProgressStatus("CSV file processed");

            return(metadata);
        }
Beispiel #22
0
        public CubeMetadata Read()
        {
            CubeMetadata metadata = new CubeMetadata();

            RaiseProgressStatus("Processing Xls file");
            int i = 0;
            foreach (DataRow row in DataTable.Rows)
            {
                i++;
                RaiseProgressStatus("Loading row {0} of {1}", i, DataTable.Rows.Count);
                var r = GetMetadata(row);

                LoadMetadata(r, false, ref metadata);
            }
            RaiseProgressStatus("Xls file processed");

            return metadata;
        }
Beispiel #23
0
 internal static DataTable WriteInDataTable(CubeMetadata metadata)
 {
     return WriteInDataTable(metadata, "MyMetadata");
 }
Beispiel #24
0
        protected CubeMetadata Metadata; //TODO REmove

        #endregion Fields

        #region Constructors

        public MetadataAdomdExtractor(string connectionString)
        {
            ConnectionString = connectionString;
            Metadata = new CubeMetadata();
        }
Beispiel #25
0
        internal void ModifySelection(CubeMetadata selectionModifier, bool add)
        {
            foreach (TreeNode pNode in this.Nodes)
            {
                if (selectionModifier.Perspectives.ContainsKey((string)pNode.Tag))
                {
                    var perspective = selectionModifier.Perspectives[(string)pNode.Tag];
                    foreach (TreeNode mgNode in pNode.Nodes)
                    {
                        mgNode.Checked = perspective.MeasureGroups.ContainsKey((string)mgNode.Tag);

                        if (perspective.MeasureGroups.ContainsKey((string)mgNode.Tag))
                        {
                            var measureGroup =  perspective.MeasureGroups[(string)mgNode.Tag];
                            foreach (TreeNode measureNode in mgNode.LastNode.Nodes)
                                if (measureGroup.Measures.ContainsKey((string)measureNode.Tag))
                                {
                                    measureNode.Checked = add;
                                    CheckParentNode(measureNode, measureNode.Checked);
                                }
                        }
                    }
                }
            }
        }
Beispiel #26
0
 public string[] Build(CubeMetadata metadata, bool notEmpty)
 {
     return this.Build(metadata, "Children", "", notEmpty);
 }
Beispiel #27
0
 public string[] Build(CubeMetadata metadata)
 {
     return this.Build(metadata, "Children", "", false);
 }
Beispiel #28
0
        private void extractMetadataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var extractForm = new MetadataExtract();
            var cfg = Configuration.Project.ConnectionStrings[
                Configuration.ConnectionStringCollection.ConnectionClass.Adomd,
                Configuration.ConnectionStringCollection.ConnectionType.Expect
                ];
            extractForm.ConnectionString = cfg.Value;

            if (extractForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                StartClick(null);
                var metadataExtractor = extractForm.MetadataExtractor;
                metadataExtractor.ProgressStatusChanged += new ProgressStatusHandler(ProgressStatus);
                try
                {
                    Metadata = metadataExtractor.GetFullMetadata();
                }
                catch (ConnectionException ex)
                {
                    MessageBox.Show(ex.Message, "Cannot connect with connectionString", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                finally
                {
                    metadataExtractor.ProgressStatusChanged -= new ProgressStatusHandler(ProgressStatus);

                    if (Metadata!=null)
                        metadataTreeview.Content=Metadata;

                    cfg.Value= extractForm.ConnectionString;

                    EndClick(null);
                }
            }
        }
Beispiel #29
0
        private void openMetadataToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            var cfg = Configuration.Project.Directories[Configuration.DirectoryCollection.DirectoryType.Metadata];
            using (var ofd = new OpenFileDialog())
            {
                ofd.InitialDirectory = cfg.FullPath;
                ofd.FileName = cfg.File;
                ofd.Filter = "CSV|*.csv|Excel 97-2003|*.xls";
                if (!string.IsNullOrEmpty(cfg.File))
                    ofd.FilterIndex = cfg.File.EndsWith("csv") ? 1 : 2;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    var mr = MetadataFactory.GetReader(ofd.FileName);
                    var openMetadataDetailsForm = new MetadataOpen();
                    if (mr.SupportSheets)
                    {
                        openMetadataDetailsForm.MetadataReader = mr;
                        openMetadataDetailsForm.ShowDialog();
                    }

                    StartClick(null);

                    metadataTreeview.Nodes.Clear();

                    mr.ProgressStatusChanged += new ProgressStatusHandler(ProgressStatus);
                    Metadata = mr.Read();
                    mr.ProgressStatusChanged -= new ProgressStatusHandler(ProgressStatus);

                    metadataTreeview.Content=Metadata;

                    if (mr.SupportSheets && openMetadataDetailsForm.Track != "None")
                    {
                        var perspTrack = mr.Read(openMetadataDetailsForm.Track);
                        metadataTreeview.Selection=perspTrack;
                    }

                    cfg.FullFileName = ofd.FileName;

                    EndClick(null);
                }
            }
        }
Beispiel #30
0
        protected CubeMetadata Metadata;//TODO REmove

        public MetadataAdomdExtractor(string connectionString)
        {
            ConnectionString = connectionString;
            Metadata         = new CubeMetadata();
        }
Beispiel #31
0
        public void Write_TwoPerspectivesCompletelyDifferent_FileIsCorrectlyBuilt()
        {
            var header = GetHeader();
            var expectedContent = header
                + "\"p1\";\"mg1\";\"m1\";\"[m1]\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p2\";\"mg2\";\"m2\";\"[m2]\";\"d2\";\"[d2]\";\"h2\";\"[h2]\";\"l2\";\"[l2]\";\"0\";\"p2\";\"[p2]\"\r\n"
                ;
            var expectedFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), "ExpectedCSV-" + MethodBase.GetCurrentMethod() + ".csv");
            if (File.Exists(expectedFilename))
                File.Delete(expectedFilename);
            File.AppendAllText(expectedFilename, expectedContent, Encoding.UTF8);

            var filename = Path.Combine(DiskOnFile.GetDirectoryPath(), @"ActualCSV-" + MethodBase.GetCurrentMethod() + ".csv");

            var metadata = new CubeMetadata();
            var pe1 = new Perspective("p1");
            metadata.Perspectives.Add(pe1);
            var mg1 = new MeasureGroup("mg1");
            pe1.MeasureGroups.Add(mg1);
            var m1 = new Measure("[m1]", "m1", "df");
            mg1.Measures.Add(m1);
            var d1 = new Dimension("[d1]", "d1");
            mg1.LinkedDimensions.Add(d1);
            var h1 = new Hierarchy("[h1]", "h1", "df");
            d1.Hierarchies.Add(h1);
            var l1 = new Level("[l1]", "l1", 0);
            h1.Levels.Add(l1);
            var p1 = new Property("[p1]", "p1");
            l1.Properties.Add(p1);

            var pe2 = new Perspective("p2");
            metadata.Perspectives.Add(pe2);
            var mg2 = new MeasureGroup("mg2");
            pe2.MeasureGroups.Add(mg2);
            var m2 = new Measure("[m2]", "m2", "df");
            mg2.Measures.Add(m2);
            var d2 = new Dimension("[d2]", "d2");
            mg2.LinkedDimensions.Add(d2);
            var h2 = new Hierarchy("[h2]", "h2", "df");
            d2.Hierarchies.Add(h2);
            var l2 = new Level("[l2]", "l2", 0);
            h2.Levels.Add(l2);
            var p2 = new Property("[p2]", "p2");
            l2.Properties.Add(p2);

            //set the object to test
            var mcw = new MetadataCsvWriter(filename);
            mcw.Write(metadata);

            //Assertion
            FileAssert.AreEqual(expectedFilename, filename);
        }
Beispiel #32
0
        private void LoadMetadata(CsvMetadata r, bool filter, ref CubeMetadata metadata)
        {
            MeasureGroup mg = null;

            if ((!filter) || r.isChecked)
            {
                metadata.Perspectives.AddOrIgnore(r.perspectiveName);
                var perspective = metadata.Perspectives[r.perspectiveName];

                if (perspective.MeasureGroups.ContainsKey(r.measureGroupName))
                {
                    mg = perspective.MeasureGroups[r.measureGroupName];
                }
                else
                {
                    mg = new MeasureGroup(r.measureGroupName);
                    perspective.MeasureGroups.Add(mg);
                }

                if (!mg.Measures.ContainsKey(r.measureUniqueName))
                {
                    mg.Measures.Add(r.measureUniqueName, r.measureCaption, r.measureDisplayFolder);
                }

                Dimension dim = null;

                if (perspective.Dimensions.ContainsKey(r.dimensionUniqueName))
                {
                    dim = perspective.Dimensions[r.dimensionUniqueName];
                }
                else
                {
                    dim = new Dimension(r.dimensionUniqueName, r.dimensionCaption);
                    perspective.Dimensions.Add(dim);
                }

                if (!dim.Hierarchies.ContainsKey(r.hierarchyUniqueName))
                {
                    var hierarchy = new Hierarchy(r.hierarchyUniqueName, r.hierarchyCaption, string.Empty);
                    dim.Hierarchies.Add(r.hierarchyUniqueName, hierarchy);
                }

                if (!dim.Hierarchies[r.hierarchyUniqueName].Levels.ContainsKey(r.levelUniqueName))
                {
                    var level = new Level(r.levelUniqueName, r.levelCaption, r.levelNumber);
                    dim.Hierarchies[r.hierarchyUniqueName].Levels.Add(r.levelUniqueName, level);
                }

                if (!string.IsNullOrEmpty(r.propertyUniqueName))
                {
                    if (!dim.Hierarchies[r.hierarchyUniqueName].Levels[r.levelUniqueName].Properties.ContainsKey(r.propertyUniqueName))
                    {
                        var prop = new Property(r.propertyUniqueName, r.propertyCaption);
                        dim.Hierarchies[r.hierarchyUniqueName].Levels[r.levelUniqueName].Properties.Add(r.propertyUniqueName, prop);
                    }
                }

                if (!mg.LinkedDimensions.ContainsKey(r.dimensionUniqueName))
                {
                    mg.LinkedDimensions.Add(dim);
                }
            }
        }
Beispiel #33
0
        internal CubeMetadata GetSelection()
        {
            CubeMetadata sel = new CubeMetadata();

            foreach (TreeNode perspNode in this.Nodes)
            {
                var selPersp = Content.Perspectives[(string)perspNode.Tag].Clone();
                sel.Perspectives.Add(selPersp);
                foreach (TreeNode mgNode in perspNode.Nodes)
                {
                    if (mgNode.Checked)
                    {
                        var selMg = selPersp.MeasureGroups[(string)mgNode.Tag];
                        foreach (TreeNode dimNode in mgNode.FirstNode.Nodes)
                        {
                            if (dimNode.Checked)
                            {
                                var cleanDim = Content.Perspectives[(string)perspNode.Tag].Dimensions[(string)dimNode.Tag].Clone(); //NOT A TRUE CLONE !!!!
                                cleanDim.Hierarchies.Clear();

                                selMg.LinkedDimensions.Add(cleanDim);
                                foreach (TreeNode hierarchyNode in dimNode.Nodes)
                                {
                                    if (hierarchyNode.Checked)
                                    {
                                        var cleanHierarchy = Content.Perspectives[(string)perspNode.Tag]
                                            .Dimensions[(string)dimNode.Tag]
                                            .Hierarchies[(string)hierarchyNode.Tag].Clone();
                                        cleanHierarchy.Levels.Clear();

                                        selMg.LinkedDimensions[(string)dimNode.Tag].Hierarchies.Add(cleanHierarchy);

                                        foreach (TreeNode levelNode in hierarchyNode.Nodes)
                                        {
                                            if (levelNode.Checked)
                                                selMg.LinkedDimensions[(string)dimNode.Tag]
                                                    .Hierarchies[(string)hierarchyNode.Tag].Levels.Add((string)levelNode.Tag,
                                                    Content.Perspectives[(string)perspNode.Tag]
                                                    .Dimensions[(string)dimNode.Tag]
                                                    .Hierarchies[(string)hierarchyNode.Tag]
                                                    .Levels[(string)levelNode.Tag]
                                                    .Clone());
                                        }
                                    }
                                }
                            }
                        }
                        foreach (TreeNode measureNode in mgNode.LastNode.Nodes)
                        {
                            if (measureNode.Checked)
                                selMg.Measures.Add(Content.Perspectives[(string)perspNode.Tag].MeasureGroups[(string)mgNode.Tag].Measures[(string)measureNode.Tag].Clone());
                        }
                    }

                }
            }
            return sel;
        }
Beispiel #34
0
        private void LoadMetadata(XlsMetadata r, bool filter, ref CubeMetadata metadata)
        {
            MeasureGroup mg = null;

            if ((!filter) || r.isChecked)
            {
                metadata.Perspectives.AddOrIgnore(r.perspectiveName);
                var perspective = metadata.Perspectives[r.perspectiveName];

                if (perspective.MeasureGroups.ContainsKey(r.measureGroupName))
                {
                    mg = perspective.MeasureGroups[r.measureGroupName];
                }
                else
                {
                    mg = new MeasureGroup(r.measureGroupName);
                    perspective.MeasureGroups.Add(mg);
                }

                if (!mg.Measures.ContainsKey(r.measureUniqueName))
                {
                    mg.Measures.Add(r.measureUniqueName, r.measureCaption, r.measureDisplayFolder);
                }

                Dimension dim = null;

                if (perspective.Dimensions.ContainsKey(r.dimensionUniqueName))
                {
                    dim = perspective.Dimensions[r.dimensionUniqueName];
                }
                else
                {
                    dim = new Dimension(r.dimensionUniqueName, r.dimensionCaption, new HierarchyCollection());
                    perspective.Dimensions.Add(dim);
                }

                if (!dim.Hierarchies.ContainsKey(r.hierarchyUniqueName))
                {
                    var hierarchy = new Hierarchy(r.hierarchyUniqueName, r.hierarchyCaption, string.Empty);
                    dim.Hierarchies.Add(r.hierarchyUniqueName, hierarchy);
                }

                if (r.levelUniqueName != null)
                {
                    if (!dim.Hierarchies[r.hierarchyUniqueName].Levels.ContainsKey(r.levelUniqueName))
                    {
                        var level = new Level(r.levelUniqueName, r.levelCaption, r.levelNumber);
                        dim.Hierarchies[r.hierarchyUniqueName].Levels.Add(r.levelUniqueName, level);
                    }

                    if (!string.IsNullOrEmpty(r.propertyUniqueName))
                    {
                        if (!dim.Hierarchies[r.hierarchyUniqueName].Levels[r.levelUniqueName].Properties.ContainsKey(r.propertyUniqueName))
                        {
                            var prop = new Property(r.propertyUniqueName, r.propertyCaption);
                            dim.Hierarchies[r.hierarchyUniqueName].Levels[r.levelUniqueName].Properties.Add(r.propertyUniqueName, prop);
                        }
                    }
                }
                if (!mg.LinkedDimensions.ContainsKey(r.dimensionUniqueName))
                    mg.LinkedDimensions.Add(dim);
            }
        }
Beispiel #35
0
        public CubeMetadata Read(string track)
        {
            CubeMetadata metadata=new CubeMetadata();

            RaiseProgressStatus((string.Format("Processing Xls file for track {0}", track)));

            int i = 0;
            foreach (DataRow row in DataTable.Rows)
            {
                i++;
                RaiseProgressStatus("Loading row {0} of {1}", i, DataTable.Rows.Count);
                var trackPos = _tracks.IndexOf(track) + _reservedColumnsCount;
                var r = GetMetadata(row, trackPos);

                LoadMetadata(r, true, ref metadata);
            }

            RaiseProgressStatus("Xls file processed");

            return metadata;
        }
Beispiel #36
0
 public FindMeasures(CubeMetadata metadata)
 {
     InitializeComponent();
     _metadata = metadata;
     Settings = new SettingsFindMeasures();
 }
Beispiel #37
0
 public string[] Build(CubeMetadata metadata, string hierarchyFunction, string slicer)
 {
     return this.Build(metadata, hierarchyFunction, slicer, false);
 }
Beispiel #38
0
 internal static DataTable WriteInDataTable(CubeMetadata metadata)
 {
     return(WriteInDataTable(metadata, "MyMetadata"));
 }
Beispiel #39
0
        internal void SetSelection(CubeMetadata selection)
        {
            foreach (TreeNode pNode in this.Nodes)
            {
                pNode.Checked = selection.Perspectives.ContainsKey((string)pNode.Tag);
                if (pNode.Checked)
                {
                    var perspective = selection.Perspectives[(string)pNode.Tag];
                    foreach (TreeNode mgNode in pNode.Nodes)
                    {
                        mgNode.Checked = perspective.MeasureGroups.ContainsKey((string)mgNode.Tag);

                        if (mgNode.Checked)
                        {
                            foreach (TreeNode dimNode in mgNode.FirstNode.Nodes)
                            {
                                dimNode.Checked = perspective.MeasureGroups[(string)mgNode.Tag].LinkedDimensions.ContainsKey((string)dimNode.Tag);
                                mgNode.FirstNode.Checked = dimNode.Checked || mgNode.FirstNode.Checked;
                                if (dimNode.Checked)
                                {
                                    foreach (TreeNode hierarchyNode in dimNode.Nodes)
                                    {
                                        hierarchyNode.Checked = perspective.MeasureGroups[(string)mgNode.Tag].
                                            LinkedDimensions[(string)dimNode.Tag].
                                            Hierarchies.ContainsKey((string)hierarchyNode.Tag);
                                        if (hierarchyNode.Checked)
                                        {
                                            foreach (TreeNode levelNode in hierarchyNode.Nodes)
                                            {
                                                levelNode.Checked = perspective.MeasureGroups[(string)mgNode.Tag].
                                                    LinkedDimensions[(string)dimNode.Tag].
                                                    Hierarchies[(string)hierarchyNode.Tag].
                                                    Levels.ContainsKey((string)levelNode.Tag);
                                            }
                                        }
                                    }
                                }
                            }

                            foreach (TreeNode measureNode in mgNode.LastNode.Nodes)
                            {
                                measureNode.Checked = perspective.MeasureGroups[(string)mgNode.Tag].Measures.ContainsKey((string)measureNode.Tag);
                                mgNode.LastNode.Checked = measureNode.Checked || mgNode.LastNode.Checked;
                            }
                        }
                    }
                }
            }
        }
Beispiel #40
0
        internal TreeNode[] MapContent(CubeMetadata metadata)
        {
            var tnc = new List<TreeNode>();

            if (metadata == null)
                return tnc.ToArray();

            foreach (var perspective in metadata.Perspectives)
            {
                var pNode = new TreeNode(perspective.Value.Name);
                pNode.Tag = perspective.Key;
                tnc.Add(pNode);

                foreach (var mg in perspective.Value.MeasureGroups)
                {
                    var mgNode = new TreeNode(mg.Value.Name);
                    mgNode.Tag = mg.Key;
                    pNode.Nodes.Add(mgNode);

                    var dimsNode = new TreeNode("Linked dimensions");
                    mgNode.Nodes.Add(dimsNode);
                    foreach (var dim in mg.Value.LinkedDimensions)
                    {
                        var dimNode = new TreeNode(dim.Value.Caption);
                        dimNode.Tag = dim.Key;
                        dimsNode.Nodes.Add(dimNode);
                        foreach (var h in dim.Value.Hierarchies)
                        {
                            var hNode = new TreeNode(h.Value.Caption);
                            hNode.Tag = h.Key;
                            dimNode.Nodes.Add(hNode);
                            foreach (var l in h.Value.Levels)
                            {
                                var lNode = new TreeNode(l.Value.Caption);
                                lNode.Tag = l.Key;
                                hNode.Nodes.Add(lNode);
                                foreach (var p in l.Value.Properties)
                                {
                                    var propNode = new TreeNode(p.Value.Caption);
                                    propNode.Tag = p.Key;
                                    lNode.Nodes.Add(propNode);
                                }
                            }
                        }
                    }

                    var measuresNode = new TreeNode("Measures");
                    mgNode.Nodes.Add(measuresNode);
                    foreach (var measure in mg.Value.Measures)
                    {
                        var measureNode = new TreeNode(measure.Value.Caption);
                        measureNode.Tag = measure.Key;
                        measuresNode.Nodes.Add(measureNode);
                    }
                }
            }

            return tnc.ToArray();
        }