예제 #1
0
        /// <inheritdoc />
        public void Run(IConsole console)
        {
            var schemes = SchemeLoader.LoadAllFromFolder(@"..\..\..\colorschemes")
                          .Concat(new [] { BuildInColorShemes.WindowsDefault, BuildInColorShemes.Windows10Default })
                          .ToArray();

            var controller = new ConsoleController();

            console = new SystemConsole(controller, new ConsoleStartConfiguration(ConsoleStartConfiguration.Colorfull)
            {
                DesiredRowWidth = 128,                            // for bars
                DesiredRowCount = (uint)(10 + 4 * schemes.Length) // many samples...
            });

            console.WriteLine($"Using '{this._heuristic.Name}' heuristics");
            console.WriteLine();

            this.PrintBaseRainbowColors(console);
            foreach (var scheme in schemes)
            {
                this.PrintSchemeRainbowColors(console, scheme);
            }

            console.WaitForNextPage();
        }
예제 #2
0
        protected void Execute(string[] args)
        {
            var console     = new SystemConsole();
            var input       = string.Empty;
            var inputHandle = new InputManager(console,
                                               new BasicCommandPrompt(),
                                               new MultiInputModerator(new IInputModerator[] { new TrimInputModerator(), new LowerInputModerator() }));

            do
            {
                input = inputHandle.ReadInput();
                if (!string.IsNullOrEmpty(input))
                {
                    ICommand cmd = null;
                    if (_commands.TryGetValue(input, out cmd))
                    {
                        cmd.Execute(console, new string[] { });
                    }
                    else
                    {
                        console.WriteLine("Did not find command: " + input);
                    }
                }
            } while (!string.IsNullOrEmpty(input));
        }
예제 #3
0
        /// <summary>
        /// Run the task, record statistics.
        /// </summary>
        /// <param name="reportStats"></param>
        /// <returns>Number of work items done by this task.</returns>
        public int RunAndMaybeStats(bool reportStats)
        {
            int count;

            if (!reportStats || ShouldNotRecordStats)
            {
                Setup();
                count = DoLogic();
                count = disableCounting ? 0 : count;
                TearDown();
                return(count);
            }
            if (reportStats && depth <= maxDepthLogStart && !ShouldNeverLogAtStart)
            {
                SystemConsole.WriteLine("------------> starting task: " + GetName());
            }
            Setup();
            Points    pnts = runData.Points;
            TaskStats ts   = pnts.MarkTaskStart(this, runData.Config.RoundNumber);

            count = DoLogic();
            count = disableCounting ? 0 : count;
            pnts.MarkTaskEnd(ts, count);
            TearDown();
            return(count);
        }
예제 #4
0
 private void PatchAssemblyInfo()
 {
     foreach (string patchFile in Directory.GetFiles(project.DirectoryPath, "AssemblyInfo.cs", SearchOption.AllDirectories))
     {
         string[] lines = File.ReadAllLines(patchFile);
         string   ver   = GetVersionByFileName(patchFile);
         for (int i = 0; i < lines.Length; i++)
         {
             if (lines[i].Contains("[assembly: AssemblyVersion("))
             {
                 lines[i] = "[assembly: AssemblyVersion(\"" + shortVersion + "\")]";
                 SystemConsole.WriteLine("{0} AssemblyVersion = <cyan>{1}", Path.GetFileName(patchFile), shortVersion);
             }
             else if (lines[i].Contains("[assembly: AssemblyInformationalVersion("))
             {
                 lines[i] = "[assembly: AssemblyInformationalVersion(\"" + ver + "\")]";
                 SystemConsole.WriteLine("{0} AssemblyInformationalVersion = <cyan>{1}", Path.GetFileName(patchFile), ver);
             }
             else if (lines[i].Contains("[assembly: AssemblyFileVersion("))
             {
                 lines[i] = "[assembly: AssemblyFileVersion(\"" + fileVersion + "\")]";
                 SystemConsole.WriteLine("{0} AssemblyFileVersion = <cyan>{1}", Path.GetFileName(patchFile), fileVersion);
             }
         }
         File.WriteAllLines(patchFile, lines);
     }
 }
예제 #5
0
 private void Help()
 {
     SystemConsole.WriteLine("csPublish [<publish.{0}>] [--create] [-root=<dir>]", Ini.PlatformExtension);
     SystemConsole.WriteLine();
     SystemConsole.WriteLine("--create: creates a default configuration.");
     SystemConsole.WriteLine();
 }
예제 #6
0
        private void PublishFileToFtp(Ini config, string sectionName, string file, string target)
        {
            FtpConnection con = new FtpConnection
            {
                EnableSSL = config.ReadBool(target, "ssl", true)
            };
            ConnectionString connectionString = config.ReadSetting(target, "Target");

            string user = config.ReadSetting(target, "Username");

            if (!string.IsNullOrEmpty(user))
            {
                connectionString.UserName = user;
            }

            string pass = config.ReadSetting(target, "Password");

            if (!string.IsNullOrEmpty(pass))
            {
                connectionString.Password = pass;
            }

            connectionString.Location = FileSystem.Combine('/', config.ReadSetting(target, "Path"), Path.GetFileName(file));
            SystemConsole.Write("<cyan>Upload<default>: {0} -> <cyan>{1}<default> ..", file, connectionString);
            con.Upload(connectionString, File.ReadAllBytes(file));
            SystemConsole.WriteLine(" <green>ok");

            bool move = config.ReadBool(sectionName, "move", false) | config.ReadBool(sectionName, "delete", false);

            SystemConsole.Write("<red>Delete<default>: {0} ..", file);
            File.Delete(file);
            SystemConsole.WriteLine(" <green>ok");
        }
예제 #7
0
 private static void Help()
 {
     SystemConsole.WriteLine(
         "csDebber <debber.ini>\n" +
         "\n" +
         "Builds a debian package using the specified debber.ini file.");
 }
예제 #8
0
 /// <summary>
 /// Task teardown work that should not be measured for that specific task. By
 /// default it does nothing, but tasks can implement this, moving work from
 /// <see cref="DoLogic()"/> to this method. Only the work done in <see cref="DoLogic()"/>
 /// is measured for this task. Notice that higher level (sequence) tasks
 /// containing this task would then measure larger time than the sum of their
 /// contained tasks.
 /// </summary>
 public virtual void TearDown()
 {
     if (++logStepCount % m_logStep == 0)
     {
         double time = (((Stopwatch.GetTimestamp() / Stopwatch.Frequency) * 1000) - runData.StartTimeMillis) / 1000.0;
         SystemConsole.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0:0000000.00}", time) + " sec --> "
                                 + Thread.CurrentThread.Name + " " + GetLogMessage(logStepCount));
     }
 }
        private List <Project> LoadProjects(Arguments args)
        {
            List <Project> projects          = new List <Project>();
            var            solutionFileNames = args.Parameters.ToArray();

            if (solutionFileNames.Length == 0)
            {
                solutionFileNames = Directory.GetFiles(".", "*.sln");
            }
            foreach (string solutionFileName in solutionFileNames)
            {
                string file = Path.GetFullPath(FileSystem.Combine(".", solutionFileName));
                SystemConsole.WriteLine("Loading {0}", file);
                if (File.Exists(file))
                {
                    string folder        = Path.GetDirectoryName(file);
                    int    projectNumber = 0;
                    foreach (string s in File.ReadAllLines(file).Where(s => s.StartsWith("Project(")))
                    {
                        projectNumber++;
                        string fileName = null;
                        try
                        {
                            string name = s.Substring(s.IndexOf('='));
                            name     = name.Split(new string[] { "\", \"" }, StringSplitOptions.None)[1];
                            fileName = Path.Combine(folder, name);
                            SystemConsole.WriteLine("Loading project {0} {1}", projectNumber, fileName);
                            if (File.Exists(fileName))
                            {
                                Project project = new Project(fileName, null, null, new ProjectCollection());
                                projects.Add(project);
                                Solution = file;
                            }
                        }
                        catch (Exception ex)
                        {
                            if (IsConsoleMode)
                            {
                                if (fileName != null)
                                {
                                    SystemConsole.WriteLine("Could not load project {0}", fileName);
                                    SystemConsole.WriteLine(ex.ToXT());
                                }
                                else
                                {
                                    SystemConsole.WriteLine("Could not load project {0}", projectNumber);
                                    SystemConsole.WriteLine(ex.ToXT());
                                }
                            }
                            throw;
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
            }
            return(projects);
        }
예제 #10
0
        public override int DoLogic()
        {
            Report rp = ReportAll(RunData.Points.TaskStats);

            SystemConsole.WriteLine();
            SystemConsole.WriteLine("------------> Report All (" + rp.Count + " out of " + rp.OutOf + ")");
            SystemConsole.WriteLine(rp.Text);
            SystemConsole.WriteLine();
            return(0);
        }
예제 #11
0
        public override int DoLogic()
        {
            CultureInfo locale = CreateLocale(culture /*language, country, variant*/);

            RunData.Locale = locale;
            SystemConsole.WriteLine("Changed Locale to: " +
                                    (locale == null ? "null" :
                                     (locale.EnglishName.Length == 0) ? "root locale" : locale.ToString()));
            return(1);
        }
예제 #12
0
 public ExtractReuters(DirectoryInfo reutersDir, DirectoryInfo outputDir)
 {
     this.reutersDir = reutersDir;
     this.outputDir  = outputDir;
     SystemConsole.WriteLine("Deleting all files in " + outputDir);
     foreach (FileInfo f in outputDir.EnumerateFiles())
     {
         f.Delete();
     }
 }
예제 #13
0
 public ExtractWikipedia(DocMaker docMaker, DirectoryInfo outputDir)
 {
     this.outputDir  = outputDir;
     this.m_docMaker = docMaker;
     SystemConsole.WriteLine("Deleting all files in " + outputDir);
     FileInfo[] files = outputDir.GetFiles();
     for (int i = 0; i < files.Length; i++)
     {
         files[i].Delete();
     }
 }
예제 #14
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         SystemConsole.WriteLine("NRT reopen times:");
         for (int i = 0; i < reopenCount; i++)
         {
             SystemConsole.Write(" " + reopenTimes[i]);
         }
         SystemConsole.WriteLine();
     }
 }
예제 #15
0
        public override int DoLogic()
        {
            Report rp = ReportSelectByPrefix(RunData.Points.TaskStats);

            SystemConsole.WriteLine();
            SystemConsole.WriteLine("------------> Report Select By Prefix (" + m_prefix + ") (" +
                                    rp.Count + " about " + rp.Reported + " out of " + rp.OutOf + ")");
            SystemConsole.WriteLine(rp.Text);
            SystemConsole.WriteLine();

            return(0);
        }
예제 #16
0
        public override int DoLogic()
        {
            Report rp = ReportSumByName(RunData.Points.TaskStats);

            SystemConsole.WriteLine();
            SystemConsole.WriteLine("------------> Report Sum By (any) Name (" +
                                    rp.Count + " about " + rp.Reported + " out of " + rp.OutOf + ")");
            SystemConsole.WriteLine(rp.Text);
            SystemConsole.WriteLine();

            return(0);
        }
예제 #17
0
        public override int DoLogic()
        {
            TaxonomyReader taxoReader = RunData.GetTaxonomyReader();

            RunData.SetTaxonomyReader(null);
            if (taxoReader.RefCount != 1)
            {
                SystemConsole.WriteLine("WARNING: CloseTaxonomyReader: reference count is currently " + taxoReader.RefCount);
            }
            taxoReader.Dispose();
            return(1);
        }
예제 #18
0
        public override int DoLogic()
        {
            IndexReader reader = RunData.GetIndexReader();

            RunData.SetIndexReader(null);
            if (reader.RefCount != 1)
            {
                SystemConsole.WriteLine("WARNING: CloseReader: reference count is currently " + reader.RefCount);
            }
            reader.DecRef();
            return(1);
        }
예제 #19
0
        private void PrintProps()
        {
            SystemConsole.WriteLine("------------> config properties:");
            List <string> propKeys = new List <string>(props.Keys);

            propKeys.Sort();
            foreach (string propName in propKeys)
            {
                SystemConsole.WriteLine(propName + " = " + props[propName]);
            }
            SystemConsole.WriteLine("-------------------------------");
        }
예제 #20
0
        private void ObfucatorComplete(string sourceDir, string file, bool embed, bool testLoad)
        {
            if (embed)
            {
                Stopwatch watch = Stopwatch.StartNew();
                SystemConsole.Write("Clean <magenta>{0}<default>...", sourceDir);
                foreach (string removeFile in Directory.GetFiles(sourceDir, "*.*"))
                {
                    switch (Path.GetExtension(removeFile).ToLowerInvariant())
                    {
                    case ".exe":
                    case ".dll":
                    case ".pdb": File.Delete(removeFile); break;
                    }
                    SystemConsole.WriteLine(" {0} <green>ok", StringExtensions.FormatTime(watch.Elapsed));
                }
            }

            string outFile = FileSystem.Combine(sourceDir, "tmp", Path.GetFileName(file));

            if (testLoad)
            {
                Stopwatch watch = Stopwatch.StartNew();
                SystemConsole.Write("Testing <cyan>{0}<default>...", outFile);
                try
                {
                    Assembly.Load(File.ReadAllBytes(outFile));
                }
                catch
                {
                    SystemConsole.WriteLine(" {0} <red>error", StringExtensions.FormatTime(watch.Elapsed));
                    throw;
                }
                SystemConsole.WriteLine(" {0} <green>ok", StringExtensions.FormatTime(watch.Elapsed));
            }
            File.Delete(file);
            File.Move(FileSystem.Combine(sourceDir, "tmp", outFile), file);

            string originalPdb = Path.ChangeExtension(file, ".pdb");

            if (File.Exists(originalPdb))
            {
                File.Delete(originalPdb);
            }

            string newPdb = FileSystem.Combine(sourceDir, "tmp", Path.ChangeExtension(outFile, ".pdb"));

            if (File.Exists(newPdb))
            {
                File.Move(newPdb, originalPdb);
            }
        }
예제 #21
0
        public static void Main(string[] args)
        {
            FileInfo      wikipedia         = null;
            DirectoryInfo outputDir         = new DirectoryInfo("./enwiki");
            bool          keepImageOnlyDocs = true;

            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];
                if (arg.Equals("--input", StringComparison.Ordinal) || arg.Equals("-i", StringComparison.Ordinal))
                {
                    wikipedia = new FileInfo(args[i + 1]);
                    i++;
                }
                else if (arg.Equals("--output", StringComparison.Ordinal) || arg.Equals("-o", StringComparison.Ordinal))
                {
                    outputDir = new DirectoryInfo(args[i + 1]);
                    i++;
                }
                else if (arg.Equals("--discardImageOnlyDocs", StringComparison.Ordinal) || arg.Equals("-d", StringComparison.Ordinal))
                {
                    keepImageOnlyDocs = false;
                }
            }

            IDictionary <string, string> properties = new Dictionary <string, string>();

            properties["docs.file"] = wikipedia.FullName;
            properties["content.source.forever"] = "false";
            properties["keep.image.only.docs"]   = keepImageOnlyDocs.ToString();
            Config config = new Config(properties);

            ContentSource source = new EnwikiContentSource();

            source.SetConfig(config);

            DocMaker docMaker = new DocMaker();

            docMaker.SetConfig(config, source);
            docMaker.ResetInputs();
            if (wikipedia.Exists)
            {
                SystemConsole.WriteLine("Extracting Wikipedia to: " + outputDir + " using EnwikiContentSource");
                outputDir.Create();
                ExtractWikipedia extractor = new ExtractWikipedia(docMaker, outputDir);
                extractor.Extract();
            }
            else
            {
                PrintUsage();
            }
        }
예제 #22
0
 static int Main(string[] args)
 {
     try
     {
         new csPublish().Run(Arguments.FromArray(args));
         return(0);
     }
     catch (Exception ex)
     {
         SystemConsole.WriteLine(ex.ToXT(true));
         return(1);
     }
 }
예제 #23
0
        /// <inheritdoc />
        public void Run(IConsole console)
        {
            var controller = new ConsoleController();

            console = new SystemConsole(controller, new ConsoleStartConfiguration(ConsoleStartConfiguration.Colorfull)
            {
                DesiredRowWidth = 128,                                 // for bars
                DesiredRowCount = (uint)(+4 * this._heuristics.Length) // many samples...
            });

            console.WriteLine($"Using '{this._scheme.Name}' scheme");
            console.WriteLine();

            this.PrintBaseRainbowColors(console);

            foreach (var heuristic in _heuristics)
            {
                this.PrintSchemeRainbowColors(console, heuristic);
            }

            console.WaitForNextPage();
        }
예제 #24
0
        /// <summary>
        /// Utility: execute benchmark from command line.
        /// </summary>
        /// <param name="args">Single argument is expected: algorithm-file.</param>
        public static void Exec(string[] args)
        {
            // verify command line args
            if (args.Length < 1)
            {
                SystemConsole.WriteLine("Usage: java Benchmark <algorithm file>");
                Environment.Exit(1);
            }

            // verify input files
            FileInfo algFile = new FileInfo(args[0]);

            if (!algFile.Exists /*|| !algFile.isFile() ||!algFile.canRead()*/)
            {
                SystemConsole.WriteLine("cannot find/read algorithm file: " + algFile.FullName);
                Environment.Exit(1);
            }

            SystemConsole.WriteLine("Running algorithm from: " + algFile.FullName);

            Benchmark benchmark = null;

            try
            {
                benchmark = new Benchmark(IOUtils.GetDecodingReader(algFile, Encoding.UTF8));
            }
            catch (Exception e)
            {
                SystemConsole.WriteLine(e.ToString());
                Environment.Exit(1);
            }

            SystemConsole.WriteLine("------------> algorithm:");
            SystemConsole.WriteLine(benchmark.Algorithm.ToString());

            // execute
            try
            {
                benchmark.Execute();
            }
            catch (Exception e)
            {
                SystemConsole.WriteLine("Error: cannot execute the algorithm! " + e.Message);
                SystemConsole.WriteLine(e.StackTrace);
            }

            SystemConsole.WriteLine("####################");
            SystemConsole.WriteLine("###  D O N E !!! ###");
            SystemConsole.WriteLine("####################");
        }
예제 #25
0
        /// <summary>
        /// Increment the round number, for config values that are extracted by round number.
        /// </summary>
        /// <returns>The new round number.</returns>
        public virtual int NewRound()
        {
            roundNumber++;

            StringBuilder sb = new StringBuilder("--> Round ").Append(roundNumber - 1).Append("-->").Append(roundNumber);

            // log changes in values
            if (valByRound.Count > 0)
            {
                sb.Append(": ");
                foreach (string name in valByRound.Keys)
                {
                    object a = valByRound[name];
                    if (a is int[])
                    {
                        int[] ai = (int[])a;
                        int   n1 = (roundNumber - 1) % ai.Length;
                        int   n2 = roundNumber % ai.Length;
                        sb.Append("  ").Append(name).Append(":").Append(ai[n1]).Append("-->").Append(ai[n2]);
                    }
                    else if (a is double[])
                    {
                        double[] ad = (double[])a;
                        int      n1 = (roundNumber - 1) % ad.Length;
                        int      n2 = roundNumber % ad.Length;
                        sb.Append("  ").Append(name).Append(":").Append(ad[n1]).Append("-->").Append(ad[n2]);
                    }
                    else if (a is string[])
                    {
                        string[] ad = (string[])a;
                        int      n1 = (roundNumber - 1) % ad.Length;
                        int      n2 = roundNumber % ad.Length;
                        sb.Append("  ").Append(name).Append(":").Append(ad[n1]).Append("-->").Append(ad[n2]);
                    }
                    else
                    {
                        bool[] ab = (bool[])a;
                        int    n1 = (roundNumber - 1) % ab.Length;
                        int    n2 = roundNumber % ab.Length;
                        sb.Append("  ").Append(name).Append(":").Append(ab[n1]).Append("-->").Append(ab[n2]);
                    }
                }
            }

            SystemConsole.WriteLine();
            SystemConsole.WriteLine(sb.ToString());
            SystemConsole.WriteLine();

            return(roundNumber);
        }
예제 #26
0
 void Help()
 {
     SystemConsole.WriteLine(
         Banner +
         "\n" +
         "csObfuscate [<cyan>--config=<value><default>] [<cyan>--sign=<filename.snk><default>] [<cyan>--option<default>] <magenta>/path/to/file.dll\n" +
         "Obfuscates a release assembly\n" +
         "\n" +
         "  <cyan>--config=<value><default>:       if set to anything else than release nothing will be done.\n" +
         "  <cyan>--sign=<filename.snk><default>:  if set the assembly will be signed after obfuscation.\n" +
         "  <cyan>--test<default>:                 if set test load the assembly after obfuscation.\n" +
         "  <cyan>--obfuscator=<type><default>:    use <cyan>crypto<default> or <cyan>obfuscar<default> (default).\n" +
         "\n");
 }
예제 #27
0
        private void Run(Arguments arguments)
        {
            try
            {
                if (arguments.IsHelpOptionFound())
                {
                    Help(); return;
                }
                string signatureFile = arguments.IsOptionPresent("sign") ? arguments.Options["sign"].Value : null;
                bool   testLoad      = arguments.IsOptionPresent("test");
                bool   debug         = arguments.IsOptionPresent("debug");
                string obfuscator    = arguments.IsOptionPresent("obfuscator") ? arguments.Options["obfuscator"].Value : "obfuscar";
                if (arguments.IsOptionPresent("config"))
                {
                    string config = arguments.Options["config"].Value;
                    if (config.ToUpper() != "RELEASE")
                    {
                        SystemConsole.WriteLine("No obfuscation at configuration <cyan>{0}", config);
                        return;
                    }
                }
                foreach (string file in arguments.Parameters)
                {
                    if (!File.Exists(file))
                    {
                        throw new FileNotFoundException();
                    }

                    Obfuscate(obfuscator, file, signatureFile, testLoad: testLoad, debug: debug);
                }
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    throw;
                }

                SystemConsole.WriteLine(ex.ToXT());
            }
            finally
            {
                if (Debugger.IsAttached || arguments.IsOptionPresent("wait"))
                {
                    SystemConsole.WriteLine("--- press <yellow>enter<default> to exit ---");
                    SystemConsole.ReadLine();
                }
            }
        }
예제 #28
0
        public override void SetConfig(Config config, ContentSource source)
        {
            base.SetConfig(config, source);
            SpatialStrategy existing;

            if (!spatialStrategyCache.TryGetValue(config.RoundNumber, out existing) || existing == null)
            {
                //new round; we need to re-initialize
                strategy = MakeSpatialStrategy(config);
                spatialStrategyCache[config.RoundNumber] = strategy;
                //TODO remove previous round config?
                shapeConverter = MakeShapeConverter(strategy, config, "doc.spatial.");
                SystemConsole.WriteLine("Spatial Strategy: " + strategy);
            }
        }
예제 #29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args">{index-dir}</param>
        /// <exception cref="IOException">if cannot access the index.</exception>
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                SystemConsole.Error.WriteLine("Usage: java QualityQueriesFinder <index-dir>");
                Environment.Exit(1);
            }
            QualityQueriesFinder qqf = new QualityQueriesFinder(FSDirectory.Open(new DirectoryInfo(args[0])));

            string[] q = qqf.BestQueries("body", 20);
            for (int i = 0; i < q.Length; i++)
            {
                SystemConsole.WriteLine(newline + FormatQueryAsTrecTopic(i, q[i], null, null));
            }
        }
 void Help()
 {
     SystemConsole.WriteLine(
         Banner +
         "\n" +
         "csPrepareRelease [<cyan>--increment<default>] <magenta>solution.sln\n" +
         "Prepares a visual studio solution for release patching csproj, AssemblyInfo, nuspec and setup files.\n" +
         "\n" +
         "  <cyan>--stable[=patch]<default>: clear meta and use only major.minor.patch.\n" +
         "  <cyan>--increment<default>:      automatically patch the solution to the next patch version.\n" +
         "  <cyan>--debug<default>:          set loglevel to debug.\n" +
         "  <cyan>--verbose<default>:        set loglevel to verbose.\n" +
         "  <cyan>--wait<default>:           wait for console key after execution.\n" +
         "\n");
 }