public void Run(ICommandInteraction writer)
        {
            var currentMachine = GetCurrentMachine();

            if (currentMachine == null)
            {
                writer.WriteError("Select active machine.");
                return;
            }
            writer.WriteLine("Available peripherals:");
            writer.WriteLine();

            var peripheralEntries = currentMachine.GetPeripheralsWithAllRegistrationPoints();
            var sysbusEntry       = peripheralEntries.First(x => x.Key.Name == Machine.SystemBusName);
            var sysbusNode        = new PeripheralNode(sysbusEntry);
            var nodeQueue         = new Queue <PeripheralNode>(peripheralEntries.Where(x => x.Key != sysbusEntry.Key).Select(x => new PeripheralNode(x)));

            while (nodeQueue.Count > 0)
            {
                var x = nodeQueue.Dequeue();
                // Adding nodes to sysbusNode is successful only if the current node's parent was already added.
                // This code effectively sorts the nodes topologically.
                if (!sysbusNode.AddChild(x))
                {
                    nodeQueue.Enqueue(x);
                }
            }
            sysbusNode.PrintTree(writer);
        }
            public void PrintTree(ICommandInteraction writer, TreeViewBlock[] pattern = null)
            {
                if (pattern == null)
                {
                    pattern = new TreeViewBlock[0];
                }
                var indent = GetIndentString(pattern);

                writer.WriteLine(String.Format("{0}{1} ({2})", indent, PeripheralEntry.Name, PeripheralEntry.Type.Name));

                if (PeripheralEntry.Parent != null)
                {
                    var newIndent = GetIndentString(UpdatePattern(pattern, Children.Count > 0 ? TreeViewBlock.Straight : TreeViewBlock.Empty));
                    if (!(PeripheralEntry.RegistrationPoint is ITheOnlyPossibleRegistrationPoint))
                    {
                        foreach (var registerPlace in RegistrationPoints)
                        {
                            writer.WriteLine(String.Format("{0}{1}", newIndent, registerPlace.PrettyString));
                        }
                    }
                    writer.WriteLine(newIndent);
                }
                else
                {
                    writer.WriteLine(GetIndentString(new TreeViewBlock[] { TreeViewBlock.Straight }));
                }

                var lastChild = Children.LastOrDefault();

                foreach (var child in Children)
                {
                    child.PrintTree(writer, UpdatePattern(pattern, child != lastChild ? TreeViewBlock.Full : TreeViewBlock.End));
                }
            }
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usage:");
     writer.WriteLine(String.Format("{0} \"name\"", Name));
 }
예제 #4
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usage:");
     writer.WriteLine(String.Format("{0} \"name\"", Name));
 }
예제 #5
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usage:");
     writer.WriteLine(String.Format("{0} <<message to log>> <<log level>>", Name));
 }
예제 #6
0
        public void Run(ICommandInteraction writer)
        {
            var currentMachine = GetCurrentMachine();

            if (currentMachine == null)
            {
                writer.WriteError("Select active machine.");
                return;
            }
            writer.WriteLine("Available peripherals:");
            var peripheralEntries = currentMachine.GetPeripheralsWithAllRegistrationPoints();

            foreach (var entry in peripheralEntries)
            {
                var isInMachine = entry.Key.Parent == null;
                var description = (isInMachine || entry.Key.RegistrationPoint is ITheOnlyPossibleRegistrationPoint) ? "{0} ({1}) in {2}\n\r" : "{0} ({1}) in {2} at ";
                var parentName  = !isInMachine?peripheralEntries.First(x => x.Key.Peripheral == entry.Key.Parent).Key.Name
                                  : EmulationManager.Instance.CurrentEmulation[currentMachine];

                var peripheralName = entry.Key.Name ?? "<unnamed>";
                var nameAndParent  = string.Format(description, peripheralName, entry.Key.Type.Name, parentName);
                writer.Write(nameAndParent);
                if (!(entry.Key.RegistrationPoint is ITheOnlyPossibleRegistrationPoint || isInMachine))
                {
                    writer.WriteLine(entry.Key.RegistrationPoint.PrettyString);
                    if (entry.Value.Count() > 1)
                    {
                        foreach (var otherEntry in entry.Value.Skip(1))
                        {
                            writer.WriteLine(String.Format("{1}and at {0}", otherEntry.PrettyString, " ".PadLeft(nameAndParent.Length - "and at".Length - 1)));
                        }
                    }
                }
            }
        }
예제 #7
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usage:");
     writer.WriteLine(String.Format("{0} <<message to log>> <<log level>>", Name));
 }
        public override void PrintHelp(ICommandInteraction writer)
        {
            base.PrintHelp(writer);

            writer.WriteLine("\nUsage:");
            writer.WriteLine("watch \"<command>\" <refresh period in ms>");
        }
예제 #9
0
 public void Run(ICommandInteraction writer)
 {
     var currentMachine = GetCurrentMachine();
     if( currentMachine == null)
     {
         writer.WriteError("Select active machine.");
         return;
     }
     writer.WriteLine("Available peripherals:");
     var peripheralEntries = currentMachine.GetPeripheralsWithAllRegistrationPoints();
     foreach(var entry in peripheralEntries)
     {
         var isInMachine = entry.Key.Parent == null;
         var description = (isInMachine || entry.Key.RegistrationPoint is ITheOnlyPossibleRegistrationPoint) ? "{0} ({1}) in {2}\n\r" : "{0} ({1}) in {2} at ";
         var parentName = !isInMachine ? peripheralEntries.First(x => x.Key.Peripheral == entry.Key.Parent).Key.Name
             : EmulationManager.Instance.CurrentEmulation[currentMachine];
         var peripheralName = entry.Key.Name ?? "<unnamed>";
         var nameAndParent = string.Format(description, peripheralName, entry.Key.Type.Name, parentName);
         writer.Write(nameAndParent);
         if(!(entry.Key.RegistrationPoint is ITheOnlyPossibleRegistrationPoint || isInMachine))
         {
             writer.WriteLine(entry.Key.RegistrationPoint.PrettyString);
             if(entry.Value.Count() > 1)
             {
                 foreach(var otherEntry in entry.Value.Skip(1))
                 {
                     writer.WriteLine(String.Format("{1}and at {0}", otherEntry.PrettyString, " ".PadLeft(nameAndParent.Length - "and at".Length-1 )));
                 }
             }
         }
     }
 }
예제 #10
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usage:");
     writer.WriteLine(String.Format("{0} - starts the current machine", Name));
     writer.WriteLine(String.Format("{0} @path - executes the script and starts the emulation", Name));
 }
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usage:");
     writer.WriteLine(Name);
     writer.WriteLine($"{Name} <<numberOfEntries>>");
 }
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("You must provide the name of the {0}.".FormatWith(noun));
     writer.WriteLine();
     writer.WriteLine(String.Format("Usage:\n\r\t{0} {1} \"value\"\n\r\n\r\t{0} {1}\n\r\t^^^\n\r\t[multiline value]\n\r\t^^^", Name, noun));
 }
예제 #13
0
파일: SetCommand.cs 프로젝트: rte-se/emul8
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("You must provide the name of the {0}.".FormatWith(noun));
     writer.WriteLine();
     writer.WriteLine(String.Format("Usage:\n\r\t{0} {1} \"value\"\n\r\n\r\t{0} {1}\n\r\t^^^\n\r\t[multiline value]\n\r\t^^^", Name, noun));
 }
예제 #14
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     var allowed = (monitor.CurrentBindingFlags & BindingFlags.NonPublic) > 0;
     writer.WriteLine();
     writer.WriteLine(allowed ? "Private fields are available":"Private fields are not available");
     return;
 }
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usage:");
     writer.WriteLine(String.Format("{0} - starts the whole emulation", Name));
     writer.WriteLine(String.Format("{0} @path - executes the script and starts the emulation", Name));
 }
        public override void PrintHelp(ICommandInteraction writer)
        {
            base.PrintHelp(writer);
            var allowed = (monitor.CurrentBindingFlags & BindingFlags.NonPublic) > 0;

            writer.WriteLine();
            writer.WriteLine(allowed ? "Private fields are available":"Private fields are not available");
            return;
        }
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine("\nOptions:");
     writer.WriteLine("===========================");
     foreach (var item in PlatformsProvider.GetAvailablePlatforms().OrderBy(x => x.Name))
     {
         writer.WriteLine(item.Name);
     }
 }
예제 #18
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Available terminals:");
     foreach (var key in console.Keys)
     {
         writer.WriteLine(string.Format("\t{0}", key));
     }
 }
예제 #19
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine("\nOptions:");
     writer.WriteLine("===========================");
     foreach(var item in PlatformsProvider.GetAvailablePlatforms().OrderBy(x=>x.Name))
     {
         writer.WriteLine(item.Name);
     }
 }
예제 #20
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Available terminals:");
     foreach(var key in console.Keys)
     {
         writer.WriteLine(string.Format("\t{0}", key));
     }
 }
 private void PrintAvailableLevels(ICommandInteraction writer)
 {
     writer.WriteLine("Available levels:\n");
     writer.WriteLine(string.Format("{0,-18}| {1}", "Level", "Name"));
     writer.WriteLine("=======================================");
     foreach (var item in LogLevel.AvailableLevels)
     {
         writer.WriteLine(string.Format("{0,-18}: {1}", item.NumericLevel, item));
     }
     writer.WriteLine();
 }
예제 #22
0
        public override int Execute(string[] args, ICommandInteraction writer)
        {
            writer.WriteLine("\nCommands:");
            writer.WriteLine(string.Format("{0,-18}|{1}", "Name", "Description"));
            writer.WriteLine("=======================================");
            foreach (var item in commands)
            {
                writer.WriteLine(string.Format("{0,-18}: {1}", item.Name, item.Description));
            }

            return(0);
        }
예제 #23
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Provide a command or {0} to execute.".FormatWith(noun));
     writer.WriteLine();
     writer.WriteLine("Available {0}s:".FormatWith(noun));
     foreach (var variable in GetVariables())
     {
         writer.WriteLine("\t{0}".FormatWith(variable));
     }
 }
예제 #24
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Provide a command or {0} to execute.".FormatWith(noun));
     writer.WriteLine();
     writer.WriteLine("Available {0}s:".FormatWith(noun));
     foreach(var variable in GetVariables())
     {
         writer.WriteLine("\t{0}".FormatWith(variable));
     }
 }
예제 #25
0
        public override void PrintHelp(ICommandInteraction writer)
        {
            base.PrintHelp(writer);
            writer.WriteLine();

            writer.WriteLine(string.Format("Current mode: {0}", monitor.CurrentNumberFormat));
            writer.WriteLine();
            writer.WriteLine("Options:");
            foreach(var item in typeof(Monitor.NumberModes).GetEnumNames())
            {
                writer.WriteLine(item);
            }
        }
        public override void PrintHelp(ICommandInteraction writer)
        {
            base.PrintHelp(writer);
            writer.WriteLine();

            writer.WriteLine(string.Format("Current mode: {0}", monitor.CurrentNumberFormat));
            writer.WriteLine();
            writer.WriteLine("Options:");
            foreach (var item in typeof(Monitor.NumberModes).GetEnumNames())
            {
                writer.WriteLine(item);
            }
        }
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usages:");
     writer.WriteLine(" logLevel");
     writer.WriteLine(" logLevel [LEVEL]");
     writer.WriteLine(" logLevel [LEVEL] [OBJECT]");
     writer.WriteLine(" logLevel [LEVEL] [BACKEND]");
     writer.WriteLine(" logLevel [LEVEL] [BACKEND] [OBJECT]");
     writer.WriteLine();
     writer.WriteLine("To see currently available backends execute command: logLevel");
     writer.WriteLine();
     PrintAvailableLevels(writer);
 }
예제 #28
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usages:");
     writer.WriteLine(" logLevel");
     writer.WriteLine(" logLevel [LEVEL]");
     writer.WriteLine(" logLevel [LEVEL] [OBJECT]");
     writer.WriteLine(" logLevel [LEVEL] [BACKEND]");
     writer.WriteLine(" logLevel [LEVEL] [BACKEND] [OBJECT]");
     writer.WriteLine();
     writer.WriteLine("To see currently available backends execute command: logLevel");
     writer.WriteLine();
     PrintAvailableLevels(writer);
 }
예제 #29
0
        public override int Execute(string[] args, ICommandInteraction writer)
        {
            writer.WriteLine("Commands history:");

            writer.WriteLine();
            var counter = 1;

            foreach (var item in history.Items)
            {
                writer.WriteLine(string.Format(" {0}: {1}", counter++, item));
            }

            writer.WriteLine();

            return(0);
        }
예제 #30
0
        public void Run(ICommandInteraction writer, LiteralToken peripheralName)
        {
            var         emu = EmulationManager.Instance.CurrentEmulation;
            IPeripheral p;
            string      fake;

            var m = monitor.Machine;

            if (m == null || !m.TryGetByName(peripheralName.Value, out p, out fake))
            {
                writer.WriteError(string.Format("Peripheral not found: {0}", peripheralName.Value));
                return;
            }

            IAnalyzableBackend backend;

            if (!emu.BackendManager.TryGetBackendFor(p, out backend))
            {
                writer.WriteError(string.Format("No backend found for {0}", peripheralName.Value));
                return;
            }

            foreach (var a in emu.BackendManager.GetAvailableAnalyzersFor(backend))
            {
                writer.WriteLine(a);
            }
        }
예제 #31
0
        public void Run(ICommandInteraction writer)
        {
            var output = $"Current virtual time: {EmulationManager.Instance.CurrentEmulation.MasterTimeSource.ElapsedVirtualTime}\nCurrent real time: {EmulationManager.Instance.CurrentEmulation.MasterTimeSource.ElapsedHostTime}";

            writer.WriteLine(output);
            Logger.LogAs(monitor, LogLevel.Info, output);
        }
예제 #32
0
        public void Run(ICommandInteraction writer, LiteralToken peripheralName)
        {
            var         emu = EmulationManager.Instance.CurrentEmulation;
            IPeripheral p;

            try
            {
                p = (IPeripheral)monitor.ConvertValueOrThrowRecoverable(peripheralName.Value, typeof(IPeripheral));
            }
            catch (RecoverableException)
            {
                writer.WriteError(string.Format("Peripheral not found: {0}", peripheralName.Value));
                return;
            }

            IAnalyzableBackend backend;

            if (!emu.BackendManager.TryGetBackendFor(p, out backend))
            {
                writer.WriteError(string.Format("No backend found for {0}", peripheralName.Value));
                return;
            }

            var def = emu.BackendManager.GetPreferredAnalyzerFor(backend);

            foreach (var a in emu.BackendManager.GetAvailableAnalyzersFor(backend))
            {
                writer.WriteLine(String.Format("{0}{1}", a, a == def ? " (default)" : String.Empty));
            }
        }
예제 #33
0
 public void Run(ICommandInteraction writer)
 {
     writer.WriteLine("Renode is quitting", ConsoleColor.Green);
     SetCurrentMachine(null);
     Quitted?.Invoke()?.Invoke();
     writer.QuitEnvironment = true;
 }
예제 #34
0
        public void Run(ICommandInteraction writer, [Values("default")] LiteralToken @default, LiteralToken peripheralName)
        {
            var         emu = EmulationManager.Instance.CurrentEmulation;
            IPeripheral p;
            string      fake;

            var m = monitor.Machine;

            if (m == null || !m.TryGetByName(peripheralName.Value, out p, out fake))
            {
                writer.WriteError(string.Format("Peripheral not found: {0}", peripheralName.Value));
                return;
            }

            IAnalyzableBackend backend;

            if (!emu.BackendManager.TryGetBackendFor(p, out backend))
            {
                writer.WriteError(string.Format("No backend found for {0}", peripheralName.Value));
                return;
            }

            var def = emu.BackendManager.GetPreferredAnalyzerFor(backend);

            writer.WriteLine(def ?? "No default analyzer found.");
        }
예제 #35
0
        public void Run(ICommandInteraction writer, LiteralToken peripheralName)
        {
            var emu = EmulationManager.Instance.CurrentEmulation;
            IPeripheral p;
            string fake;

            var m = monitor.Machine;
            if(m == null || !m.TryGetByName(peripheralName.Value, out p, out fake))
            {
                writer.WriteError(string.Format("Peripheral not found: {0}", peripheralName.Value));
                return;
            }

            IAnalyzableBackend backend;
            if(!emu.BackendManager.TryGetBackendFor(p, out backend))
            {
                writer.WriteError(string.Format("No backend found for {0}", peripheralName.Value));
                return;
            }

            foreach(var a in emu.BackendManager.GetAvailableAnalyzersFor(backend))
            {
                writer.WriteLine(a);
            }
        }
예제 #36
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usage:");
     writer.WriteLine($"{Name} width height");
     writer.WriteLine("Generates testing image");
     writer.WriteLine();
     writer.WriteLine($"{Name} path_to_image");
     writer.WriteLine("Supported file formats:");
     writer.WriteLine("jpeg");
     writer.WriteLine("png");
 }
        public override int Execute(string[] args, ICommandInteraction writer)
        {
            foreach (var name in Enum.GetNames(typeof(ConsoleColor)))
            {
                writer.WriteLine(name, (ConsoleColor)Enum.Parse(typeof(ConsoleColor), name));
            }

            return(0);
        }
예제 #38
0
 public void Run(ICommandInteraction writer)
 {
     var currentMachine = GetCurrentMachine();
     if(currentMachine == null)
     {
         writer.WriteError("Select active machine.");
         return;
     }
     writer.WriteLine("Starting emulation...");
     currentMachine.Start();        
 }
        public override int Execute(string[] args, ICommandInteraction writer)
        {
            if (args.Length != 1)
            {
                writer.WriteError("Usage: Print");
                return(1);
            }

            writer.WriteLine(Calculator.Value.ToString());

            return(0);
        }
예제 #40
0
파일: HaltCommand.cs 프로젝트: rasomc/emul8
        public void Halt(ICommandInteraction writer)
        {
            var currentMachine = GetCurrentMachine();

            if (currentMachine == null)
            {
                writer.WriteError("Select active machine.");
                return;
            }
            writer.WriteLine("Pausing emulation...");
            currentMachine.Pause();
        }
 public override void PrintHelp(ICommandInteraction writer)
 {
     writer.WriteLine("Usage:");
     writer.WriteLine("------");
     writer.WriteLine("showAnalyzer ([externalName]) [peripheral] ([typeName])");
     writer.WriteLine("\tshows analyzer for [peripheral]");
     writer.WriteLine("");
     writer.WriteLine("[externalName] (optional) - if set, command will create external named [externalName]; this can be used only for analyzers implementing IExternal interface");
     writer.WriteLine("[typeName] (optional) - if set, command will select analyzer provided in class [typeName]; this must be used when there are more than one analyzers available and no default is set"); 
 }
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     PrintCurrentPath(writer);
     writer.WriteLine(string.Format("Default 'PATH' value is: {0}", monitorPath.DefaultPath));
     writer.WriteLine();
     writer.WriteLine("You can use following commands:");
     writer.WriteLine(String.Format("'{0} set @path'\tto set 'PATH' to the given value", Name));
     writer.WriteLine(String.Format("'{0} add @path'\tto append the given value to 'PATH'", Name));
     writer.WriteLine(String.Format("'{0} reset'\t\tto reset 'PATH' to it's default value", Name));
 }
예제 #43
0
        private bool TryCompilePlugin(string filename, ICommandInteraction writer)
        {
            string sha;

            using (var shaComputer = SHA256.Create())
            {
                using (var f = File.OpenRead(filename))
                {
                    var bytesSha = shaComputer.ComputeHash(f);

                    var strBldr = new StringBuilder(32 * 2);
                    foreach (var b in bytesSha)
                    {
                        strBldr.AppendFormat("{0:X2}", b);
                    }
                    sha = strBldr.ToString();

                    if (scannedFilesCache.Contains(sha))
                    {
                        writer.WriteLine($"Code from file {filename} has already been compiled. Ignoring...");
                        return(true);
                    }
                }
            }

            try
            {
                if (!EmulationManager.Instance.CompiledFilesCache.TryGetEntryWithSha(sha, out var compiledCode))
                {
                    var compiler = new AdHocCompiler();
                    compiledCode = compiler.Compile(filename);
                    EmulationManager.Instance.CompiledFilesCache.StoreEntryWithSha(sha, compiledCode);
                }

                cache.ClearCache();
                var result = TypeManager.Instance.ScanFile(compiledCode);
                if (result)
                {
                    scannedFilesCache.Add(sha);
                }
                return(result);
            }
            catch (Exception e)
                when(e is RecoverableException ||
                     e is InvalidOperationException)
                {
                    writer.WriteError("Errors during compilation or loading:\r\n" + e.Message.Replace(Environment.NewLine, "\r\n"));
                    return(false);
                }
        }
예제 #44
0
파일: HelpCommand.cs 프로젝트: rte-se/emul8
 public void GeneralHelp(ICommandInteraction writer)
 {
     writer.WriteLine("Available commands:");
     writer.WriteLine(string.Format("{0,-18}| {1}", "Name", "Description"));
     writer.WriteLine("================================================================================");
     foreach(var item in GetCommands().OrderBy(x=>x.Name))
     {
         writer.WriteLine(string.Format("{0,-18}: {1}", item.Name, item.Description));    
     }
     writer.WriteLine();
     writer.WriteLine("You can also provide a device name to access its methods.");
     writer.WriteLine("Use <TAB> for auto-completion.");
 }
예제 #45
0
        public override void PrintHelp(ICommandInteraction writer)
        {
            base.PrintHelp(writer);

            writer.WriteLine("\nTo load a script you have to provide an existing file name.");
            writer.WriteLine();
            writer.WriteLine("Supported file formats:");
            writer.WriteLine("*.cs  - plugin file");
            writer.WriteLine("*.py  - python script");
            writer.WriteLine("other - monitor script");
        }
예제 #46
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Current 'using':");
     if(!GetUsings().Any())
     {
         writer.WriteLine("\t[none]");
     }
     foreach(var use in GetUsings())
     {
         writer.WriteLine ("\t"+ use.Substring(0, use.Length-1)); //to remove the trailing dot
     }
     writer.WriteLine();
     writer.WriteLine(String.Format("To clear all current usings execute \"{0} -\".", Name));
 }
예제 #47
0
        public void Run(ICommandInteraction writer, [Values("default")] LiteralToken @default, LiteralToken peripheralName)
        {
            var emu = EmulationManager.Instance.CurrentEmulation;
            IPeripheral p;
            string fake;

            var m = monitor.Machine;
            if(m == null || !m.TryGetByName(peripheralName.Value, out p, out fake))
            {
                writer.WriteError(string.Format("Peripheral not found: {0}", peripheralName.Value));
                return;
            }

            IAnalyzableBackend backend;
            if(!emu.BackendManager.TryGetBackendFor(p, out backend))
            {
                writer.WriteError(string.Format("No backend found for {0}", peripheralName.Value));
                return;
            }

            var def = emu.BackendManager.GetPreferredAnalyzerFor(backend);
            writer.WriteLine(def ?? "No default analyzer found.");
        }
예제 #48
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Usage:");
     writer.WriteLine("- to trace only function call with a registered handler:");
     writer.WriteLine("{0} {1} cpuName \"functionName\"".FormatWith(Name, TraceEnableCommand));
     writer.WriteLine();
     writer.WriteLine("- to trace function call and returned value with a registered handler:");
     writer.WriteLine("{0} {1} cpuName \"functionName\" true".FormatWith(Name, TraceEnableCommand));
     writer.WriteLine();
     writer.WriteLine("- to trace function call without a handler, with or without return value:");
     writer.WriteLine("{0} {1} cpuName \"functionName\" [true|false] [number of parameters]".FormatWith(Name, TraceEnableCommand));
     writer.WriteLine();
     writer.WriteLine("- to trace function call without a handler, with or without return value, with specified variable types:");
     writer.WriteLine("{0} {1} cpuName \"functionName\" [true|false] [list of parameter types]".FormatWith(Name, TraceEnableCommand));
     writer.WriteLine("(Note, that if return value is expected, the last parameter type must relate to return value.");
     writer.WriteLine();
     writer.WriteLine("- to disable tracing of a function:");
     writer.WriteLine("{0} {1} cpuName \"functionName\"".FormatWith(Name, TraceDisableCommand));
     writer.WriteLine();
     writer.WriteLine("Handlers available for functions:");
     writer.WriteLine(handlers.Keys.Select(x => "- " + x).Stringify("\r\n"));
     writer.WriteLine();
     writer.WriteLine("Possible values for parameter types:");
     writer.WriteLine(Enum.GetNames(typeof(FunctionCallParameterType)).Where(x => !x.Contains("Array")).Select(x => "- " + x).Stringify("\r\n"));
 }
예제 #49
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteError("\nYou must specify the filename (full path or relative) for output file.");
 }
예제 #50
0
파일: MachCommand.cs 프로젝트: rte-se/emul8
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     var currentMachine = GetCurrentMachine();
     if(currentMachine == null)
     {
         writer.WriteError("No machine selected.");
     }
     else
     {
         writer.WriteLine(string.Format("Current machine: {0}", EmulationManager.Instance.CurrentEmulation[currentMachine]));
     }
     if(EmulationManager.Instance.CurrentEmulation.MachinesCount > 0)
     {
         writer.WriteLine("Available machines:");
         var emu = EmulationManager.Instance.CurrentEmulation;
         var longestNameLength = emu.Machines.Max(m => emu[m].Length);
         var i = 0;
         foreach(var machine in emu.Machines)
         {
             writer.WriteLine(string.Format("\t{2}: {0,-" + longestNameLength + "} {1}", emu[machine], machine.Platform != null ? string.Format("[{0}]", machine.Platform.Name) : string.Empty, i++));
         }
     }
     writer.WriteLine();
     writer.WriteLine("You can use the following commands:");
     writer.WriteLine("'mach set [\"name\"|number]'\tto enable the given machine");
     writer.WriteLine("'mach add \"name\"'\tto create a new machine with the specified name");
     writer.WriteLine("'mach rem \"name\"'\tto remove a machine");
     writer.WriteLine("'mach create'\tto create a new machine with generic name and switch to it");
     writer.WriteLine("'mach clear'\tto clear the current selection");
 }
예제 #51
0
        private void PrintMonitorInfo(string name, MonitorInfo info, ICommandInteraction writer, string lookup = null)
        {
            var ColorDefault = string.Format("\x1B[{0};{1}m", 0, 0);
            var ColorRed = string.Format("\x1B[{0};{1}m", 1, 31);
            var ColorGreen = string.Format("\x1B[{0};{1}m", 0, 32);
            var ColorYellow = string.Format("\x1B[{0};{1}m", 0, 33);

            if(info == null)
            {
                return;
            }
            if(info.Methods != null && info.Methods.Any(x => lookup == null || x.Name == lookup))
            {
                writer.WriteLine("\nFollowing methods are available:");
                var methodsOutput = new StringBuilder();

                foreach(var method in info.Methods.Where(x=> lookup == null || x.Name==lookup))
                {
                    methodsOutput.Append(" - " + ColorGreen + TypePrettyName(method.ReturnType) + ColorDefault + " " + method.Name);

                    IEnumerable<ParameterInfo> parameters;

                    if(method.IsExtension())
                    {
                        parameters = method.GetParameters().Skip(1);
                    }
                    else
                    {
                        parameters = method.GetParameters();
                    }
                    parameters = parameters.Where(x => !Attribute.IsDefined(x, typeof(AutoParameterAttribute)));

                    methodsOutput.Append(" (");

                    var lastParameter = parameters.LastOrDefault();
                    foreach(var param in parameters.Where(x=> !x.IsRetval))
                    {
                        if(param.IsOut)
                        {
                            methodsOutput.Append(ColorYellow + "out ");
                        }
                        methodsOutput.Append(ColorGreen + TypePrettyName(param.ParameterType) + ColorDefault + " " + param.Name);
                        if(param.IsOptional)
                        {
                            methodsOutput.Append(" = " + ColorRed);
                            if(param.DefaultValue == null)
                            {
                                methodsOutput.Append("null");
                            }
                            else
                            {
                                if(param.ParameterType.Name == "String")
                                {
                                    methodsOutput.Append('"');
                                }
                                methodsOutput.Append(param.DefaultValue);
                                if(param.ParameterType.Name == "String")
                                {
                                    methodsOutput.Append('"');
                                }
                            }
                            methodsOutput.Append(ColorDefault);
                        }
                        if(lastParameter != param)
                        {
                            methodsOutput.Append(", ");
                        }
                    }
                    methodsOutput.Append(")");
                    writer.WriteLine(methodsOutput.ToString());
                    methodsOutput.Clear();
                }
                writer.WriteLine(string.Format("\n\rUsage:\n\r {0} MethodName param1 param2 ...\n\r", name));
            }
         
            if(info.Properties != null && info.Properties.Any(x => lookup == null || x.Name == lookup))
            {
                writer.WriteLine("\nFollowing properties are available:");

                foreach(var property in info.Properties.Where(x=> lookup==null || x.Name==lookup))
                {
                    writer.Write(string.Format(
                        " - " + ColorGreen + "{1} " + ColorDefault + "{0}\n\r",
                        property.Name,
                        TypePrettyName(property.PropertyType)
                    ));
                    writer.Write("     available for ");
                    if(property.IsCurrentlyGettable(CurrentBindingFlags))
                    {
                        writer.Write(ColorYellow + "'get'" + ColorDefault);
                    }
                    if(property.IsCurrentlyGettable(CurrentBindingFlags) && property.IsCurrentlySettable(CurrentBindingFlags))
                    {
                        writer.Write(" and ");
                    }
                    if(property.IsCurrentlySettable(CurrentBindingFlags))
                    {
                        writer.Write(ColorYellow + "'set'" + ColorDefault);
                    }
                    writer.WriteLine();
                }
                writer.WriteLine(string.Format(
                    "\n\rUsage: \n\r - " + ColorYellow + "get" + ColorDefault + ": {0} PropertyName\n\r - " + ColorYellow + "set" + ColorDefault + ": {0} PropertyName Value\n\r",
                    name
                ));
            }

            if(info.Indexers != null && info.Indexers.Any(x => lookup == null || x.Name == lookup))
            {
                writer.WriteLine("\nFollowing indexers are available:");
                foreach(var indexer in info.Indexers.Where(x=> lookup==null || x.Name==lookup))
                {
                    var parameterFormat = new StringBuilder();
                    parameterFormat.Append(string.Format(
                        " - " + ColorGreen + "{1} " + ColorDefault + "{0}[",
                        indexer.Name,
                        TypePrettyName(indexer.PropertyType)
                    ));
                    var parameters = indexer.GetIndexParameters();
                    var lastParameter = parameters.LastOrDefault();
                    foreach(var param in parameters)
                    {

                        parameterFormat.Append(ColorGreen + TypePrettyName(param.ParameterType) + ColorDefault + " " + param.Name);
                        if(param.IsOptional)
                        {
                            parameterFormat.Append(" = " + ColorRed);
                            if(param.DefaultValue == null)
                            {
                                parameterFormat.Append("null");
                            }
                            else
                            {
                                if(param.ParameterType.Name == "String")
                                {
                                    parameterFormat.Append('"');
                                }
                                parameterFormat.Append(param.DefaultValue);
                                if(param.ParameterType.Name == "String")
                                {
                                    parameterFormat.Append('"');
                                }
                            }
                            parameterFormat.Append(ColorDefault);
                        }
                        if(lastParameter != param)
                        {
                            parameterFormat.Append(", ");
                        }
                    }
                    parameterFormat.Append(']');
                    writer.Write(parameterFormat.ToString());
                    writer.Write("     available for ");
                    if(indexer.IsCurrentlyGettable(CurrentBindingFlags))
                    {
                        writer.Write(ColorYellow + "'get'" + ColorDefault);
                    }
                    if(indexer.IsCurrentlyGettable(CurrentBindingFlags) && indexer.IsCurrentlySettable(CurrentBindingFlags))
                    {
                        writer.Write(" and ");
                    }
                    if(indexer.IsCurrentlySettable(CurrentBindingFlags))
                    {
                        writer.Write(ColorYellow + "'set'" + ColorDefault);
                    }
                    writer.WriteLine();
                }
                writer.WriteLine(string.Format(
                    "\n\rUsage: \n\r - " + ColorYellow + "get" + ColorDefault + ": {0} IndexerName [param1 param2 ...]\n\r - "
                    + ColorYellow + "set" + ColorDefault + ": {0} IndexerName [param1 param2 ... ] Value\n\r   IndexerName is optional if every indexer has the same name.",
                    name
                ));
            }

            if(info.Fields != null && info.Fields.Any(x => lookup == null || x.Name == lookup))
            {
                writer.WriteLine("\nFollowing fields are available:");

                foreach(var field in info.Fields.Where(x=> lookup==null || x.Name==lookup))
                {
                    writer.Write(string.Format(" - " + ColorGreen + "{1} " + ColorDefault + "{0}", field.Name, TypePrettyName(field.FieldType)));
                    if(field.IsLiteral || field.IsInitOnly)
                    {
                        writer.Write(" (read only)");
                    }
                    writer.WriteLine("");
                }
                writer.WriteLine(string.Format(
                    "\n\rUsage: \n\r - " + ColorYellow + "get" + ColorDefault + ": {0} fieldName\n\r - " + ColorYellow + "set" + ColorDefault + ": {0} fieldName Value\n\r",
                    name
                ));
            }
        }
예제 #52
0
        private void PrintCurrentLevels(ICommandInteraction writer)
        {
            string objectName;
            string machineName;

            writer.WriteLine("Currently set levels:\n");
            writer.WriteLine(string.Format("{0,-18}| {1,-36}| {2}", "Backend", "Emulation element", "Level"));
            writer.WriteLine("=================================================================");
            foreach(var backend in Logger.GetBackends().Where(b => b.Value.IsControllable))
            {
                writer.WriteLine(string.Format("{0,-18}: {1,-36}: {2}", backend.Key, string.Empty, backend.Value.GetLogLevel()));
                foreach (var custom in backend.Value.GetCustomLogLevels())
                {
                    EmulationManager.Instance.CurrentEmulation.CurrentLogger.TryGetName(custom.Key, out objectName, out machineName);
                    writer.WriteLine(string.Format("{0,-18}: {1,-36}: {2}", string.Empty, string.Format("{0}:{1}", machineName, objectName), custom.Value));
                }
                writer.WriteLine("-----------------------------------------------------------------");
            }
        }
예제 #53
0
        private void ProcessDeviceAction(Type device, string name, IEnumerable<Token> p, ICommandInteraction writer)
        {
            var devInfo = GetMonitorInfo(device);
            if(!p.Any())
            {
                if(devInfo != null)
                {
                    PrintMonitorInfo(name, devInfo, writer);
                }
            }
            else
            {
                object result;
                try
                {
                    result = ExecuteDeviceAction(device, name, p);
                }
                catch(ParametersMismatchException)
                {
                    if(devInfo != null)
                    {
                        PrintMonitorInfo(name, devInfo, writer, p.First().OriginalValue);
                    }
                    throw;
                }
                if(result != null)
                {
                    PrintActionResult(result, writer);

                    if(result.GetType().IsEnum)
                    {
                        writer.WriteLine("\nPossible values are:");
                        foreach(var entry in Enum.GetValues(result.GetType()))
                        {
                            writer.WriteLine(string.Format("\t{0} ({1})", entry, /*(int)*/entry));
                        }
                        writer.WriteLine();
                    }
                }
            }            
        }
예제 #54
0
        private void RunCommand(ICommandInteraction writer, Command command, IList<Token> parameters)
        {
            var commandType = command.GetType();
            var runnables = commandType.GetMethods().Where(x => x.GetCustomAttributes(typeof(RunnableAttribute), true).Any());
            ICommandInteraction candidateWriter = null;
            MethodInfo foundCandidate = null;
            bool lastIsAccurateMatch = false;
            IEnumerable<object> preparedParameters = null;

            foreach(var candidate in runnables)
            {
                bool isAccurateMatch = false;
                var candidateParameters = candidate.GetParameters();
                var writers = candidateParameters.Where(x => typeof(ICommandInteraction).IsAssignableFrom(x.ParameterType)).ToList();

                var lastIsArray = candidateParameters.Length > 0
                                  && typeof(IEnumerable<Token>).IsAssignableFrom(candidateParameters[candidateParameters.Length - 1].ParameterType);

                if(writers.Count > 1
                //all but last (and optional writer) should be tokens
                   || candidateParameters.Skip(writers.Count).Take(candidateParameters.Length - writers.Count - 1).Any(x => !typeof(Token).IsAssignableFrom(x.ParameterType))
                //last one should be Token or IEnumerable<Token>
                   || (candidateParameters.Length > writers.Count
                   && !typeof(Token).IsAssignableFrom(candidateParameters[candidateParameters.Length - 1].ParameterType)
                   && !lastIsArray))
                {
                    throw new RecoverableException(String.Format("Method {0} of command {1} has invalid signature, will not process further. You should file a bug report.", 
                        candidate.Name, command.Name));
                }
                IList<Token> parametersWithoutLastArray = null;
                IList<ParameterInfo> candidateParametersWithoutArrayAndWriters = null;
                if(lastIsArray)
                {
                    candidateParametersWithoutArrayAndWriters = candidateParameters.Skip(writers.Count).Take(candidateParameters.Length - writers.Count - 1).ToList();
                    if(parameters.Count < candidateParameters.Length - writers.Count) //without writer
                    {
                        continue;
                    }
                    parametersWithoutLastArray = parameters.Take(candidateParametersWithoutArrayAndWriters.Count()).ToList();
                }
                else
                {
                    candidateParametersWithoutArrayAndWriters = candidateParameters.Skip(writers.Count).ToList();
                    if(parameters.Count != candidateParameters.Length - writers.Count) //without writer
                    {
                        continue;
                    }
                    parametersWithoutLastArray = parameters;
                }
                //Check for types
                if(parametersWithoutLastArray.Zip(
                       candidateParametersWithoutArrayAndWriters,
                       (x, y) => new {FromUser = x.GetType(), FromMethod = y.ParameterType})
                    .Any(x => !x.FromMethod.IsAssignableFrom(x.FromUser)))
                {
                    continue;
                }
              
                bool constraintsOk = true;
                //Check for constraints
                for(var i = 0; i < parametersWithoutLastArray.Count; ++i)
                {
                    var attribute = candidateParametersWithoutArrayAndWriters[i].GetCustomAttributes(typeof(ValuesAttribute), true);
                    if(attribute.Any())
                    {
                        if(!((ValuesAttribute)attribute[0]).Values.Contains(parametersWithoutLastArray[i].GetObjectValue()))
                        {
                            constraintsOk = false;
                            break;
                        }
                    }
                }
                if(lastIsArray)
                {
                    var arrayParameters = parameters.Skip(parametersWithoutLastArray.Count()).ToArray();
                    var elementType = candidateParameters.Last().ParameterType.GetElementType();
                    if(!arrayParameters.All(x => elementType.IsAssignableFrom(x.GetType())))
                    {
                        constraintsOk = false;
                    }
                    else
                    {
                        var array = Array.CreateInstance(elementType, arrayParameters.Length);
                        for(var i = 0; i < arrayParameters.Length; ++i)
                        {
                            array.SetValue(arrayParameters[i], i);
                        }
                        preparedParameters = parametersWithoutLastArray.Concat(new object[] { array });
                    }
                }
                else
                {
                    preparedParameters = parameters;
                }

                if(!constraintsOk)
                {
                    continue;
                }

                if(!parametersWithoutLastArray.Zip(
                       candidateParametersWithoutArrayAndWriters,
                       (x, y) => new {FromUser = x.GetType(), FromMethod = y.ParameterType})
                    .Any(x => x.FromMethod != x.FromUser))
                {
                    isAccurateMatch = true;
                }
                if(foundCandidate != null && (lastIsAccurateMatch == isAccurateMatch)) // if one is not better than the other
                {
                    throw new RecoverableException(String.Format("Ambiguous choice between methods {0} and {1} of command {2}. You should file a bug report.", 
                        foundCandidate.Name, candidate.Name, command.Name));
                }
                if(lastIsAccurateMatch) // previous was better
                {
                    continue;
                }
                foundCandidate = candidate;
                lastIsAccurateMatch = isAccurateMatch;

                if(writers.Count == 1)
                {
                    candidateWriter = writer;
                }
            }

            if(foundCandidate != null)
            {
                var parametersWithWriter = candidateWriter == null ? preparedParameters : new object[] { candidateWriter }.Concat(preparedParameters);
                try
                {
                    foundCandidate.Invoke(command, parametersWithWriter.ToArray());
                }
                catch(TargetInvocationException e)
                {
                    if(e.InnerException != null)
                    {
                        throw e.InnerException;
                    }
                    throw;
                }
                return;
            }
            if(parameters.Any(x => x is VariableToken))
            {
                RunCommand(writer, command, ExpandVariables(parameters));
                return;
            }
            writer.WriteError(String.Format("Bad parameters for command {0} {1}", command.Name, string.Join(" ", parameters.Select(x => x.OriginalValue))));
            command.PrintHelp(writer);
            writer.WriteLine();
        }
예제 #55
0
 private static void PrettyPrint2DArray(string[,] table, ICommandInteraction writer)
 {
     var columnLengths = new int[table.GetLength(1)];
     for(var i = 0; i < columnLengths.Length; i++)
     {
         for(var j = 0; j < table.GetLength(0); j++)
         {
             columnLengths[i] = Math.Max(table[j, i].Length, columnLengths[i]);
         }
     }
     var lineLength = columnLengths.Sum() + columnLengths.Length + 1;
     writer.WriteLine("".PadRight(lineLength, '-'));
     for(var i = 0; i < table.GetLength(0); i++)
     {
         if(i == 1)
         {
             writer.WriteLine("".PadRight(lineLength, '-'));
         }
         writer.Write('|');
         for(var j = 0; j < table.GetLength(1); j++)
         {
             writer.Write(table[i, j].PadRight(columnLengths[j]));
             writer.Write('|');
         }
         writer.WriteLine();
     }
     writer.WriteLine("".PadRight(lineLength, '-'));
 }
예제 #56
0
 private void PrintActionResult(object result, ICommandInteraction writer, bool withNewLine = true)
 {
     var endl = "";
     if(withNewLine)
     {
         endl = "\r\n"; //Cannot be Environment.NewLine, we need \r explicitly.
     }
     var enumerable = result as IEnumerable;
     if(result is int || result is long || result is uint || result is ushort || result is byte)
     {
         result.GetType();
         writer.Write(string.Format(GetNumberFormat(CurrentNumberFormat, 2 * Marshal.SizeOf(result.GetType())) + endl, result));
     }
     else if(result is string[,])
     {
         var table = result as string[,];
         PrettyPrint2DArray(table, writer);
     }
     else if(result is IDictionary)
     {
         dynamic dict = result;
         var length = 0;
         foreach(var entry in dict)
         {
             var value = entry.Key.ToString();
             length = length > value.Length ? length : value.Length;
         }
         foreach(var entry in dict)
         {
             var format = GetResultFormat(entry.Key, 0, length) + " : " + GetResultFormat(entry.Value, 1);
             string entryResult = string.Format(format, entry.Key, entry.Value); //DO NOT INLINE WITH WriteLine. May result with CS1973, but may even fail in runtime.
             writer.WriteLine(entryResult);
         }
         return;
     }
     else if(enumerable != null && !(result is string))
     {
         writer.Write("[\r\n");
         foreach(var item in enumerable)
         {
             PrintActionResult(item, writer, false);
             writer.Write(", ");
         }
         writer.Write("\r\n]" + endl);
     }
     else
     {
         writer.Write(result + endl);
     }
 }
예제 #57
0
 //TODO: unused, but maybe should be used.
 private void PrintPython(IEnumerable<Token> p, ICommandInteraction writer)
 {
     if(!p.Any())
     {
         writer.WriteLine("\nPython commands:");
         writer.WriteLine("===========================");
         foreach(var command in pythonRunner.GetPythonCommands())
         {
             writer.WriteLine(command);
         }
         writer.WriteLine();
     }
 }
예제 #58
0
 private void PrintAvailableLevels(ICommandInteraction writer)
 {
     writer.WriteLine("Available levels:\n");
     writer.WriteLine(string.Format("{0,-18}| {1}", "Level", "Name"));
     writer.WriteLine("=======================================");
     foreach(var item in LogLevel.AvailableLevels)
     {
         writer.WriteLine(string.Format("{0,-18}: {1}", item.NumericLevel, item));
     }
     writer.WriteLine();
 }
예제 #59
0
 public override void PrintHelp(ICommandInteraction writer)
 {
     base.PrintHelp(writer);
     writer.WriteLine();
     writer.WriteLine("Provide a command or variable to execute.");
 }