示例#1
0
        public void Evaluate()
        {
            var files = DirectoryDescendentFilesEvaluator.Evaluate(Properties.Settings.Default.InspectionPath).Where(x => x.EndsWith(".css")).ToList();
            var count = files.Count;

            double oldPercentage = 0;
            var    i             = 0;

            var references = new List <string>();

            Parallel.ForEach(files, file =>
            {
                var line = File.ReadAllLines(file).Count(x => (x.Contains("url")));

                Interlocked.Increment(ref i);

                lock (Lock)
                {
                    if (line != 0)
                    {
                        references.Add(file.Replace(Properties.Settings.Default.InspectionPath, "") + ": " + line);
                    }

                    var newPercentage = (double)Math.Round((100m / count) * i);

                    if (newPercentage != oldPercentage)
                    {
                        Ux.UpdateProgress((int)newPercentage);
                        oldPercentage = newPercentage;
                    }
                }
            });

            Ux.WriteLine("Count: " + references.Count);
            foreach (var reference in references.OrderBy(x => x))
            {
                Ux.WriteLine(reference);
            }

            Ux.WriteLine("");

            Ux.ResetProgress();
        }
        public List <CssEvaluationResult> Present(List <string> files)
        {
            var results = new List <CssEvaluationResult>();

            var    i             = 0;
            var    count         = files.Count();
            double oldPercentage = 0;


            Parallel.ForEach(files, file =>
            {
                var contents = File.ReadAllLines(file);

                var result = CssValidationEvaluator.Evaluate(file, contents, false);
                if (result != null)
                {
                    results.Add(result);
                }

                Interlocked.Increment(ref i);

                lock (Lock)
                {
                    var newPercentage = (double)Math.Round((100m / count) * i);

                    if (newPercentage != oldPercentage /* && newPercentage % 5 == 0*/)
                    {
                        Ux.UpdateProgress((int)newPercentage);
                        oldPercentage = newPercentage;
                    }
                }
            });

            Ux.WriteLine(string.Format("Total number of files: {0}", results.Count()));
            Ux.WriteLine(string.Format("<style type='text/css'> declarations: {0}", results.Sum(x => x.Page.Count)));
            Ux.WriteLine(string.Format("<style type='text/css'> lines of code: {0}", results.Sum(x => x.Page.Sum(y => y))));
            Ux.WriteLine(string.Format("<div style='...'> declarations: {0}", results.Sum(x => x.Inline.Count)));
            Ux.WriteLine(string.Format("Razor declarations: {0}", results.Sum(x => x.Razor.Count)));
            Ux.ResetProgress();

            return(results);
        }
        public List <JavaScriptEvaluationResult> Present(List <string> files)
        {
            var results = new List <JavaScriptEvaluationResult>();

            var    count         = files.Count();
            var    i             = 0;
            double oldPercentage = 0;
            double newPercentage;

            var attributes = JsAttributesProvider.Attributes.ToList();

            if (true)
            {
                Parallel.ForEach(files, file =>
                {
                    var contents = File.ReadAllLines(file);

                    var result = JsValidationEvaluator.Evaluate(file, contents, attributes, false);
                    if (result != null)
                    {
                        results.Add(result);
                    }

                    Interlocked.Increment(ref i);

                    lock (LockTarget)
                    {
                        newPercentage = (double)Math.Round((100m / count) * i);

                        if (newPercentage != oldPercentage /* && newPercentage % 5 == 0*/)
                        {
                            Ux.UpdateProgress((int)newPercentage);
                            oldPercentage = newPercentage;
                        }
                    }
                });
            }
            else
            {
                foreach (var result in from file in files let contents = File.ReadAllLines(file) select JsValidationEvaluator.Evaluate(file, contents, attributes, false))
                {
                    if (result != null)
                    {
                        results.Add(result);
                    }

                    i++;
                    newPercentage = (double)Math.Round((100m / count) * i);

                    if (newPercentage != oldPercentage /* && newPercentage % 5 == 0*/)
                    {
                        Ux.UpdateProgress((int)newPercentage);
                        oldPercentage = newPercentage;
                    }
                }
            }

            var comparer = StringComparer.OrdinalIgnoreCase;

            Ux.WriteLine(string.Format("Total number of files: {0}", results.Count()));
            Ux.WriteLine(string.Format("Total <script type='text/javascript'> declarations: {0}", results.Sum(x => x.PageInstances.Length)));
            Ux.WriteLine(string.Format("Total <script type='text/javascript'> lines of code: {0}", results.Sum(x => x.PageInstances.Sum(y => y.Lines.Count))));
            Ux.WriteLine(string.Format("Total <script type='text/javascript'> lines of code containing '@': {0}", results.Sum(x => x.PageInstances.Sum(y => y.AtSymbols))));
            Ux.WriteLine(string.Format("Total <div onSomeEvent='...'> declarations: {0}", results.Sum(x => x.Block.Sum(y => y.InlineJavascriptTags.Count))));

            foreach (var attr in attributes.Where(tag => results.Any(x => x.Block.Any(y => comparer.Equals(y.AttributeName, tag)))))
            {
                Ux.WriteLine(string.Format("Total html {0} instances: {1}", attr, results.Sum(x => x.Block.Count(y => comparer.Equals(y.AttributeName, attr)))));
            }

            Ux.WriteLine(string.Format("Total Razor declarations: {0}", results.Sum(x => x.Razor.Count)));
            foreach (var attr in attributes.Where(tag => results.Any(x => x.Razor.Any(y => comparer.Equals(y.AttributeName, tag)))))
            {
                Ux.WriteLine(string.Format("Total razor {0} instances: {1}", attr, results.Sum(x => x.Razor.Count(y => comparer.Equals(y.AttributeName, attr)))));
            }

            Ux.ResetProgress();

            return(results);
        }