Beispiel #1
0
        protected bool WordListEntry(out string output)
        {
            BaseUtils.StringParser l = new BaseUtils.StringParser(paras[0].isstring ? paras[0].value : vars[paras[0].value]);
            string c = vars.Exists(paras[1].value) ? vars[paras[1].value] : paras[1].value;

            output = "";

            int count;

            if (c.InvariantParse(out count))
            {
                List <string> ll = l.NextQuotedWordList();
                if (count >= 0 && count < ll.Count)
                {
                    output = ll[count];
                }
            }
            else
            {
                output = "Parameter should be an integer constant or a variable name with an integer in its value";
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        protected bool WordListCount(out string output)
        {
            BaseUtils.StringParser l  = new BaseUtils.StringParser(paras[0].isstring ? paras[0].value : vars[paras[0].value]);
            List <string>          ll = l.NextQuotedWordList();

            output = ll.Count.ToStringInvariant();
            return(true);
        }
Beispiel #3
0
        public bool AddFromString(BaseUtils.StringParser p, FromMode fm, Dictionary <string, string> altops = null)
        {
            Dictionary <string, string> newvars = ReadFromString(p, fm, altops);

            if (newvars != null)
            {
                Add(newvars);
            }
            return(newvars != null);
        }
Beispiel #4
0
        static public string GetLogicalCondition(BaseUtils.StringParser sp, string delimchars, out LogicalCondition value)
        {
            value = LogicalCondition.Or;

            string condi = sp.NextQuotedWord(delimchars);       // next is the inner condition..

            if (condi == null)
            {
                return("Condition operator missing");
            }

            condi = condi.Replace(" ", "");

            if (Enum.TryParse <ConditionEntry.LogicalCondition>(condi.Replace(" ", ""), true, out value))
            {
                return("");
            }
            else
            {
                return("Condition operator " + condi + " is not recognised");
            }
        }
        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);
        }
Beispiel #6
0
        private Dictionary <string, string> ReadFromString(BaseUtils.StringParser p, FromMode fm, Dictionary <string, string> altops = null)
        {
            Dictionary <string, string> newvars = new Dictionary <string, string>();

            while (!p.IsEOL)
            {
                string varname = p.NextQuotedWord("= ");

                if (varname == null)
                {
                    return(null);
                }

                if (altops != null)         // with extended ops, the ops are returned in the altops function, one per variable found
                {                           // used only with let and set..
                    if (varname.EndsWith("$+"))
                    {
                        varname         = varname.Substring(0, varname.Length - 2);
                        altops[varname] = "$+=";
                    }
                    else if (varname.EndsWith("$"))
                    {
                        varname         = varname.Substring(0, varname.Length - 1);
                        altops[varname] = "$=";
                    }
                    else if (varname.EndsWith("+"))
                    {
                        varname         = varname.Substring(0, varname.Length - 1);
                        altops[varname] = "+=";
                    }
                    else
                    {
                        altops[varname] = "=";             // varname is good, it ended with a = or space, default is =

                        bool dollar = p.IsCharMoveOn('$'); // check for varname space $+
                        bool add    = p.IsCharMoveOn('+');

                        if (dollar && add)
                        {
                            altops[varname] = "$+=";
                        }
                        else if (dollar)
                        {
                            altops[varname] = "$=";
                        }
                        else if (add)
                        {
                            altops[varname] = "+=";
                        }
                    }
                }

                if (!p.IsCharMoveOn('='))
                {
                    return(null);
                }

                string value = (fm == FromMode.OnePerLine) ? p.NextQuotedWordOrLine() : p.NextQuotedWord((fm == FromMode.MultiEntryComma) ? ", " : ",) ");

                if (value == null)
                {
                    return(null);
                }

                newvars[varname] = value;

                if (fm == FromMode.MultiEntryCommaBracketEnds && p.PeekChar() == ')')        // bracket, stop don't remove.. outer bit wants to check its there..
                {
                    return(newvars);
                }
                else if (fm == FromMode.OnePerLine && !p.IsEOL)        // single entry, must be eol now
                {
                    return(null);
                }
                else if (!p.IsEOL && !p.IsCharMoveOn(','))   // if not EOL, but not comma, incorrectly formed list
                {
                    return(null);
                }
            }

            return(newvars);
        }
Beispiel #7
0
 public bool FromString(string s, FromMode fm)    // string, not bracketed.
 {
     BaseUtils.StringParser p = new BaseUtils.StringParser(s);
     return(FromString(p, fm));
 }
Beispiel #8
0
        private Control MakeNode(string s)
        {
            BaseUtils.StringParser sp = new BaseUtils.StringParser(s); // ctrl string is tag,panelid enum number
            int tagid = sp.NextInt(",") ?? 0;                          // enum id

            sp.IsCharMoveOn(',');
            int panelid = sp.NextInt(",") ?? NoTabPanelSelected; // if not valid, we get an empty tab control

            if (panelid >= FixedPanelOffset)                     // this range of ids are UCCB directly in the splitter, so are not changeable
            {
                PanelInformation.PanelInfo pi = PanelInformation.GetPanelInfoByPanelID((PanelInformation.PanelIDs)(panelid - FixedPanelOffset));
                if (pi == null)
                {
                    pi = PanelInformation.GetPanelInfoByPanelID(PanelInformation.PanelIDs.Log); // make sure we have a valid one - can't return nothing
                }
                UserControlCommonBase uccb = PanelInformation.Create(pi.PopoutID);              // must return as we made sure pi is valid
                uccb.AutoScaleMode = AutoScaleMode.Inherit;                                     // very very important and took 2 days to work out!
                uccb.Dock          = DockStyle.Fill;
                uccb.Tag           = tagid;
                uccb.Name          = "UC-" + tagid.ToStringInvariant();

                return(uccb);
            }
            else                        // positive ones are tab strip with the panel id selected, if valid..
            {
                ExtendedControls.TabStrip tabstrip = new ExtendedControls.TabStrip();
                tabstrip.ImageList = PanelInformation.GetUserSelectablePanelImages(TabListSortAlpha);
                tabstrip.TextList  = PanelInformation.GetUserSelectablePanelDescriptions(TabListSortAlpha);
                tabstrip.TagList   = PanelInformation.GetUserSelectablePanelIDs(TabListSortAlpha).Cast <Object>().ToArray();
                tabstrip.ListSelectionItemSeparators = PanelInformation.GetUserSelectableSeperatorIndex(TabListSortAlpha);

                tabstrip.Dock      = DockStyle.Fill;
                tabstrip.StripMode = ExtendedControls.TabStrip.StripModeType.ListSelection;

                tabstrip.Tag  = tagid;                        // Tag stores the ID index of this view
                tabstrip.Name = Name + "." + tagid.ToStringInvariant();

                //System.Diagnostics.Debug.WriteLine("Make new tab control " + tabstrip.Name + " id "  + tagid + " of " + panelid );

                tabstrip.OnRemoving += (tab, ctrl) =>
                {
                    UserControlCommonBase uccb = ctrl as UserControlCommonBase;
                    uccb.CloseDown();
                    AssignTHC();        // in case we removed anything
                };

                tabstrip.OnCreateTab += (tab, si) =>                                                                                    // called when the tab strip wants a new control for a tab.
                {
                    PanelInformation.PanelInfo pi = PanelInformation.GetPanelInfoByPanelID((PanelInformation.PanelIDs)tab.TagList[si]); // must be valid, as it came from the taglist
                    Control c = PanelInformation.Create(pi.PopoutID);
                    (c as UserControlCommonBase).AutoScaleMode = AutoScaleMode.Inherit;
                    c.Name = pi.WindowTitle;        // tabs uses Name field for display, must set it
                    System.Diagnostics.Trace.WriteLine("SP:Create Tab " + c.Name);
                    return(c);
                };

                tabstrip.OnPostCreateTab += (tab, ctrl, i) =>                       // only called during dynamic creation..
                {
                    int tabstripid           = (int)tab.Tag;                        // tag from tab strip
                    int displaynumber        = DisplayNumberOfSplitter(tabstripid); // tab strip - use tag to remember display id which helps us save context.
                    UserControlCommonBase uc = ctrl as UserControlCommonBase;

                    if (uc != null)
                    {
                        System.Diagnostics.Trace.WriteLine("SP:Make Tab " + tabstripid + " with dno " + displaynumber + " Use THC " + ucursor_inuse.GetHashCode());
                        uc.Init(discoveryform, displaynumber);              // init..

                        uc.Scale(this.FindForm().CurrentAutoScaleFactor()); // keeping to the contract, scale and
                        discoveryform.theme.ApplyStd(uc);                   // theme the uc. between init and set cursor

                        uc.SetCursor(ucursor_inuse);
                        uc.LoadLayout();
                        uc.InitialDisplay();
                    }

                    AssignTHC();        // in case we added one
                };

                tabstrip.OnPopOut += (tab, i) => { discoveryform.PopOuts.PopOut((PanelInformation.PanelIDs)tabstrip.TagList[i]); };

                PanelInformation.PanelIDs[] pids = PanelInformation.GetUserSelectablePanelIDs(TabListSortAlpha); // sort order v.important.. we need the right index, dep

                int indexofentry = Array.FindIndex(pids, x => x == (PanelInformation.PanelIDs)panelid);          // find ID in array..  -1 if not valid ID, it copes with -1

                if (indexofentry >= 0)                                                                           // if we have a panel, open it
                {
                    tabstrip.Create(indexofentry);                                                               // create but not post create during the init phase. Post create is only used during dynamics
                }

                return(tabstrip);
            }
        }
Beispiel #9
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);
        }
        private Control MakeNode(string s)
        {
            BaseUtils.StringParser sp = new BaseUtils.StringParser(s); // ctrl string is tag,panelid enum number
            int tagid = sp.NextInt(",") ?? 0;                          // enum id

            sp.IsCharMoveOn(',');
            int panelid = sp.NextInt(",") ?? NoTabPanelSelected; // if not valid, we get an empty tab control

            if (panelid >= FixedPanelOffset)                     // this range of ids are UCCB directly in the splitter, so are not changeable
            {
                PanelInformation.PanelInfo pi = PanelInformation.GetPanelInfoByPanelID((PanelInformation.PanelIDs)(panelid - FixedPanelOffset));
                if (pi == null)
                {
                    pi = PanelInformation.GetPanelInfoByPanelID(PanelInformation.PanelIDs.Log); // make sure we have a valid one - can't return nothing
                }
                UserControlCommonBase uccb = PanelInformation.Create(pi.PopoutID);              // must return as we made sure pi is valid
                uccb.Dock = DockStyle.Fill;

                uccb.Tag  = tagid;
                uccb.Name = "UC-" + tagid.ToStringInvariant();

                return(uccb);
            }
            else                        // positive ones are tab strip with the panel id selected, if valid..
            {
                ExtendedControls.TabStrip tabstrip = new ExtendedControls.TabStrip();
                tabstrip.ImageList      = PanelInformation.GetPanelImages();
                tabstrip.TextList       = PanelInformation.GetPanelDescriptions();
                tabstrip.TagList        = PanelInformation.GetPanelIDs().Cast <Object>().ToArray();
                tabstrip.Dock           = DockStyle.Fill;
                tabstrip.DropDownWidth  = 500;
                tabstrip.DropDownHeight = 500;
                tabstrip.StripMode      = ExtendedControls.TabStrip.StripModeType.ListSelection;

                tabstrip.Tag  = tagid;                        // Tag stores the ID index of this view
                tabstrip.Name = Name + "." + tagid.ToStringInvariant();

                //System.Diagnostics.Debug.WriteLine("Make new tab control " + tabstrip.Name + " id "  + tagid + " of " + panelid );

                tabstrip.OnRemoving += (tab, ctrl) =>
                {
                    UserControlCommonBase uccb = ctrl as UserControlCommonBase;
                    uccb.Closing();
                    AssignTHC();        // in case we removed anything
                };

                tabstrip.OnCreateTab += (tab, si) =>
                {
                    PanelInformation.PanelInfo pi = PanelInformation.GetPanelInfoByPanelID((PanelInformation.PanelIDs)tab.TagList[si]); // must be valid, as it came from the taglist
                    Control c = PanelInformation.Create(pi.PopoutID);
                    c.Name = pi.WindowTitle;                                                                                            // tabs uses Name field for display, must set it

                    return(c);
                };

                tabstrip.OnPostCreateTab += (tab, ctrl, i) =>                       // only called during dynamic creation..
                {
                    int tabstripid           = (int)tab.Tag;                        // tag from tab strip
                    int displaynumber        = DisplayNumberOfSplitter(tabstripid); // tab strip - use tag to remember display id which helps us save context.
                    UserControlCommonBase uc = ctrl as UserControlCommonBase;

                    if (uc != null)
                    {
                        System.Diagnostics.Trace.WriteLine("SP:Make Tab " + tabstripid + " with dno " + displaynumber + " Use THC " + ucursor_inuse.GetHashCode());
                        uc.Init(discoveryform, displaynumber);
                        uc.SetCursor(ucursor_inuse);
                        uc.LoadLayout();
                        uc.InitialDisplay();
                    }

                    //System.Diagnostics.Debug.WriteLine("And theme {0}", i);
                    discoveryform.theme.ApplyToControls(tab);
                    AssignTHC();        // in case we added one
                };

                tabstrip.OnPopOut += (tab, i) => { discoveryform.PopOuts.PopOut((PanelInformation.PanelIDs)tabstrip.TagList[i]); };

                discoveryform.theme.ApplyToControls(tabstrip, applytothis: true);

                PanelInformation.PanelIDs[] pids = PanelInformation.GetPanelIDs();

                panelid = Array.FindIndex(pids, x => x == (PanelInformation.PanelIDs)panelid); // find ID in array..  -1 if not valid ID, it copes with -1

                if (panelid >= 0)                                                              // if we have a panel, open it
                {
                    tabstrip.Create(panelid);                                                  // create but not post create yet...
                }

                return(tabstrip);
            }
        }
Beispiel #11
0
        // if includeevent is set, it must be there..
        // demlimchars is normally space, but can be ") " if its inside a multi.

        public string Read(BaseUtils.StringParser sp, bool includeevent = false, string delimchars = " ")
        {
            Fields         = new List <ConditionEntry>();
            InnerCondition = OuterCondition = LogicalCondition.Or;
            EventName      = ""; Action = "";
            ActionVars     = new Variables();

            if (includeevent)
            {
                string actionvarsstr;
                if ((EventName = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                    (Action = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                    (actionvarsstr = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(','))
                {
                    return("Incorrect format of EVENT data associated with condition");
                }

                if (actionvarsstr.HasChars())
                {
                    ActionVars = new Variables(actionvarsstr, Variables.FromMode.MultiEntryComma);
                }
            }

            LogicalCondition?ic = null;

            while (true)
            {
                string var = sp.NextQuotedWord(delimchars);             // always has para cond
                if (var == null)
                {
                    return("Missing parameter (left side) of condition");
                }

                string cond = sp.NextQuotedWord(delimchars);
                if (cond == null)
                {
                    return("Missing condition operator");
                }

                ConditionEntry.MatchType mt;
                if (!ConditionEntry.MatchTypeFromString(cond, out mt))
                {
                    return("Condition operator " + cond + " is not recognised");
                }

                string value = "";

                if (ConditionEntry.IsNullOperation(mt)) // null operators (Always..)
                {
                    if (!var.Equals("Condition", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return("Condition must preceed fixed result operator");
                    }
                    var = "Condition";                         // fix case..
                }
                else if (!ConditionEntry.IsUnaryOperation(mt)) // not unary, require right side
                {
                    value = sp.NextQuotedWord(delimchars);
                    if (value == null)
                    {
                        return("Missing value part (right side) of condition");
                    }
                }

                ConditionEntry ce = new ConditionEntry()
                {
                    ItemName = var, MatchCondition = mt, MatchString = value
                };
                Fields.Add(ce);

                if (sp.IsEOL || sp.PeekChar() == ')')           // end is either ) or EOL
                {
                    InnerCondition = (ic == null) ? LogicalCondition.Or : ic.Value;
                    return("");
                }
                else
                {
                    LogicalCondition nic;
                    string           err = GetLogicalCondition(sp, delimchars, out nic);
                    if (err.Length > 0)
                    {
                        return(err + " for inner condition");
                    }

                    if (ic == null)
                    {
                        ic = nic;
                    }
                    else if (ic.Value != nic)
                    {
                        return("Cannot specify different inner conditions between expressions");
                    }
                }
            }
        }
Beispiel #12
0
 public string Read(string s, bool includeevent = false, string delimchars = " ")
 {
     BaseUtils.StringParser sp = new BaseUtils.StringParser(s);
     return(Read(sp, includeevent, delimchars));
 }
Beispiel #13
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);
        }
Beispiel #14
0
        static public 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
            {
                return("Unknown control type " + type);
            }

            string text = sp.NextQuotedWordComma();

            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;
            }

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

            lastpos = new System.Drawing.Point(x.Value, y.Value);
            return(null);
        }
Beispiel #15
0
        public string Read(BaseUtils.StringParser sp, bool includeevent = false, string delimchars = " ") // if includeevent is set, it must be there..
        {                                                                                                 // demlimchars is normally space, but can be ") " if its inside a multi.
            fields         = new List <ConditionEntry>();
            innercondition = outercondition = ConditionEntry.LogicalCondition.Or;
            eventname      = ""; action = ""; actiondata = "";

            if (includeevent)
            {
                if ((eventname = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                    (action = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                    (actiondata = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(','))
                {
                    return("Incorrect format of EVENT data associated with condition");
                }
            }

            ConditionEntry.LogicalCondition?ic = null;

            while (true)
            {
                string var = sp.NextQuotedWord(delimchars);             // always has para cond
                if (var == null)
                {
                    return("Missing parameter (left side) of condition");
                }

                string cond = sp.NextQuotedWord(delimchars);
                if (cond == null)
                {
                    return("Missing condition operator");
                }

                ConditionEntry.MatchType mt;
                if (!ConditionEntry.MatchTypeFromString(cond, out mt))
                {
                    return("Condition operator " + cond + " is not recognised");
                }

                string value = "";

                if (ConditionEntry.IsNullOperation(mt)) // null operators (Always..)
                {
                    if (!var.Equals("Condition", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return("Condition must preceed fixed result operator");
                    }
                    var = "Condition";                         // fix case..
                }
                else if (!ConditionEntry.IsUnaryOperation(mt)) // not unary, require right side
                {
                    value = sp.NextQuotedWord(delimchars);
                    if (value == null)
                    {
                        return("Missing value part (right side) of condition");
                    }
                }

                ConditionEntry ce = new ConditionEntry()
                {
                    itemname = var, matchtype = mt, matchstring = value
                };
                fields.Add(ce);

                if (sp.IsEOL || sp.PeekChar() == ')')           // end is either ) or EOL
                {
                    innercondition = (ic == null) ? ConditionEntry.LogicalCondition.Or : ic.Value;
                    return("");
                }
                else
                {
                    ConditionEntry.LogicalCondition nic;
                    string err = ConditionEntry.GetLogicalCondition(sp, delimchars, out nic);
                    if (err.Length > 0)
                    {
                        return(err + " for inner condition");
                    }

                    if (ic == null)
                    {
                        ic = nic;
                    }
                    else if (ic.Value != nic)
                    {
                        return("Cannot specify different inner conditions between expressions");
                    }
                }
            }
        }