private static bool PropertyRead(ConfigResource resource, PropertyType propertyType, Queue<string> keyQueue, string key, string val)
        {
            bool success = false;
            if (config != null)
            {
                switch (propertyType)
                {
                    case PropertyType.Property:
                        success = true;
                        ApplyProperty(keyQueue, key, val);
                        break;
                    case PropertyType.If:
                        if (config.Properties.ContainsKey(val))
                        {
                            success = !Convert.ToBoolean(config.Properties[val]);
                        }
                        break;
                    case PropertyType.Import:
                        ConfigResource res = resource.GetLocalConfigResource(string.Format(@"{0}.properties", val));
                        success = res.Exists;
                        break;
                }
            }

            return success;
        }
 public static void Populate(IScintillaConfig scintillaConfig, ConfigResource resource)
 {
     config = scintillaConfig;
     if (config != null)
     {
         PropertiesReader.Read(resource, PropertyRead);
     }
 }
Exemplo n.º 3
0
 private ConfigResource GetResource(string filename)
 {
     ConfigResource res = null;
     if (directory != null)
     {
         FileInfo fileInfo = new FileInfo(directory.FullName + "\\" + filename);
         res = new ConfigResource(fileInfo);
     }
     else if ((resourceAssembly != null) && (resourcePath != null))
     {
         res = new ConfigResource(resourceAssembly, resourcePath, filename);
     }
     return res;
 }
Exemplo n.º 4
0
 private void comboBoxSample_SelectedIndexChanged(object sender, EventArgs e)
 {
     string lang = this.comboBoxSample.SelectedItem.ToString();
     this.scintillaControlSample.ConfigurationManager.Language = lang;
     
     ConfigResource resource = new ConfigResource(System.Reflection.Assembly.GetExecutingAssembly(), "Scintilla.Configuration.Samples", lang);
     if (resource.Exists)
     {
         StreamReader reader = new StreamReader(resource.OpenRead());
         this.scintillaControlSample.Text = reader.ReadToEnd();
         reader.Close();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="propsFileInfo"></param>
        /// <param name="propertyRead"></param>
        public static void Read(ConfigResource resource, PropertyReadDelegate propertyRead)
        {
            if (!resource.Exists) return;
            StreamReader reader = new StreamReader(resource.OpenRead());

            char c = ' ', prev = '\\';
            int lastStart = 0, ignoreCount = 0;
            bool ignoreProperties = false;
            string key = null, var = null;
            StringBuilder currentVar = new StringBuilder();
            StringBuilder currentToken = new StringBuilder();

            Queue<string> queue = new Queue<string>();
            StringBuilder currentTokenPiece = new StringBuilder();

            ReadMode mode = ReadMode.Key;
            ReadMode nextModeAfterSpaces = ReadMode.Key;

            string line = reader.ReadLine();
            while (line != null)
            {
                int start = 0;
                bool skipLine = false;

                while ((start < line.Length) && char.IsWhiteSpace(line[start])) ++start;

                if (start >= line.Length)
                {
                    propertyRead(resource, PropertyType.EmptyLine, queue, string.Empty, string.Empty);
                }
                else if (line[start] == '#')
                {
                    propertyRead(resource, PropertyType.Comment, queue, "#", line);
                }
                else
                {
                    if (ignoreProperties)
                    {
                        if ((ignoreCount == 0) || (start == lastStart))
                        {
                            ignoreCount++;
                            lastStart = start;
                            skipLine = true;
                        }
                        else
                        {
                            ignoreCount = 0;
                            ignoreProperties = false;
                        }
                    }

                    if (skipLine)
                    {
                        propertyRead(resource, PropertyType.EmptyLine, queue, string.Empty, string.Empty);
                    }
                    else
                    {
                        for (int i = start; i < line.Length; i++)
                        {
                            c = line[i];

                            if (mode == ReadMode.Key)
                            {
                                if (c == '=')
                                {
                                    if (currentTokenPiece.Length > 0)
                                    {
                                        queue.Enqueue(currentTokenPiece.ToString());
                                    }

                                    currentTokenPiece.Remove(0, currentTokenPiece.Length);

                                    key = currentToken.ToString();
                                    currentToken.Remove(0, currentToken.Length);

                                    mode = ReadMode.Value;
                                    continue;
                                }
                                else if (char.IsWhiteSpace(c))
                                {
                                    key = currentToken.ToString();
                                    currentToken.Remove(0, currentToken.Length);
                                    currentTokenPiece.Remove(0, currentTokenPiece.Length);

                                    if (key == "if")
                                    {
                                        nextModeAfterSpaces = ReadMode.If;
                                    }
                                    else if (key == "import")
                                    {
                                        nextModeAfterSpaces = ReadMode.Import;
                                    }
                                    else
                                    {
                                        break;
                                    }

                                    mode = ReadMode.FlushWhiteSpace;
                                    continue;
                                }
                                else if (c == '.')
                                {
                                    currentToken.Append(c);

                                    queue.Enqueue(currentTokenPiece.ToString());
                                    currentTokenPiece.Remove(0, currentTokenPiece.Length);
                                }
                                else
                                {
                                    currentTokenPiece.Append(c);
                                    currentToken.Append(c);
                                }
                            }
                            else if (mode == ReadMode.FlushWhiteSpace)
                            {
                                if (!char.IsWhiteSpace(c))
                                {
                                    currentToken.Append(c);
                                    mode = nextModeAfterSpaces;
                                }
                            }
                            else if (mode == ReadMode.Import)
                            {
                                currentToken.Append(c);
                            }
                            else if (mode == ReadMode.If)
                            {
                                currentToken.Append(c);
                            }
                            else if (mode == ReadMode.Value)
                            {
                                currentToken.Append(c);
                            }
                            prev = c;
                        }

                        if (prev != '\\')
                        {
                            var = currentToken.ToString();
                            if (mode == ReadMode.If)
                            {
                                ignoreProperties = propertyRead(resource, PropertyType.If, queue, key, var);
                            }
                            else if (mode == ReadMode.Import)
                            {
                                // Open another file inline with this one.
                                if (propertyRead(resource, PropertyType.Import, queue, key, var))
                                {
                                    ConfigResource res = resource.GetLocalConfigResource(string.Format(@"{0}.properties", var));
                                    //success = res.Exists;
                                    //FileInfo fileToImport = new FileInfo(string.Format(@"{0}\{1}.properties", propsFileInfo.Directory.FullName, var));
                                    if (res.Exists)
                                    {
                                        Read(res, propertyRead);
                                    }
                                }
                            }
                            else if (mode == ReadMode.Value)
                            {
                                propertyRead(resource, PropertyType.Property, queue, key, var);
                            }
                            currentToken.Remove(0, currentToken.Length);
                            queue.Clear();
                            key = null;
                            mode = ReadMode.Key;
                        }
                        else
                        {
                            currentToken.Remove(currentToken.Length - 1, 1);
                        }
                    }
                }
                line = reader.ReadLine();
            }
            reader.Close();

            if (key != null)
            {
                var = currentToken.ToString();
                propertyRead(resource, PropertyType.Property, queue, key, var);
            }
        }