public void Split(string refactorPath, string generatedFilesPath, string[] filesToRefactor)
        {
            var failedFiles       = new List <string>();
            var avoidedOverWrites = new List <string>();
            var filesCreated      = 0;

            for (var i = 0; i < filesToRefactor.Length; i++)
            {
                var file    = filesToRefactor[i];
                var newPath = DirectoryMimicker.Mimick(refactorPath, generatedFilesPath, file);

                SeperatedJs seperatedJs;

                //Ux.WriteLine(string.Format("Processing item {0}", i.ToString(CultureInfo.InvariantCulture)));

                try
                {
                    seperatedJs = AdvancedJsSeperationService.Evaluate(File.ReadAllLines(file), Properties.Settings.Default.SolutionPath, newPath, file, false);
                }
                catch (Exception e)
                {
                    //Ux.WriteLine(string.Format("{0} ({1})", e.Message, file));
                    failedFiles.Add(file + e.Message);
                    continue;
                }

                SplitJsFileCreator.Create(seperatedJs, newPath, avoidedOverWrites, ref filesCreated, file, false);
            }

            Ux.WriteLine(string.Format("Refactored {0} files", filesCreated));

            JsRefactorResultsPresenter.Present(failedFiles, avoidedOverWrites);
        }
        /// <summary>
        /// Evaluates css for a group of files
        /// </summary>
        /// <param name="numberOfGroups"></param>
        /// <param name="directories"></param>
        /// <param name="specificGroup">Not zero indexed - 1 means group 1, 0 means all</param>
        public void Evaluate(int numberOfGroups, string[] directories, int specificGroup)
        {
            var groupedFilesViewModels = DirectoryGroupEvaluator.Evaluate(numberOfGroups, directories);

            var groupedResults = new List <List <CssEvaluationResult> >();

            var i = 1;

            foreach (var fileList in groupedFilesViewModels)
            {
                if (specificGroup == 0 || i == specificGroup)
                {
                    Ux.WriteLine(string.Format("Group{0} ({1} - {2})", i, fileList.StartDir, fileList.EndDir));
                    groupedResults.Add(CssStatsPresenter.Present(fileList.Files));
                    Ux.WriteLine("");
                    ScrollDown(null, null);
                }
                i++;
            }

            Ux.DisplayBoolOption("Store detailed CSS results to disk?", () =>
            {
                i = 1;
                foreach (var resultGroup in groupedResults)
                {
                    CssStatsStorageService.Store(resultGroup, string.Format("Group {0}", specificGroup > 0 ? specificGroup : i));
                    ScrollDown(null, null);
                    i++;
                }
                //FolderPresenter.Present(Properties.Settings.Default.ResultsPath);
            }, null);

            Ux.WriteLine("");
        }
        public void View(List <string> files)
        {
            if (Directory.Exists(Properties.Settings.Default.InspectionPath))
            {
                var results = JavaScriptStatsPresenter.Present(FilteredFilesEvaluator.Evaluate(files));
                Ux.DisplayBoolOption("Store detailed JavaScript results to disk?", () => CssJavaScriptStorageService.Store(results, string.Empty), null);

                Ux.WriteLine("");
            }
            else
            {
                MessageBox.Show("Invalid Directory");
            }
        }
예제 #4
0
        public void View(List <string> files)
        {
            if (PathExistenceEvaluator.Evaluate(Properties.Settings.Default.InspectionPath))
            {
                var results = CssStatsPresenter.Present(FilteredFilesEvaluator.Evaluate(files));
                Ux.DisplayBoolOption("Store detailed CSS results to disk?", () =>
                {
                    var filename = CssStatsStorageService.Store(results, string.Empty);
                    //FilePresenter.Present(filename);
                }, null);

                Ux.WriteLine("");
            }
            else
            {
                MessageBox.Show("Please specify the results folder first.", "Invalid Directory");
            }
        }
예제 #5
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);
        }
예제 #7
0
        public void Execute()
        {
            SettingsValidator.Validate();

            var directory = SettingsEvaluator.GetApTwoDirectory();

            var files = DirectoryDescendentFilesEvaluator.Evaluate(directory).OrderBy(x => x).ToList();

            var loop = true;

            while (loop)
            {
                Ux.WriteLine(string.Format("Analysing: {0}", directory));

                Ux.AddOption("Exit", () => loop = false);

                Ux.AddOptionWithHeadingSpace("View all file extensions", () => FileExtensionPresenter.Present(files));
                Ux.AddOption("View all files", () => ListPresenter.Present(files));
                Ux.AddOption("View filtered extensions", () => FilteredFilesPresenter.PresentFilteredExtensions());
                Ux.AddOption("View filtered files", () => FilteredFilesPresenter.PresentFilteredFiles(files));
                Ux.AddOption("View filtered file statistics", () => FilteredFilesStatsPresenter.Present(files));

                Ux.AddOptionWithHeadingSpace("Count inline CSS on filtered files", () =>
                {
                    var results = CssStatsPresenter.Present(FilteredFilesEvaluator.Evaluate(files));
                    Ux.DisplayBoolOption("Store detailed CSS results to disk?", () => CssStatsStorageService.Store(results, string.Empty), null);
                });

                Ux.AddOptionWithHeadingSpace("Count inline Javascript on filtered files", () =>
                {
                    var results = JavaScriptStatsPresenter.Present(FilteredFilesEvaluator.Evaluate(files));
                    Ux.DisplayBoolOption("Store detailed JavaScript results to disk?", () => JavaScriptStatsStorageService.Store(results, string.Empty), null);
                });

                Ux.AddOptionWithHeadingSpace("Count inline Javascript and CSS on specific file...", () => JavaScriptFileStatsPresenter.Present());

                Ux.DisplayOptions("Please choose an option");
            }
        }
        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);
        }
예제 #9
0
        public string Store(List <JavaScriptEvaluationResult> results, string groupName)
        {
            var attributeTotals = new List <AttributeTotal>();

            var sb = new StringBuilder();

            sb.Append("Filename,Inline Instances,Total Inline LOC, Contains '@'");

            var comparer = StringComparer.OrdinalIgnoreCase;

            var attributesInUse = RelevantAttributesEvaluator.Evaluate(results);

            foreach (var attribute in attributesInUse)
            {
                sb.AppendFormat(",{0}", attribute);
            }

            sb.AppendLine(",Total Inline Instances,Total Razor Instances");

            foreach (var result in results.OrderBy(x => x.FileName))
            {
                sb.AppendFormat("{0},{1},{2},{3}",
                                result.FileName,
                                result.PageInstances.Length,
                                result.PageInstances.Sum(x => x.Lines.Count), result.PageInstances.Any(x => x.AtSymbols > 0));

                foreach (var attribute in attributesInUse)
                {
                    var blockCount = result.Block.Where(x => comparer.Equals(attribute, x.AttributeName)).Sum(x => x.InlineJavascriptTags.Count);
                    var razorCount = result.Razor.Count(x => comparer.Equals(attribute, x.AttributeName));
                    sb.AppendFormat(",{0}", blockCount + razorCount);

                    attributeTotals.Add(new AttributeTotal
                    {
                        Attribute  = attribute,
                        BlockCount = blockCount,
                        RazorCount = razorCount
                    });
                }

                sb.AppendFormat(",{0},{1}", result.Block.Sum(x => x.InlineJavascriptTags.Count), result.Razor.Count);
                sb.AppendLine("");
            }

            sb.AppendFormat("Total: {0},{1},{2},{3}",
                            results.Count,
                            results.Sum(x => x.PageInstances.Length),
                            results.Sum(x => x.PageInstances.Sum(y => y.Lines.Count)),
                            results.Sum(x => x.PageInstances.Count(y => y.AtSymbols > 0)));


            foreach (var attribute in attributesInUse)
            {
                sb.AppendFormat(",{0}", attributeTotals.Where(x => x.Attribute == attribute).Sum(x => x.BlockCount + x.RazorCount));
            }

            sb.AppendFormat(",{0},{1}", attributeTotals.Sum(x => x.BlockCount), attributeTotals.Sum(x => x.RazorCount));

            var filename = StorageService.Store(sb, JavaScriptStatsFileNameEvaluator.Evaluate(groupName));

            Ux.WriteLine(string.Format("Saved to {0}", filename));
            Ux.WriteLine("");

            return(filename);
        }