Ejemplo n.º 1
0
        public static PluginProperty ReadSettingsProperty(string typeLine, string settingLine)
        {
            //Get type and setting data

            string[] words = settingLine.Split(
                new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries
                );
            string settingType  = typeLine.Replace("//@", "").Trim();
            string settingName  = words[1];
            string settingValue = words[3].Replace(";", "").Trim();

            PluginProperty pp = null;

            //Handle type

            switch (settingType)
            {
            //String setting property

            case "string":
                string stringValue = "";

                for (int w = 3; w < words.Length; w++)
                {
                    if (words[w].IndexOf('\'') != -1)
                    {
                        stringValue += (w > 3 ? " " : "") + words[w].Replace("'", "").Replace(";", "").Trim();
                    }
                    else
                    {
                        break;
                    }
                }
                pp = new PluginStringProperty(settingName, stringValue);
                break;

            //Number setting property

            case "number":
                pp = new PluginNumberProperty(settingName, double.Parse(settingValue));
                break;

            //Bool setting property

            case "bool":
                string boolValue = settingValue[0].ToString().ToUpper() + settingValue.ToLower().Substring(1, settingValue.Length - 1);
                pp = new PluginBoolProperty(settingName, bool.Parse(boolValue));
                break;
            }

            return(pp);
        }
Ejemplo n.º 2
0
        public static PluginProperty ReadProperty(string line)
        {
            try
            {
                PluginProperty result = null;

                //Read property values

                string[] words = line.Replace("//@", "").Split(
                    new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries
                    );

                //Check if valid property

                if (words.Length <= 1)
                {
                    return(null);
                }

                //Read property data

                string propertyType = words[0].ToLower();
                string propertyName = words[1];
                string propertyValue;

                //Handle p

                switch (propertyType)
                {
                //Number property

                case "number":
                    propertyValue = words[2];

                    result = new PluginNumberProperty(
                        propertyName,
                        double.Parse(propertyValue)
                        );
                    break;

                //Bool property

                case "bool":
                    propertyValue = words[2][0].ToString().ToUpper() + words[2].ToLower().Substring(1, words[2].Length - 1);

                    result = new PluginBoolProperty(
                        propertyName,
                        bool.Parse(propertyValue)
                        );
                    break;

                //String property

                case "string":
                    propertyValue = "";

                    for (int w = 2; w < words.Length; w++)
                    {
                        if (words[w].IndexOf('\"') != -1)
                        {
                            propertyValue += (w > 2 ? " " : "") + words[w].Replace("\"", "");
                        }
                        else
                        {
                            break;
                        }
                    }

                    result = new PluginStringProperty(
                        propertyName,
                        propertyValue
                        );
                    break;
                }

                return(result);
            }
            catch (Exception exc)
            {
                Logger.Error("Could not load plugin property: ", exc);
                return(null);
            }
        }