public static Microsoft.AnalysisServices.AdomdServer.Set ParallelGenerate(Microsoft.AnalysisServices.AdomdServer.Set IterationSet, string SetExpression) { List <ParallelQueryThreadInfo> threadInfos = new List <ParallelQueryThreadInfo>(); string connectionString = "Data Source=" + Context.CurrentServerID + ";initial catalog=" + Context.CurrentDatabaseName + ";"; foreach (Microsoft.AnalysisServices.AdomdServer.Tuple t in IterationSet) { //build the text of current tuple string tupleText = "("; for (int n = 1; n <= t.Members.Count; n++) { tupleText += t.Members[n - 1].UniqueName; if (n < t.Members.Count) { tupleText += ","; } } tupleText += ")"; //build the object that will be passed to the worker thread ParallelQueryThreadInfo info = new ParallelQueryThreadInfo(); info.connectionString = connectionString; info.query = "with member measures.internalcalc as SetToStr(" + SetExpression + ") select measures.internalcalc on 0 from [" + Context.CurrentCube.Name + "] where(" + tupleText + ")"; info.autoEvent = new AutoResetEvent(false); threadInfos.Add(info); ThreadPool.QueueUserWorkItem(new WaitCallback(RunAQuery), info); } StringBuilder sFinalSet = new StringBuilder("{"); for (int i = 0; i < threadInfos.Count; i++) { //wait until they've finished while (!threadInfos[i].autoEvent.WaitOne(1000, false)) { Context.CheckCancelled(); } if (threadInfos[i].ex != null) { throw threadInfos[i].ex; } if (i > 0) { sFinalSet.Append(" + "); } sFinalSet.Append(threadInfos[i].returnValue); } sFinalSet.Append("}"); //union the sets they return return(MDX.StrToSet(sFinalSet.ToString())); }
public static Microsoft.AnalysisServices.AdomdServer.Set ParallelUnion(string SetExpression1, string SetExpression2) { List <ParallelQueryThreadInfo> threadInfos = new List <ParallelQueryThreadInfo>(); string connectionString = "Data Source=" + Context.CurrentServerID + ";initial catalog=" + Context.CurrentDatabaseName + ";"; for (int n = 0; n < 2; n++) { //build the object that will be passed to the worker thread ParallelQueryThreadInfo info = new ParallelQueryThreadInfo(); info.connectionString = connectionString; if (n == 0) { info.query = "with member measures.internalcalc as SetToStr(" + SetExpression1 + ") select measures.internalcalc on 0 from [" + Context.CurrentCube.Name + "]"; } else { info.query = "with member measures.internalcalc as SetToStr(" + SetExpression2 + ") select measures.internalcalc on 0 from [" + Context.CurrentCube.Name + "]"; } info.autoEvent = new AutoResetEvent(false); threadInfos.Add(info); ThreadPool.QueueUserWorkItem(new WaitCallback(RunAQuery), info); } StringBuilder sFinalSet = new StringBuilder("{"); for (int i = 0; i < threadInfos.Count; i++) { //wait until they've finished while (!threadInfos[i].autoEvent.WaitOne(1000, false)) { Context.CheckCancelled(); } if (threadInfos[i].ex != null) { throw threadInfos[i].ex; } if (i > 0) { sFinalSet.Append(" + "); } sFinalSet.Append(threadInfos[i].returnValue); } sFinalSet.Append("}"); return(MDX.StrToSet(sFinalSet.ToString())); }
private static Set buildAsymmetricSet(params Member[] memberList) { Context.TraceEvent(100, 0, "AsymmetricSet: Starting"); // build a list of all the unique Hierarchies from the members in memberList. List <Hierarchy> hierList = new List <Hierarchy>(); foreach (Member m in memberList) { // Check that the member variable is correctly populated. If the user passes // in a non-existant member we get a member object whose properties are all // null or empty strings. if (m.UniqueName.Length > 0) { if (!hierList.Exists(delegate(Hierarchy h) { if (h.UniqueName == m.ParentLevel.ParentHierarchy.UniqueName) { return(true); } else { return(false); } })) { hierList.Add(m.ParentLevel.ParentHierarchy); } } } // SetBuilder & TupleBuilder are IDisposeable so we ensure they // are disposed by utilizing a using block. using (SetBuilder asymSet = new SetBuilder()) { foreach (Member paramMbr in memberList) { if (paramMbr.UniqueName.Length > 0) { // create a tuple for each member that was passed in, // combined with the default member from the other hierarchies. using (TupleBuilder tb = new TupleBuilder()) { foreach (Hierarchy h in hierList) // for each unique hierarchy { Hierarchy paramHier = paramMbr.ParentLevel.ParentHierarchy; if (paramHier.UniqueName == h.UniqueName) { //System.Diagnostics.Trace.WriteLine("Adding member " + paramMbr.UniqueName); tb.Add(paramMbr); } else { Member defMbr = MDX.StrToSet(h.DefaultMember).Tuples[0].Members[0]; //System.Diagnostics.Trace.WriteLine("Adding default member " + defMbr.UniqueName); tb.Add(defMbr); } } Tuple t = tb.ToTuple(); // if the members added to the TupleBuilder will result in a non-existant tuple // (eg. [Calendar Quarter 1] and [December]) the ToTuple method returns a Tuple // containing 0 members. If such a tuple is added to the SetBuilder, the // SetBuilder.ToSet will throw an exception if (t.Members.Count > 0) { asymSet.Add(tb.ToTuple()); } } // using tb } } //foreach paramMbr Context.TraceEvent(100, asymSet.Count, "AsymmetricSet: Finished (" + asymSet.Count.ToString() + " tuples generated)"); return(asymSet.ToSet()); } //using SetBuilder }