コード例 #1
0
ファイル: MetadataCsvWriterTest.cs プロジェクト: zyh329/nbi
        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);
        }
コード例 #2
0
ファイル: MetadataCsvWriterTest.cs プロジェクト: zyh329/nbi
        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);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: Waltervondehans/NBi
        private void saveAsMetadataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StartClick(null);
            var cfg = Configuration.Project.Directories[Configuration.DirectoryCollection.DirectoryType.Metadata];
            using (var sfd = new SaveFileDialog())
            {
                sfd.InitialDirectory =cfg.Path;
                sfd.FileName = cfg.File;
                sfd.Filter = "CSV|*.csv|Excel 97-2003|*.xls";
                if(!string.IsNullOrEmpty(cfg.File))
                    sfd.FilterIndex = cfg.File.EndsWith("csv") ? 1 : 2;

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    IMetadataWriter mw = null;
                    switch (Path.GetExtension(sfd.FileName))
                    {
                        case ".csv":
                            mw = new MetadataCsvWriter(sfd.FileName);
                            break;
                        case ".xls":
                        case ".xlsx":
                            mw = new MetadataExcelOleDbWriter(sfd.FileName);
                            var saveForm = new MetadataSave();
                            saveForm.MetadataWriter = mw;
                            if (saveForm.ShowDialog() != DialogResult.OK)
                            {
                                EndClick(null);
                                return;
                            }
                            break;
                        default:
                            throw new NotImplementedException();
                    }

                    mw.ProgressStatusChanged += new ProgressStatusHandler(ProgressStatus);
                    mw.Write(Metadata);
                    mw.ProgressStatusChanged -= new ProgressStatusHandler(ProgressStatus);

                    cfg.FullFileName = sfd.FileName;
                }
            }
            EndClick(null);
        }