private Level[] GetProblemLevels(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox sandboxParam) { #if DENALI || SQL2014 var sandbox = sandboxParam; #else var sandbox = (Microsoft.AnalysisServices.BackEnd.DataModelingSandboxAmo)sandboxParam.Impl; #endif List <Level> levels = new List <Level>(); SSAS.TabularHideMemberIfAnnotation annotation = GetAnnotation(sandboxParam); foreach (Dimension d in sandbox.Database.Dimensions) { foreach (Hierarchy h in d.Hierarchies) { foreach (Level l in h.Levels) { SSAS.TabularLevelHideMemberIf levelAnnotation = annotation.Find(l); if (levelAnnotation != null) { if (levelAnnotation.HideMemberIf != l.HideMemberIf) { levels.Add(l); } } } } } return(levels.ToArray()); }
internal void SetHideMemberIf(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox sandbox, IEnumerable <Tuple <string, string, string> > hierarchyLevels, List <HideIfValue> newValues) { try { Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.AMOCode 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 = sandbox.CreateTransaction(properties)) { if (!TabularHelpers.EnsureDataSourceCredentials(sandbox)) { 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(sandbox); 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.Commit(); } }; sandbox.ExecuteAMOCode(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationType.Update, Microsoft.AnalysisServices.BackEnd.DataModelingSandbox.OperationCancellability.AlwaysExecute, code, true); } catch (System.Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, "BIDS Helper - Error"); } }
public void FixPreBuildWarning(Microsoft.AnalysisServices.BackEnd.DataModelingSandbox sandbox) { SSAS.TabularHideMemberIfAnnotation annotation = GetAnnotation(sandbox); List <Tuple <string, string, string> > levels = new List <Tuple <string, string, string> >(); List <HideIfValue> values = new List <HideIfValue>(); foreach (Level l in GetProblemLevels(sandbox)) { SSAS.TabularLevelHideMemberIf levelAnnotation = annotation.Find(l); levels.Add(new Tuple <string, string, string>(l.ParentDimension.Name, l.Parent.Name, l.Name)); values.Add(levelAnnotation.HideMemberIf); } SetHideMemberIf(sandbox, levels, values); }
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"); } }