Exemplo n.º 1
0
 public static Microsoft.AnalysisServices.Database GetDatabase(string serverName, string databaseName)
 {
     Microsoft.AnalysisServices.Server server = new Microsoft.AnalysisServices.Server();
     server.Connect(serverName);
     Microsoft.AnalysisServices.Database db = server.Databases.FindByName(databaseName);
     // if db is null either it does not exist or we do not have admin rights to it
     if (db == null)
     {
         throw new ArgumentException($"The database '{databaseName}' could not be found. Either it does not exist or you do not have admin rights to it.");
     }
     return(db);
 }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)

                try
                {
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(saveFileDialog1.FileName, false, Encoding.Default, 10))
                    {
                        string filerowheader = string.Format("\"{0}\",\"{1}\",\"{2}\"", "Database", "Role", "Member");
                        file.WriteLine(filerowheader);
                        using (Microsoft.AnalysisServices.Server Server = new Microsoft.AnalysisServices.Server())
                        {
                            Server.Connect(serverName.Text);
                            foreach (Microsoft.AnalysisServices.Database ssasdb in Server.Databases)
                            {
                                string Databasename = ssasdb.Name;
                                foreach (Microsoft.AnalysisServices.Role CubeDbRole in ssasdb.Roles)
                                {
                                    string Rolename = CubeDbRole.Name;
                                    foreach (Microsoft.AnalysisServices.RoleMember CubeRoleMember in CubeDbRole.Members)
                                    {
                                        string RoleMember = CubeRoleMember.Name;
                                        string filerow = string.Format("\"{0}\",\"{1}\",\"{2}\"", Databasename, Rolename, RoleMember);
                                        file.WriteLine(filerow);
                                    }
                                }
                            }
                        }
                    }
                    MessageBox.Show("Выгрузка успешно завершена", "Инфо");
                }
                catch (Exception ex)
                {

                    if (ex is Microsoft.AnalysisServices.AmoException)
                    {
                        throw new ApplicationException("Ошибка чтения данных сервера SSAS",  ex);
                    }

                    if (ex is System.IO.IOException)
                    {
                        throw new ApplicationException("Ошибка открытия или записи в файл. Проверьте не открыт ли он в другой программе.", ex);
                    }
                    throw new Exception("Неизвестная и самая страшная ошибка, потому что неизвестная", ex);

                }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(saveFileDialog1.FileName, false, Encoding.Default, 10))
                    {
                        string filerowheader = string.Format("\"{0}\",\"{1}\",\"{2}\"", "Database", "Role", "Member");
                        file.WriteLine(filerowheader);
                        using (Microsoft.AnalysisServices.Server Server = new Microsoft.AnalysisServices.Server())
                        {
                            Server.Connect(serverName.Text);
                            foreach (Microsoft.AnalysisServices.Database ssasdb in Server.Databases)
                            {
                                string Databasename = ssasdb.Name;
                                foreach (Microsoft.AnalysisServices.Role CubeDbRole in ssasdb.Roles)
                                {
                                    string Rolename = CubeDbRole.Name;
                                    foreach (Microsoft.AnalysisServices.RoleMember CubeRoleMember in CubeDbRole.Members)
                                    {
                                        string RoleMember = CubeRoleMember.Name;
                                        string filerow    = string.Format("\"{0}\",\"{1}\",\"{2}\"", Databasename, Rolename, RoleMember);
                                        file.WriteLine(filerow);
                                    }
                                }
                            }
                        }
                    }
                    MessageBox.Show("Выгрузка успешно завершена", "Инфо");
                }
                catch (Exception ex)
                {
                    if (ex is Microsoft.AnalysisServices.AmoException)
                    {
                        throw new ApplicationException("Ошибка чтения данных сервера SSAS", ex);
                    }

                    if (ex is System.IO.IOException)
                    {
                        throw new ApplicationException("Ошибка открытия или записи в файл. Проверьте не открыт ли он в другой программе.", ex);
                    }
                    throw new Exception("Неизвестная и самая страшная ошибка, потому что неизвестная", ex);
                }
            }
        }
Exemplo n.º 4
0
 public AmoServer(AmoType amoType)
 {
     _type = amoType;
     if (amoType == AmoType.AnalysisServices)
     {
         Log.Debug("{class} {method} {message}", "AmoServer", "<constructor>", "Using Microsoft.AnalysisServices");
         _svr = new Microsoft.AnalysisServices.Server();
     }
     else
     {
         Log.Debug("{class} {method} {message}", "AmoServer", "<constructor>", "Using Microsoft.Excel.Amo");
         AmoServer.VoidDelegate f = delegate
         {
             _xlSvr = new ExcelAmo.Microsoft.AnalysisServices.Server();
         };
         f();
     }
 }
Exemplo n.º 5
0
            public static Dax.Model.Model GetDaxModel(string serverName, string databaseName, bool readStatisticsFromData = true)
            {
                Microsoft.AnalysisServices.Server server = new Microsoft.AnalysisServices.Server();
                server.Connect(serverName);
                Microsoft.AnalysisServices.Database      db       = server.Databases[databaseName];
                Microsoft.AnalysisServices.Tabular.Model tomModel = db.Model;
                var daxModel = Dax.Model.Extractor.TomExtractor.GetDaxModel(tomModel, "TestDaxModel", "0.1");

                var connectionString = GetConnectionString(serverName, databaseName);

                using (var connection = new OleDbConnection(connectionString)) {
                    // Populate statistics from DMV
                    Dax.Model.Extractor.DmvExtractor.PopulateFromDmv(daxModel, connection, databaseName, "TestDaxModel", "0.1");

                    // Populate statistics by querying the data model
                    if (readStatisticsFromData)
                    {
                        Dax.Model.Extractor.StatExtractor.UpdateStatisticsModel(daxModel, connection);
                    }
                }
                return(daxModel);
            }
        /// <summary>
        /// Загрузка доступных кубов сервера ОЛАП
        /// </summary>
        /// <returns> True/False </returns>
        public Boolean Load_CubeRoles(BackgroundWorker worker, DoWorkEventArgs e)
        {
            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return(false);
            }
            else
            {
                try
                {
                    using (Microsoft.AnalysisServices.Server server = new Microsoft.AnalysisServices.Server())
                    {
                        server.Connect(serverName);

                        imaxDB = server.Databases.Count;

                        if (imaxDB <= 0)
                        {
                            // report to form
                            worker.ReportProgress(100);
                            return(true);
                        }
                        // грузим кубы ( БД )
                        foreach (Microsoft.AnalysisServices.Database asDB in server.Databases)
                        {
                            // Проверка на отмену загрузки
                            if (worker.CancellationPending)
                            {
                                e.Cancel = true;
                                return(false);
                            }
                            // report to form
                            worker.ReportProgress((int)(iCountDB / imaxDB * 100));


                            Cubes.Add(asDB);
                            // Грузим роли для куба
                            foreach (Microsoft.AnalysisServices.Role dbRole in asDB.Roles)
                            {
                                // Проверка на отмену загрузки
                                if (worker.CancellationPending)
                                {
                                    e.Cancel = true;
                                    return(false);
                                }

                                //string sDBname = asDB.Name;
                                //string sRolname = dbRole.Name;

                                Roles.Add(string.Format(asDB.Name + " _{0}", ++iCountRole), dbRole);

                                // Грузим членов роли
                                foreach (Microsoft.AnalysisServices.RoleMember mmbr in dbRole.Members)
                                {
                                    // Проверка на отмену загрузки
                                    if (worker.CancellationPending)
                                    {
                                        e.Cancel = true;
                                        return(false);
                                    }

                                    RoleMembers.Add(string.Format(dbRole.Name + " _{0}", ++iCountMmbr), mmbr);
                                }
                            }
                            //счетчик загрузки
                            iCountDB++;
                        }
                        server.Disconnect();
                    }

                    return(true);
                }
                catch (Exception errr)
                {
                    MessageBox.Show(string.Format("Ошибка получения данных:\n" + errr.Message), "Загрузка ролей из ОЛАП");

                    return(false);
                    //throw;
                }
            }
        }
Exemplo n.º 7
0
        public static DataTable GetConfiguration()
        {
            var table = new DataTable(ConfigurationType.PerformanceCounters.ToString(), "Configuration");

            table.Columns.Add("CategoryName", typeof(string));
            table.Columns.Add("CounterName", typeof(string));
            table.Columns.Add("CounterType", typeof(string));
            table.Columns.Add("IsActive", typeof(string));
            table.Columns.Add("IsDefault", typeof(string));

            Version version;

            using (var server = new Microsoft.AnalysisServices.Server())
            {
                server.Connect("*");
                version = Version.Parse(server.Version);
            }

            string olapCategory = DecodeOlapCategory(Microsoft.AnalysisServices.AdomdServer.Context.CurrentServerID, version);

            try
            {
                var systemPerformanceCounters = PerformanceCounterCategory.GetCategories()
                                                .Where((c) => c.CategoryName.StartsWith(olapCategory))
                                                .Select((c) => c.GetCounters())
                                                .SelectMany((c) => c);

                try
                {
                    var configuredPerformanceCounters = new[]
                    {
                        new
                        {
                            CategoryName = default(string),
                            CounterName  = default(string),
                        }
                    }
                    .Take(0);

                    Action action = () =>
                    {
                        var configurationFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ProcedureContext.ConfigurationFileRelativePath);

                        if (File.Exists(configurationFile))
                        {
                            configuredPerformanceCounters = XDocument.Load(configurationFile).Root
                                                            .Elements(ProcedureConfiguration.XConfigPerformanceCollection)
                                                            .Descendants(ProcedureConfiguration.XConfigPerformanceItem)
                                                            .Select((e) => new
                            {
                                CategoryName = e.Attribute(ProcedureConfiguration.XConfigPerformanceAttributeCategory).Value,
                                CounterName  = e.Attribute(ProcedureConfiguration.XConfigPerformanceAttributeName).Value,
                            })
                                                            .ToArray();
                        }
                    };

                    using (var task = Task.Factory.StartNew(action))
                        task.Wait();

                    var defaultPerformanceCounters = DefaultPerformanceCounters(Microsoft.AnalysisServices.AdomdServer.Context.CurrentServerID, version)
                                                     .ToList();
                    try
                    {
                        foreach (var counter in systemPerformanceCounters)
                        {
                            bool isDefault = defaultPerformanceCounters.Any((c) => c.CategoryName.ToLower() == counter.CategoryName.ToLower() && c.CounterName.ToLower() == counter.CounterName.ToLower());
                            bool isActive  = configuredPerformanceCounters.Any((c) => c.CategoryName.ToLower() == counter.CategoryName.ToLower() && c.CounterName.ToLower() == counter.CounterName.ToLower());

                            table.Rows.Add(
                                counter.CategoryName,
                                counter.CounterName,
                                counter.CounterType,
                                isDefault || isActive,
                                isDefault
                                );
                        }
                    }
                    finally
                    {
                        foreach (var counter in defaultPerformanceCounters)
                        {
                            counter.Dispose();
                        }
                    }
                }
                finally
                {
                    foreach (var counter in systemPerformanceCounters)
                    {
                        counter.Dispose();
                    }
                }
            }
            finally
            {
                PerformanceCounter.CloseSharedResources();
            }

            return(table);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Загрузка доступных кубов сервера ОЛАП
        /// </summary>
        /// <returns> True/False </returns>
        public Boolean Load_CubeRoles(BackgroundWorker worker, DoWorkEventArgs e)
        {
            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return false;
            }
            else
            {
                try
                {
                    using (Microsoft.AnalysisServices.Server server = new Microsoft.AnalysisServices.Server())
                    {
                        server.Connect(serverName);

                        imaxDB = server.Databases.Count;

                        if (imaxDB <= 0)
                        {
                            // report to form
                            worker.ReportProgress(100);
                            return true;
                        }
                        // грузим кубы ( БД )
                        foreach (Microsoft.AnalysisServices.Database asDB in server.Databases)
                        {
                            // Проверка на отмену загрузки
                            if (worker.CancellationPending)
                            {
                                e.Cancel = true;
                                return false;
                            }
                            // report to form
                            worker.ReportProgress((int)(iCountDB/imaxDB*100));

                            Cubes.Add(asDB);
                            // Грузим роли для куба
                            foreach (Microsoft.AnalysisServices.Role dbRole in asDB.Roles)
                            {
                                // Проверка на отмену загрузки
                                if (worker.CancellationPending)
                                {
                                    e.Cancel = true;
                                    return false;
                                }

                                //string sDBname = asDB.Name;
                                //string sRolname = dbRole.Name;

                                Roles.Add(string.Format( asDB.Name+" _{0}", ++iCountRole ), dbRole);

                                // Грузим членов роли
                                foreach (Microsoft.AnalysisServices.RoleMember mmbr in dbRole.Members)
                                {
                                    // Проверка на отмену загрузки
                                    if (worker.CancellationPending)
                                    {
                                        e.Cancel = true;
                                        return false;
                                    }

                                    RoleMembers.Add(string.Format(dbRole.Name+" _{0}", ++iCountMmbr), mmbr);
                                }

                            }
                            //счетчик загрузки
                            iCountDB++;
                        }
                        server.Disconnect();
                    }

                    return true;

                }
                catch (Exception errr)
                {

                    MessageBox.Show(string.Format("Ошибка получения данных:\n"+errr.Message), "Загрузка ролей из ОЛАП");

                    return false;
                    //throw;

                }
            }
        }
 public mycOLAPserver(string sOLAPserverName)
 {
     Name   = sOLAPserverName;
     Server = new Microsoft.AnalysisServices.Server();
 }