Esempio n. 1
0
        public void ExecuteProcess(string serv, string proc)
        {
            IntPtr hServer = IntPtr.Zero;
            IntPtr hProcess = IntPtr.Zero;
            IntPtr hVariableNames = IntPtr.Zero;
            IntPtr hVariableTypes = IntPtr.Zero;
            IntPtr hPromptStrings = IntPtr.Zero;
            IntPtr hDefaultValues = IntPtr.Zero;
            IntPtr hParamVariableName = IntPtr.Zero;
            IntPtr hParamVariableType = IntPtr.Zero;
            IntPtr hParamPromptString = IntPtr.Zero;
            IntPtr hParamDefaultValue = IntPtr.Zero;
            IntPtr hParamValue = IntPtr.Zero;
            IntPtr hParamArray = IntPtr.Zero;
            IntPtr hResult = IntPtr.Zero;
            IntPtr[] argsarray = null;

            int num_variables = 0;
            int errorcode;
            string errorstring;
            string errorlogfile;

            hServer = TM1API.SystemFunctions.TM1SystemServerHandle(this.UserHandle, serv);

            if (hServer != IntPtr.Zero)
            {
                ProcessParameter ppinfo;
                string variable;
                string prompt;
                string value = null;
                string type = null;
                int typeindex;

                var ppsinfo = new List<ProcessParameter>();

                ParameterDialog pdlg = null;

                // Get a handle to the process
                hProcess = TM1API.ObjectFunctions.TM1ObjectListHandleByNameGet(this.PoolHandle, hServer, TM1API.ProcessFunctions.TM1ServerProcesses(), TM1API.ValueFunctions.TM1ValString(this.PoolHandle, proc, proc.Length));
                hVariableNames = TM1API.ObjectFunctions.TM1ObjectPropertyGet(this.PoolHandle, hProcess, TM1API.ProcessFunctions.TM1ProcessParametersNames());
                hVariableTypes = TM1API.ObjectFunctions.TM1ObjectPropertyGet(this.PoolHandle, hProcess, TM1API.ProcessFunctions.TM1ProcessParametersTypes());
                hPromptStrings = TM1API.ObjectFunctions.TM1ObjectPropertyGet(this.PoolHandle, hProcess, TM1API.ProcessFunctions.TM1ProcessParametersPromptStrings());
                hDefaultValues = TM1API.ObjectFunctions.TM1ObjectPropertyGet(this.PoolHandle, hProcess, TM1API.ProcessFunctions.TM1ProcessParametersDefaultValues());

                num_variables = TM1API.ValueFunctions.TM1ValArrayMaxSize(this.UserHandle, hVariableNames);

                for (int count = 0; count < num_variables; count++)
                {
                    hParamVariableName = TM1API.ValueFunctions.TM1ValArrayGet(this.UserHandle, hVariableNames, count + 1);
                    hParamVariableType = TM1API.ValueFunctions.TM1ValArrayGet(this.UserHandle, hVariableTypes, count + 1);
                    hParamPromptString = TM1API.ValueFunctions.TM1ValArrayGet(this.UserHandle, hPromptStrings, count + 1);
                    hParamDefaultValue = TM1API.ValueFunctions.TM1ValArrayGet(this.UserHandle, hDefaultValues, count + 1);

                    variable = TM1API.ValueFunctions.TM1ValStringGet(this.UserHandle, hParamVariableName).ToString();
                    typeindex = TM1API.ValueFunctions.TM1ValIndexGet(this.UserHandle, hParamVariableType);
                    prompt = TM1API.ValueFunctions.TM1ValStringGet(this.UserHandle, hParamPromptString).ToString();

                    if (typeindex == 32)
                    {
                        type = "String";
                        value = TM1API.ValueFunctions.TM1ValStringGet(this.UserHandle, hParamDefaultValue).ToString();
                    }
                    else if (typeindex == 33)
                    {
                        type = "Numeric";
                        value = TM1API.ValueFunctions.TM1ValRealGet(this.UserHandle, hParamDefaultValue).ToString();
                    }

                    ppinfo = new ProcessParameter(variable, prompt, type, value);
                    ppsinfo.Add(ppinfo);
                    ppinfo = null;
                }

                if (ppsinfo.Count > 0)
                {
                    pdlg = new ParameterDialog(ppsinfo, serv + " - " + proc);

                    if (pdlg.ShowDialog() == DialogResult.OK)
                    {
                        ppsinfo = pdlg.FinalParamValues;

                        argsarray = new IntPtr[ppsinfo.Count];

                        for (int argcount = 0; argcount < ppsinfo.Count; argcount++)
                        {
                            if (ppsinfo[argcount].Type.Equals("Numeric"))
                            {
                                hParamValue = TM1API.ValueFunctions.TM1ValReal(this.PoolHandle, Double.Parse(ppsinfo[argcount].Value));
                            }
                            else if (ppsinfo[argcount].Type.Equals("String"))
                            {
                                hParamValue = TM1API.ValueFunctions.TM1ValString(this.PoolHandle, ppsinfo[argcount].Value, ppsinfo[argcount].Value.Length);
                            }

                            argsarray[argcount] = hParamValue;
                        }

                        hParamArray = TM1API.ValueFunctions.TM1ValArray(this.PoolHandle, argsarray, ppsinfo.Count);
                    }
                }

                hResult = TM1API.ProcessFunctions.TM1ProcessExecuteEx(this.PoolHandle, hProcess, hParamArray);

                if (TM1API.ValueFunctions.TM1ValType(this.UserHandle, hResult) == TM1API.ValueFunctions.TM1ValTypeArray())
                {
                    CheckProcessResult(hResult, out errorcode, out errorstring, out errorlogfile);

                    if (errorcode > 0)
                    {
                        MessageBox.Show(errorcode.ToString() + ": " + errorstring, "Error in process execution", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    // Success!
                }
            }
            else
            {
                MessageBox.Show("An active connection to the server could not be found.", "Error in process execution", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void OkayBtn_Click(object sender, EventArgs e)
        {
            ProcessParameter ppi = null;
            string variable = null;
            string type = null;
            string prompt = null;
            string value = null;

            foreach (ListViewItem lvi in this.ParamsListView.Items)
            {
                variable = lvi.SubItems[0].Text;
                type = lvi.SubItems[1].Text;
                prompt = lvi.SubItems[2].Text;
                value = lvi.SubItems[3].Text;

                ppi = new ProcessParameter(variable, prompt, type, value);
                this.FinalParamValues.Add(ppi);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }