Exemplo n.º 1
0
        public void Write_TwoDimensionsSameMeasureGroup_FileIsCorrectlyBuilt()
        {
            var header          = GetHeader();
            var expectedContent = header
                                  + "\"p\";\"mg\";\"m1\";\"[m1]\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                                  + "\"p\";\"mg\";\"m1\";\"[m1]\";\"d2\";\"[d2]\";\"h2\";\"[h2]\";\"l2\";\"[l2]\";\"1\";\"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 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 d1 = new Dimension("[d1]", "d1");

            mg.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 d2 = new Dimension("[d2]", "d2");

            mg.LinkedDimensions.Add(d2);
            var h2 = new Hierarchy("[h2]", "h2", "df");

            d2.Hierarchies.Add(h2);
            var l2 = new Level("[l2]", "l2", 1);

            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);
        }
Exemplo n.º 2
0
        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);
        }