Exemple #1
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.Functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed)
            {
                BaseUtils.StringParser sp = new BaseUtils.StringParser(res);

                string nextcmd = sp.NextWordLCInvariant(" ");

                if (nextcmd == null)
                {
                    ap.ReportError("Missing command in ProgramWindow");
                }
                else if (nextcmd.Equals("tab") || nextcmd.Equals("opentab") || nextcmd.Equals("closetab"))
                {
                    string tabname = sp.NextQuotedWord(lowercase: System.Globalization.CultureInfo.InvariantCulture, replaceescape: true);

                    if (!(ap.ActionController as ActionController).DiscoveryForm.SelectTabPage(tabname, nextcmd.Equals("opentab"), nextcmd.Equals("closetab")))
                    {
                        ap.ReportError("Tab page name " + tabname + " not found");
                    }
                }
                else if (nextcmd.Equals("topmost"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.TopMost = true;
                }
                else if (nextcmd.Equals("normalz"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.TopMost = false;
                }
                else if (nextcmd.Equals("showintaskbar"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.ShowInTaskbar = true;
                }
                else if (nextcmd.Equals("notshowintaskbar"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.ShowInTaskbar = false;
                }
                else if (nextcmd.Equals("minimize"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.WindowState = FormWindowState.Minimized;
                }
                else if (nextcmd.Equals("normal"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.WindowState = FormWindowState.Normal;
                }
                else if (nextcmd.Equals("maximize"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.WindowState = FormWindowState.Maximized;
                }
                else if (nextcmd.Equals("location"))
                {
                    int?x = sp.NextWordComma().InvariantParseIntNull();
                    int?y = sp.NextWordComma().InvariantParseIntNull();
                    int?w = sp.NextWordComma().InvariantParseIntNull();
                    int?h = sp.NextWord().InvariantParseIntNull();

                    if (x.HasValue && y.HasValue && w.HasValue && h.HasValue)
                    {
                        (ap.ActionController as ActionController).DiscoveryForm.Location = new Point(x.Value, y.Value);
                        (ap.ActionController as ActionController).DiscoveryForm.Size     = new Size(w.Value, h.Value);
                    }
                    else
                    {
                        ap.ReportError("Location needs x,y,w,h in Popout");
                    }
                }
                else if (nextcmd.Equals("position"))
                {
                    int?x = sp.NextWordComma().InvariantParseIntNull();
                    int?y = sp.NextWord().InvariantParseIntNull();

                    if (x.HasValue && y.HasValue)
                    {
                        (ap.ActionController as ActionController).DiscoveryForm.Location = new Point(x.Value, y.Value);
                    }
                    else
                    {
                        ap.ReportError("Position needs x,y in Popout");
                    }
                }
                else if (nextcmd.Equals("size"))
                {
                    int?w = sp.NextWordComma().InvariantParseIntNull();
                    int?h = sp.NextWord().InvariantParseIntNull();

                    if (w.HasValue && h.HasValue)
                    {
                        (ap.ActionController as ActionController).DiscoveryForm.Size = new Size(w.Value, h.Value);
                    }
                    else
                    {
                        ap.ReportError("Size needs x,y,w,h in Popout");
                    }
                }
                else
                {
                    ap.ReportError("Unknown command " + nextcmd + " in Popout");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
        static private string MakeEntry(string instr, out Entry entry, ref System.Drawing.Point lastpos)
        {
            entry = null;

            BaseUtils.StringParser sp = new BaseUtils.StringParser(instr);

            string name = sp.NextQuotedWordComma();

            if (name == null)
            {
                return("Missing name");
            }

            string type = sp.NextWordComma(lowercase: true);

            Type ctype = null;

            if (type == null)
            {
                return("Missing type");
            }
            else if (type.Equals("button"))
            {
                ctype = typeof(ExtendedControls.ButtonExt);
            }
            else if (type.Equals("textbox"))
            {
                ctype = typeof(ExtendedControls.TextBoxBorder);
            }
            else if (type.Equals("checkbox"))
            {
                ctype = typeof(ExtendedControls.CheckBoxCustom);
            }
            else if (type.Equals("label"))
            {
                ctype = typeof(System.Windows.Forms.Label);
            }
            else if (type.Equals("combobox"))
            {
                ctype = typeof(ExtendedControls.ComboBoxCustom);
            }
            else if (type.Equals("datetime"))
            {
                ctype = typeof(ExtendedControls.CustomDateTimePicker);
            }
            else if (type.Equals("numberboxlong"))
            {
                ctype = typeof(ExtendedControls.NumberBoxLong);
            }
            else if (type.Equals("numberboxdouble"))
            {
                ctype = typeof(ExtendedControls.NumberBoxDouble);
            }
            else
            {
                return("Unknown control type " + type);
            }

            string text = sp.NextQuotedWordComma();     // normally text..

            if (text == null)
            {
                return("Missing text");
            }

            int?x = sp.NextWordComma().InvariantParseIntNullOffset(lastpos.X);
            int?y = sp.NextWordComma().InvariantParseIntNullOffset(lastpos.Y);
            int?w = sp.NextWordComma().InvariantParseIntNull();
            int?h = sp.NextWordComma().InvariantParseIntNull();

            if (x == null || y == null || w == null || h == null)
            {
                return("Missing position/size");
            }

            string tip = sp.NextQuotedWordComma();      // tip can be null

            entry = new ConfigurableForm.Entry(name, ctype,
                                               text, new System.Drawing.Point(x.Value, y.Value), new System.Drawing.Size(w.Value, h.Value), tip);

            if (type.Contains("textbox") && tip != null)
            {
                int?v = sp.NextWordComma().InvariantParseIntNull();
                entry.textboxmultiline = v.HasValue && v.Value != 0;
            }

            if (type.Contains("checkbox") && tip != null)
            {
                int?v = sp.NextWordComma().InvariantParseIntNull();
                entry.checkboxchecked = v.HasValue && v.Value != 0;

                v = sp.NextWordComma().InvariantParseIntNull();
                entry.clearonfirstchar = v.HasValue && v.Value != 0;
            }

            if (type.Contains("combobox"))
            {
                entry.comboboxitems = sp.LineLeft.Trim();
                if (tip == null || entry.comboboxitems.Length == 0)
                {
                    return("Missing paramters for combobox");
                }
            }

            if (type.Contains("datetime"))
            {
                entry.customdateformat = sp.NextWord();
            }

            if (type.Contains("numberboxdouble"))
            {
                double?min = sp.NextWordComma().InvariantParseDoubleNull();
                double?max = sp.NextWordComma().InvariantParseDoubleNull();
                entry.numberboxdoubleminimum = min.HasValue ? min.Value : double.MinValue;
                entry.numberboxdoublemaximum = max.HasValue ? max.Value : double.MaxValue;
                entry.numberboxformat        = sp.NextWordComma();
            }

            if (type.Contains("numberboxlong"))
            {
                long?min = sp.NextWordComma().InvariantParseLongNull();
                long?max = sp.NextWordComma().InvariantParseLongNull();
                entry.numberboxlongminimum = min.HasValue ? min.Value : long.MinValue;
                entry.numberboxlongmaximum = max.HasValue ? max.Value : long.MaxValue;
                entry.numberboxformat      = sp.NextWordComma();
            }

            lastpos = new System.Drawing.Point(x.Value, y.Value);
            return(null);
        }
Exemple #3
0
        public string Read(System.IO.TextReader sr, ref int lineno)         // read from stream
        {
            string err = "";

            programsteps = new List <ActionBase>();
            Name         = "";

            List <int> indents     = new List <int>();
            List <int> level       = new List <int>();
            int        indentpos   = -1;
            int        structlevel = 0;

            string completeline;

            int initiallineno = lineno;

            while ((completeline = sr.ReadLine()) != null)
            {
                lineno++;

                completeline = completeline.Replace("\t", "    ");  // detab, to spaces, tabs are worth 4.
                BaseUtils.StringParser p = new BaseUtils.StringParser(completeline);

                if (!p.IsEOL)
                {
                    int    curindent = p.Position;
                    string cmd       = "";
                    if (p.IsStringMoveOn("//"))         // special, this is allowed to butt against text and still work
                    {
                        cmd = "//";
                    }
                    else
                    {
                        cmd = p.NextWord();
                    }

                    if (cmd.Equals("Else", StringComparison.InvariantCultureIgnoreCase))
                    {
                        //System.Diagnostics.Debug.WriteLine("Else " + cmd + " " + p.LineLeft);
                        if (p.IsStringMoveOn("If", StringComparison.InvariantCultureIgnoreCase))   // if Else followed by IF
                        {
                            cmd = "Else If";
                        }
                    }

                    string line = p.LineLeft;           // and the rest of the line..

                    int    commentpos = line.LastIndexOf("//");
                    string comment    = "";

                    if (cmd != "//" && commentpos >= 0 && !line.InQuotes(commentpos))       // if not // command, and we have one..
                    {
                        comment = line.Substring(commentpos + 2).Trim();
                        line    = line.Substring(0, commentpos).TrimEnd();
                        //System.Diagnostics.Debug.WriteLine("Line <" + line + "> <" + comment + ">");
                    }

                    if (cmd.Equals("PROGRAM", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Name = line;
                    }
                    else if (cmd.Equals("END", StringComparison.InvariantCultureIgnoreCase) && line.Equals("PROGRAM", StringComparison.InvariantCultureIgnoreCase))
                    {
                        break;
                    }
                    else
                    {
                        ActionBase a = ActionBase.CreateAction(cmd, line, comment);
                        string     vmsg;

                        if (a == null)
                        {
                            err += lineno + " " + Name + " Unrecognised command " + cmd + Environment.NewLine;
                        }
                        else if ((vmsg = a.VerifyActionCorrect()) != null)
                        {
                            err += lineno + " " + Name + ":" + vmsg + Environment.NewLine + " " + completeline.Trim() + Environment.NewLine;
                        }
                        else
                        {
                            //System.Diagnostics.Debug.WriteLine(indentpos + ":" + structlevel + ": Cmd " + cmd + " : " + line);

                            if (indentpos == -1)
                            {
                                indentpos = curindent;
                            }
                            else if (curindent > indentpos)        // more indented, up one structure
                            {
                                structlevel++;
                                indentpos = curindent;
                            }
                            else if (curindent < indentpos)   // deindented
                            {
                                int tolevel = -1;
                                for (int i = indents.Count - 1; i >= 0; i--)            // search up and find the entry with the indent..
                                {
                                    if (indents[i] <= curindent)
                                    {
                                        tolevel = i;
                                        break;
                                    }
                                }

                                if (tolevel >= 0)       // if found, we have a statement to hook to..
                                {                       // while in DO loop, or Else/Elseif in IF
                                    if ((a.Type == ActionBase.ActionType.While && programsteps[tolevel].Type == ActionBase.ActionType.Do) ||
                                        ((a.Type == ActionBase.ActionType.Else || a.Type == ActionBase.ActionType.ElseIf) && programsteps[tolevel].Type == ActionBase.ActionType.If))
                                    {
                                        int reallevel = level[tolevel] + 1;     // else, while are dedented, but they really are on level+1
                                        a.LevelUp   = structlevel - reallevel;
                                        structlevel = reallevel;
                                        indentpos   = indents[tolevel] + 4;     // and our indent should continue 4 in, so we don't match against this when we do indent
                                    }
                                    else
                                    {
                                        a.LevelUp   = structlevel - level[tolevel];
                                        structlevel = level[tolevel];   // if found, we are at that.. except..
                                        indentpos   = indents[tolevel]; // and back to this level
                                    }
                                }
                            }

                            a.LineNumber = lineno;

                            //System.Diagnostics.Debug.WriteLine("    >>>> " + indentpos + ":" + structlevel);

                            indents.Add(indentpos);
                            level.Add(structlevel);
                            programsteps.Add(a);
                        }
                    }
                }
                else
                {
                    if (programsteps.Count > 0)
                    {
                        programsteps[programsteps.Count - 1].Whitespace = 1;
                    }
                }
            }

            if (programsteps.Count > 0)
            {
                programsteps[programsteps.Count - 1].Whitespace = 0;        // last cannot have whitespace..
            }
            progclass = Classify();
            return(err);
        }