Beispiel #1
0
        private void btnFromString_Click(object sender, EventArgs e)
        {
            SimpleD.Group MainGroup = new SimpleD.Group();
            //Open from the string.
            txtErrors.Text = MainGroup.FromString(txtData.Text);

            try
            {
                //Get The Group
                Group TheGroup = MainGroup.GetGroup("the group"); //Names are not case sensitive.

                //Get the value from the group.
                TextBox1.Text = TheGroup.GetValue(TextBox1.Name);

                //Get sub group.
                Group SubGroup = TheGroup.GetGroup("SubGroup");
                CheckBox1.Checked =bool.Parse(SubGroup.GetValue("The check box"));

                //Get the other group.
                Group OtherGroup = MainGroup.GetGroup("OtherGroup");
                NumericUpDown1.Value = Decimal.Parse(OtherGroup.GetValue(NumericUpDown1.Name));

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"Error");
            }
        }
Beispiel #2
0
        private void btnToString_Click(object sender, EventArgs e)
        {
            SimpleD.Group MainGroup = new SimpleD.Group();

            //The Group
            Group TheGroup = MainGroup.CreateGroup("The Group"); //Create group inside MainGroup.
            TheGroup.SetValue(TextBox1.Name, TextBox1.Text);

            //Sub group
            Group SubGroup = TheGroup.CreateGroup("SubGroup"); //Create the sub group from 'The Group'
            SubGroup.SetValue("The check box", CheckBox1.Checked.ToString()); //Yes there can be spaces in group and property names.

            //Other group    There is nothing new here.
            Group OtherGroup = MainGroup.CreateGroup("OtherGroup");
            OtherGroup.BraceStyle = Group.Style.NoStyle; //Set the style.
            OtherGroup.SetValue(NumericUpDown1.Name, NumericUpDown1.Value.ToString());

            //Save to the data text box.
            txtData.Text = MainGroup.ToString();
        }
Beispiel #3
0
        private void fromStringBase(bool isFirst, string data, ref int index, ref int line, ref StringBuilder Results)
        {
            if (data == "")
            {
                Results.Append("Data is empty!");
                return;
            }

            byte State = 0; //0 = Get name    1 = In property   2 = Finish comment

            int StartLine = line;
            int ErrorLine = 0;
            StringBuilder sbName = new StringBuilder();
            StringBuilder sbValue = null;

            while (index < data.Length)
            {
                Char chr = data[index];

                switch (State)
                {
                    case 0://Get name

                        switch (chr)
                        {
                            case '=':
                                sbValue = new StringBuilder();
                                ErrorLine = line;
                                State = 1; //Get property value
                                break;

                            case ';':
                                String tName = sbName.ToString().Trim();
                                if (tName == "")
                                {
                                    Results.Append(" #Found end of property but no name at line: " + line + " Could need AllowSemicolonInValue enabled.");
                                }
                                else
                                {
                                    Properties.Add(new Property(tName, ""));
                                }
                                sbName = new StringBuilder();
                                break;

                            case '{': //New group
                                ++index;
                                Group newGroup = new Group(sbName.ToString().Trim());
                                newGroup.fromStringBase(false, data, ref index, ref line, ref Results);
                                if (Info.AllowEmpty || !newGroup.IsEmpty()) Groups.Add(newGroup);
                                sbName = new StringBuilder();
                                break;

                            case '}': //End current group
                                return;

                            case '/': //Start of comment
                                if (index + 1 < data.Length && data[index + 1] == '*')
                                {
                                    State = 2;
                                    ErrorLine = line;
                                    break;
                                }
                                sbName.Append(chr); //Don't start comment.
                                break;

                            default:
                                sbName.Append(chr);
                                break;
                        }
                        break;

                    case 1: //Get propergy value
                        if (chr == ';')
                        {
                            if (Info.AlllowSemicolonInValue && index + 1 < data.Length && data[index + 1] == ';')
                            {
                                ++index;
                            }
                            else
                            {
                                Property newProp = new Property(sbName.ToString().Trim(), sbValue.ToString());
                                if (Info.AllowEmpty || !newProp.IsEmpty()) Properties.Add(newProp);
                                sbName = new StringBuilder();
                                sbValue = null;
                                State = 0;
                                break;
                            }
                        }
                        else if (chr == '=' && !Info.AllowEqualsInValue) //Should there be = in value?
                        {
                            Results.Append("  #Missing end of property " + sbName.ToString().Trim() + " at line: " + ErrorLine);
                            ErrorLine = line;
                            sbName = new StringBuilder();
                            sbValue = null;
                            break;
                        }

                        sbValue.Append(chr);
                        break;

                    case 2: //Finsh comment
                        if (chr == '/' && data[index - 1] == '*')
                        {
                            State = 0;
                        }
                        break;
                }

                if (chr == "\n"[0]) ++line;
                ++index;
            }

            if (State == 1)
            {
                String tName = sbName.ToString().Trim();
                if (Info.AllowEmpty || tName != "") Properties.Add(new Property(tName, sbValue.ToString()));
                Results.Append(" #Missing end of property " + tName + " at line: " + ErrorLine);
            }
            else if (State == 2)
            {
                Results.Append(" #Missing end of comment " + sbName.ToString().Trim() + " at line: " + ErrorLine);
            }
            else if (!isFirst) //The base group does not need to be ended.
            {
                Results.Append("  #Missing end of group " + Name + " at line: " + ErrorLine);
            }
        }
Beispiel #4
0
 /// <summary>Creats new group and calls FromString(). Note: There is no way to check for errors.</summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static Group Parse(string data)
 {
     Group g = new Group();
     g.FromString(data);
     return g;
 }