Ejemplo n.º 1
0
        public override void Run(IConsoleContext InConsole, Dictionary <string, object> InArguments)
        {
            InConsole.WriteLine("");
            InConsole.WriteLine("ShiftOS Terminal help:");
            InConsole.WriteLine("");
            InConsole.WriteLine("Tips:");
            InConsole.WriteLine("");
            foreach (var tip in InConsole.CurrentSystem.GetUsefulTips().OrderBy(x => x))
            {
                InConsole.WriteLine($" - {tip}");
            }
            InConsole.WriteLine("");
            InConsole.WriteLine("Terminal commands:");
            InConsole.WriteLine("");

            foreach (var command in InConsole.CurrentSystem.GetInstalledCommands().OrderBy(x => x.Name))
            {
                InConsole.WriteLine($" - {command.Name}: {command.HelpText}");
            }

            InConsole.WriteLine("");
            InConsole.WriteLine("Programs:");
            InConsole.WriteLine("");
            foreach (var program in InConsole.CurrentSystem.GetInstalledPrograms().OrderBy(x => x))
            {
                InConsole.WriteLine($" - {program}: {InConsole.CurrentSystem.GetProgramDescription(program)}");
            }
            InConsole.WriteLine("");
        }
        public static async Task <ConsoleCommandResult> ExecuteToFile(this IConsoleContext context, string filename, string command,
                                                                      string commandstring = null, IScope scope = null, bool append = false)
        {
            filename = EnvironmentInfo.ResolvePath(filename);
            Directory.CreateDirectory(Path.GetDirectoryName(filename));
            if (!File.Exists(filename))
            {
                append = false;
            }
            ConsoleCommandResult result = null;

            using (var s = new FileStream(filename, append ? FileMode.Append : FileMode.Create, FileAccess.Write)) {
                using (var sw = new StreamWriter(s)) {
                    var proxy = context.GetProxy(_ => {
                        _.Out       = sw;
                        _.OutStream = s;
                        return(_);
                    });
                    result = await proxy.Execute(command, commandstring, scope);

                    sw.Flush();
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public override void Run(IConsoleContext InConsole, Dictionary <string, object> InArguments)
        {
            var windowTitle = InArguments["<window>"].ToString();

            int x, y = 0;

            if (!int.TryParse(InArguments["<x>"].ToString(), out x))
            {
                InConsole.WriteLine("Error: invalid x coordinate");
                return;
            }
            if (!int.TryParse(InArguments["<y>"].ToString(), out y))
            {
                InConsole.WriteLine("Error: invalid y coordinate");
                return;
            }

            var window = InConsole.CurrentSystem.GetWindows().FirstOrDefault(z => z.WindowTitle == windowTitle);

            if (window == null)
            {
                InConsole.WriteLine($"Error: No window found with name {windowTitle}.");
                return;
            }

            window.Left = x;
            window.Top  = y;
        }
Ejemplo n.º 4
0
        protected override async Task InternalExecute(IConsoleContext context, ConsoleCommandResult result, string commandname, string commandstring, IScope scope)
        {
            var data   = ReportProvider.Search(commandstring);
            var pretty = context.Parameters.Get("pretty").ToBool();

            context.WriteLine(data.stringify(pretty: pretty));
        }
Ejemplo n.º 5
0
        protected override async Task InternalExecute(IConsoleContext context, ConsoleCommandResult result, string commandname, string commandstring, IScope scope)
        {
            var cmd = commandstring.Trim();

            if (string.IsNullOrWhiteSpace(cmd))
            {
                cmd = "all";
            }
            var d = new ResetEventData(cmd == "all");

            foreach (var component in Container.GetComponents())
            {
                if (component.Lifestyle == Lifestyle.Singleton && null != component.Implementation)
                {
                    var type = component.Implementation.GetType();
                    var ra   = type.GetCustomAttribute <RequireResetAttribute>();
                    if (null != ra && ra.IsMatch(type, cmd))
                    {
                        if (typeof(IResetable).IsAssignableFrom(type))
                        {
                            context.WriteLine(type.Name + " : " +
                                              ((IResetable)component.Implementation).Reset(d).stringify());
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static void Output(IConsoleContext context)
        {
            var content = "";

            for (var i = 0; i < _Instance.logs.Count; ++i)
            {
                var log = _Instance.logs[i];
                if (_Instance._IsScopeEnabled(log.Scope) && log.Level <= _Instance.logLevel)
                {
                    switch (log.Level)
                    {
                    case LogLevel.VERBOSE:
                        content += "<li class='list-group-item list-group-item-info'><span class='glyphicon glyphicon-info-sign' aria-hidden='true'></span> [" + log.Scope + "] " + log.Message + "</li>";
                        break;

                    case LogLevel.WARNING:
                        content += "<li class='list-group-item list-group-item-warning'><span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span> [" + log.Scope + "] " + log.Message + "</li>";
                        break;

                    case LogLevel.ERROR:
                        content += "<li class='list-group-item list-group-item-danger'><span class='glyphicon glyphicon-remove-sign' aria-hidden='true'></span> [" + log.Scope + "] " + log.Message + "</li>";
                        break;

                    case LogLevel.EXCEPTION:
                        content += "<li class='list-group-item list-group-item-danger'><span class='glyphicon glyphicon-flash' aria-hidden='true'></span> [" + log.Scope + "] " + log.Message + "</li>";
                        break;
                    }
                }
            }

            context.Response.WriteString(content);
        }
Ejemplo n.º 7
0
 internal CommandRunner(IConsoleContext consoleContext, IVsExtensionManager extensionManager,
                        InstalledVersion installedVersion, string rootSuffix)
 {
     Console           = consoleContext;
     _extensionManager = extensionManager;
     _installedVersion = installedVersion;
     _rootSuffix       = rootSuffix;
 }
Ejemplo n.º 8
0
        public override void Run(IConsoleContext InConsole, Dictionary <string, object> InArguments)
        {
            string program = InArguments["<program>"].ToString();

            if (!InConsole.CurrentSystem.LaunchProgram(program))
            {
                InConsole.WriteLine("Error: Program not found.");
            }
        }
Ejemplo n.º 9
0
 public static void SetLogScope(IConsoleContext context)
 {
     foreach (string scope in context.Request.QueryString)
     {
         var enabled = bool.Parse(context.Request.QueryString.Get(scope));
         _Instance._SetLogScope(scope, enabled);
         break;
     }
 }
Ejemplo n.º 10
0
 internal static void PrintHelp(IConsoleContext consoleContext)
 {
     consoleContext.WriteLine("vsixutil [/install] extensionPath [/rootSuffix name]");
     consoleContext.WriteLine("vsixutil /uninstall identifier [/rootSuffix name]");
     consoleContext.WriteLine("vsixutil /list [filter]");
     consoleContext.WriteLine("");
     consoleContext.WriteLine("The following filters can be used with all commands:");
     consoleContext.WriteLine("   /version 15 | 2017");
     consoleContext.WriteLine("   /product com | Community | preview");
 }
Ejemplo n.º 11
0
        public override void Run(IConsoleContext InConsole, Dictionary <string, object> InArguments)
        {
            int amount = 0;

            if (!int.TryParse(InArguments["<amount>"].ToString(), out amount))
            {
                InConsole.WriteLine("That's not a valid number.");
                return;
            }

            InConsole.WriteLine($"Congrats, you now have {amount} more Codepoints. :)");
            InConsole.CurrentSystem.AddCodepoints(amount);
        }
Ejemplo n.º 12
0
        public async Task <ConsoleCommandResult> Execute(IConsoleContext context, string commandname = null, string commandstring = null, IScope scope = null)
        {
            var result = new ConsoleCommandResult();

            try {
                await InternalExecute(context, result, commandname, commandstring, scope);
            }
            catch (Exception e) {
                if (0 == result.Status)
                {
                    result.Status = -1;
                }
                if (string.IsNullOrWhiteSpace(result.StatusDescription))
                {
                    result.StatusDescription = e.GetType().Name + ": " + e.Message;
                }
                if (null == result.Error)
                {
                    result.Error = e;
                }
            }
            return(result);
        }
Ejemplo n.º 13
0
        public override void Run(IConsoleContext InConsole, Dictionary <string, object> InArguments)
        {
            string window = InArguments["<window>"].ToString();

            var win = InConsole.CurrentSystem.GetWindows().FirstOrDefault(x => x.WindowTitle == window);

            if (win == null)
            {
                InConsole.WriteLine($"Error: No window named {window} found.");
                return;
            }

            if (win.Enabled == false)
            {
                win.Enabled = true;
                win.Opacity = 1;
            }
            else
            {
                win.Opacity = 0;
                win.Enabled = false;
            }
        }
Ejemplo n.º 14
0
        public override void Run(IConsoleContext InConsole, Dictionary <string, object> InArguments)
        {
            string setting = InArguments["<setting>"].ToString();
            string value   = InArguments["<value>"].ToString();

            switch (setting)
            {
            case "username":
                InConsole.CurrentSystem.Username = value;
                break;

            case "osname":
                if (!InConsole.CurrentSystem.HasShiftoriumUpgrade("osname"))
                {
                    goto default;
                }
                InConsole.CurrentSystem.OSName = value;
                break;

            default:
                InConsole.WriteLine("Error: setting not found.");
                break;
            }
        }
Ejemplo n.º 15
0
 public static void IndexHTMLContent(IConsoleContext context)
 {
     context.Response.WriteString(IndexHTML.CONTENT, "text/html");
 }
Ejemplo n.º 16
0
 public static void WriteLine(this IConsoleContext consoleContext)
 {
     consoleContext.WriteLine("");
 }
Ejemplo n.º 17
0
 protected abstract Task InternalExecute(IConsoleContext context, ConsoleCommandResult result, string commandname, string commandstring, IScope scope);
Ejemplo n.º 18
0
 public override void Run(IConsoleContext InConsole, Dictionary <string, object> InArguments)
 {
     InConsole.WriteLine(InConsole.CurrentSystem.GetTimeOfDay());
 }
Ejemplo n.º 19
0
 protected override async Task InternalExecute(IConsoleContext context, ConsoleCommandResult result, string commandname, string commandstring, IScope scope)
 {
     var request = ResolveService<IReportRequest>("", context);
     await Reports.Execute(request);
 }
Ejemplo n.º 20
0
 public ReportRequest(IConsoleContext context) : this()
 {
     ConsoleContext = context;
     Initialize();
 }
Ejemplo n.º 21
0
 public static void WriteLine(this IConsoleContext consoleContext, string text, params object[] args)
 {
     consoleContext.WriteLine(string.Format(text, args));
 }
Ejemplo n.º 22
0
        public static CommandLine ParseCommandLine(IConsoleContext consoleContext, params string[] args)
        {
            if (args.Length == 0)
            {
                return(CommandLine.Help);
            }

            var       toolAction    = ToolAction.Help;
            VsVersion?version       = null;
            string    product       = null;
            var       rootSuffix    = "";
            var       defaultDomain = false;
            var       arg           = "";

            int index = 0;

            while (index < args.Length)
            {
                switch (args[index].ToLower())
                {
                case "/i":
                case "/install":
                    if (index + 1 >= args.Length)
                    {
                        consoleContext.Write("/install requires an argument");
                        return(CommandLine.Help);
                    }

                    toolAction = ToolAction.Install;
                    arg        = args[index + 1];
                    index     += 2;
                    break;

                case "/u":
                case "/uninstall":
                    if (index + 1 >= args.Length)
                    {
                        consoleContext.Write("/uninstall requires an argument");
                        return(CommandLine.Help);
                    }

                    toolAction = ToolAction.Uninstall;
                    arg        = args[index + 1];
                    index     += 2;
                    break;

                case "/v":
                case "/version":
                    if (index + 1 >= args.Length)
                    {
                        consoleContext.Write("/version requires an argument");
                        return(CommandLine.Help);
                    }

                    version = VsVersionUtil.ToVsVersion(args[index + 1]);
                    index  += 2;
                    break;

                case "/p":
                case "/product":
                    if (index + 1 >= args.Length)
                    {
                        consoleContext.Write("/product requires an argument");
                        return(CommandLine.Help);
                    }

                    product = args[index + 1];
                    index  += 2;
                    break;

                case "/r":
                case "/rootsuffix":
                    if (index + 1 >= args.Length)
                    {
                        consoleContext.Write("/rootSuffix requires an argument");
                        return(CommandLine.Help);
                    }

                    rootSuffix = args[index + 1];
                    index     += 2;
                    break;

                case "/defaultdomain":
                    defaultDomain = true;
                    index++;
                    break;

                case "/l":
                case "/list":
                    toolAction = ToolAction.List;
                    if (index + 1 < args.Length)
                    {
                        arg = args[index + 1];
                    }

                    index = args.Length;
                    break;

                case "/help":
                    toolAction = ToolAction.Help;
                    index      = args.Length;
                    break;

                default:
                    arg = args[index];
                    if (!arg.StartsWith("/") && args.Length == 1)
                    {
                        // Default to Install if there's a single argument.
                        toolAction = ToolAction.Install;
                        index     += 1;
                        break;
                    }

                    consoleContext.WriteLine("{0} is not a valid argument", arg);
                    return(CommandLine.Help);
                }
            }

            return(new CommandLine(toolAction, version, product, rootSuffix, arg, defaultDomain: defaultDomain));
        }
Ejemplo n.º 23
0
 protected override async Task InternalExecute(IConsoleContext context, ConsoleCommandResult result, string commandname, string commandstring, IScope scope)
 {
     var request = ResolveService <IReportRequest>("", context);
     await Reports.Execute(request);
 }
Ejemplo n.º 24
0
        public static void SetLogLevel(IConsoleContext context)
        {
            var level = int.Parse(context.Request.QueryString.Get(0));

            _Instance._SetLogLevel((LogLevel)level);
        }
Ejemplo n.º 25
0
 public override void Run(IConsoleContext InConsole, Dictionary <string, object> InArguments)
 {
     InConsole.WriteLine($"You have {InConsole.CurrentSystem.GetCodepoints()} Codepoints.");
 }
Ejemplo n.º 26
0
 public override void Run(IConsoleContext InConsole, Dictionary <string, object> InArguments)
 {
     InConsole.CurrentSystem.Shutdown();
 }
Ejemplo n.º 27
0
 public ConsoleListener(IConsoleContext context,IScope scope = null) {
     _context = context;
     Scope = scope ?? new Scope();
 }
Ejemplo n.º 28
0
 public abstract void Run(IConsoleContext InConsole, Dictionary<string, object> InArguments);
Ejemplo n.º 29
0
 public ConsoleListener(IConsoleContext context, IScope scope = null)
 {
     _context = context;
     Scope    = scope ?? new Scope();
 }
Ejemplo n.º 30
0
        public CommandRunner Create(IConsoleContext consoleContext, InstalledVersion installedVersion, string rootSuffix)
        {
            var extensionManager = ExtensionManagerFactory.CreateExtensionManager(installedVersion, rootSuffix);

            return(new CommandRunner(consoleContext, extensionManager, installedVersion, rootSuffix));
        }