/* Microsoft SQL Server Integration Services Script Component * Write scripts using Microsoft Visual C# 2008. * ScriptMain is the entry point class of the script.*/ using System; using System.Data; using Microsoft.SqlServer.Dts.Pipeline.Wrapper; using Microsoft.SqlServer.Dts.Runtime.Wrapper; using SSAS = Microsoft.AnalysisServices; //using System.Windows.Forms; [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute] public class ScriptMain : UserComponent { private string _mdx = ""; public override void PreExecute() { base.PreExecute(); /* Add your code here for preprocessing or remove if not needed */ } public override void PostExecute() { base.PostExecute(); SSAS.Server sikAS = new SSAS.Server(); try { sikAS.Connect("Data source=" + Variables.settingCubeServer); SSAS.Database db = sikAS.Databases.FindByName(Variables.settingCubeDatenbank); SSAS.Cube cb = db.Cubes.FindByName(Variables.settingCubeCube); //MessageBox.Show("neuer Inhalt: " + _mdx); string old = cb.MdxScripts[0].Commands[0].Text; int start = old.IndexOf("/*Beginn Statusberechnungen*/"); int ende = -1; if (start != -1) { ende = old.IndexOf("/* Ende Statusberechnungen */") + "/* Ende Statusberechnungen */".Length; if (ende == -1) ende = old.Length; } //MessageBox.Show(old.Substring(start, ende-start)); string newmdx; if ((start == -1) && (ende == -1)) newmdx = old; else newmdx = old.Remove(start, ende - start); newmdx += "/*Beginn Statusberechnungen*/\n/* Den Text zwischen diesen Markierungen NICHT verändern, da er autogeneriert ist*/\n"; newmdx += "/* erzeugt am " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss") + " */\n"; newmdx += _mdx; newmdx += "/* Ende Statusberechnungen */"; cb.MdxScripts[0].Commands[0].Text = newmdx; cb.MdxScripts[0].Update(); } catch (Exception e) { bool b = true; this.ComponentMetaData.FireError(10, "changing cube's mdx", "error: " + e.Message, "", 0, out b); } } public override void Eingabe0_ProcessInputRow(Eingabe0Buffer Row) { _mdx += "CREATE MEMBER CURRENTCUBE.[Measures].[" + Row.MeasureName + "_Status]\nAS " + Row.Formel + ", \nVISIBLE = 1;\n"; } }