Exemplo n.º 1
0
 static PackageInfoFields()
 {
     fields = new List <string>();
     foreach (string s in AApiVersionedFields.GetContentFields(0, typeof(APackage)))
     {
         if (!s.Contains("Stream") && !s.Contains("List"))
         {
             fields.Add(s);
         }
     }
 }
Exemplo n.º 2
0
        static void ReadConfig()
        {
            keywords.AddRange(reserved.ToArray());
            keywords.AddRange(AApiVersionedFields.GetContentFields(0, typeof(IResourceKey)).ToArray()); // must be correct case

            helpers = new Dictionary <string, Dictionary <string, string> >();

            // Parse *.helper in Helpers/ in folder where this assembly lives.

            string folder = Path.Combine(Path.GetDirectoryName(typeof(HelperManager).Module.FullyQualifiedName), "Helpers");

            foreach (string file in Directory.GetFiles(folder, "*.helper"))
            {
                StreamReader sr = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read));
                Dictionary <string, string> target = new Dictionary <string, string>();
                target.Add("file", Path.GetFileNameWithoutExtension(file));

                bool inCommentBlock = false;

                for (string s = sr.ReadLine(); s != null; s = sr.ReadLine())
                {
                    s = s.Trim();

                    #region Comments
                    if (inCommentBlock)
                    {
                        int i = s.IndexOf("*/");
                        if (i > -1)
                        {
                            s = s.Substring(i + 2).Trim();
                            inCommentBlock = false;
                        }
                    }

                    string[] commentMarks = { "#", ";", "//" };
                    for (int i = 0; s.Length > 0 && i < commentMarks.Length; i++)
                    {
                        int j = s.IndexOf(commentMarks[i]);
                        if (j > -1)
                        {
                            s = s.Substring(0, j).Trim();
                        }
                    }

                    if (inCommentBlock || s.Length == 0)
                    {
                        continue;
                    }

                    if (s.Contains("/*"))
                    {
                        s = s.Substring(0, s.IndexOf("/*")).Trim();
                        inCommentBlock = true;
                    }
                    #endregion

                    string[] headtail = s.Trim().Split(new char[] { ':', '=' }, 2);
                    if (headtail.Length != 2)
                    {
                        continue;
                    }
                    string keyword = headtail[0].Trim();
                    if (reserved.Contains(keyword.ToLower()))
                    {
                        keyword = keyword.ToLower();
                    }
                    if (!keywords.Contains(keyword))
                    {
                        continue;
                    }
                    if (target.ContainsKey(keyword))
                    {
                        continue;
                    }
                    target.Add(keyword, headtail[1].Trim());
                }

                sr.Close();

                if (target.Count > 0 && target.ContainsKey("command"))
                {
                    helpers.Add(Path.GetFileNameWithoutExtension(file), target);
                }
            }
        }