internal void SetHideMemberIf(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox sandboxParam, IEnumerable <Tuple <string, string, string> > hierarchyLevels, List <HideIfValue> newValues) { try { #if DENALI || SQL2014 Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.AMOCode code; var sandbox = sandboxParam; #else Microsoft.AnalysisServices.BackEnd.AMOCode code; var sandbox = (Microsoft.AnalysisServices.BackEnd.DataModelingSandboxAmo)sandboxParam.Impl; #endif code = delegate { Microsoft.AnalysisServices.BackEnd.SandboxTransactionProperties properties = new Microsoft.AnalysisServices.BackEnd.SandboxTransactionProperties(); properties.RecalcBehavior = Microsoft.AnalysisServices.BackEnd.TransactionRecalcBehavior.AlwaysRecalc; List <Dimension> dims = new List <Dimension>(); using (Microsoft.AnalysisServices.BackEnd.SandboxTransaction tran = sandboxParam.CreateTransaction(properties)) { if (!TabularHelpers.EnsureDataSourceCredentials(sandboxParam)) { MessageBox.Show("Cancelling apply of HideMemberIf because data source credentials were not entered.", "BIDS Helper Tabular HideMemberIf - Cancelled!"); tran.RollbackAndContinue(); return; } SSAS.TabularHideMemberIfAnnotation annotation = GetAnnotation(sandboxParam); foreach (Tuple <string, string, string> tuple in hierarchyLevels) { Dimension d = sandbox.Database.Dimensions.GetByName(tuple.Item1); if (!dims.Contains(d)) { dims.Add(d); } Hierarchy h = d.Hierarchies.GetByName(tuple.Item2); Level l = h.Levels.GetByName(tuple.Item3); l.HideMemberIf = newValues[0]; newValues.RemoveAt(0); annotation.Set(l); } TabularHelpers.SaveXmlAnnotation(sandbox.Database, HIDEMEMBERIF_ANNOTATION, annotation); sandbox.Database.Update(UpdateOptions.ExpandFull); //bug in AS2012 (still not working in RTM CU1) requires ProcessFull to successfully switch from HideMemberIf=Never to NoName foreach (Dimension d in dims) { d.Process(ProcessType.ProcessFull); } tran.GetType().InvokeMember("Commit", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public, null, tran, null); //The .Commit() function used to return a list of strings, but in the latest set of code it is a void method which leads to "method not found" errors //tran.Commit(); } }; #if DENALI || SQL2014 sandbox.ExecuteAMOCode(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationType.Update, Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationCancellability.AlwaysExecute, code, true); #else sandboxParam.ExecuteEngineCode(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationType.Update, Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationCancellability.AlwaysExecute, code, true); #endif } catch (System.Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Error"); } }
internal void ExecuteSyncDescriptions(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox sandbox, IServiceProvider provider, string tableName) { try { #if DENALI || SQL2014 var db = sandbox.Database; Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.AMOCode code; #else Database db = null; if (!sandbox.IsTabularMetadata) { db = ((Microsoft.AnalysisServices.BackEnd.DataModelingSandboxAmo)sandbox.Impl).Database; } else { db = null; } Microsoft.AnalysisServices.BackEnd.AMOCode code; #endif code = delegate { int iDescriptionsSet; Microsoft.AnalysisServices.BackEnd.SandboxTransactionProperties properties = new Microsoft.AnalysisServices.BackEnd.SandboxTransactionProperties(); properties.RecalcBehavior = Microsoft.AnalysisServices.BackEnd.TransactionRecalcBehavior.Default; using (Microsoft.AnalysisServices.BackEnd.SandboxTransaction tran = sandbox.CreateTransaction(properties)) { if (!TabularHelpers.EnsureDataSourceCredentials(sandbox)) { MessageBox.Show("Cancelling Sync Descriptions because data source credentials were not entered.", "BIDS Helper Tabular Sync Descriptions - Cancelled!"); tran.RollbackAndContinue(); return; } #if !(DENALI || SQL2014) Microsoft.AnalysisServices.BackEnd.DataModelingTable table = sandbox.Tables[tableName]; if (table.IsStructuredDataSource) { MessageBox.Show("BI Developer Extensions does not yet support modern (Power Query) data sources.", "BI Developer Extensions"); return; } iDescriptionsSet = SyncDescriptionsPlugin.SyncDescriptions(table, true); if (iDescriptionsSet > 0) { table.UpdateNowOrLater(); } #else Dimension d = db.Dimensions.GetByName(tableName); iDescriptionsSet = SyncDescriptionsPlugin.SyncDescriptions(d, true, provider, true); if (iDescriptionsSet > 0) { db.Update(UpdateOptions.ExpandFull); } #endif tran.GetType().InvokeMember("Commit", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public, null, tran, null); //The .Commit() function used to return a list of strings, but in the latest set of code it is a void method which leads to "method not found" errors //tran.Commit(); } MessageBox.Show("Set " + iDescriptionsSet + " descriptions successfully.", "BIDS Helper - Sync Descriptions"); }; #if DENALI || SQL2014 sandbox.ExecuteAMOCode(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationType.Update, Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationCancellability.AlwaysExecute, code, true); #else sandbox.ExecuteEngineCode(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationType.Update, Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationCancellability.AlwaysExecute, code, true); #endif } catch (System.Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Error"); } }
private void ExecSandbox(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox sandboxParam) { try { #if DENALI || SQL2014 var sb = sandboxParam; var conn = sandboxParam.AdomdConnection; #elif SQL2017 var sb = (Microsoft.AnalysisServices.BackEnd.DataModelingSandboxAmo)sandboxParam.Impl; var localConn = sandboxParam.AdomdConnection; var conn = new localAdomdClient.Microsoft.AnalysisServices.AdomdClient.AdomdConnection(localConn.ConnectionString); #else var sb = (Microsoft.AnalysisServices.BackEnd.DataModelingSandboxAmo)sandboxParam.Impl; var localConn = sandboxParam.AdomdConnection; var conn = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection(localConn.ConnectionString); #endif if (sb == null) { throw new Exception("Can't get Sandbox!"); } cube = sb.Cube; if (cube == null) { throw new Exception("The workspace database cube doesn't exist."); } SSAS.TabularActionsEditorForm form = new SSAS.TabularActionsEditorForm(cube, conn); if (form.ShowDialog() == DialogResult.OK) { #if DENALI || SQL2014 Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.AMOCode code; #else Microsoft.AnalysisServices.BackEnd.AMOCode code; #endif code = delegate { using (Microsoft.AnalysisServices.BackEnd.SandboxTransaction tran = sandbox.CreateTransaction()) { foreach (Perspective p in cube.Perspectives) { p.Actions.Clear(); } cube.Actions.Clear(); foreach (Microsoft.AnalysisServices.Action action in form.Actions()) { cube.Actions.Add(action); foreach (Perspective p in cube.Perspectives) { if (form.ActionInPerspective(action.ID, p.ID)) { p.Actions.Add(action.ID); } } } TabularHelpers.SaveXmlAnnotation(cube, SSAS.TabularActionsEditorForm.ACTION_ANNOTATION, form.Annotation); cube.Update(UpdateOptions.ExpandFull); tran.GetType().InvokeMember("Commit", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public, null, tran, null); //The .Commit() function used to return a list of strings, but in the latest set of code it is a void method which leads to "method not found" errors //tran.Commit(); } }; #if DENALI || SQL2014 sandbox.ExecuteAMOCode(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationType.Update, Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationCancellability.AlwaysExecute, code, true); #else sandboxParam.ExecuteEngineCode(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationType.Update, Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationCancellability.AlwaysExecute, code, true); #endif } } catch (System.Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Error"); } }