Ejemplo n.º 1
0
        private static void CopyBinaries()
        {
            WriteHeader("Copying binaries");
            var mainProject = GetMainProject(_currentRelease.Projects);

            outputDir = new DirectoryInfo(_currentRelease.Output)
                        .Combine(mainProject.GetVersion().ToString());

            if (outputDir.Exists)
            {
                Cli.WriteLine("Deleting ~Yellow~{0}~R~", outputDir.FullName);
                outputDir.Delete(true);
            }

            Cli.WriteLine();
            WriteProgressHeader("Copying");

            var progress = new CliProgressBar(_currentRelease.Projects.Length);

            progress.Write();

            _currentRelease.Projects
            .Iter(x =>
            {
                new DirectoryInfo(x.OutputPath).CopyTo(outputDir.FullName, true);
                progress.Value++;
                progress.Write();
            });

            Cli.WriteLine();
            Cli.WriteLine();
        }
Ejemplo n.º 2
0
        private static void Cleanup()
        {
            WriteHeader("Cleaning up");
            Cli.WriteLine("Searching...");
            var fsos = new List <FileSystemInfo>();

            if (_currentRelease.Cleanup.FilePatterns != null && _currentRelease.Cleanup.FilePatterns.Any())
            {
                fsos.AddRange(
                    outputDir
                    .GetFiles("*", SearchOption.AllDirectories)
                    .Where(x => _currentRelease.Cleanup.FilePatterns.Any(y => Regex.IsMatch(x.FullName, y))));
            }

            if (_currentRelease.Cleanup.Files != null && _currentRelease.Cleanup.Files.Any())
            {
                fsos.AddRange(_currentRelease.Cleanup.Files.Select(x => new FileInfo(Path.Combine(outputDir.FullName, x))));
            }

            if (_currentRelease.Cleanup.Directories != null && _currentRelease.Cleanup.Directories.Any())
            {
                fsos.AddRange(_currentRelease.Cleanup.Directories.Select(x => outputDir.Combine(x)));
            }

            Cli.WriteLine("~Cyan~{0}~R~ files and directories found", fsos.Count);
            Cli.WriteLine();
            WriteProgressHeader("Deleting");

            var progress = new CliProgressBar(fsos.Count);

            progress.Write();

            fsos.Iter(x =>
            {
                if (!x.Exists)
                {
                    progress.Value++;
                    progress.Write();
                    return;
                }

                var dir = x as DirectoryInfo;

                if (dir != null)
                {
                    dir.Delete(true);
                }
                else
                {
                    x.Delete();
                }

                progress.Value++;
                progress.Write();
            });
            Cli.WriteLine();
            Cli.WriteLine();
        }
Ejemplo n.º 3
0
        private static void IndeterminateSample2()
        {
            Console.WriteLine("\nThis progress bar shows indeterminate progress and removes itself when complete, polling periodically for an update");

            var bar = new CliProgressBar("Please wait");

            int secs = 5;
            bar.RenderAndPollIndeterminate(() =>
            {
                return secs-- > 0;
            }, TimeSpan.FromSeconds(1));
            bar.Wipe();
        }
Ejemplo n.º 4
0
        private static void IndeterminateSample2()
        {
            Console.WriteLine("\nThis progress bar shows indeterminate progress and removes itself when complete, polling periodically for an update");

            var bar = new CliProgressBar("Please wait");

            int secs = 5;

            bar.RenderAndPollIndeterminate(() =>
            {
                return(secs-- > 0);
            }, TimeSpan.FromSeconds(1));
            bar.Wipe();
        }
Ejemplo n.º 5
0
        private static void IndeterminateSample()
        {
            Console.WriteLine("\nThis progress bar shows indeterminate progress as long as it takes to run the given action");

            var bar = new CliProgressBar("Please wait");

            bar.RenderUntilIndeterminate(() =>
            {
                bar.Message = "Phase 1".ToConsoleString();
                Thread.Sleep(1000);
                bar.Message = "Phase 2".ToConsoleString();
                Thread.Sleep(1000);
                bar.Message = "Phase 3".ToConsoleString();
                Thread.Sleep(1000);
            });
        }
Ejemplo n.º 6
0
        private static void IndeterminateSample()
        {
            Console.WriteLine("\nThis progress bar shows indeterminate progress as long as it takes to run the given action");

            var bar = new CliProgressBar("Please wait");

            bar.RenderUntilIndeterminate(() =>
            {
                bar.Message = "Phase 1".ToConsoleString();
                Thread.Sleep(1000);
                bar.Message = "Phase 2".ToConsoleString();
                Thread.Sleep(1000);
                bar.Message = "Phase 3".ToConsoleString();
                Thread.Sleep(1000);
            });
        }
Ejemplo n.º 7
0
        private static void DeterminateSample()
        {
            Console.WriteLine("This progress bar shows determinate progress and stays visible after the operation is complete");

            var bar = new CliProgressBar("My operation is {%} complete");

            var start = DateTime.Now;
            bar.RenderAndPollDeterminate(() =>
            {
                var delta = DateTime.Now - start;
                bar.Progress = Math.Min(delta.TotalSeconds / 4, 1);
                if (delta > TimeSpan.FromSeconds(3))
                {
                    bar.Message = "The operation was cancelled".ToConsoleString();
                    bar.FillColor = ConsoleColor.Red;
                    throw new OperationCanceledException();
                }
            }
            , TimeSpan.FromMilliseconds(100));
        }
Ejemplo n.º 8
0
        private static void DeterminateSample()
        {
            Console.WriteLine("This progress bar shows determinate progress and stays visible after the operation is complete");

            var bar = new CliProgressBar("My operation is {%} complete");

            var start = DateTime.Now;

            bar.RenderAndPollDeterminate(() =>
            {
                var delta    = DateTime.Now - start;
                bar.Progress = Math.Min(delta.TotalSeconds / 4, 1);
                if (delta > TimeSpan.FromSeconds(3))
                {
                    bar.Message   = "The operation was cancelled".ToConsoleString();
                    bar.FillColor = ConsoleColor.Red;
                    throw new OperationCanceledException();
                }
            }
                                         , TimeSpan.FromMilliseconds(100));
        }
        public void Unset(DirectoryInfo Directory)
        {
            var files = Directory
                        .GetFiles("*", SearchOption.AllDirectories)
                        .Where(x => x.Extension == ".php" || x.Extension == ".inc");

            var progressBar = new CliProgressBar(files.Count());

            progressBar.Write();

            foreach (FileInfo f in files)
            {
                //try
                //{
                IOHelper.TryAction(() =>
                {
                    var backupFile = new FileInfo(f.FullName + ".phpvhbackup");

                    if (backupFile.Exists)
                    {
                        backupFile.CopyTo(f.FullName, true);
                        backupFile.Delete();
                    }
                }, 512, 0);

                progressBar.Value++;
                progressBar.Write();
                //}
                //catch (System.Exception ex)
                //{
                //    ScannerCli.DisplayError(string.Format("\r\nError unhooking {0}:\r\n{1}\r\n\r\n", f.FullName, ex.Message));
                //}
            }

            Cli.WriteLine();

            //foreach (DirectoryInfo d in Directory.GetDirectories())
            //    Unset(d);
        }
Ejemplo n.º 10
0
        public void TestProgressBarDeterminateSanity()
        {
            var bar = new CliProgressBar("", 10);
            bar.Progress = .5;
            bar.Render();
            Assert.AreEqual(6, bar.renderedMessage.Length);

            for(int i = 0; i < bar.renderedMessage.Length; i++)
            {
                if(i < 3)
                {
                    // the first three characters should be filled since the progress is .5
                    Assert.AreEqual(bar.renderedMessage[i].ForegroundColor, bar.MessageFillColor);
                    Assert.AreEqual(bar.renderedMessage[i].BackgroundColor, bar.FillColor);
                }
                else
                {
                    // the final three characters should NOT BE FILLED since the progress is .5
                    Assert.AreEqual(bar.renderedMessage[i].ForegroundColor, ConsoleString.DefaultForegroundColor);
                    Assert.AreEqual(bar.renderedMessage[i].BackgroundColor, ConsoleString.DefaultBackgroundColor);
                }
            }
        }
Ejemplo n.º 11
0
        public void TestProgressBarDeterminateSanity()
        {
            var bar = new CliProgressBar("", 10);

            bar.Progress = .5;
            bar.Render();
            Assert.AreEqual(6, bar.renderedMessage.Length);

            for (int i = 0; i < bar.renderedMessage.Length; i++)
            {
                if (i < 3)
                {
                    // the first three characters should be filled since the progress is .5
                    Assert.AreEqual(bar.renderedMessage[i].ForegroundColor, bar.MessageFillColor);
                    Assert.AreEqual(bar.renderedMessage[i].BackgroundColor, bar.FillColor);
                }
                else
                {
                    // the final three characters should NOT BE FILLED since the progress is .5
                    Assert.AreEqual(bar.renderedMessage[i].ForegroundColor, ConsoleString.DefaultForegroundColor);
                    Assert.AreEqual(bar.renderedMessage[i].BackgroundColor, ConsoleString.DefaultBackgroundColor);
                }
            }
        }
Ejemplo n.º 12
0
 static ProgressBarz()
 {
     Bar = new CliProgressBar("Initalizing...");
 }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            WriteHeader("Loading release settings");
            var script = "PhpVH.alx";

            Cli.WriteLine("Executing ~Cyan~{0}~R~", script);
            var interpreter = new AphidInterpreter();

            interpreter.InterpretFile(script);
            _currentRelease = interpreter.GetReturnValue().ConvertTo <Release>();
            var projects = _currentRelease.Projects;

            Cli.WriteLine();

            WriteHeader("Copying binaries");

            var outputDir = new DirectoryInfo(_currentRelease.Output)
                            .Combine(GetReleaseVersion(projects).ToString());

            if (outputDir.Exists)
            {
                Cli.WriteLine("Deleting ~Yellow~{0}~R~", outputDir.FullName);
                outputDir.Delete(true);
            }

            Cli.WriteLine();
            WriteProgressHeader("Copying");

            var progress = new CliProgressBar(projects.Length);

            progress.Write();

            projects
            .Iter(x =>
            {
                new DirectoryInfo(x.OutputPath).CopyTo(outputDir.FullName, true);
                progress.Value++;
                progress.Write();
            });

            Cli.WriteLine();
            Cli.WriteLine();
            WriteHeader("Cleaning up");
            Cli.WriteLine("Searching...");
            var fsos = new List <FileSystemInfo>();

            if (_currentRelease.Cleanup.FilePatterns != null && _currentRelease.Cleanup.FilePatterns.Any())
            {
                fsos.AddRange(
                    outputDir
                    .GetFiles("*", SearchOption.AllDirectories)
                    .Where(x => _currentRelease.Cleanup.FilePatterns.Any(y => Regex.IsMatch(x.FullName, y))));
            }

            if (_currentRelease.Cleanup.Files != null && _currentRelease.Cleanup.Files.Any())
            {
                fsos.AddRange(_currentRelease.Cleanup.Files.Select(x => new FileInfo(Path.Combine(outputDir.FullName, x))));
            }

            if (_currentRelease.Cleanup.Directories != null && _currentRelease.Cleanup.Directories.Any())
            {
                fsos.AddRange(_currentRelease.Cleanup.Directories.Select(x => outputDir.Combine(x)));
            }

            Cli.WriteLine("~Cyan~{0}~R~ files and directories found", fsos.Count);
            Cli.WriteLine();
            WriteProgressHeader("Deleting");

            progress = new CliProgressBar(fsos.Count);
            progress.Write();

            fsos.Iter(x =>
            {
                var dir = x as DirectoryInfo;

                if (dir != null)
                {
                    dir.Delete(true);
                }
                else
                {
                    x.Delete();
                }

                progress.Value++;
                progress.Write();
            });
        }
        public void Set(DirectoryInfo Directory)
        {
            IEnumerable <FileInfo> files = null;

            try
            {
                files = Directory
                        .GetFiles("*", SearchOption.AllDirectories)
                        .Where(x =>
                               x.Extension.ToLower() == ".php" ||
                               x.Extension.ToLower() == ".inc");
            }
            catch (UnauthorizedAccessException)
            {
                var error = string.Format("\r\nError enumerating files in {0}", Directory.FullName);
                ScannerCli.DisplayError(error);
                return;
            }

            var progressBar = new CliProgressBar(files.Count());

            progressBar.Write();

            files.AsyncIter(f =>
            {
                if (!CreateBackup(f))
                {
                    return;
                }

                string php = File.ReadAllText(f.FullName);

                PhpToken[] tokens = null;

                Action getTokens                   = () =>
                                            tokens = PhpParser.StripWhitespaceAndComments(new PhpLexer(php)
                                                                                          .GetTokens()
                                                                                          .ToArray());

                getTokens();

                lock (Program.PageFieldTable)
                {
                    if (!Program.PageFieldTable.ContainsKey(f.FullName))
                    {
                        Program.PageFieldTable.Add(f.FullName, new Dictionary <string, List <string> >());
                    }

                    var superglobals = StaticAnalyzer.FindSuperglobalFields(tokens);

                    foreach (var superglobal in superglobals)
                    {
                        if (!Program.PageFieldTable[f.FullName].ContainsKey(superglobal.Key))
                        {
                            Program.PageFieldTable[f.FullName].Add(superglobal.Key, new List <string>());
                        }


                        var newValues = superglobal.Value
                                        .Where(x => !Program.PageFieldTable[f.FullName][superglobal.Key].Contains(x));

                        Program.PageFieldTable[f.FullName][superglobal.Key].AddRange(newValues);
                    }
                }

                lock (Program.FileIncludeTable)
                    Program.FileIncludeTable.Add(f.FullName,
                                                 PhpParser.GetIncludedFiles(tokens));

                var functions = PhpParser.GetGlobalFunctionCalls(tokens);

                if (Program.Config.CodeCoverageReport > 0)
                {
                    php = ScanMetrics.Default.Annotator.AnnotateCode(f.FullName, php, tokens);
                }

                if (!Program.Config.HookSuperglobals)
                {
                    php = PreloadHelper.Patch(php);
                }

                foreach (Hook h in this)
                {
                    h.Set(ref php);
                }

                getTokens();

                string include = "require_once('" +
                                 Program.Config.WebRoot.Replace('\\', '/') + "/" + Hook.HookFileName + "');";

                if (tokens.Length >= 2 && tokens[1].TokenType == PhpTokenType.namespaceKeyword)
                {
                    var eos = tokens.FirstOrDefault(x => x.TokenType == PhpTokenType.EndOfStatement);

                    php = php.Insert(eos.Index + 1, "\r\n" + include + "\r\n");
                }
                else
                {
                    php = "<?php " + include + " ?>" + php;
                }

                try
                {
                    File.WriteAllText(f.FullName, php);
                }
                catch (UnauthorizedAccessException ex)
                {
                    ScannerCli.DisplayError(string.Format("\r\n\r\nError hooking file\r\n{0}\r\n", ex.Message));

                    return;
                }
                progressBar.Value++;
                progressBar.Write();
            });
        }
Ejemplo n.º 15
0
 static ProgressBarz() {
     Bar = new CliProgressBar("Initalizing...");
 }