Пример #1
0
        public CommandTable GetCommandList()
        {
            CommandTable cmdlist = new CommandTable();

            cmdlist = _command.GetAllCommandList();
            return(cmdlist);
        }
Пример #2
0
        private static void InitializeCommandsAndIcons()
        {
            foreach (KeyValuePair <Assembly, List <IPluginClient> > Entry in LoadedPluginTable)
            {
                foreach (IPluginClient Plugin in Entry.Value)
                {
                    List <ICommand> PluginCommandList = Plugin.CommandList;
                    if (PluginCommandList != null)
                    {
                        List <ICommand> FullPluginCommandList = new List <ICommand>();
                        FullCommandList.Add(FullPluginCommandList, Plugin.Name);

                        foreach (ICommand Command in PluginCommandList)
                        {
                            FullPluginCommandList.Add(Command);

                            if (!IsSeparatorCommand(Command))
                            {
                                CommandTable.Add(Command, Plugin);
                            }
                        }
                    }

                    Icon PluginIcon = Plugin.Icon;
                    if (PluginIcon != null)
                    {
                        ConsolidatedPluginList.Add(Plugin);
                    }
                }
            }
        }
Пример #3
0
        public void cmdJobs(string args)
        {
            if (JobCollection.Current.Count <= 0)
            {
                _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
                return;
            }

            CommandTable tb = new CommandTable();

            _IO.WriteLine("");

            tb.AddRow(tb.AddRow(Lang.Get("Id"), Lang.Get("Status"), Lang.Get("Module")).MakeSeparator());

            foreach (Job j in JobCollection.Current)
            {
                CommandTableRow row;
                if (j.IsRunning)
                {
                    row              = tb.AddRow(j.Id.ToString(), Lang.Get("Running"), j.FullPathModule);
                    row[0].Align     = CommandTableCol.EAlign.Right;
                    row[1].ForeColor = ConsoleColor.Green;
                }
                else
                {
                    row              = tb.AddRow(j.Id.ToString(), Lang.Get("Dead"), j.FullPathModule);
                    row[0].Align     = CommandTableCol.EAlign.Right;
                    row[1].ForeColor = ConsoleColor.Red;
                }
            }

            tb.OutputColored(_IO);
            _IO.WriteLine("");
        }
Пример #4
0
        /// <summary>
        /// Get's the list of all the commands, descriptions
        /// </summary>
        /// <returns></returns>
        public CommandTable GetAllCommandList()
        {
            List <CommandList> cmdList  = new List <CommandList>();
            List <Temperature> tempList = new List <Temperature>();

            DocusignData.Models.Data datalist = new DocusignData.Models.Data();
            tempList = GetTemperatures();

            foreach (var item in datalist.commands)
            {
                string hotResponse  = "";
                string coldResponse = "";
                if (datalist.temperatureResponses.Count > 0)
                {
                    hotResponse  = datalist.temperatureResponses.Find(x => (x.CommandID == item.CommandID) && (x.TemperatueId == 1)).Response.ToString();
                    coldResponse = datalist.temperatureResponses.Find(x => (x.CommandID == item.CommandID) && (x.TemperatueId == 2)).Response.ToString();
                }
                cmdList.Add(new CommandList {
                    CommandID = item.CommandID, Description = item.CommandDescription, HotResponse = hotResponse, ColdResponse = coldResponse
                });
            }
            CommandTable cmd = new CommandTable
            {
                CommandList     = cmdList,
                TemperatureList = tempList
            };


            return(cmd);
        }
        public async Task IntegrationTestOrderAttack()
        {
            // Arrange
            CommandQueue repository       = new CommandQueue(DevelopmentStorageAccountConnectionString);
            Guid         targetRegionGuid = new Guid("8449A25B-363D-4F01-B3D9-7EF8C5D42047");

            // Act
            Guid operationGuid;

            using (IBatchOperationHandle batchOperation = new BatchOperationHandle(CommandTable))
            {
                operationGuid = await repository.OrderAttack(batchOperation, SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", targetRegionGuid, 5U);
            }

            // Assert
            var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + RegionGuid.ToString() + "_" + targetRegionGuid.ToString());
            var result    = await CommandTable.ExecuteAsync(operation);

            CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry;

            Assert.IsNotNull(queuedCommand);
            Assert.AreEqual(operationGuid, queuedCommand.OperationId);
            Assert.AreEqual(SessionGuid, queuedCommand.SessionId);
            Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId);
            Assert.AreEqual(CommandQueueMessageType.Attack, queuedCommand.MessageType);
            Assert.AreEqual(RegionGuid, queuedCommand.SourceRegion);
            Assert.AreEqual("DummyEtag", queuedCommand.SourceRegionEtag);
            Assert.AreEqual(targetRegionGuid, queuedCommand.TargetRegion);
            Assert.AreEqual(5U, queuedCommand.NumberOfTroops);
        }
        public async Task IntegrationTestOrderAttack_MergeWithExisting()
        {
            // Arrange
            CommandQueue           repository         = new CommandQueue(DevelopmentStorageAccountConnectionString);
            Guid                   targetRegionGuid   = new Guid("7E3BCD95-EB8B-4401-A987-F613A3428676");
            Guid                   initialOperationId = Guid.NewGuid();
            CommandQueueTableEntry newCommand         = CommandQueueTableEntry.CreateAttackMessage(initialOperationId, SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", targetRegionGuid, 5U);

            CommandTable.Execute(TableOperation.Insert(newCommand));

            // Act
            Guid operationGuid;

            using (IBatchOperationHandle batchOperation = new BatchOperationHandle(CommandTable))
            {
                operationGuid = await repository.OrderAttack(batchOperation, SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", targetRegionGuid, 4U);
            }

            // Assert
            var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + RegionGuid.ToString() + "_" + targetRegionGuid.ToString());
            var result    = await CommandTable.ExecuteAsync(operation);

            CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry;

            Assert.IsNotNull(queuedCommand);
            Assert.AreEqual(operationGuid, queuedCommand.OperationId);
            Assert.AreNotEqual(operationGuid, initialOperationId);
            Assert.AreEqual(SessionGuid, queuedCommand.SessionId);
            Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId);
            Assert.AreEqual(CommandQueueMessageType.Attack, queuedCommand.MessageType);
            Assert.AreEqual(RegionGuid, queuedCommand.SourceRegion);
            Assert.AreEqual("DummyEtag", queuedCommand.SourceRegionEtag);
            Assert.AreEqual(targetRegionGuid, queuedCommand.TargetRegion);
            Assert.AreEqual(9U, queuedCommand.NumberOfTroops);
        }
Пример #7
0
        public bool Run(ManagementScope connection)
        {
            CommandTable table = new CommandTable();

            table.AddRow(table.AddRow("Name", "Value").MakeSeparator());

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(connection, new ObjectQuery(Sql));

            foreach (ManagementObject q in searcher.Get())
            {
                foreach (PropertyData p in q.Properties)
                {
                    try
                    {
                        CommandTableRow row = table.AddRow(1, new string[] { p.Name, p.Value.ToString() });
                        row[0].ForeColor = ConsoleColor.DarkGray;
                        row[1].Align     = CommandTableCol.EAlign.None;
                    }
                    catch { }
                }

                table.AddSeparator(2, '-');
            }

            WriteTable(table);
            return(true);
        }
Пример #8
0
        private void AddMenuItem(ToolStripItemCollection destinationItems, System.Windows.Controls.MenuItem menuItem)
        {
            string MenuHeader = (string)menuItem.Header;

            ToolStripMenuItem NewMenuItem;

            if (menuItem.Icon is Bitmap MenuBitmap)
            {
                NewMenuItem = new ToolStripMenuItem(MenuHeader, MenuBitmap);
            }

            else if (menuItem.Icon is Icon MenuIcon)
            {
                NewMenuItem = new ToolStripMenuItem(MenuHeader, MenuIcon.ToBitmap());
            }

            else
            {
                NewMenuItem = new ToolStripMenuItem(MenuHeader);
            }

            NewMenuItem.Click += OnMenuClicked;
            // See PrepareMenuItem for using the visibility to carry Visible/Enabled flags
            NewMenuItem.Visible = (menuItem.Visibility != System.Windows.Visibility.Collapsed);
            NewMenuItem.Enabled = (menuItem.Visibility == System.Windows.Visibility.Visible);
            NewMenuItem.Checked = menuItem.IsChecked;

            destinationItems.Add(NewMenuItem);
            MenuTable.Add(NewMenuItem, this);
            CommandTable.Add(NewMenuItem, menuItem.Command);
        }
Пример #9
0
        public void cmdSearch(string args)
        {
            args = args.Trim().ToLowerInvariant();


            string[] pars = ArgumentHelper.ArrayFromCommandLine(args);
            if (pars != null && pars.Length > 0)
            {
                CommandTable tb = new CommandTable();

                bool primera1 = false;
                foreach (Module m in ModuleCollection.Current.Search(pars))
                {
                    if (!primera1)
                    {
                        if (tb.Count > 0)
                        {
                            tb.AddRow("", "", "");
                        }
                        CommandTableRow row = tb.AddRow(Lang.Get("Type"), Lang.Get("Path"), Lang.Get("Disclosure"));
                        tb.AddRow(row.MakeSeparator());
                        tb.AddRow("", "", "");
                        primera1 = true;
                    }

                    tb.AddRow(Lang.Get("Modules"), m.FullPath, m.DisclosureDate.ToShortDateString());
                }
                bool primera2 = false;
                foreach (IModule m in PayloadCollection.Current.Search(pars))
                {
                    if (!primera2)
                    {
                        if (tb.Count > 0)
                        {
                            tb.AddRow("", "", "");
                        }
                        CommandTableRow row = tb.AddRow(Lang.Get("Type"), Lang.Get("Path"), "");
                        tb.AddRow(row.MakeSeparator());
                        tb.AddRow("", "", "");
                        primera2 = true;
                    }

                    tb.AddRow(Lang.Get("Payload"), m.FullPath, "");
                }

                if (primera1 || primera2)
                {
                    tb.OutputColored(_IO);
                }
                else
                {
                    _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
                }
            }
            else
            {
                _IO.WriteInfo(Lang.Get("Be_More_Specific"));
            }
        }
Пример #10
0
 public void WriteTable(CommandTable table)
 {
     if (_IO == null)
     {
         return;
     }
     table.OutputColored(_IO);
 }
Пример #11
0
 private static void OnMenuClicked(ToolStripMenuItem menuItem)
 {
     if (MenuTable.ContainsKey(menuItem) && CommandTable.ContainsKey(menuItem))
     {
         TaskbarIcon TaskbarIcon = MenuTable[menuItem];
         if (CommandTable[menuItem] is RoutedCommand Command && TaskbarIcon.Target != null)
         {
             Command.Execute(TaskbarIcon, TaskbarIcon.Target);
         }
     }
 }
        public static void ClassInit(TestContext context)
        {
            CloudStorageEmulatorShepherd shepherd = new CloudStorageEmulatorShepherd();

            shepherd.Start();

            StorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
            TableClient    = StorageAccount.CreateCloudTableClient();

            CommandTable = CommandQueue.GetCommandQueueTableForSession(TableClient, SessionGuid);
            CommandTable.DeleteIfExists();
            CommandTable.CreateIfNotExists();
        }
Пример #13
0
        public static List <string> GetDescription(string solutionDir)
        {
            string xmlFile = solutionDir + @"CFIExtension\CFIPackage.vsct";

            // A FileStream is needed to read the XML document.
            FileStream fs     = new FileStream(xmlFile, FileMode.Open);
            XmlReader  reader = XmlReader.Create(fs);

            XmlSerializer serializer   = new XmlSerializer(typeof(CommandTable));
            CommandTable  commandTable = (CommandTable)serializer.Deserialize(reader);

            fs.Close();

            List <string> description = new List <string>();

            description.Add("Functions:");

            if (commandTable == null || commandTable.Commands == null)
            {
                return(description);
            }

            var commands = commandTable.Commands;

            int i = 0;

            foreach (var b in commands.Buttons.Button)
            {
                var txt = b.Strings.ToolTipText;
                if (string.IsNullOrEmpty(txt))
                {
                    txt = b.Strings.MenuText;
                }
                if (string.IsNullOrEmpty(txt))
                {
                    txt = b.Strings.CommandName;
                }
                if (string.IsNullOrEmpty(txt))
                {
                    txt = b.Strings.ButtonText;
                }

                description.Add(string.Format(" {0}. {1}", ++i, txt));
            }

            return(description);
        }
Пример #14
0
        static void DisplayAvailableCommands(CommandMenuItem menu, bool inner)
        {
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            CommandTable tb = new CommandTable();

            if (!inner)
            {
                menu.IO.WriteLine(Lang.Get("Available_Commands") + ":");
                menu.IO.WriteLine("");

                tb.AddRow(tb.AddRow(Lang.Get("Short"), Lang.Get("Command")).MakeSeparator());
            }

            bool entra         = false;
            var  abbreviations = menu.CommandAbbreviations().OrderBy(it => it.Key);

            foreach (var ab in abbreviations)
            {
                //if (ab.Value == null)
                //{
                //    menu.IO.Write("      ");
                //}
                //else
                //{
                //    menu.IO.Write(ab.Value.PadRight(3) + " | ");
                //}

                tb.AddRow(ab.Value, ab.Key)[0].Align = CommandTableCol.EAlign.Right;
                //menu.IO.WriteLine(ab.Key);
                entra = true;
            }

            if (entra)
            {
                menu.IO.WriteLine(tb.Output());
            }

            if (!inner)
            {
                menu.IO.WriteLine(Lang.Get("Type_Help"));
            }
        }
Пример #15
0
        //执行端发送Command控制命令节点
        public bool CreateCmdByCommandTable(CommandTable ct)
        {
            //进行多命令信息的初始化
            List <Step> CmdStepList = new List <Step>();

            CmdStepList = ct.GetStepList();

            int StepCount = CmdStepList.Count;

            m_CmdIndex = 0; //重新开始执行
            int devIndex = 0;

            SequenceCmdList.Clear(); //清空原来执行的内容

            if (StepCount > 0)       //说明具有多缓冲命令信息
            {
                //进行命令消息的存储
                for (int i = 0; i < StepCount; i++)
                {
                    devIndex = GetDevIndexByAddress(CmdStepList[i].Source.Address);
                    deviceconfig_autocmditem SequenceCmdItem = new deviceconfig_autocmditem();

                    SequenceCmdItem.secs           = CmdStepList[i].Time;        //执行时间S
                    SequenceCmdItem.ChangeTime     = CmdStepList[i].ChangeTime;  //变换时间
                    SequenceCmdItem.HoldTime       = CmdStepList[i].HodeTime;    //持续时间
                    SequenceCmdItem.DestValue      = CmdStepList[i].TargetValue; //目标值
                    SequenceCmdItem.ExeFlag        = false;                      //执行标志为false
                    SequenceCmdItem.devAddress     = CmdStepList[i].Source.Address;
                    SequenceCmdItem.devIndex       = GetDevIndexByAddress(CmdStepList[i].Source.Address);
                    SequenceCmdItem.ObjID          = CmdStepList[i].Source.ObjID;
                    SequenceCmdItem.ObjCmd         = CmdStepList[i].Source.ObjCmd;
                    SequenceCmdItem.ObjIdent       = devd[SequenceCmdItem.devIndex].devName;
                    SequenceCmdItem.RemoteSendPort = devd[SequenceCmdItem.devIndex].Sendport;
                    SequenceCmdList.Add(SequenceCmdItem);
                }
            }

            m_process_tick    = 0; //设定计时的ticket;
            m_CmdIndex        = 0; //当前cmdIndex的序号
            m_autorunfalg     = 1; //定义当前自动运行的状态标识
            m_StopPeriod_tick = 0; //当前停止的时间
            m_lastStopTicket  = 0; //记录上次停止的ticket
            LogHelper.Log("************" + System.DateTime.Now.ToString(HyConst.DATETIME_yMdHmsf_STRING) + "程序运行开始" + "***********");
            return(true);
        }
Пример #16
0
        public void cmdLoad(string args)
        {
            if (string.IsNullOrEmpty(args))
            {
                _IO.WriteError(Lang.Get("Incorrect_Command_Usage"));
                return;
            }
            args = args.Trim();
            if (!File.Exists(args))
            {
                _IO.WriteError(Lang.Get("File_Not_Exists", args));
                return;
            }

            try
            {
                _IO.SetForeColor(ConsoleColor.Gray);
                _IO.Write(Lang.Get("Reading_File", args));

                Assembly.Load(File.ReadAllBytes(args));
                //Assembly.LoadFile(args);

                _IO.SetForeColor(ConsoleColor.Green);
                _IO.WriteLine(Lang.Get("Ok").ToUpperInvariant());
            }
            catch
            {
                _IO.SetForeColor(ConsoleColor.Red);
                _IO.WriteLine(Lang.Get("Error").ToUpperInvariant());
            }
            CommandTable tb = new CommandTable();

            _IO.WriteLine("");

            tb.AddRow(tb.AddRow(Lang.Get("Type"), Lang.Get("Count")).MakeSeparator());

            tb.AddRow(Lang.Get("Modules"), ModuleCollection.Current.Load().ToString())[1].Align   = CommandTableCol.EAlign.Right;
            tb.AddRow(Lang.Get("Payloads"), PayloadCollection.Current.Load().ToString())[1].Align = CommandTableCol.EAlign.Right;
            tb.AddRow(Lang.Get("Encoders"), EncoderCollection.Current.Load().ToString())[1].Align = CommandTableCol.EAlign.Right;
            tb.AddRow(Lang.Get("Nops"), NopCollection.Current.Load().ToString())[1].Align         = CommandTableCol.EAlign.Right;

            tb.OutputColored(_IO);
            _IO.WriteLine("");
        }
Пример #17
0
        static void Main(string[] args)
        {
            //Initializes the server on port 35565. MaxPlayers=4
            NetworkManager.Init(35565, 4);


            //Initialize Content
            CommandTable.Init();
            PacketTable.Init();
            PacketManager.Lock(); //Locks the PacketManager.

            //Start Game Logic
            GameStarter.Start(Game.Start, Game.Stop, Game.Update);

            //Start listening for clients
            NetworkManager.StartListener();

            _isRunning = true;
            StartCommandLoop();
        }
Пример #18
0
        public void cmdVersion(string args)
        {
            _IO.WriteLine("");

            CommandTable tb = new CommandTable();

            _IO.WriteLine(Lang.Get("Version_Start"));
            _IO.WriteLine("");

            tb.AddRow(tb.AddRow(Lang.Get("File"), Lang.Get("Version")).MakeSeparator());

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (asm.GlobalAssemblyCache)
                {
                    continue;
                }

                string file = "??";
                if (string.IsNullOrEmpty(asm.Location))
                {
                    file = asm.ManifestModule.ScopeName;
                }
                else
                {
                    file = Path.GetFileName(asm.Location);
                }

                tb.AddRow(file, asm.ImageRuntimeVersion);
            }

            tb.AddRow("", "");

            tb.AddRow(tb.AddRow(Lang.Get("Module"), Lang.Get("Count")).MakeSeparator());
            tb.AddRow(Lang.Get("Modules"), ModuleCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Encoders"), EncoderCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Payloads"), PayloadCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Nops"), NopCollection.Current.Count.ToString());

            _IO.WriteLine(tb.Output());
        }
Пример #19
0
        private void DecodeAddr(int entryPoint)
        {
            ecl_offset = entryPoint;
            stopVM     = false;

            while (stopVM == false)
            {
                int command = ecl_ptr[ecl_offset + MemBase];

                int    addr = ecl_offset;
                string txt  = string.Format("0x{0:X4} 0x{1:X2} ", addr, command);

                CmdItem cmd;
                if (CommandTable.TryGetValue(command, out cmd))
                {
                    bool lastSkip = skipNext;

                    currentAddr = addr;
                    txt        += string.Format("{0} {1}", cmd.Name(), cmd.Dump());

                    if (lastSkip)
                    {
                        skipNext = false;
                        lastSkip = false;
                    }
                }
                else
                {
                    txt += "Unknown command";
                    break;
                }

                if (stopVM)
                {
                    txt += "\n\r";
                }

                AddLine(addr, txt, (ecl_offset - addr) & 0xFFFF);
            }
        }
Пример #20
0
        public async Task RunAsync_CanResolveScopedServices()
        {
            var services = new ServiceCollection();

            services.AddScoped <DisposableService>();
            services.AddTransient <TestCommand>();

            var activator = new DefaultCommandActivator(services.BuildServiceProvider());

            var commandTable = new CommandTable(activator);

            commandTable.RegisterCommands <TestCommand>();

            var runner = new CommandRunner(commandTable, new DefaultCommandSelector(),
                                           new ParameterBinder(new List <IPropertyConverter>()));

            // Test sync
            await runner.RunAsync("test");

            // Test await async
            await runner.RunAsync("test-async");
        }
Пример #21
0
        static void DisplayAvailableCommands(CommandMenuItem menu, bool inner)
        {
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            CommandTable tb = new CommandTable();

            if (!inner)
            {
                menu.IO.WriteLine(Lang.Get("Available_Commands") + ":");
                menu.IO.WriteLine("");

                tb.AddRow(tb.AddRow(Lang.Get("Short"), Lang.Get("Command")).MakeSeparator());
            }

            bool entra         = false;
            var  abbreviations = menu.CommandAbbreviations().OrderBy(it => it.Key);

            foreach (var ab in abbreviations)
            {
                CommandTableRow row = tb.AddRow(ab.Value, ab.Key);
                row[0].Align     = CommandTableCol.EAlign.Right;
                row[0].ForeColor = ConsoleColor.Yellow;

                entra = true;
            }

            if (entra)
            {
                tb.OutputColored(menu.IO);
            }
            if (!inner)
            {
                menu.IO.WriteLine(Lang.Get("Type_Help"));
            }
        }
        public async Task IntegrationTestCreateReinforceMessage()
        {
            // Arrange
            CommandQueue repository = new CommandQueue(DevelopmentStorageAccountConnectionString);

            // Act
            Guid operationGuid = await repository.DeployReinforcements(SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", 10U);

            // Assert
            var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + operationGuid.ToString());
            var result    = await CommandTable.ExecuteAsync(operation);

            CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry;

            Assert.IsNotNull(queuedCommand);
            Assert.AreEqual(operationGuid, queuedCommand.OperationId);
            Assert.AreEqual(SessionGuid, queuedCommand.SessionId);
            Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId);
            Assert.AreEqual(CommandQueueMessageType.Reinforce, queuedCommand.MessageType);
            Assert.AreEqual(RegionGuid, queuedCommand.TargetRegion);
            Assert.AreEqual("DummyEtag", queuedCommand.TargetRegionEtag);
            Assert.AreEqual(10U, queuedCommand.NumberOfTroops);
        }
Пример #23
0
        private void ParseTextSection(string line)
        {
            // Check for label
            var labelIndex = line.IndexOf(":", StringComparison.Ordinal);

            if (labelIndex > -1)
            {
                var label = line.Substring(0, labelIndex);
                CommandTable.Add(label, CommandList.Count);

                if (line.Length > labelIndex + 1)
                {
                    line = line.Substring(labelIndex + 1).Trim(' ', '\t');
                }
                else
                {
                    return;
                }
            }

            // Add new Command
            CommandList.Add(line);
        }
Пример #24
0
        static void DisplayAvailableCommands(CommandMenuItem menu, bool inner)
        {
            if (menu == null) throw new ArgumentNullException("menu");

            CommandTable tb = new CommandTable();

            if (!inner)
            {
                menu.IO.WriteLine(Lang.Get("Available_Commands") + ":");
                menu.IO.WriteLine("");

                tb.AddRow(tb.AddRow(Lang.Get("Short"), Lang.Get("Command")).MakeSeparator());
            }

            bool entra = false;
            var abbreviations = menu.CommandAbbreviations().OrderBy(it => it.Key);
            foreach (var ab in abbreviations)
            {
                //if (ab.Value == null)
                //{
                //    menu.IO.Write("      ");
                //}
                //else
                //{
                //    menu.IO.Write(ab.Value.PadRight(3) + " | ");
                //}

                tb.AddRow(ab.Value, ab.Key)[0].Align = CommandTableCol.EAlign.Right;
                //menu.IO.WriteLine(ab.Key);
                entra = true;
            }

            if (entra) menu.IO.WriteLine(tb.Output());

            if (!inner) menu.IO.WriteLine(Lang.Get("Type_Help"));
        }
        public async Task IntegrationTestRedeploy()
        {
            // Arrange
            CommandQueue repository       = new CommandQueue(DevelopmentStorageAccountConnectionString);
            Guid         targetRegionGuid = new Guid("8449A25B-363D-4F01-B3D9-7EF8C5D42047");

            // Act
            Guid operationGuid = await repository.Redeploy(SessionGuid, SessionPhaseGuid, String.Empty, RegionGuid, targetRegionGuid, 5U);

            // Assert
            var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + operationGuid.ToString());
            var result    = await CommandTable.ExecuteAsync(operation);

            CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry;

            Assert.IsNotNull(queuedCommand);
            Assert.AreEqual(operationGuid, queuedCommand.OperationId);
            Assert.AreEqual(SessionGuid, queuedCommand.SessionId);
            Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId);
            Assert.AreEqual(CommandQueueMessageType.Redeploy, queuedCommand.MessageType);
            Assert.AreEqual(RegionGuid, queuedCommand.SourceRegion);
            Assert.AreEqual(targetRegionGuid, queuedCommand.TargetRegion);
            Assert.AreEqual(5U, queuedCommand.NumberOfTroops);
        }
Пример #26
0
 public void Add(string[] _Name, CommandType _CommandType, UserFlags _FlagsRequired, string _Description, CommandTable _SubCommandTable, Delegate _ProcMethod)
 {
     System.Reflection.MethodInfo mi = _ProcMethod.Method;
     System.Reflection.ParameterInfo[] pars = mi.GetParameters();
     CommandData data = new CommandData { CommandName = _Name, CommandType = _CommandType, FlagsRequired = _FlagsRequired, Description = _Description, SubCommandTable = _SubCommandTable, ProcMethod = mi, ParameterInfo = pars, ParameterCount = pars.Length - 2 };
     _dict.Add(_Name, data);
 }
Пример #27
0
 /// <summary>
 /// Recursively explores children of a command table to return a command that a user can use with their permission.
 /// Returns null if no command was found.
 /// </summary>
 /// <param name="user">The calling user</param>
 /// <param name="tbl">The parent command table to use</param>
 /// <param name="args">An array containing the issued command</param>
 /// <param name="argIdx">The index of the current position in args[]</param>
 protected CommandData GetCommandData(User user, CommandTable tbl, ref string[] args, ref int argIdx)
 {
     CommandData cmd = tbl[args[argIdx].ToLower()];
     if (cmd != null)
     {
         if (cmd.SubCommandTable != null)
         {
             if (++argIdx < args.Length)
             {
                 CommandData cmd2 = GetCommandData(user, cmd.SubCommandTable, ref args, ref argIdx);
                 if (cmd2 != null && UserHasRankOrHigher(user, cmd2.FlagsRequired))
                     return cmd2;
             }
             argIdx--;
         }
         if (UserHasRankOrHigher(user, cmd.FlagsRequired))
             return cmd;
     }
     return null;
 }
Пример #28
0
        public void cmdInfo(string args)
        {
            if (!CheckModule(false, EModuleType.None))
            {
                return;
            }
            args = args.Trim().ToLowerInvariant();

            Module curM = _Current.ModuleType == EModuleType.Module ? (Module)_Current : null;

            CommandTable tb = new CommandTable();

            tb.AddRow(Lang.Get("Path"), _Current.ModulePath, "")[0].ForeColor = ConsoleColor.DarkGray;
            tb.AddRow(Lang.Get("Name"), _Current.Name, "")[0].ForeColor       = ConsoleColor.DarkGray;

            tb.AddRow("", "", "");

            ModuleInfoAttribute mInfo = _Current == null ? null : _Current.GetType().GetCustomAttribute <ModuleInfoAttribute>();

            if (mInfo != null && !string.IsNullOrEmpty(mInfo.Author))
            {
                CommandTableRow row = tb.AddRow(1, Lang.Get("Author"), mInfo.Author, "");
                row[0].ForeColor = ConsoleColor.DarkGray;
                row[1].Align     = CommandTableCol.EAlign.None;
                row[2].Align     = CommandTableCol.EAlign.None;
            }

            if (curM != null)
            {
                if (curM.DisclosureDate != DateTime.MinValue)
                {
                    tb.AddRow(Lang.Get("DisclosureDate"), curM.DisclosureDate.ToString(), "")[0].ForeColor = ConsoleColor.DarkGray;
                }

                if (curM.References != null && curM.References.Length > 0)
                {
                    tb.AddRow("", "", "");

                    StringBuilder sb = new StringBuilder();
                    foreach (Reference r in curM.References)
                    {
                        if (r == null)
                        {
                            continue;
                        }
                        sb.AppendLine(r.Type.ToString() + " - " + r.Value);
                    }

                    foreach (CommandTableRow row in tb.AddSplitRow(1, Lang.Get("References"), sb.ToString(), ""))
                    {
                        row[0].ForeColor = ConsoleColor.DarkGray;
                        row[1].Align     = CommandTableCol.EAlign.None;
                        row[2].Align     = CommandTableCol.EAlign.None;
                    }
                }
            }

            if (mInfo != null && !string.IsNullOrEmpty(mInfo.Description))
            {
                foreach (CommandTableRow row in tb.AddSplitRow(1, Lang.Get("Description"), mInfo.Description, ""))
                {
                    row[0].ForeColor = ConsoleColor.DarkGray;
                    row[1].Align     = CommandTableCol.EAlign.None;
                    row[2].Align     = CommandTableCol.EAlign.None;
                }
            }
            tb.OutputColored(_IO);
        }
Пример #29
0
 public static CommandTupleList ListCommand(CommandTable t) => new CommandTupleList(t);
Пример #30
0
 public void Add(string _Name, string _Alias1, string _Alias2, string _Alias3, string _Alias4, CommandType _CommandType, UserFlags _FlagsRequired, string _Description, CommandTable _SubCommandTable, Delegate _ProcMethod)
 {
     Add(new string[] { _Name, _Alias1, _Alias2, _Alias3, _Alias4 }, _CommandType, _FlagsRequired, _Description, _SubCommandTable, _ProcMethod);
 }
Пример #31
0
        public void cmdJobs(string args)
        {
            if (JobCollection.Current.Count <= 0)
            {
                _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
                return;
            }

            CommandTable tb = new CommandTable();

            _IO.WriteLine("");

            tb.AddRow(tb.AddRow(Lang.Get("Id"), Lang.Get("Status"), Lang.Get("Module")).MakeSeparator());

            foreach (Job j in JobCollection.Current)
            {
                CommandTableRow row;
                if (j.IsRunning)
                {
                    row = tb.AddRow(j.Id.ToString(), Lang.Get("Running"), j.FullPathModule);
                    row[0].Align = CommandTableCol.EAlign.Right;
                    row[1].ForeColor = ConsoleColor.Green;
                }
                else
                {
                    row = tb.AddRow(j.Id.ToString(), Lang.Get("Dead"), j.FullPathModule);
                    row[0].Align = CommandTableCol.EAlign.Right;
                    row[1].ForeColor = ConsoleColor.Red;
                }
            }

            tb.OutputColored(_IO);
            _IO.WriteLine("");
        }
Пример #32
0
        /// <summary>
        ///     Creates a new Prexonite virtual machine.
        /// </summary>
        public Engine()
        {
            //Thread local storage for stack
            _stackSlot = Thread.AllocateDataSlot();

            //Metatable
            _meta = MetaTable.Create();

            //PTypes
            _pTypeMap = new Dictionary<Type, PType>();
            _ptypemapiterator = new PTypeMapIterator(this);
            //int
            PTypeMap[typeof (int)] = PType.Int;
            PTypeMap[typeof (long)] = PType.Int;
            PTypeMap[typeof (short)] = PType.Int;
            PTypeMap[typeof (byte)] = PType.Int;

#if UseNonCTSIntegers
            PTypeMap[typeof(uint)]      = IntPType.Instance;
            PTypeMap[typeof(ulong)]     = IntPType.Instance;
            PTypeMap[typeof(ushort)]    = IntPType.Instance;
            PTypeMap[typeof(sbyte)]     = IntPType.Instance;
#endif

            //char
            PTypeMap[typeof (char)] = PType.Char;

            //bool
            PTypeMap[typeof (bool)] = PType.Bool;

            //real
            PTypeMap[typeof (float)] = PType.Real;
            PTypeMap[typeof (double)] = PType.Real;

            //string
            PTypeMap[typeof (string)] = PType.String;

            PTypeMap[typeof (List<PValue>)] = PType.List;
            PTypeMap[typeof (PValue[])] = PType.List;
            PTypeMap[typeof (PValueHashtable)] = PType.Hash;

            //Registry
            _pTypeRegistry = new SymbolTable<Type>();
            _pTypeRegistryIterator = new PTypeRegistryIterator(this);
            PTypeRegistry[IntPType.Literal] = typeof (IntPType);
            PTypeRegistry[BoolPType.Literal] = typeof (BoolPType);
            PTypeRegistry[RealPType.Literal] = typeof (RealPType);
            PTypeRegistry[CharPType.Literal] = typeof (CharPType);
            PTypeRegistry[StringPType.Literal] = typeof (StringPType);
            PTypeRegistry[NullPType.Literal] = typeof (NullPType);
            PTypeRegistry[ObjectPType.Literal] = typeof (ObjectPType);
            PTypeRegistry[ListPType.Literal] = typeof (ListPType);
            PTypeRegistry[StructurePType.Literal] = typeof (StructurePType);
            PTypeRegistry[HashPType.Literal] = typeof (HashPType);
            PTypeRegistry[StructurePType.Literal] = typeof (StructurePType);

            //Assembly registry
            _registeredAssemblies = new List<Assembly>();
            foreach (
                var assName in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
                _registeredAssemblies.Add(Assembly.Load(assName.FullName));

            //Commands
            _commandTable = new CommandTable();
            PCommand cmd;

            Commands.AddEngineCommand(PrintAlias, ConsolePrint.Instance);

            Commands.AddEngineCommand(PrintLineAlias, ConsolePrintLine.Instance);

            Commands.AddEngineCommand(MetaAlias, Prexonite.Commands.Core.Meta.Instance);

            Commands.AddEngineCommand(BoxedAlias, Boxed.Instance);

            // The concatenate command has been renamed to `string_concat` for Prexonite 2
            Commands.AddEngineCommand(ConcatenateAlias, Concat.Instance);
            Commands.AddEngineCommand(OldConcatenateAlias, Concat.Instance);

            Commands.AddEngineCommand(MapAlias, cmd = Map.Instance);
            Commands.AddEngineCommand(SelectAlias, cmd);

            Commands.AddEngineCommand(FoldLAlias, FoldL.Instance);

            Commands.AddEngineCommand(FoldRAlias, FoldR.Instance);

            Commands.AddEngineCommand(DisposeAlias, Dispose.Instance);

            // There is a macro that uses the same alias (CallAlias)
            //  it has the same purpose. For backwards compatibility,
            //  the command table will retain the old binding.
            Commands.AddEngineCommand(CallAlias, Call.Instance);
            Commands.AddEngineCommand(Call.Alias, Call.Instance);

            Commands.AddEngineCommand(ThunkAlias, ThunkCommand.Instance);
            Commands.AddEngineCommand(AsThunkAlias, AsThunkCommand.Instance);
            Commands.AddEngineCommand(ForceAlias, ForceCommand.Instance);
            Commands.AddEngineCommand(ToSeqAlias, ToSeqCommand.Instance);

            // There is a macro that uses the same alias (Call_MemberAlias)
            //  it has the same purpose. For backwards compatibility,
            //  the command table will retain the old binding.
            Commands.AddEngineCommand(Call_MemberAlias, Call_Member.Instance);
            Commands.AddEngineCommand(Call_Member.Alias, Call_Member.Instance);

            Commands.AddEngineCommand(CallerAlias, Caller.Instance);

            Commands.AddEngineCommand(PairAlias, Pair.Instance);

            Commands.AddEngineCommand(UnbindAlias, Unbind.Instance);

            Commands.AddEngineCommand(SortAlias, Sort.Instance);
            Commands.AddEngineCommand(SortAlternativeAlias, Sort.Instance);

            Commands.AddEngineCommand(LoadAssemblyAlias, LoadAssembly.Instance);

            Commands.AddEngineCommand(DebugAlias, new Debug());

            Commands.AddEngineCommand(SetCenterAlias, SetCenterCommand.Instance);

            Commands.AddEngineCommand(SetLeftAlias, SetLeftCommand.Instance);

            Commands.AddEngineCommand(SetRightAlias, SetRightCommand.Instance);

            Commands.AddEngineCommand(AllAlias, All.Instance);

            Commands.AddEngineCommand(WhereAlias, Where.Instance);

            Commands.AddEngineCommand(SkipAlias, Skip.Instance);

            Commands.AddEngineCommand(LimitAlias, cmd = Limit.Instance);
            Commands.AddEngineCommand(TakeAlias, cmd);

            Commands.AddEngineCommand(AbsAlias, Abs.Instance);

            Commands.AddEngineCommand(CeilingAlias, Ceiling.Instance);

            Commands.AddEngineCommand(ExpAlias, Exp.Instance);

            Commands.AddEngineCommand(FloorAlias, Floor.Instance);

            Commands.AddEngineCommand(LogAlias, Log.Instance);

            Commands.AddEngineCommand(MaxAlias, Max.Instance);

            Commands.AddEngineCommand(MinAlias, Min.Instance);

            Commands.AddEngineCommand(PiAlias, Pi.Instance);

            Commands.AddEngineCommand(RoundAlias, Round.Instance);

            Commands.AddEngineCommand(SinAlias, Sin.Instance);
            Commands.AddEngineCommand(CosAlias, Cos.Instance);

            Commands.AddEngineCommand(SqrtAlias, Sqrt.Instance);

            Commands.AddEngineCommand(TanAlias, Tan.Instance);

            Commands.AddEngineCommand(CharAlias, Char.Instance);

            Commands.AddEngineCommand(CountAlias, Count.Instance);

            Commands.AddEngineCommand(DistinctAlias, cmd = new Distinct());
            Commands.AddEngineCommand(UnionAlias, cmd);
            Commands.AddEngineCommand(UniqueAlias, cmd);

            Commands.AddEngineCommand(FrequencyAlias, new Frequency());

            Commands.AddEngineCommand(GroupByAlias, new GroupBy());

            Commands.AddEngineCommand(IntersectAlias, new Intersect());

            // There is a macro that uses the same alias (Call_TailAlias)
            //  it has the same purpose. For backwards compatibility,
            //  the command table will retain the old binding.
            Commands.AddEngineCommand(Call_TailAlias, Call_Tail.Instance);
            Commands.AddEngineCommand(Call_Tail.Alias, Call_Tail.Instance);

            Commands.AddEngineCommand(ListAlias, List.Instance);

            Commands.AddEngineCommand(EachAlias, Each.Instance);

            Commands.AddEngineCommand(ExistsAlias, new Exists());

            Commands.AddEngineCommand(ForAllAlias, new ForAll());

            Commands.AddEngineCommand(CompileToCilAlias, CompileToCil.Instance);

            Commands.AddEngineCommand(TakeWhileAlias, TakeWhile.Instance);

            Commands.AddEngineCommand(ExceptAlias, Except.Instance);

            Commands.AddEngineCommand(RangeAlias, Range.Instance);

            Commands.AddEngineCommand(ReverseAlias, Reverse.Instance);

            Commands.AddEngineCommand(HeadTailAlias, HeadTail.Instance);

            Commands.AddEngineCommand(AppendAlias, Append.Instance);

            Commands.AddEngineCommand(SumAlias, Sum.Instance);

            Commands.AddEngineCommand(Contains.Alias, Contains.Instance);

            Commands.AddEngineCommand(ChanAlias, Chan.Instance);

            Commands.AddEngineCommand(SelectAlias, Select.Instance);

            Commands.AddEngineCommand(Call_AsyncAlias, CallAsync.Instance);
            Commands.AddEngineCommand(CallAsync.Alias, CallAsync.Instance);

            Commands.AddEngineCommand(AsyncSeqAlias, AsyncSeq.Instance);

            Commands.AddEngineCommand(CallSubPerformAlias, CallSubPerform.Instance);

            Commands.AddEngineCommand(PartialCallAlias, new PartialCallCommand());

            Commands.AddEngineCommand(PartialMemberCallAlias, PartialMemberCallCommand.Instance);

            Commands.AddEngineCommand(PartialConstructionAlias, PartialConstructionCommand.Instance);

            Commands.AddEngineCommand(PartialTypeCheckAlias, PartialTypeCheckCommand.Instance);
            Commands.AddEngineCommand(PartialTypeCastAlias, PartialTypecastCommand.Instance);
            Commands.AddEngineCommand(PartialStaticCallAlias, PartialStaticCallCommand.Instance);
            Commands.AddEngineCommand(FunctionalPartialCallCommand.Alias,
                FunctionalPartialCallCommand.Instance);
            Commands.AddEngineCommand(FlippedFunctionalPartialCallCommand.Alias,
                FlippedFunctionalPartialCallCommand.Instance);
            Commands.AddEngineCommand(PartialCallStarImplCommand.Alias,
                PartialCallStarImplCommand.Instance);

            Commands.AddEngineCommand(ThenAlias, ThenCommand.Instance);

            Commands.AddEngineCommand(Id.Alias, Id.Instance);
            Commands.AddEngineCommand(Const.Alias, Const.Instance);

            OperatorCommands.AddToEngine(this);

            Commands.AddEngineCommand(CreateEnumerator.Alias, CreateEnumerator.Instance);

            Commands.AddEngineCommand(CreateModuleName.Alias, CreateModuleName.Instance);

            Commands.AddEngineCommand(GetUnscopedAstFactory.Alias, GetUnscopedAstFactory.Instance);

            Commands.AddEngineCommand(CreateSourcePosition.Alias, CreateSourcePosition.Instance);

            Commands.AddEngineCommand(SeqConcat.Alias, SeqConcat.Instance);
        }
Пример #33
0
        public void cmdSearch(string args)
        {
            args = args.Trim().ToLowerInvariant();


            string[] pars = ArgumentHelper.ArrayFromCommandLine(args);
            if (pars != null && pars.Length > 0)
            {
                CommandTable tb = new CommandTable();

                bool primera1 = false;
                foreach (Module m in ModuleCollection.Current.Search(pars))
                {
                    if (!primera1)
                    {
                        if (tb.Count > 0) tb.AddRow("", "", "");
                        CommandTableRow row = tb.AddRow(Lang.Get("Type"), Lang.Get("Path"), Lang.Get("Disclosure"));
                        tb.AddRow(row.MakeSeparator());
                        tb.AddRow("", "", "");
                        primera1 = true;
                    }

                    tb.AddRow(Lang.Get("Modules"), m.FullPath, m.DisclosureDate.ToShortDateString());
                }
                bool primera2 = false;
                foreach (IModule m in PayloadCollection.Current.Search(pars))
                {
                    if (!primera2)
                    {
                        if (tb.Count > 0) tb.AddRow("", "", "");
                        CommandTableRow row = tb.AddRow(Lang.Get("Type"), Lang.Get("Path"), "");
                        tb.AddRow(row.MakeSeparator());
                        tb.AddRow("", "", "");
                        primera2 = true;
                    }

                    tb.AddRow(Lang.Get("Payload"), m.FullPath, "");
                }

                if (primera1 || primera2)
                    tb.OutputColored(_IO);
                else
                    _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
            }
            else
            {
                _IO.WriteInfo(Lang.Get("Be_More_Specific"));
            }
        }
Пример #34
0
        public void cmdLoad(string args)
        {
            if (string.IsNullOrEmpty(args))
            {
                _IO.WriteError(Lang.Get("Incorrect_Command_Usage"));
                return;
            }
            args = args.Trim();
            if (!File.Exists(args))
            {
                _IO.WriteError(Lang.Get("File_Not_Exists", args));
                return;
            }

            try
            {
                _IO.SetForeColor(ConsoleColor.Gray);
                _IO.Write(Lang.Get("Reading_File", args));

                Assembly.Load(File.ReadAllBytes(args));
                //Assembly.LoadFile(args);

                _IO.SetForeColor(ConsoleColor.Green);
                _IO.WriteLine(Lang.Get("Ok").ToUpperInvariant());
            }
            catch
            {
                _IO.SetForeColor(ConsoleColor.Red);
                _IO.WriteLine(Lang.Get("Error").ToUpperInvariant());
            }
            CommandTable tb = new CommandTable();

            _IO.WriteLine("");

            tb.AddRow(tb.AddRow(Lang.Get("Type"), Lang.Get("Count")).MakeSeparator());

            tb.AddRow(Lang.Get("Modules"), ModuleCollection.Current.Load().ToString())[1].Align = CommandTableCol.EAlign.Right;
            tb.AddRow(Lang.Get("Payloads"), PayloadCollection.Current.Load().ToString())[1].Align = CommandTableCol.EAlign.Right;
            tb.AddRow(Lang.Get("Encoders"), EncoderCollection.Current.Load().ToString())[1].Align = CommandTableCol.EAlign.Right;
            tb.AddRow(Lang.Get("Nops"), NopCollection.Current.Load().ToString())[1].Align = CommandTableCol.EAlign.Right;

            tb.OutputColored(_IO);
            _IO.WriteLine("");
        }
Пример #35
0
        public void cmdVersion(string args)
        {
            _IO.WriteLine("");

            CommandTable tb = new CommandTable();

            _IO.WriteLine(Lang.Get("Version_Start"));
            _IO.WriteLine("");

            tb.AddRow(tb.AddRow(Lang.Get("File"), Lang.Get("Version")).MakeSeparator());

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (asm.GlobalAssemblyCache) continue;

                string file = "??";
                if (string.IsNullOrEmpty(asm.Location))
                    file = asm.ManifestModule.ScopeName;
                else file = Path.GetFileName(asm.Location);

                tb.AddRow(file, asm.ImageRuntimeVersion);
            }

            tb.AddRow("", "");

            tb.AddRow(tb.AddRow(Lang.Get("Module"), Lang.Get("Count")).MakeSeparator());
            tb.AddRow(Lang.Get("Modules"), ModuleCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Encoders"), EncoderCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Payloads"), PayloadCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Nops"), NopCollection.Current.Count.ToString());

            _IO.WriteLine(tb.Output());
        }
Пример #36
0
 public RADTupleList(CommandTable t) : this(t.Data as Table)
 {
 }
Пример #37
0
        public void cmdInfo(string args)
        {
            if (!CheckModule(false, EModuleType.None)) return;
            args = args.Trim().ToLowerInvariant();

            Module curM = _Current.ModuleType == EModuleType.Module ? (Module)_Current : null;

            CommandTable tb = new CommandTable();

            tb.AddRow(Lang.Get("Path"), _Current.Path, "")[0].ForeColor = ConsoleColor.DarkGray;
            tb.AddRow(Lang.Get("Name"), _Current.Name, "")[0].ForeColor = ConsoleColor.DarkGray;

            tb.AddRow("", "", "");

            if (!string.IsNullOrEmpty(_Current.Author))
            {
                CommandTableRow row = tb.AddRow(1, Lang.Get("Author"), _Current.Author, "");
                row[0].ForeColor = ConsoleColor.DarkGray;
                row[1].Align = CommandTableCol.EAlign.None;
                row[2].Align = CommandTableCol.EAlign.None;
            }

            if (curM != null)
            {
                if (curM.DisclosureDate != DateTime.MinValue) tb.AddRow(Lang.Get("DisclosureDate"), curM.DisclosureDate.ToString(), "")[0].ForeColor = ConsoleColor.DarkGray;
                tb.AddRow(Lang.Get("IsLocal"), curM.IsLocal.ToString(), "")[0].ForeColor = ConsoleColor.DarkGray;
                tb.AddRow(Lang.Get("IsRemote"), curM.IsRemote.ToString(), "")[0].ForeColor = ConsoleColor.DarkGray;

                if (curM.References != null && curM.References.Length > 0)
                {
                    tb.AddRow("", "", "");

                    StringBuilder sb = new StringBuilder();
                    foreach (Reference r in curM.References)
                    {
                        if (r == null) continue;
                        sb.AppendLine(r.Type.ToString() + " - " + r.Value);
                    }

                    foreach (CommandTableRow row in tb.AddSplitRow(1, Lang.Get("References"), sb.ToString(), ""))
                    {
                        row[0].ForeColor = ConsoleColor.DarkGray;
                        row[1].Align = CommandTableCol.EAlign.None;
                        row[2].Align = CommandTableCol.EAlign.None;
                    }
                }
            }

            if (!string.IsNullOrEmpty(_Current.Description))
            {
                foreach (CommandTableRow row in tb.AddSplitRow(1, Lang.Get("Description"), _Current.Description, ""))
                {
                    row[0].ForeColor = ConsoleColor.DarkGray;
                    row[1].Align = CommandTableCol.EAlign.None;
                    row[2].Align = CommandTableCol.EAlign.None;
                }
            }
            tb.OutputColored(_IO);
        }
Пример #38
0
 public CommandTupleList(CommandTable data) : this(new RADTupleList(data))
 {
 }
Пример #39
0
        public void cmdShow(string args)
        {
            if (!CheckModule(false, EModuleType.None)) return;
            args = args.Trim().ToLowerInvariant();

            Module curM = _Current.ModuleType == EModuleType.Module ? (Module)_Current : null;

            switch (args)
            {
                case "":
                case "info": { cmdInfo(args); break; }
                case "options":
                case "config":
                    {
                        // set target id
                        Target[] ps = null;

                        if (curM != null)
                        {
                            ps = curM.Targets;
                            if (ps != null)
                            {
                                int ix = 0;
                                foreach (Target t in ps) { t.Id = ix; ix++; }
                            }
                        }

                        CommandTable tb = new CommandTable();

                        string title = "";
                        for (int x = 0; x <= 2; x++)
                        {
                            PropertyInfo[] pis = null;

                            object pv = _Current;
                            switch (x)
                            {
                                case 0:
                                    {
                                        if (_Current.ModuleType == EModuleType.Payload)
                                            title = Lang.Get("Payload_Options", _Current.FullPath);
                                        else
                                            title = Lang.Get("Module_Options", _Current.FullPath);

                                        pis = ReflectionHelper.GetProperties(_Current, true, true, true);
                                        break;
                                    }
                                case 1:
                                    {
                                        title = Lang.Get("Current_Target");
                                        if (ps != null && ps.Length > 1)
                                            pis = ReflectionHelper.GetProperties(_Current, "Target");
                                        break;
                                    }
                                case 2:
                                    {
                                        if (curM != null)
                                        {
                                            if (curM.Payload != null)
                                            {
                                                pv = curM.Payload;
                                                pis = ReflectionHelper.GetProperties(curM.Payload, true, true, true);
                                                title = Lang.Get("Payload_Options", curM.Payload.FullPath);
                                            }
                                            else
                                            {
                                                if (curM.PayloadRequirements != null)
                                                {
                                                    pis = ReflectionHelper.GetProperties(_Current, "Payload");
                                                    title = Lang.Get("Selected_Payload");
                                                }
                                            }
                                        }
                                        break;
                                    }
                            }

                            if (pis != null)
                            {
                                bool primera = true;// (x != 1 || !hasX0);
                                foreach (PropertyInfo pi in pis)
                                {
                                    ConfigurableProperty c = pi.GetCustomAttribute<ConfigurableProperty>();
                                    if (c == null)
                                        continue;

                                    if (primera)
                                    {
                                        if (tb.Count > 0) tb.AddRow("", "", "");
                                        CommandTableRow row = tb.AddRow(0, title, "", "");
                                        tb.AddRow("", "", "");

                                        row[0].Align = CommandTableCol.EAlign.None;
                                        row[1].Align = CommandTableCol.EAlign.None;
                                        row[2].Align = CommandTableCol.EAlign.None;
                                        primera = false;
                                    }

                                    object val = pi.GetValue(pv);
                                    if (val == null)
                                    {
                                        val = "NULL";
                                        CommandTableRow row = tb.AddRow(pi.Name, val.ToString(), c.Description);
                                        if (c.Required) row[1].ForeColor = ConsoleColor.Red;
                                        else
                                        {
                                            if (x == 0 || x == 3)
                                                row[1].ForeColor = ConsoleColor.Cyan;
                                        }
                                    }
                                    else
                                    {
                                        CommandTableRow row = tb.AddRow(pi.Name, val.ToString(), c.Description);
                                        if (x == 0 || x == 3)
                                            row[1].ForeColor = ConsoleColor.Cyan;
                                    }
                                }
                            }
                        }

                        string separator = tb.Separator;
                        foreach (CommandTableRow row in tb)
                        {
                            foreach (CommandTableCol col in row)
                            {
                                if (col.ReplicatedChar == '\0')
                                {
                                    switch (col.Index)
                                    {
                                        case 0: _IO.SetForeColor(ConsoleColor.DarkGray); break;
                                        case 1: _IO.SetForeColor(col.ForeColor); break;
                                        case 2: _IO.SetForeColor(ConsoleColor.Yellow); break;
                                    }
                                }
                                else _IO.SetForeColor(col.ForeColor);

                                if (col.Index != 0) _IO.Write(separator);
                                _IO.Write(col.GetFormatedValue());
                            }
                            _IO.WriteLine("");
                        }
                        break;
                    }
                case "payloads":
                    {
                        Payload[] ps = curM == null ? null : PayloadCollection.Current.GetPayloadAvailables(curM.PayloadRequirements);
                        if (ps == null || ps.Length == 0)
                            _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
                        else
                        {
                            CommandTable tb = new CommandTable();

                            tb.AddRow(tb.AddRow(Lang.Get("Name"), Lang.Get("Description")).MakeSeparator());

                            foreach (Payload p in ps)
                                tb.AddRow(p.FullPath, p.Description);

                            _IO.Write(tb.Output());
                        }
                        break;
                    }
                case "targets":
                    {
                        Target[] ps = curM == null ? null : curM.Targets;
                        if (ps == null || ps.Length <= 1)
                            _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
                        else
                        {
                            CommandTable tb = new CommandTable();

                            tb.AddRow(tb.AddRow(Lang.Get("Name"), Lang.Get("Description")).MakeSeparator());

                            int ix = 0;
                            foreach (Target p in ps)
                            {
                                p.Id = ix; ix++;
                                tb.AddRow(p.Id.ToString(), p.Name);
                            }

                            _IO.Write(tb.Output());
                        }
                        break;
                    }
                default:
                    {
                        // incorrect use
                        _IO.WriteError(Lang.Get("Incorrect_Command_Usage"));
                        _IO.AddInput("help show");
                        break;
                    }
            }
        }
Пример #40
0
        public static bool Init(bool isElevated, string embeddedPluginName, Guid embeddedPluginGuid, Dispatcher dispatcher, IPluginLogger logger)
        {
            PluginInterfaceType = typeof(IPluginClient);

            Assembly CurrentAssembly         = Assembly.GetExecutingAssembly();
            string   Location                = CurrentAssembly.Location;
            string   AppFolder               = Path.GetDirectoryName(Location);
            int      AssemblyCount           = 0;
            int      CompatibleAssemblyCount = 0;

            Dictionary <Assembly, List <Type> > PluginClientTypeTable = new Dictionary <Assembly, List <Type> >();
            Assembly    PluginAssembly;
            List <Type> PluginClientTypeList;

            if (embeddedPluginName != null)
            {
                AssemblyName[] AssemblyNames = CurrentAssembly.GetReferencedAssemblies();
                foreach (AssemblyName name in AssemblyNames)
                {
                    if (name.Name == embeddedPluginName)
                    {
                        FindPluginClientTypesByName(name, out PluginAssembly, out PluginClientTypeList);
                        if (PluginAssembly != null && PluginClientTypeList != null && PluginClientTypeList.Count > 0)
                        {
                            PluginClientTypeTable.Add(PluginAssembly, PluginClientTypeList);
                        }
                    }
                }
            }

            string[] Assemblies = Directory.GetFiles(AppFolder, "*.dll");
            foreach (string AssemblyPath in Assemblies)
            {
                FindPluginClientTypesByPath(AssemblyPath, out PluginAssembly, out PluginClientTypeList);
                if (PluginAssembly != null && PluginClientTypeList != null)
                {
                    PluginClientTypeTable.Add(PluginAssembly, PluginClientTypeList);
                }
            }

            foreach (KeyValuePair <Assembly, List <Type> > Entry in PluginClientTypeTable)
            {
                AssemblyCount++;

                PluginAssembly       = Entry.Key;
                PluginClientTypeList = Entry.Value;

                if (PluginClientTypeList.Count > 0)
                {
                    CompatibleAssemblyCount++;

                    CreatePluginList(PluginAssembly, PluginClientTypeList, embeddedPluginGuid, logger, out List <IPluginClient> PluginList);
                    if (PluginList.Count > 0)
                    {
                        LoadedPluginTable.Add(PluginAssembly, PluginList);
                    }
                }
            }

            if (LoadedPluginTable.Count > 0)
            {
                foreach (KeyValuePair <Assembly, List <IPluginClient> > Entry in LoadedPluginTable)
                {
                    foreach (IPluginClient Plugin in Entry.Value)
                    {
                        IPluginSettings Settings = new PluginSettings(GuidToString(Plugin.Guid), logger);
                        Plugin.Initialize(isElevated, dispatcher, Settings, logger);

                        if (Plugin.RequireElevated)
                        {
                            RequireElevated = true;
                        }
                    }
                }

                foreach (KeyValuePair <Assembly, List <IPluginClient> > Entry in LoadedPluginTable)
                {
                    foreach (IPluginClient Plugin in Entry.Value)
                    {
                        List <ICommand> PluginCommandList = Plugin.CommandList;
                        if (PluginCommandList != null)
                        {
                            List <ICommand> FullPluginCommandList = new List <ICommand>();
                            FullCommandList.Add(FullPluginCommandList, Plugin.Name);

                            foreach (ICommand Command in PluginCommandList)
                            {
                                FullPluginCommandList.Add(Command);

                                if (Command != null)
                                {
                                    CommandTable.Add(Command, Plugin);
                                }
                            }
                        }

                        Icon PluginIcon = Plugin.Icon;
                        if (PluginIcon != null)
                        {
                            ConsolidatedPluginList.Add(Plugin);
                        }
                    }
                }

                foreach (IPluginClient Plugin in ConsolidatedPluginList)
                {
                    if (Plugin.HasClickHandler)
                    {
                        PreferredPlugin = Plugin;
                        break;
                    }
                }

                if (PreferredPlugin == null && ConsolidatedPluginList.Count > 0)
                {
                    PreferredPlugin = ConsolidatedPluginList[0];
                }

                return(true);
            }
            else
            {
                logger.AddLog($"Could not load plugins, {AssemblyCount} assemblies found, {CompatibleAssemblyCount} are compatible.");
                return(false);
            }
        }
Пример #41
0
        /// <summary>
        /// Sets up the command tables
        /// </summary>
        protected void InitCommandTables()
        {
            cmdTable = new CommandTable();

            //help commands
            cmdTable.Add("commands", "cmds", CommandType.General, UserFlags.Normal, "Returns a list of all the commands available to you", null, new Action<User, string>(cmd_Commands));

            //testing commands (temp?)
            cmdTable.Add("admin", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Admin));
            cmdTable.Add("mod", "moderator", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Mod));
            cmdTable.Add("thread", "threads", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Thread));

            //normal user
            cmdTable.Add("join", "j", CommandType.General, UserFlags.Normal, "Joins a channel", null, new Action<User, string>(cmd_Join));
            cmdTable.Add("rejoin", "rj", CommandType.General, UserFlags.Normal, "Rejoins your current channel", null, new Action<User, string>(cmd_Rejoin));
            cmdTable.Add("stats", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Stats));
            cmdTable.Add("users", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Users));
            cmdTable.Add("whisper", "w", "message", "msg", "m", CommandType.General, UserFlags.Normal, "", null, new Action<User, List<User>, string>(cmd_Whisper));
            cmdTable.Add("say", "talk", "s", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Talk));
            cmdTable.Add("emote", "me", "em", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Emote));
            cmdTable.Add("who", CommandType.General, UserFlags.Normal, "", null, new Action<User, string>(cmd_Who));

            //operator
            cmdTable.Add("kick", CommandType.Moderation, UserFlags.Operator, "Kicks a user from the channel", null, new Action<User, List<User>, string>(cmd_Kick));
            cmdTable.Add("ban", CommandType.Moderation, UserFlags.Operator, "Bans a user from the channel", null, new Action<User, List<User>, string>(cmd_Ban));
            cmdTable.Add("ipban", "banip", CommandType.Moderation, UserFlags.Operator, "Bans a user's IP from the channel", null, new Action<User, List<User>, string>(cmd_IPBan));
            cmdTable.Add("unban", "unipban", "unbanip", CommandType.Moderation, UserFlags.Operator, "Unbans a user & their IP from the channel", null, new Action<User, List<User>, string>(cmd_Unban));
            cmdTable.Add("op", "operator", CommandType.Moderation, UserFlags.Operator, "Gives up your operator status to another user", null, new Action<User, List<User>, string>(cmd_Op));
            cmdTable.Add("resign", CommandType.General, UserFlags.Operator, "Gives up your operator status", null, new Action<User, string>(cmd_Resign));

            //moderator

            //admin
            cmdTable.Add("invisible", "invis", CommandType.General, UserFlags.Admin, "", null, new Action<User, string>(cmd_Invisible));
            cmdTable.Add("visible", "vis", CommandType.General, UserFlags.Admin, "", null, new Action<User, string>(cmd_Visible));
            cmdTable.Add("pop", "move", CommandType.General, UserFlags.Admin, "", null, new Action<User, List<User>, string>(cmd_Pop));
        }
Пример #42
0
        public override bool Run()
        {
            DbConnection db = Get();

            if (db == null)
            {
                return(false);
            }

            WriteInfo("Connecting ...");

            using (db)
            {
                try { db.Open(); }
                catch (Exception e)
                {
                    WriteError(e.Message);
                    return(false);
                }

                using (DbCommand cmd = db.CreateCommand())
                {
                    cmd.CommandText = Query;

                    if (IsQuery(Query))
                    {
                        WriteInfo("Detecting Query Type");
                        // Query
                        cmd.CommandType = CommandType.Text;
                        using (DataTable dt = new DataTable()
                        {
                            TableName = Query
                        })
                        {
                            using (DbDataAdapter adapter = DbProviderFactories.GetFactory(db).CreateDataAdapter())
                            {
                                adapter.SelectCommand = cmd;
                                adapter.Fill(dt);
                            }

                            CommandTable table = new CommandTable(dt);

                            switch (QueryOutFormat)
                            {
                            case EFormat.Console:
                            {
                                WriteTable(table);
                                break;
                            }

                            case EFormat.Txt:
                            {
                                File.WriteAllText(QueryOutFile.FullName, table.Output());
                                break;
                            }

                            case EFormat.Xml:
                            {
                                dt.WriteXml(QueryOutFile.FullName, XmlWriteMode.WriteSchema, true);
                                break;
                            }
                            }

                            if (QueryOutFormat != EFormat.Console)
                            {
                                QueryOutFile.Refresh();
                                WriteInfo("OutFile Size: ", QueryOutFile.Length.ToString(), QueryOutFile.Length <= 0 ? ConsoleColor.Red : ConsoleColor.Green);
                            }

                            WriteInfo("Rows    : ", dt.Rows.Count.ToString(), dt.Rows.Count <= 0 ? ConsoleColor.Red : ConsoleColor.Green);
                            WriteInfo("Columns : ", dt.Columns.Count.ToString(), dt.Columns.Count <= 0 ? ConsoleColor.Red : ConsoleColor.Green);
                        }
                    }
                    else
                    {
                        // Non query
                        WriteInfo("Detecting Non-Query Type");

                        int x = cmd.ExecuteNonQuery();
                        WriteInfo("Affected rows", x.ToString(), x <= 0 ? ConsoleColor.Red : ConsoleColor.Green);
                    }

                    WriteInfo("Disconnecting");
                    db.Close();
                }
            }

            return(true);
        }