Esempio n. 1
0
        private void ExecuteSubFunctions(EditorManager manager)
        {
            while (_selectedFunction.SubFunctions.Any())
            {
                string function = ReplaceDynamicParameters(_selectedFunction.SubFunctions.Dequeue());

                string[] fargs = function.ParseArguments();

                manager.GetClipEditor(fargs[0]);
                manager.ClipEditor.EditorResponse += HandleResponseFromClippy;
                manager.ClipEditor.DefineParameters();
                manager.ClipEditor.SetParameters(fargs);

                if (!manager.ClipEditor.HasAllParameters)
                {
                    throw new Exception(String.Format("Not all parameters are passed in the user defined function {0}, function: {1}", _udfName, function));
                }

                manager.ClipEditor.SourceData = SourceData;
                manager.ClipEditor.Edit();
                SourceData = manager.ClipEditor.SourceData;
                manager.ClipEditor.EditorResponse -= HandleResponseFromClippy;
            }
        }
Esempio n. 2
0
        private void FunctionOnLeave(object sender, EventArgs e)
        {
            errorLabel.Text     = String.Empty;
            functions.BackColor = Color.White;

            string[] arguments = clipManager.GetArgumentsFromString(functions.Text);
            if (arguments.Length == 0)
            {
                return;
            }

            if (functions.Text.Equals(_currentCommand, StringComparison.CurrentCultureIgnoreCase))
            {
                string[] newArgs = new string[parametersGrid.Rows.Count + 1];
                newArgs[0] = arguments[0];
                for (int ia = 1; ia < newArgs.Length; ia++)
                {
                    newArgs[ia] = parametersGrid.Rows[ia - 1].Cells[1].Value.ToString();
                }
                arguments = newArgs;
            }

            _currentCommand = arguments[0];

            clipManager.GetClipEditor(arguments[0]);
            clipManager.ClipEditor.EditorResponse           += HandleResponseFromClippy;
            clipManager.ClipEditor.PersistentEditorResponse += HandlePersistentResponse;
            try
            {
                clipManager.ClipEditor.SetParameters(arguments);
            }
            catch (ClippyLib.InvalidParameterException pe)
            {
                MessageBox.Show(pe.ParameterMessage, "Error creating parameters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                functions.Focus();
            }
            catch (ClippyLib.UndefinedFunctionException udfe)
            {
                errorLabel.Text     = udfe.FunctionMessage;
                functions.BackColor = Color.Yellow;
                functions.Focus();
                return;
            }

            DataTable parms = new DataTable();

            parms.Columns.Add("Parameter");
            parms.Columns.Add("Value");
            foreach (Parameter p in clipManager.ClipEditor.ParameterList)
            {
                DataRow dr = parms.NewRow();
                dr["Parameter"] = p.ParameterName;
                dr["Value"]     = p.Value ?? p.DefaultValue ?? String.Empty;

                parms.Rows.Add(dr);
            }
            parametersGrid.DataSource = parms;

            int parmRow = 0;

            foreach (Parameter p in clipManager.ClipEditor.ParameterList)
            {
                parametersGrid.Rows[parmRow++].Cells[1].ToolTipText = p.Expecting;
            }

            if (clipManager.ClipEditor.ParameterList.Count == 0)
            {
                executeButton.Focus();
            }
        }
Esempio n. 3
0
        public override void Edit()
        {
            EditorManager manager = new EditorManager();

            if(_arguments[0].Equals("help", StringComparison.CurrentCultureIgnoreCase))
            {
                RespondToExe(manager.Help(_arguments));
                return;
            }

            List<string> functions = Udf(_arguments);
            if (functions.Count == 0)
                throw new UndefinedFunctionException(String.Format("Function:{0} does not exist or is not valid", _udfName));

            //there could be multiple functions per UDF, one per line
            for (int fi = 0; fi < functions.Count; fi++)
            {
                string function = functions[fi];

                for (int i = 1; i < _arguments.Length; i++)
                {
                    function = function.Replace("%" + (i - 1).ToString() + "%", _arguments[i]);
                }

                for (int i = 0; i < ParameterList.Count; i++)
                {
                    function = function.Replace("%" + i.ToString() + "%", ParameterList[i].Value);
                }

                string[] fargs = GetArgsFromString(function);
                manager.GetClipEditor(fargs[0]);

                manager.ClipEditor.EditorResponse += new EventHandler<EditorResponseEventArgs>(HandleResponseFromClippy);

                manager.ClipEditor.DefineParameters();
                manager.ClipEditor.SetParameters(fargs);
                if (!manager.ClipEditor.HasAllParameters)
                {
                    throw new Exception(String.Format("Not all parameters are passed in the user defined function {0}, function: {1}", _udfName, function));
                }
                manager.ClipEditor.SourceData = SourceData;
                manager.ClipEditor.Edit();
                SourceData = manager.ClipEditor.SourceData;

                manager.ClipEditor.EditorResponse -= HandleResponseFromClippy;

            }
        }