Пример #1
0
        public void EqualsTest()
        {
            Stream cs1Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt");

            StreamReader cs1Reader = new StreamReader(cs1Stream);
            string cs1Text = cs1Reader.ReadToEnd();

            CsParser cs1Parser = new CsParser();
            ParseResult cs1Result = cs1Parser.Parse(cs1Text);
            Entity cs1Entity1 = new Entity(cs1Result, DateTime.Now, 1);
            Entity cs1Entity2 = new Entity(cs1Result, DateTime.Now, 2);
            Entity cs1Entity3 = new Entity(cs1Result, DateTime.Now, 1);

            Stream cs2Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt");
            StreamReader cs2Reader = new StreamReader(cs2Stream);
            string cs2Text = cs2Reader.ReadToEnd();

            CsParser cs2Parser = new CsParser();
            ParseResult cs2Result = cs2Parser.Parse(cs2Text);
            Entity cs2Entity1 = new Entity(cs2Result, DateTime.Now, 1);
            Entity cs2Entity2 = new Entity(cs2Result, DateTime.Now, 2);

            Assert.AreNotEqual(cs2Entity2, cs2Entity1);
            Assert.AreNotEqual(cs1Entity2, cs1Entity1);
            Assert.AreEqual(cs1Entity1, cs1Entity3);
        }
Пример #2
0
        /// <summary>
        /// Creates a collection of entities from a collection go IFiles.
        /// </summary>
        /// <returns>The entities.</returns>
        /// <param name="files">Files.</param>
        public static EntityCollection MakeEntities(IEnumerable<IFile> files)
        {
            EntityCollection entities = new EntityCollection();

            ParallelOptions parallelOptions = new ParallelOptions
            {
                    MaxDegreeOfParallelism = 8
            };

            switch (CheckProjectType(files))
            {
                case ProjectType.CSharp:
                    CsParser csParser = new CsParser();
                    Parallel.ForEach(files.Where(x => Path.GetExtension(x.Path) == ".cs"), parallelOptions, item => {
                        entities.Add(csParser.Parse(item), item.Date.DateTime, item.Revisions);
                    });
                    break;

                case ProjectType.Unicon:
                    IcnParser icnParser = new IcnParser();
                    Parallel.ForEach(files.Where(x => Path.GetExtension(x.Path) == ".icn"), parallelOptions, item => {
                        entities.Add(icnParser.Parse(item), item.Date.DateTime, item.Revisions);
                    });
                    break;

                case ProjectType.Java:
                    JavaParser javaParser = new JavaParser();
                    Parallel.ForEach(files.Where(x => Path.GetExtension(x.Path) == ".java"), parallelOptions, item => {
                        entities.Add(javaParser.Parse(item), item.Date.DateTime, item.Revisions);
                    });
                    break;
            }

            return entities;
        }