Esempio n. 1
0
        static void _Work_old()
        {
            // 项目中所有的文件
            int i = 0;

            foreach (Project project in ProjectManager.Projects)
            {
                var files = project.Root.SubFiles2;

                var tags = TagParser.Parse(files.ToArray());

                //var tags = new List<ITag>();
                //foreach (string file in files)
                //{
                //    var t = TagParser.Parse(new string[] { file, });
                //    if (t != null && t.Count > 0)
                //        tags.AddRange(t);
                //    Thread.Sleep(5);
                //}

                if (tags != null)
                {
                    TagCache.Add(i, tags.ToArray());
                }
                ++i;
            }

            while (true)
            {
                DateTime current = DateTime.Now;

                try
                {
                    Dictionary <string, Pair <Language, int> > t = null;
                    List <Pair <string[], int> > f = null;
                    lock (typeof(TagUpdater))
                    {
                        if (_ChangedFiles.Count > 0)
                        {
                            t             = _ChangedFiles;
                            _ChangedFiles = new Dictionary <string, Pair <Language, int> >();
                        }
                        if (_DeletedFiles.Count > 0)
                        {
                            f             = _DeletedFiles;
                            _DeletedFiles = new List <Pair <string[], int> >();
                        }
                    }

                    if (f != null)
                    {
                        foreach (var obj in f)
                        {
                            string[] files = obj.First;
                            if (files != null)
                            {
                                TagCache.Remove(obj.Second, files);
                            }
                        }
                    }

                    if (t != null)
                    {
                        foreach (string file in t.Keys)
                        {
                            List <ITag> lst;
                            if (t[file].First == Language.Other)
                            {
                                lst = TagParser.Parse(new string[] { file });
                            }
                            else
                            {
                                lst = TagParser.Parse(t[file].First, file);
                            }
                            TagCache.Update(t[file].Second, file, lst);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utility.Debug("TagUpdater Work Thread Error: {0}\n{1}", ex.Message, ex.StackTrace);
                }

                var d = DateTime.Now - current;
                if (d.TotalSeconds < 1)
                {
                    Thread.Sleep((int)(1 - d.TotalSeconds) * 1000);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Force the use of a language to parse the source file to generate tags
        /// </summary>
        /// <param name="lang"></param>
        /// <param name="sourceFiles"></param>
        /// <returns></returns>
        public static List <ITag> Parse(Language lang, params string[] sourceFiles)
        {
            if (sourceFiles.Length == 0)
            {
                return(new List <ITag>());
            }
            if (!_Parsers.ContainsKey(lang))
            {
                return(new List <ITag>());
            }

            if (File.Exists(_TempFile))
            {
                File.Delete(_TempFile);
            }
            TagParser parser = _Parsers[lang];
            string    args   = parser.Args;
            {
                string language = lang.ToString();
                if (lang == Language.Cpp)
                {
                    language = "C++";
                }
                else if (lang == Language.CSharp)
                {
                    language = "C#";
                }
                else
                {
                    language = lang.ToString();
                }

                if (args.ToLower().IndexOf("--language-force") == -1)
                {
                    args += " --language-force=" + language;
                }
            }
            StringBuilder sb = new StringBuilder();

            foreach (string file in sourceFiles)
            {
                sb.AppendFormat("\"{0}\" ", file);
            }
            args = string.Format("{0} -f \"{1}\"  {2}", args, _TempFile, sb.ToString());
            string stdout = _ExecuteCtag(args);

            if (!File.Exists(_TempFile))
            {
                return(new List <ITag>());
            }

            List <ITag> lst = new List <ITag>();

            foreach (string line in File.ReadAllLines(_TempFile))
            {
                ITag tag = parser.Parse(line);
                if (tag != null)
                {
                    lst.Add(tag);
                }
            }
            File.Delete(_TempFile);
            return(lst);
        }