예제 #1
0
        protected override void GetCount()
        {
            string[] folders = Directory.GetDirectories(this.File);
            foreach (string folder in folders)
            {
                CodeFolder codeFolder = new CodeFolder();
                codeFolder.File = folder;
                codeFolder.Parent = this;
            }

            string[] files = Directory.GetFiles(this.File, "*.*", SearchOption.TopDirectoryOnly);
            foreach (string file in files)
            {
                AbstractCodeFile codeFile = CodeFileFactory.Create(file);
                if (null != codeFile)
                {
                    codeFile.Parent = this;
                }
            }

            foreach (AbstractCodeFile codeFile in this.IncludeFiles)
            {
                codeFile.Count();
                //OnProgress(codeFile);
            }
        }
예제 #2
0
        public static AbstractCodeFile Create(string file)
        {
            AbstractCodeFile codeFile = null;

            FileInfo info = new FileInfo(file);
            if ((info.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
            {
                codeFile = new CodeFolder();
            }
            else
            {
                string ext = Path.GetExtension(file).ToLower();

                if (counterDict.ContainsKey(ext))
                {
                    codeFile = Activator.CreateInstance(counterDict[ext]) as AbstractCodeFile;
                }
                else
                {
                    codeFile = FindType(ext);
                }

                if (null == codeFile)
                {
                    counterDict.Add(ext, typeof(NormalCodeFile));
                    codeFile = new NormalCodeFile();
                }
            }

            codeFile.File = file;

            return codeFile;
        }
예제 #3
0
        private void CountFile(XmlNodeList csNodeList)
        {
            string fileDir = Path.GetDirectoryName(this.File);
            foreach (XmlNode node in csNodeList)
            {
                string fileName = node.Attributes["Include"].Value;
                string file = Path.Combine(fileDir, fileName);

                if (System.IO.File.Exists(file))
                {
                    string[] fileNamePart = fileName.Split('\\');
                    string key = string.Empty;
                    for (int i = 0; i < fileNamePart.Length - 1; i++)
                    {
                        key = string.Join("\\", fileNamePart, 0, i + 1);
                        if (!this.codeFileDict.ContainsKey(key))
                        {
                            CodeFolder codeFolder = new CodeFolder();
                            codeFolder.File = fileNamePart[i];
                            this.codeFileDict.Add(key, codeFolder);
                            if (0 == i)
                            {
                                codeFolder.Parent = this;
                            }
                            else
                            {
                                codeFolder.Parent = this.codeFileDict[Path.GetDirectoryName(key)];
                            }
                        }
                    }

                    AbstractCodeFile codeFile = CodeFileFactory.Create(file);
                    if (null != codeFile)
                    {
                        if (this.codeFileDict.ContainsKey(key))
                        {
                            codeFile.Parent = this.codeFileDict[key];
                        }
                        else
                        {
                            codeFile.Parent = this;
                        }
                    }
                }
            }

            foreach (AbstractCodeFile codeFile in this.IncludeFiles)
            {
                codeFile.Count();
            }
        }