Пример #1
0
        private static bool CommandExperimental(List <string> args, RavenCli cli)
        {
            var isOn  = args.First().Equals("on");
            var isOff = args.First().Equals("off");

            if (!isOff && !isOn)
            {
                WriteError("Experimental cli commands can be set to only on or off. Setting to off.", cli);
                return(false);
            }

            return(isOn); // here rc is not an exit code, it is a setter to _experimental
        }
Пример #2
0
 private static bool CommandClear(List <string> args, RavenCli cli)
 {
     if (cli._consoleColoring)
     {
         Console.Clear();
     }
     else
     {
         cli._writer.Write(GetDelimiterString(Delimiter.Clear));
     }
     cli._writer.Flush();
     return(true);
 }
Пример #3
0
        private static bool CommandLogout(List <string> args, RavenCli cli)
        {
            if (cli._consoleColoring)
            {
                WriteText("'logout' command not supported on console cli", WarningColor, cli);
                return(true);
            }

            cli._writer.WriteLine("Logging out..", TextColor, cli);
            cli._writer.Write(GetDelimiterString(Delimiter.Logout));
            cli._writer.Flush();
            return(true);
        }
Пример #4
0
 private static bool CommandPrompt(List <string> args, RavenCli cli)
 {
     try
     {
         Prompt.Invoke(args, true, cli._server, cli._writer);
     }
     catch (Exception ex)
     {
         WriteError("Cannot set prompt to desired args, because of : " + ex.Message, cli);
         return(false);
     }
     return(true);
 }
Пример #5
0
        private string ReadLine(RavenCli cli)
        {
            if (cli._consoleColoring == false)
            {
                cli._writer.Write(GetDelimiterString(Delimiter.ReadLine));
                cli._writer.Flush();
            }

            var rc = _consoleColoring ? Console.ReadLine() : cli._reader.ReadLine();

            cli._writer.Flush();
            return(rc);
        }
Пример #6
0
        private static char ReadKey(RavenCli cli)
        {
            if (cli._consoleColoring)
            {
                var rc = Console.ReadKey().KeyChar;
                cli._writer.Flush();
                return(rc);
            }

            cli._writer.Write(GetDelimiterString(Delimiter.ReadKey));
            cli._writer.Flush();
            var c = cli._reader.Read();

            return(Convert.ToChar(c));
        }
Пример #7
0
        private static bool CommandImportDir(List <string> args, RavenCli cli)
        {
            // ImportDir <databaseName> <path-to-dir>
            WriteText($"ImportDir for database {args[0]} from dir `{args[1]}` to {cli._server.WebUrl}", ConsoleColor.Yellow, cli);

            var url = $"{cli._server.WebUrl}/databases/{args[0]}/smuggler/import-dir?dir={args[1]}";

            using (var client = new HttpClient())
            {
                WriteText("Sending at " + DateTime.UtcNow, TextColor, cli);
                var result = client.GetAsync(url).Result;
                WriteText("At " + DateTime.UtcNow + " : Http Status Code = " + result.StatusCode, TextColor, cli);
            }
            WriteText("Http client closed.", TextColor, cli);
            return(true);
        }
Пример #8
0
 private static void WriteText(string txt, ConsoleColor color, RavenCli cli, bool newLine = true)
 {
     if (cli._consoleColoring)
     {
         Console.ForegroundColor = color;
     }
     cli._writer.Write(txt);
     if (newLine)
     {
         cli._writer.WriteLine();
     }
     if (cli._consoleColoring)
     {
         Console.ResetColor();
     }
     cli._writer.Flush();
 }
Пример #9
0
        private static bool CommandStats(List <string> args, RavenCli cli)
        {
            if (cli._consoleColoring == false)
            {
                // beware not to allow this from remote - will disable local console!
                WriteText("'stats' command not supported on remote pipe connection. Use `info` or `prompt %M` instead", TextColor, cli);
                return(true);
            }

            Console.ResetColor();

            LoggingSource.Instance.DisableConsoleLogging();
            LoggingSource.Instance.SetupLogMode(LogMode.None, cli._server.Configuration.Logs.Path.FullPath);

            Program.WriteServerStatsAndWaitForEsc(cli._server);

            return(true);
        }
Пример #10
0
 private static bool CommandLogo(List <string> args, RavenCli cli)
 {
     if (args == null || args.Count == 0 || args.First().Equals("no-clear") == false)
     {
         if (cli._consoleColoring)
         {
             Console.Clear();
         }
     }
     if (cli._consoleColoring)
     {
         new WelcomeMessage(Console.Out).Print();
     }
     else
     {
         new WelcomeMessage(cli._writer).Print();
     }
     return(true);
 }
Пример #11
0
 private static void PrintCliHeader(RavenCli cli)
 {
     if (cli._consoleColoring)
     {
         Console.ForegroundColor = PromptHeaderColor;
     }
     try
     {
         Prompt.Invoke(cli._promptArgs, false, cli._server, cli._writer);
     }
     catch (Exception ex)
     {
         WriteError("PromptError:" + ex.Message, cli);
     }
     WriteText("> ", PromptArrowColor, cli, newLine: false);
     if (cli._consoleColoring)
     {
         Console.ForegroundColor = UserInputColor;
     }
 }
Пример #12
0
        private static bool CommandGc(List <string> args, RavenCli cli)
        {
            int genNum;

            genNum = args == null || args.Count == 0 ? 2 : Convert.ToInt32(args.First());

            WriteText("Before collecting, managed memory used: ", TextColor, cli, newLine: false);
            WriteText(new Size(GC.GetTotalMemory(false), SizeUnit.Bytes).ToString(), ConsoleColor.Cyan, cli);
            var startTime = DateTime.UtcNow;

            WriteText("Garbage Collecting... ", TextColor, cli, newLine: false);

            switch (genNum)
            {
            case 0:
                GC.Collect(0);
                break;

            case 1:
                GC.Collect(1);
                break;

            case 2:
                GC.Collect(GC.MaxGeneration);
                break;

            default:
                WriteError("Invalid argument passed to GC. Can be 0, 1 or 2", cli);
                return(false);
            }

            GC.WaitForPendingFinalizers();
            var actionTime = DateTime.UtcNow - startTime;

            WriteText("Collected.", ConsoleColor.Green, cli);
            WriteText("After collecting, managed memory used:  ", TextColor, cli, newLine: false);
            WriteText(new Size(GC.GetTotalMemory(false), SizeUnit.Bytes).ToString(), ConsoleColor.Cyan, cli, newLine: false);
            WriteText(" at ", TextColor, cli, newLine: false);
            WriteText(actionTime.TotalSeconds + " Seconds", ConsoleColor.Cyan, cli);
            return(true);
        }
Пример #13
0
        private static bool CommandTimer(List <string> args, RavenCli cli)
        {
            switch (args.First())
            {
            case "on":
                cli._server.ServerStore.Engine.Timeout.Disable = false;
                WriteText("Timer enabled", TextColor, cli);
                break;

            case "off":
                cli._server.ServerStore.Engine.Timeout.Disable = true;
                WriteText("Timer disabled", TextColor, cli);
                break;

            case "fire":
                cli._server.ServerStore.Engine.Timeout.ExecuteTimeoutBehavior();
                WriteText("Timer fired", TextColor, cli);
                break;
            }

            return(true);
        }
Пример #14
0
        private static bool CommandInfo(List <string> args, RavenCli cli)
        {
            new ClusterMessage(Console.Out, cli._server.ServerStore).Print();
            var memoryInfo = MemoryInformation.GetMemoryInfo();

            WriteText(
                $" Build {ServerVersion.Build}, Version {ServerVersion.Version}, SemVer {ServerVersion.FullVersion}, Commit {ServerVersion.CommitHash}" +
                Environment.NewLine +
                $" PID {Process.GetCurrentProcess().Id}, {IntPtr.Size * 8} bits, {ProcessorInfo.ProcessorCount} Cores, Arch: {RuntimeInformation.OSArchitecture}" +
                Environment.NewLine +
                $" {memoryInfo.TotalPhysicalMemory} Physical Memory, {memoryInfo.AvailableMemory} Available Memory" +
                Environment.NewLine +
                $" {RuntimeSettings.Describe()}",
                ConsoleColor.Cyan, cli);

            var bitsNum = IntPtr.Size * 8;

            if (bitsNum == 64 && cli._server.Configuration.Storage.ForceUsing32BitsPager)
            {
                WriteText(" Running in 32 bits mode", ConsoleColor.DarkCyan, cli);
            }

            return(true);
        }
Пример #15
0
        private static bool CommandHelpPrompt(List <string> args, RavenCli cli)
        {
            string[][] commandDescription =
            {
                new[] { "%D",    "UTC Date"                                                                     },
                new[] { "%T",    "UTC Time"                                                                     },
                new[] { "%M",    "Memory information (WS:WorkingSet, UM:Unmanaged, M:Managed, MP:MemoryMapped)" },
                new[] { "%R",    "Momentary Req/Sec"                                                            },
                new[] { "label", "any label"                                                                    }
            };

            var msg = new StringBuilder();

            msg.Append("Usage: prompt <[label] | [ %D | %T | %M ] | ...>" + Environment.NewLine + Environment.NewLine);
            msg.Append("Options:" + Environment.NewLine);
            WriteText(msg.ToString(), TextColor, cli);

            foreach (var cmd in commandDescription)
            {
                WriteText("\t" + cmd[0], ConsoleColor.Yellow, cli, newLine: false);
                WriteText(new string(' ', 25 - cmd[0].Length) + cmd[1], ConsoleColor.DarkYellow, cli);
            }
            return(true);
        }
Пример #16
0
        private static bool CommandScript(List <string> args, RavenCli cli)
        {
            // script <database|server> [databaseName]
            if (args.Count < 1 || args.Count > 2)
            {
                WriteError("Invalid number of arguments passed to script", cli);
                return(false);
            }

            DocumentDatabase database = null;

            switch (args[0].ToLower())
            {
            case "database":
                if (args.Count != 2)
                {
                    WriteError("Invalid number of arguments passed to script - missing database name", cli);
                    return(false);
                }
                database = cli._server.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(args[1]).Result;
                if (database == null)
                {
                    WriteError($"Cannot find database named '{args[1]}'", cli);
                    return(false);
                }
                break;

            case "server":
                break;

            default:
                WriteError($"Invalid arguments '{args[0]}' passed to script", cli);
                return(false);
            }

            var jsCli = new JavaScriptCli();

            if (jsCli.CreateScript(cli._reader, cli._writer, cli._consoleColoring, database, cli._server) == false)
            {
                WriteError("Invalid JavaScript entered, or user cancelled", cli);
                return(false);
            }

            using (cli._server.ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
            {
                var adminJsScript = new AdminJsScript(jsCli.Script);
                var result        = jsCli.AdminConsole.ApplyScript(adminJsScript);

                if (cli._consoleColoring)
                {
                    Console.ForegroundColor = ConsoleColor.Magenta;
                }

                WriteText(result, TextColor, cli);

                if (cli._consoleColoring)
                {
                    Console.ResetColor();
                }
            }
            return(true);
        }
Пример #17
0
 private static void WriteWarning(string txt, RavenCli cli)
 {
     WriteText($"WARNING: {txt}", WarningColor, cli);
     WriteText("", TextColor, cli);
 }
Пример #18
0
 private static void WriteError(string txt, RavenCli cli)
 {
     WriteText($"ERROR: {txt}", ErrorColor, cli);
     WriteText("", TextColor, cli);
 }