/// <summary> /// Deploys the specified database to the specified target server and database ID, using the specified options. /// Returns a list of DAX errors (if any) on objects inside the database, in case the deployment was succesful. /// </summary> /// <param name="db"></param> /// <param name="targetConnectionString"></param> /// <param name="targetDatabaseID"></param> /// <param name="options"></param> /// <returns></returns> internal static DeploymentResult Deploy(TOM.Database db, string targetConnectionString, string targetDatabaseID, DeploymentOptions options, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(targetConnectionString)) { throw new ArgumentNullException("targetConnectionString"); } var s = new TOM.Server(); s.Connect(targetConnectionString); var tmsl = GetTMSL(db, s, targetDatabaseID, options, true); cancellationToken.Register(s.CancelCommand); var result = s.Execute(tmsl); if (result.ContainsErrors) { throw new Exception(string.Join("\n", result.Cast <XmlaResult>().SelectMany(r => r.Messages.Cast <XmlaMessage>().Select(m => m.Description)).ToArray())); } s.Refresh(); var deployedDB = s.Databases[targetDatabaseID]; return (new DeploymentResult( TabularModelHandler.CheckErrors(deployedDB).Select(t => string.Format("Error on {0}: {1}", GetName(t.Item1), t.Item2)), TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.DependencyError || t.Item2 == TOM.ObjectState.EvaluationError || t.Item2 == TOM.ObjectState.SemanticError) .Select(t => string.Format("Warning! Object not in \"Ready\"-state: {0} ({1})", GetName(t.Item1), t.Item2.ToString())), TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.CalculationNeeded || t.Item2 == TOM.ObjectState.NoData) .Select(t => string.Format("Information: Unprocessed object: {0} ({1})", GetName(t.Item1), t.Item2.ToString())) )); }
public static DeploymentResult GetLastDeploymentResults(TOM.Database database) { return (new DeploymentResult( TabularModelHandler.CheckErrors(database).Select(t => string.Format("Error on {0}: {1}", GetName(t.Item1), t.Item2)), TabularModelHandler.GetObjectsNotReady(database).Where(t => t.Item2 == TOM.ObjectState.DependencyError || t.Item2 == TOM.ObjectState.EvaluationError || t.Item2 == TOM.ObjectState.SemanticError) .Select(t => string.Format("Warning! Object not in \"Ready\"-state: {0} ({1})", GetName(t.Item1), t.Item2.ToString())), TabularModelHandler.GetObjectsNotReady(database).Where(t => t.Item2 == TOM.ObjectState.CalculationNeeded || t.Item2 == TOM.ObjectState.NoData || t.Item2 == TOM.ObjectState.Incomplete) .Select(t => string.Format("Information: Unprocessed object: {0} ({1})", GetName(t.Item1), t.Item2.ToString())), database.Server )); }
/// <summary> /// Deploys the specified database to the specified target server and database ID, using the specified options. /// Returns a list of DAX errors (if any) on objects inside the database, in case the deployment was succesful. /// </summary> /// <param name="db"></param> /// <param name="targetConnectionString"></param> /// <param name="targetDatabaseName"></param> /// <param name="options"></param> /// <returns></returns> internal static DeploymentResult Deploy(TOM.Database db, string targetConnectionString, string targetDatabaseName, DeploymentOptions options, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(targetConnectionString)) { throw new ArgumentNullException("targetConnectionString"); } var destinationServer = new TOM.Server(); destinationServer.Connect(targetConnectionString); if (!destinationServer.SupportedCompatibilityLevels.Contains(db.CompatibilityLevel.ToString())) { throw new DeploymentException($"The specified server does not support Compatibility Level {db.CompatibilityLevel}"); } var tmsl = GetTMSL(db, destinationServer, targetDatabaseName, options, true); cancellationToken.Register(destinationServer.CancelCommand); var result = destinationServer.Execute(tmsl); if (result.ContainsErrors) { throw new DeploymentException(string.Join("\n", result.Cast <XmlaResult>().SelectMany(r => r.Messages.Cast <XmlaMessage>().Select(m => m.Description)).ToArray())); } // Refresh the server object to make sure we get an updated list of databases, in case a new database was made: destinationServer.Refresh(); // Fully refresh the deployed database object, to make sure we get updated error messages for the full object tree: var deployedDB = destinationServer.Databases.GetByName(targetDatabaseName); deployedDB.Refresh(true); return (new DeploymentResult( TabularModelHandler.CheckErrors(deployedDB).Select(t => string.Format("Error on {0}: {1}", GetName(t.Item1), t.Item2)), TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.DependencyError || t.Item2 == TOM.ObjectState.EvaluationError || t.Item2 == TOM.ObjectState.SemanticError) .Select(t => string.Format("Warning! Object not in \"Ready\"-state: {0} ({1})", GetName(t.Item1), t.Item2.ToString())), TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.CalculationNeeded || t.Item2 == TOM.ObjectState.NoData) .Select(t => string.Format("Information: Unprocessed object: {0} ({1})", GetName(t.Item1), t.Item2.ToString())), destinationServer )); }