亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

檢索多維數據庫對象目錄

檢索多維數據庫對象目錄

C#
ABOUTYOU 2022-12-24 13:49:04
我正在嘗試列出在 SSAS 服務器中找到的所有對象(多維數據集、維度、分區...)。我可以使用以下項目來做到這一點:GitHub - SSASAMODB我正在嘗試為每個對象檢索相關目錄(在數據目錄中)。我無法這樣做,因為文件名包含一些增量數字,每次您對數據庫中的對象進行更改時,這些數字都會更改。例子:多維數據集名稱:TestCube文件夾:|Data Dir|\<SSASDB>\TestCube.0.cub更改并重新處理 Cube 后,它會更改為另一個值|Data Dir|\<SSASDB>\TestCube.1.cubAMO 類中是否有返回每個對象的文件夾路徑的屬性?文件夾名稱中包含的增量編號的值是多少?有一些解決方法嗎?由于我只安裝了 SQL Server Data Tools 商業智能工具,我需要一個與SSIS 腳本任務兼容的解決方案,因為這是我處理數據的唯一方式。注意網上有很多關于從腳本任務中使用AMO的文章環境: SQL Server 2014
查看完整描述

1 回答

?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

由于您以多維數據集為例,這意味著您正在使用多維模型而不是表格。


SSAS 數據目錄內容層次結構

使用 SSAS 構建多個多維立方體后,我可以假設以下樹是數據目錄層次結構:


|- Data Directory

    |- Database (.db)

        |- Dimension (.dim)

        |- Role (.role)

        |- Mining Structure (.dms)

        |- Data Source (.ds)

        |- Data Source View (.dsv)

        |- Multidimensional Cube (.cub)

            |- Measure Group (.det)

                |- Partition (.prt)

                |- AggregationDesign (.agg)

上面樹中的每個對象都可以以目錄或/和 XML 文件的形式存儲。

操作和 Kpis 信息存儲在多維數據集 XML 配置文件中。

例子:

  • 對象:立方體

  • 目錄:<DataDir>\<database>\<cube ID>.cub\

  • XML文件:<DataDir>\<database>\<cube ID>.cub.xml

將 SSAS AMO 對象鏈接到數據目錄文件

使用 AMO 讀取數據

為了從部署的 Analysis Cube 中讀取 SSAS 對象,我改進了以下項目的代碼以添加更多對象并將它們與相關目錄/文件鏈接起來。

更新方法

要將每個 AMO 對象映射到相關的目錄/XML 文件,我們必須從頂層(數據庫)開始遍歷對象并檢索在每個級別中找到的文件/目錄,并使用 .ID 屬性和擴展名(如上面的樹)

以下代碼是用 C# 編寫的,它是上面鏈接中發布的方法的更新版本:

請注意,該方法僅適用于本地服務器,或者您必須具有與包含數據目錄的原始驅動器相同盤符的映射網絡驅動器。此外,您必須具有訪問分析服務器對象的權限

該代碼被視為概念證明,可以改進

SSAS對象類

public class SSASObject

{


    public enum ObjectType{


        Cube = 0,

        MeasureGroup = 1,

        Dimension = 2,

        Partition = 3,

        AggregationDesign = 4,

        MiningStructure = 5,

        Role = 6,

        DataSource = 7,

        DataSourceView = 8,

        Database = 9,

        Server = 10,

        Kpi = 11,

        Action = 12


    }


    public int ID { get; set; } //incremental ID 

    public int? ParentID { get; set; } // Parent incremental ID

    public ObjectType Type { get; set; } // The Object type

    public string ObjectID { get; set; } // Object ID defined in SSAS

    public string ObjectName { get; set; } // Object Name defined in SSAS

    public string Extension { get; set; } // The Object extension

    public string FolderPath { get; set; } // The Object related directory

    public string FolderName { get; set; } // The directory name

    public DateTime? FolderModifiedDate { get; set; } // The directory last modified date

    public string FolderIncremetalID { get; set; } // The Incremental Number mentioned in the directory name

    public string XMLFilePath { get; set; } // The Object related XML file

    public string XMLFileName { get; set; } // The XML file name

    public DateTime? XmlModifiedDate { get; set; } // The XML file last modified date

    public string XmlIncremetalID { get; set; }  // The incremental number mentioned in the XML file name      



}

SSASAMO級

public static class SSASAMO

{

    public static List<SSASObject> ReadMeta(string ServerName)

    {

        try

        {



            List<SSASObject> result = new List<SSASObject>();


            String ConnStr;


            DateTime? dt = null;

            int idx = 0;

            int DbID = 0;

            int CubeID = 0;

            int ObjectID = 0;


            string DataDir;

            string OLAPServerName = ServerName;


            ConnStr = "Provider=MSOLAP;Data Source=" + OLAPServerName + ";";


            Server OLAPServer = new Server();

            OLAPServer.Connect(ConnStr);


            DataDir = OLAPServer.ServerProperties["DataDir"].Value;


            string[] DatabasesDir = System.IO.Directory.GetDirectories(DataDir, "*", System.IO.SearchOption.TopDirectoryOnly);

            string[] DatabasesFiles = System.IO.Directory.GetFiles(DataDir, "*", System.IO.SearchOption.TopDirectoryOnly);


            result.Add(new SSASObject

            {

                ID = idx,

                ParentID = null,

                FolderModifiedDate = System.IO.Directory.GetLastWriteTime(DataDir),

                FolderPath = DataDir,

                ObjectName = OLAPServerName,

                Type = SSASObject.ObjectType.Server

            });


            // Database

            foreach (Database OLAPDatabase in OLAPServer.Databases)

            {



                string CurrentDbDir = DatabasesDir.Where(x => x.StartsWith(DataDir + "\\" +  OLAPDatabase.ID.ToString() + ".") && x.EndsWith(".db")).DefaultIfEmpty("").First();

                string CurrentDbXmlFile = DatabasesFiles.Where(x => x.StartsWith(DataDir + "\\" + OLAPDatabase.ID.ToString() + ".") && x.EndsWith(".db.xml")).DefaultIfEmpty("").First();


                string[] DbObjectsDir = System.IO.Directory.GetDirectories(CurrentDbDir, "*", System.IO.SearchOption.TopDirectoryOnly);

                string[] DbObjectsFiles = System.IO.Directory.GetFiles(CurrentDbDir, "*", System.IO.SearchOption.TopDirectoryOnly);



                idx++;

                DbID = idx;

                result.Add(new SSASObject

                {

                    ID = idx,

                    ParentID = 0,

                    ObjectID = OLAPDatabase.ID,

                    FolderModifiedDate = CurrentDbDir == "" ? dt : System.IO.Directory.GetLastWriteTime(CurrentDbDir),

                    XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                                  System.IO.Path.GetFileNameWithoutExtension(CurrentDbXmlFile)).Substring(

                                                  System.IO.Path.GetFileNameWithoutExtension(CurrentDbXmlFile).IndexOf(".") + 1),

                    Extension = ".db",

                    FolderName = System.IO.Path.GetFileName(CurrentDbDir),

                    FolderPath = CurrentDbDir,

                    ObjectName = OLAPDatabase.Name,

                    Type = SSASObject.ObjectType.Database,

                    XMLFileName = System.IO.Path.GetFileName(CurrentDbXmlFile),

                    XMLFilePath = CurrentDbXmlFile,

                    XmlModifiedDate = CurrentDbXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(CurrentDbXmlFile),

                    FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(CurrentDbDir).Substring(

                                                  System.IO.Path.GetFileNameWithoutExtension(CurrentDbDir).IndexOf(".") + 1)

                });




                //Data Source

                foreach (DataSource OLAPDataSource in OLAPDatabase.DataSources)

                {

                    idx++;

                    string CurrentDataSourceDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDataSource.ID.ToString() + ".") && x.EndsWith(".ds")).DefaultIfEmpty("").First();

                    string CurrentDataSourceXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDataSource.ID.ToString() + ".") && x.EndsWith(".ds.xml")).DefaultIfEmpty("").First();

                    result.Add(new SSASObject

                    {

                        ID = idx,

                        ParentID = DbID,

                        ObjectID = OLAPDataSource.ID,

                        FolderModifiedDate = CurrentDataSourceDir == "" ? dt : System.IO.Directory.GetLastWriteTime(CurrentDataSourceDir),

                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceXmlFile)).Substring(

                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceXmlFile).IndexOf(".") + 1),

                        Extension = ".ds",

                        FolderName = System.IO.Path.GetFileName(CurrentDataSourceDir),

                        FolderPath = CurrentDbDir,

                        ObjectName = OLAPDataSource.Name,

                        Type = SSASObject.ObjectType.DataSource,

                        XMLFileName = System.IO.Path.GetFileName(CurrentDataSourceXmlFile),

                        XMLFilePath = CurrentDataSourceXmlFile,

                        XmlModifiedDate = CurrentDataSourceXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(CurrentDataSourceXmlFile),

                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceDir).Substring(

                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceDir).IndexOf(".") + 1)

                    });



                }


                //Data Source View

                foreach (DataSourceView OLAPDataSourceView in OLAPDatabase.DataSourceViews)

                {

                    idx++;

                    string CurrentDataSourceViewDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDataSourceView.ID.ToString() + ".") && x.EndsWith(".dsv")).DefaultIfEmpty("").First();

                    string CurrentDataSourceViewXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDataSourceView.ID.ToString() + ".") && x.EndsWith(".dsv.xml")).DefaultIfEmpty("").First();

                    result.Add(new SSASObject

                    {

                        ID = idx,

                        ParentID = DbID,

                        ObjectID = OLAPDataSourceView.ID,

                        FolderModifiedDate = CurrentDataSourceViewDir == "" ? dt : System.IO.Directory.GetLastWriteTime(CurrentDataSourceViewDir),

                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceViewXmlFile)).Substring(

                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceViewXmlFile).IndexOf(".") + 1),

                        Extension = ".dsv",

                        FolderName = System.IO.Path.GetFileName(CurrentDataSourceViewDir),

                        FolderPath = CurrentDbDir,

                        ObjectName = OLAPDataSourceView.Name,

                        Type = SSASObject.ObjectType.DataSourceView,

                        XMLFileName = System.IO.Path.GetFileName(CurrentDataSourceViewXmlFile),

                        XMLFilePath = CurrentDataSourceViewXmlFile,

                        XmlModifiedDate = CurrentDataSourceViewXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(CurrentDataSourceViewXmlFile),

                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceViewDir).Substring(

                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceViewDir).IndexOf(".") + 1)

                    });



                }



                //Dimension

                foreach (Dimension OLAPDimension in OLAPDatabase.Dimensions)

                {


                    idx++;

                    string DimensionDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDimension.ID.ToString() + ".") && x.EndsWith(".dim")).DefaultIfEmpty("").First();

                    string DimensionXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDimension.ID.ToString() + ".") && x.EndsWith(".dim.xml")).DefaultIfEmpty("").First();


                    result.Add(new SSASObject

                    {

                        ID = idx,

                        ParentID = DbID,

                        ObjectID = OLAPDimension.ID,

                        FolderModifiedDate = DimensionDir == "" ? dt : System.IO.Directory.GetLastWriteTime(DimensionDir),

                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                                  System.IO.Path.GetFileNameWithoutExtension(DimensionXmlFile)).Substring(

                                                  System.IO.Path.GetFileNameWithoutExtension(DimensionXmlFile).IndexOf(".") + 1),

                        Extension = ".dim",

                        FolderName = System.IO.Path.GetFileName(DimensionDir),

                        FolderPath = DimensionDir,

                        ObjectName = OLAPDimension.Name,

                        Type = SSASObject.ObjectType.Dimension,

                        XMLFileName = System.IO.Path.GetFileName(DimensionXmlFile),

                        XMLFilePath = DimensionXmlFile,

                        XmlModifiedDate = DimensionXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(DimensionXmlFile),

                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(DimensionDir).Substring(

                                             System.IO.Path.GetFileNameWithoutExtension(DimensionDir).IndexOf(".") + 1)

                    });

                }


                // Cube

                foreach (Cube OLAPCubex in OLAPDatabase.Cubes)

                {



                    idx++;

                    CubeID = idx;


                    string CubeDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPCubex.ID.ToString() + ".") && x.EndsWith(".cub")).DefaultIfEmpty("").First();

                    string CubeXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPCubex.ID.ToString() + ".") && x.EndsWith(".cub.xml")).DefaultIfEmpty("").First();


                    string[] CubeMeasureGroupsDir = System.IO.Directory.GetDirectories(CubeDir, "*", System.IO.SearchOption.TopDirectoryOnly);

                    string[] CubeMeasureGroupsFiles = System.IO.Directory.GetFiles(CubeDir, "*", System.IO.SearchOption.TopDirectoryOnly);



                    result.Add(new SSASObject

                    {

                        ID = idx,

                        ParentID = DbID,

                        ObjectID = OLAPCubex.ID,

                        FolderModifiedDate = CubeDir == "" ? dt : System.IO.Directory.GetLastWriteTime(CubeDir),

                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                                  System.IO.Path.GetFileNameWithoutExtension(CubeXmlFile)).Substring(

                                                  System.IO.Path.GetFileNameWithoutExtension(CubeXmlFile).IndexOf(".") + 1),

                        Extension = ".cub",

                        FolderName = System.IO.Path.GetFileName(CubeDir),

                        FolderPath = CubeDir,

                        ObjectName = OLAPCubex.Name,

                        Type = SSASObject.ObjectType.Cube,

                        XMLFileName = System.IO.Path.GetFileName(CubeXmlFile),

                        XMLFilePath = CubeXmlFile,

                        XmlModifiedDate = CubeXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(CubeXmlFile),

                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(CubeDir).Substring(

                                             System.IO.Path.GetFileNameWithoutExtension(CubeDir).IndexOf(".") + 1)

                    });


                    //Measure Group

                    foreach (MeasureGroup OLAPMeasureGroup in OLAPCubex.MeasureGroups)

                    {


                        idx++;

                        ObjectID = idx;

                        string MeasureGroupDir = CubeMeasureGroupsDir.Where(x => x.StartsWith(CubeDir + "\\" + OLAPMeasureGroup.ID.ToString() + ".") && x.EndsWith(".det")).DefaultIfEmpty("").First();

                        string MeasureGroupXmlFile = CubeMeasureGroupsFiles.Where(x => x.StartsWith(CubeDir + "\\" + OLAPMeasureGroup.ID.ToString() + ".") && x.EndsWith(".det.xml")).DefaultIfEmpty("").First();


                        string[] GroupPartitionDir = System.IO.Directory.GetDirectories(MeasureGroupDir, "*", System.IO.SearchOption.TopDirectoryOnly);

                        string[] GroupPartitionFiles = System.IO.Directory.GetFiles(MeasureGroupDir, "*", System.IO.SearchOption.TopDirectoryOnly);


                        result.Add(new SSASObject

                        {

                            ID = idx,

                            ParentID = CubeID,

                            ObjectID = OLAPMeasureGroup.ID,

                            FolderModifiedDate = MeasureGroupDir == "" ? dt : System.IO.Directory.GetLastWriteTime(MeasureGroupDir),

                            XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                                  System.IO.Path.GetFileNameWithoutExtension(MeasureGroupXmlFile)).Substring(

                                                  System.IO.Path.GetFileNameWithoutExtension(MeasureGroupXmlFile).IndexOf(".") + 1),

                            Extension = ".det",

                            FolderName = System.IO.Path.GetFileName(MeasureGroupDir),

                            FolderPath = MeasureGroupDir,

                            ObjectName = OLAPMeasureGroup.Name,

                            Type = SSASObject.ObjectType.MeasureGroup,

                            XMLFileName = System.IO.Path.GetFileName(MeasureGroupXmlFile),

                            XMLFilePath = MeasureGroupXmlFile,

                            XmlModifiedDate = MeasureGroupXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(MeasureGroupXmlFile),

                            FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(MeasureGroupDir).Substring(

                                                 System.IO.Path.GetFileNameWithoutExtension(MeasureGroupDir).IndexOf(".") + 1)

                        });


                        //Aggregations

                        foreach (AggregationDesign OLAPAggregationDesign in OLAPMeasureGroup.AggregationDesigns)

                        {


                            string AggregationDir = GroupPartitionDir.Where(x => x.StartsWith(MeasureGroupDir + "\\" + OLAPAggregationDesign.ID.ToString() + ".") && x.EndsWith(".agg")).DefaultIfEmpty("").First();

                            string AggregationXmlFile = GroupPartitionFiles.Where(x => x.StartsWith(MeasureGroupDir + "\\" + OLAPAggregationDesign.ID.ToString() + ".") && x.EndsWith(".agg.xml")).DefaultIfEmpty("").First();


                            idx++;


                            result.Add(new SSASObject

                            {

                                ID = idx,

                                ParentID = ObjectID,

                                ObjectID = OLAPAggregationDesign.ID,

                                FolderModifiedDate = AggregationDir == "" ? dt : System.IO.Directory.GetLastWriteTime(AggregationDir),

                                XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                                  System.IO.Path.GetFileNameWithoutExtension(AggregationXmlFile)).Substring(

                                                  System.IO.Path.GetFileNameWithoutExtension(AggregationXmlFile).IndexOf(".") + 1),

                                Extension = ".agg",

                                FolderName = System.IO.Path.GetFileName(AggregationDir),

                                FolderPath = AggregationDir,

                                ObjectName = OLAPAggregationDesign.Name,

                                Type = SSASObject.ObjectType.AggregationDesign,

                                XMLFileName = System.IO.Path.GetFileName(AggregationXmlFile),

                                XMLFilePath = AggregationXmlFile,

                                XmlModifiedDate = AggregationXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(AggregationXmlFile),

                                FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(AggregationDir).Substring(

                                                     System.IO.Path.GetFileNameWithoutExtension(AggregationDir).IndexOf(".") + 1)


                            });



                        }



                        //Partitions

                        foreach (Partition OLAPPartition in OLAPMeasureGroup.Partitions)

                        {


                            string PartitionDir = GroupPartitionDir.Where(x => x.StartsWith(MeasureGroupDir + "\\" + OLAPPartition.ID.ToString() + ".") && x.EndsWith(".prt")).DefaultIfEmpty("").First();

                            string PartitionXmlFile = GroupPartitionFiles.Where(x => x.StartsWith(MeasureGroupDir + "\\" + OLAPPartition.ID.ToString() + ".") && x.EndsWith(".prt.xml")).DefaultIfEmpty("").First();


                            idx++;


                            result.Add(new SSASObject

                            {

                                ID = idx,

                                ParentID = ObjectID,

                                ObjectID = OLAPPartition.ID,

                                FolderModifiedDate = PartitionDir == "" ? dt : System.IO.Directory.GetLastWriteTime(PartitionDir),

                                XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                                  System.IO.Path.GetFileNameWithoutExtension(PartitionXmlFile)).Substring(

                                                  System.IO.Path.GetFileNameWithoutExtension(PartitionXmlFile).IndexOf(".") + 1),

                                Extension = ".prt",

                                FolderName = System.IO.Path.GetFileName(PartitionDir),

                                FolderPath = PartitionDir,

                                ObjectName = OLAPPartition.Name,

                                Type = SSASObject.ObjectType.Partition,

                                XMLFileName = System.IO.Path.GetFileName(PartitionXmlFile),

                                XMLFilePath = PartitionXmlFile,

                                XmlModifiedDate = PartitionXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(PartitionXmlFile),

                                FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(PartitionDir).Substring(

                                                     System.IO.Path.GetFileNameWithoutExtension(PartitionDir).IndexOf(".") + 1)


                            });


                        }







                    }



                }


                //Mining Structure

                foreach (MiningStructure OLAPMiningStructure in OLAPDatabase.MiningStructures)

                {


                    idx++;


                    string MiningStructureDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPMiningStructure.ID.ToString() + ".") && x.EndsWith(".dms")).DefaultIfEmpty("").First();

                    string MiningStructureXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPMiningStructure.ID.ToString() + ".") && x.EndsWith(".dms.xml")).DefaultIfEmpty("").First();


                    result.Add(new SSASObject

                    {

                        ID = idx,

                        ParentID = DbID,

                        ObjectID = OLAPMiningStructure.ID,

                        FolderModifiedDate = MiningStructureDir == "" ? dt : System.IO.Directory.GetLastWriteTime(MiningStructureDir),

                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                          System.IO.Path.GetFileNameWithoutExtension(MiningStructureXmlFile)).Substring(

                                          System.IO.Path.GetFileNameWithoutExtension(MiningStructureXmlFile).IndexOf(".") + 1),

                        Extension = ".ds",

                        FolderName = System.IO.Path.GetFileName(MiningStructureDir),

                        FolderPath = MiningStructureDir,

                        ObjectName = OLAPMiningStructure.Name,

                        Type = SSASObject.ObjectType.MiningStructure,

                        XMLFileName = System.IO.Path.GetFileName(MiningStructureXmlFile),

                        XMLFilePath = MiningStructureXmlFile,

                        XmlModifiedDate = MiningStructureXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(MiningStructureXmlFile),

                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(MiningStructureDir).Substring(

                                             System.IO.Path.GetFileNameWithoutExtension(MiningStructureDir).IndexOf(".") + 1)


                    });

                }



                //Role

                foreach (Role OLAPRole in OLAPDatabase.Roles)

                {


                    idx++;


                    string RoleDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPRole.ID.ToString() + ".") && x.EndsWith(".dms")).DefaultIfEmpty("").First();

                    string RoleXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPRole.ID.ToString() + ".") && x.EndsWith(".dms.xml")).DefaultIfEmpty("").First();


                    result.Add(new SSASObject

                    {

                        ID = idx,

                        ParentID = DbID,

                        ObjectID = OLAPRole.ID,

                        FolderModifiedDate = RoleDir == "" ? dt : System.IO.Directory.GetLastWriteTime(RoleDir),

                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(

                                          System.IO.Path.GetFileNameWithoutExtension(RoleXmlFile)).Substring(

                                          System.IO.Path.GetFileNameWithoutExtension(RoleXmlFile).IndexOf(".") + 1),

                        Extension = ".ds",

                        FolderName = System.IO.Path.GetFileName(RoleDir),

                        FolderPath = RoleDir,

                        ObjectName = OLAPRole.Name,

                        Type = SSASObject.ObjectType.Role,

                        XMLFileName = System.IO.Path.GetFileName(RoleXmlFile),

                        XMLFilePath = RoleXmlFile,

                        XmlModifiedDate = RoleXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(RoleXmlFile),

                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(RoleDir).Substring(

                                             System.IO.Path.GetFileNameWithoutExtension(RoleDir).IndexOf(".") + 1)


                    });


                }


            }




            return result;

        }

        catch (Exception ex)

        {

            return null;

        }

    }


}

GitHub項目

我創建了一個小型 Windows 應用程序并將其上傳到 GitHub,您可以將其作為單獨的工具使用,或者您可以簡單地復制到 Script Task 項目中的 Classes 并在 Script 中使用它。


查看完整回答
反對 回復 2022-12-24
  • 1 回答
  • 0 關注
  • 100 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號