Ejemplo n.º 1
0
        public void RestoreCube(string connectionString, string abfFilePath)
        {
            if (string.IsNullOrEmpty(abfFilePath))
            {
                FailedToRestore($"abfFilePath is null or empty.");
                //throw new ArgumentNullException($"abfFilePath is null or empty.");
            }

            if (string.IsNullOrEmpty(connectionString))
            {
                FailedToRestore($"connectionString is null or empty.");
                //throw new ArgumentNullException($"connectionString is null or empty.");
            }

            try
            {
                if (ConnectSSASServer(connectionString))
                {
                    string SSASDBName = Path.GetFileNameWithoutExtension(abfFilePath);
                    ssasServer.Restore(abfFilePath, SSASDBName, true);
                    ssasServer.Restore(abfFilePath, SSASDBName, true);
                    ssasServer.Refresh();

                    AMO.Database ssasDataBase = ssasServer.Databases[SSASDBName];
                    ssasDataBase.Cubes[0].Update();
                    ssasDataBase.Cubes[0].Refresh();

                    RestoredSuccessfully();
                }
                else
                {
                    FailedToRestore($"Failed to connect to the server.");
                }
            }
            catch (NullReferenceException nex)
            {
                FailedToRestore(nex.Message);
                //throw new Exception(nex.Message);
            }
            catch (Exception ex)
            {
                FailedToRestore(ex.Message);
                //throw new Exception(ex.Message);
            }
            finally
            {
                DisConnectSSASServer();
            }
        }