예제 #1
0
        public static MeasuresContainer CreateFromDatabase(Database database)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }
            if (database.Model == null)
            {
                throw new ArgumentNullException(nameof(database.Model));
            }

            var measures = new List <DaxMeasure>();

            foreach (var table in database.Model.Tables)
            {
                foreach (var tableMeasure in table.Measures)
                {
                    var measure    = ToSystemEnding(tableMeasure);
                    var newMeasure = new DaxMeasure(measure.Name, table.Name, measure.Expression);
                    newMeasure.CalcProperty = DaxCalcProperty.CreateFromJsonMeasure(measure);

                    measures.Add(newMeasure);
                }
            }

            return(new MeasuresContainer(measures));
        }
        /// <summary>
        /// Extracts the deployed cube structure from the deployed instance and outputs it to a folder
        /// </summary>
        /// <param name="db"></param>
        public static void ExportCubeDefinition(Microsoft.AnalysisServices.Tabular.Database db)
        {
            string outputDir = Path.Combine(Properties.Settings.Default.OutputDir, Properties.Settings.Default.AsDatabaseId);

            CreateOrCleanDirectory(outputDir);

            var    dbJson   = Microsoft.AnalysisServices.Tabular.JsonScripter.ScriptCreateOrReplace(db);
            string filePath = Path.Combine(outputDir, "CreateOrReplace.json");

            File.WriteAllText(filePath, dbJson);

            int counter = 0;
            int totalLines;

            string line;
            {
                System.IO.StreamReader file = new System.IO.StreamReader(filePath);
                while ((line = file.ReadLine()) != null)
                {
                    counter++;
                }
                totalLines = counter;
                file.Close();
            }



            StringBuilder newDb = new StringBuilder();

            counter = 0;
            {
                System.IO.StreamReader file = new System.IO.StreamReader(filePath);
                while ((line = file.ReadLine()) != null)
                {
                    if (counter == 0)
                    {
                        newDb.AppendLine(line);
                    }
                    else
                    {
                        if (counter > 5 && counter < totalLines - 2)
                        {
                            // strip off first few white space characters so the file formats match
                            newDb.AppendLine(line.Substring(4));
                        }
                    }
                    counter++;
                }
                file.Close();
            }



            filePath = Path.Combine(outputDir, "Model.bim");

            File.WriteAllText(filePath, newDb.ToString());
        }