/// <summary> /// run ManageApps.exe to create client name and config /// </summary> /// <param name="clientName">client name</param> /// <param name="clientSideAppKey">client-side appKey</param> /// <param name="clientConfigJson">client configuration</param> /// <returns>server-side app key</returns> public static string CreateClientNameAndConfig(string clientName, string clientSideAppKey, string clientConfigJson) { // use the manageapps utility to create a client name and configuration string command1 = $"cd {ConfigurationManager.AppSettings["ManageAppsRelativePath"]} & {manageAppsExecutable} -Name={TestConstants.EnvironmentName}"; command1 += $" -CreateClientNameAndConfig -AppKey={TestConstants.AppKey} -ClientName={clientName}"; if (!string.IsNullOrEmpty(clientSideAppKey)) { command1 += $" -ClientSideAppKey={clientSideAppKey}"; } if (!string.IsNullOrEmpty(clientConfigJson)) { command1 += $" -ClientConfigJson=\"{clientConfigJson}\""; } string command1Output = RunCommand.Execute(command1); // expected output: "Client-side app key: <client-side-app-key>\nServer-side app key: <server-side-app-key>" string expectedOutputPattern1 = @"^Client-side app key: ([\w-]+)"; string expectedOutputPattern2 = @"^Server-side app key: ([\w-]+)"; var match1 = Regex.Match(command1Output, expectedOutputPattern1, RegexOptions.Multiline); var match2 = Regex.Match(command1Output, expectedOutputPattern2, RegexOptions.Multiline); if (!match1.Success || !match2.Success) { return(null); } return(match2.Groups[1].Value); }
private void ShotCommand_Execute() { TransmitData data = new TransmitData() { CanId = (int)this.CanId, IsExtId = this.IsExtId, DLC = (int)this.DLC, Payload = this.Payload.ToArray() }; var results = new List <ValidationResult>(); if (!Validator.TryValidateObject(data, new ValidationContext(data), results, true)) { foreach (var error in results) { MessageBox.Show(error.ErrorMessage, (string)Manager <LanguageCultureInfo> .StaticInstance.GetResource("#WarningMsgBoxTitle"), MessageBoxButton.OK, MessageBoxImage.Error); } if (Status == TransmitState.Transmiting) { RunCommand.Execute(); } return; } Task.Run(() => { TransmitToSelectedChannels?.Invoke(data); }); }
public async Task can_start_application() { var builder = new WebHostBuilder() .UseKestrel() .UseUrls("http://localhost:5111") .UseStartup <Startup>(); var input = new RunInput { WebHostBuilder = builder }; var command = new RunCommand(); var task = Task.Factory.StartNew(() => command.Execute(input)); command.Started.Wait(5.Seconds()); using (var client = new HttpClient()) { var text = await client.GetStringAsync("http://localhost:5111"); text.ShouldBe("Hello"); } command.Reset.Set(); await task; }
public void TestDotnetRun() { var runCommand = new RunCommand(TestProject); runCommand.Execute() .Should() .Pass(); }
public void CreateAndDeleteDevAppKeys() { // do NOT use the standard appKey from TestConstants.AppKey. Instead, we want to create an app key that will // only be used by this test string appKey = "7147f211-d768-411a-b87f-1cab4d83042f"; string appName = "UnitTestApp"; string command1 = this.manageAppsExecutable + " -Name=" + this.environment + " -CreateAppAndDeveloper -AppName=" + appName + " -PlatformType=Windows"; string command1Output = RunCommand.Execute(command1); // expected output: "Application UnitTestApp created, appHandle = <app-handle> developerId = <guid>" string expectedOutputPattern = "^Application " + appName + @" created, appHandle = ([\w-]+) developerId = ([\w-]+)"; // use a regular expression to extract the appHandle and developerId from the output of ManageApps.exe string appHandle = null; string developerId = null; var match = Regex.Match(command1Output, expectedOutputPattern, RegexOptions.Multiline); if (match.Success == true) { appHandle = match.Groups[1].Value; developerId = match.Groups[2].Value; } else { Assert.Fail("Test failed: failed to find expected output from ManageApps.exe"); } string command2 = this.manageAppsExecutable + " -Name=" + this.environment + " -CreateAppKey -DeveloperId=" + developerId + " -AppHandle=" + appHandle + " -AppKey=" + appKey; string command2Output = RunCommand.Execute(command2); expectedOutputPattern = "^AppKey = " + appKey + " created for appHandle = " + appHandle; match = Regex.Match(command2Output, expectedOutputPattern, RegexOptions.Multiline); if (match.Success == false) { Assert.Fail("Test failed: failed to find expected output from ManageApps.exe"); } string command3 = this.manageAppsExecutable + " -Name=" + this.environment + " -DeleteAppKey -DeveloperId=" + developerId + " -AppHandle=" + appHandle + " -AppKey=" + appKey; string command3Output = RunCommand.Execute(command3); expectedOutputPattern = "^AppKey = " + appKey + " deleted for appHandle = " + appHandle; match = Regex.Match(command3Output, expectedOutputPattern, RegexOptions.Multiline); if (match.Success == false) { Assert.Fail("Test failed: failed to find expected output from ManageApps.exe"); } string command4 = this.manageAppsExecutable + " -Name=" + this.environment + " -DeleteApp -DeveloperId=" + developerId + " -AppHandle=" + appHandle; string command4Output = RunCommand.Execute(command4); expectedOutputPattern = "^Application " + appName + " deleted, appHandle = " + appHandle + " developerId = " + developerId; match = Regex.Match(command4Output, expectedOutputPattern, RegexOptions.Multiline); if (match.Success == false) { Assert.Fail("Test failed: failed to find expected output from ManageApps.exe"); } }
public void Writeline() { _out = new StringWriter(); _error = new StringWriter(); _runCommand = new RunCommand() { FileName = "FailWithError.exe",Params=new{Test="value"}, Out = _out, Error = _error }; _exitstatus = _runCommand.Execute(); Console.WriteLine(_out.ToString()); Console.WriteLine(_error.ToString()); }
public void DepsDependencyContextIsValidOnBuild() { var testProjectPath = Path.Combine(RepoRoot, "TestAssets", "TestProjects", "DependencyContextValidator", "TestAppDeps"); var testProject = Path.Combine(testProjectPath, "project.json"); var runCommand = new RunCommand(testProject); runCommand.Execute().Should().Pass(); }
public void TestCommonUsage(string arg1, string arg2, bool?expectedVerbose, int?expectedRunId) { string[] args = new string[] { arg1, arg2 }; Command c = new RunCommand(); c.ParseArguments(args); c.Execute(); Assert.Equal <bool?>(expectedVerbose, (c as RunCommand).Verbose); Assert.Equal <int?>(expectedRunId, (c as RunCommand).RunId); Assert.Equal <bool?>(true, (c as RunCommand).GotExecuted); }
public void Execute_InvalidBatchWithoutArguments_Exception() { var processInfo = Mock.Of <IRunCommand> ( c => c.Argument == string.Empty && c.FullPath == FullPathInvalid && c.TimeOut == 1000 ); var command = new RunCommand(processInfo); Assert.Throws <InvalidProgramException>(() => command.Execute()); }
public void TestDotnetRun() { var restoreCommand = new TestCommand("dotnet"); restoreCommand.Execute($"restore {TestProject}") .Should() .Pass(); var runCommand = new RunCommand(TestProject); runCommand.Execute() .Should() .Pass(); }
public void Execute_InvalidBatchWithoutArguments_Exception() { var runArgs = Mock.Of <IRunCommandArgs> ( c => c.Argument == new LiteralScalarResolver <string>(string.Empty) && c.Path == new LiteralScalarResolver <string>(Path) && c.Name == new LiteralScalarResolver <string>(INVALID_BATCH_FILE) && c.TimeOut == new LiteralScalarResolver <int>(1000) ); var command = new RunCommand(runArgs); Assert.Throws <NBiException>(() => command.Execute()); }
public void Execute_InvalidBatchWithoutArgumentsNoWait_Success() { var processInfo = Mock.Of <IRunCommand> ( c => c.Argument == string.Empty && c.FullPath == FullPath && c.TimeOut == 0 ); var command = new RunCommand(processInfo); command.Execute(); Assert.Pass(); }
public void Execute(string folderName) { using (new WithCurrentDirectory(folderName)) { var command = new RunCommand(new NativeSolutionReader(), new GitStatusDiffer(@"C:\Program Files\Git\bin\git.exe")); var configuration = Configuration.Load("mpv.config"); (bool success, var results) = command.Execute(configuration); var updatedFiles = results .UpdatedFiles .ToList(); Assert.True(success); Assert.NotEmpty(updatedFiles); _testOutputHelper.WriteLine(string.Join(Environment.NewLine, updatedFiles)); } }
public void Compilation_of_app_with_P2P_reference_to_fsharp_library_should_be_runnable() { var testProject = Path.Combine(s_testProjectsRoot, "TestApp", "project.json"); var runCommand = new RunCommand(testProject); var oldDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(Path.GetDirectoryName(testProject)); var result = runCommand.Execute(); result.Should().Pass(); Directory.SetCurrentDirectory(oldDirectory); }
public void Execute_ExistingBatchWithoutArguments_Executed() { var processInfo = Mock.Of <IRunCommand> ( c => c.Argument == string.Empty && c.FullPath == FullPath && c.TimeOut == 1000 ); var command = new RunCommand(processInfo); command.Execute(); Assert.That(File.Exists(TARGET_FILE), Is.True); }
/// <summary> /// deletes client name and its corresponding configuration /// </summary> /// <param name="clientName">client name</param> /// <returns>true if client name deleted successfully</returns> public static bool DeleteClientNameAndConfig(string clientName) { // use the manageapps utility to delete the client name and its corresponding configuration string command1 = $"cd {ConfigurationManager.AppSettings["ManageAppsRelativePath"]} & {manageAppsExecutable} -Name={TestConstants.EnvironmentName}"; command1 += $" -DeleteClientNameAndConfig -AppKey={TestConstants.AppKey} -ClientName={clientName}"; string command1Output = RunCommand.Execute(command1); // expected output: "Client configuration for client name: <client-name> deleted." string expectedOutputPattern = @"^Client configuration for client name: ([\w-]+) deleted."; var match1 = Regex.Match(command1Output, expectedOutputPattern, RegexOptions.Multiline); return(match1.Success); }
public void Execute_InvalidBatchWithoutArgumentsNoWait_Success() { var runArgs = Mock.Of <IRunCommandArgs> ( c => c.Argument == new LiteralScalarResolver <string>(string.Empty) && c.Path == new LiteralScalarResolver <string>(Path) && c.Name == new LiteralScalarResolver <string>(BATCH_FILE) && c.TimeOut == new LiteralScalarResolver <int>(0) ); var command = new RunCommand(runArgs); command.Execute(); Assert.Pass(); }
public void Execute_ExistingBatchWithoutArguments_Executed() { var runArgs = Mock.Of <IRunCommandArgs> ( c => c.Argument == new LiteralScalarResolver <string>(string.Empty) && c.Path == new LiteralScalarResolver <string>(Path) && c.Name == new LiteralScalarResolver <string>(BATCH_FILE) && c.TimeOut == new LiteralScalarResolver <int>(1000) ); var command = new RunCommand(runArgs); command.Execute(); Assert.That(File.Exists(TARGET_FILE), Is.True); }
/// <summary> /// delete the user as an adminstrator for this app /// </summary> /// <param name="environment">name of service environment</param> /// <param name="appHandle">app handle</param> /// <param name="userHandle">user handle</param> /// <returns>true if user is deleted from admin list</returns> public static bool DeleteAdmin(string environment, string appHandle, string userHandle) { // step 3: use the manageapps utility to register the user as an administrator string command1 = "cd " + ConfigurationManager.AppSettings["ManageAppsRelativePath"] + " & " + manageAppsExecutable + " -Name=" + environment + " -DeleteAppAdmin -AppHandle=" + appHandle + " -UserHandle=" + userHandle; string command1Output = RunCommand.Execute(command1); // expected output: "UserHandle = <user-handle> deleted from list of admins for appHandle = <app-handle>" string expectedOutputPattern = @"^UserHandle = ([\w-]+) deleted from list of admins for appHandle = ([\w-]+)"; var match = Regex.Match(command1Output, expectedOutputPattern, RegexOptions.Multiline); if (match.Success == false) { return(false); } return(true); }
/// <summary> /// run ManageApps.exe to get the app handle /// </summary> /// <param name="environment">name of service environment</param> /// <returns>the app handle</returns> public static string GetAppHandle(string environment) { // lookup the apphandle associated with the appkey string command1 = "cd " + ConfigurationManager.AppSettings["ManageAppsRelativePath"] + " & " + manageAppsExecutable + " -Name=" + environment + " -GetAppHandle -AppKey=" + TestConstants.AppKey; string command1Output = RunCommand.Execute(command1); // expected output: "AppHandle = <app-handle> for application with appKey = <app-key>" string expectedOutputPattern = @"^AppHandle = ([\w-]+) for application with appKey = ([\w-]+)"; var match = Regex.Match(command1Output, expectedOutputPattern, RegexOptions.Multiline); if (match.Success == true) { return(match.Groups[1].Value); } else { return(null); } }
public async Task can_start_application() { var builder = Host.CreateDefaultBuilder(); var input = new RunInput { HostBuilder = builder }; var command = new RunCommand(); var task = Task.Factory.StartNew(() => command.Execute(input)); command.Started.Wait(5.Seconds()); command.Reset.Set(); await task; }
/// <summary> /// run ManageApps.exe to get the developer id /// </summary> /// <param name="environment">name of service environment</param> /// <returns>the developer id</returns> public static string GetDeveloperId(string environment) { string appHandle = ManageAppsUtils.GetAppHandle(environment); // lookup the developer id associated with the app handle string command1 = "cd " + ConfigurationManager.AppSettings["ManageAppsRelativePath"] + " & " + manageAppsExecutable + " -Name=" + environment + " -GetAppDeveloperId -AppHandle=" + appHandle; string command1Output = RunCommand.Execute(command1); // expected output: "DeveloperId = <developer-id> for appHandle = <app-handle>" string expectedOutputPattern = @"^DeveloperId = ([\w-]+) for appHandle = ([\w-]+)"; var match = Regex.Match(command1Output, expectedOutputPattern, RegexOptions.Multiline); if (match.Success == true) { return(match.Groups[1].Value); } else { return(null); } }
private void ParseCommand(string line) { if (string.IsNullOrEmpty(line)) { return; } //NOTE: Parse in ascending length order! if (line.Substring(0, 1).Equals("#")) { return; } if (line.Length < 4) { Warn("invalid command: {0}", line); return; } if (line.Substring(0, 4).ToLower().Equals("quit") || line.Substring(0, 4).ToLower().Equals("exit")) { return; } var idx = line.IndexOf(' '); string cmd; if (idx < 0) { idx = 0; cmd = line; } else { cmd = line.Substring(0, idx).ToLower(); } var args = idx == 0 ? string.Empty : line.Substring(idx + 1).Trim(); if (CR.abort.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new AbortCommand(); c.Execute(context); StopTimer(CR.abort + " " + args); return; } if (CR.addalias.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new AddAliasCommand(); c.Execute(context, args); StopTimer(CR.addalias + " " + args); return; } if (CR.addindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new AddIndexCommand(); c.Execute(context, args); StopTimer(CR.addindex + " " + args); return; } if (CR.close.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CloseCommand(); c.Execute(context, args); StopTimer(CR.close + " " + args); return; } if (CR.commit.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CommitCommand(); c.Execute(context, args); StopTimer(CR.commit + " " + args); return; } if (CR.compactcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CompactContainerCommand(); c.Execute(context, args); StopTimer(CR.compactcontainer + " " + args); return; } if (CR.contextquery.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new ContextQueryCommand(); c.Execute(context, args); StopTimer(CR.contextquery + " " + args); return; } if (CR.cquery.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CQueryCommand(); c.Execute(context, args); StopTimer(CR.cquery + " " + args); return; } if (CR.createcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CreateContainerCommand(); c.Execute(context, args); StopTimer(CR.createcontainer + " " + args); return; } if (CR.delindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new DeleteIndexCommand(); c.Execute(context, args); StopTimer(CR.delindex + " " + args); return; } if (CR.echo.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { Msg(args); return; } if (CR.getdocuments.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new GetDocumentsCommand(); c.Execute(context, args); StopTimer(CR.getdocuments + " " + args); return; } if (CR.getmetadata.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new GetMetadataCommand(); c.Execute(context, args); StopTimer(CR.getmetadata + " " + args); return; } if (CR.help.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { var c = new HelpCommand(); c.Execute(args); return; } if (CR.info.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new InfoCommand(); c.Execute(context, args); StopTimer(CR.info + " " + args); return; } if (CR.listindexes.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new ListIndexesCommand(); c.Execute(context, args); StopTimer(CR.listindexes + " " + args); return; } if (CR.lookupedgeindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new LookupEdgeIndexCommand(); c.Execute(context, args); StopTimer(CR.lookupedgeindex + " " + args); return; } if (CR.lookupindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new LookupIndexCommand(); c.Execute(context, args); StopTimer(CR.lookupindex + " " + args); return; } if (CR.lookupstats.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new LookupStatisticsCommand(); c.Execute(context, args); StopTimer(CR.lookupstats + " " + args); return; } if (CR.opencontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new OpenContainerCommand(); c.Execute(context, args); StopTimer(CR.opencontainer + " " + args); return; } if (CR.preload.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new PreloadCommand(); c.Execute(context, args); StopTimer(CR.preload + " " + args); return; } if (CR.prepare.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new PrepareCommand(); c.Execute(context, args); StopTimer(CR.prepare + " " + args); return; } if (CR.print.IndexOf(cmd, 0, StringComparison.Ordinal) == 0 || cmd.ToLower().Equals("printnames")) { StartTimer(); var c = new PrintCommand(); c.Execute(context, cmd.Equals("printnames") ? "printnames " + args : args); StopTimer(cmd.Equals("printnames") ? "printNames" : CR.print); return; } if (CR.putdocuments.Equals(cmd)) { StartTimer(); var c = new PutDocumentsCommand(); c.Execute(context, args); StopTimer(CR.putdocuments + " " + args); return; } if (CR.putdocument.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new PutDocumentCommand(); c.Execute(context, args); StopTimer(CR.putdocument + " " + args); return; } if (CR.query.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new QueryCommand(); c.Execute(context, args); StopTimer(CR.query + " " + args); return; } if (CR.queryplan.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new QueryPlanCommand(); c.Execute(context, args); StopTimer(CR.queryplan + " " + args); return; } if (CR.reindexcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new ReindexContainerCommand(); c.Execute(context, args); StopTimer(CR.reindexcontainer + " " + args); return; } if (CR.removealias.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new RemoveAliasCommand(); c.Execute(context, args); StopTimer(CR.removealias + " " + args); return; } if (CR.removecontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new RemoveContainerCommand(); c.Execute(context, args); StopTimer(CR.removecontainer + " " + args); return; } if (CR.removedocument.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new RemoveDocumentCommand(); c.Execute(context, args); StopTimer(CR.removedocument + " " + args); return; } if (CR.run.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { var c = new RunCommand(); c.Execute(context, args); var l2 = new List <string>(originalArgs) { "-s", c.Script }; StartTimer(); Main(l2.ToArray()); StopTimer(CR.run + " " + args); return; } if (CR.setautoindexing.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetAutoIndexingCommand(); c.Execute(context, args); StopTimer(CR.setautoindexing + " " + args); return; } if (CR.setbaseuri.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetBaseUriCommand(); c.Execute(context, args); StopTimer(CR.setbaseuri + " " + args); return; } if (CR.setignore.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { var c = new SetIgnoreCommand(); c.Execute(context, args); ignoreErrors = c.Ignore; return; } if (CR.setlazy.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetLazyCommand(); c.Execute(context, args); StopTimer(CR.setlazy + " " + args); return; } if (CR.setmetadata.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetMetadataCommand(); c.Execute(context, args); StopTimer(CR.setmetadata + " " + args); return; } if (CR.setnamespace.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetNamespaceCommand(); c.Execute(context, args); StopTimer(CR.setnamespace + " " + args); return; } if (CR.setprojection.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetProjectionCommand(); c.Execute(context, args); StopTimer(CR.setprojection + " " + args); return; } if (CR.setquerytimeout.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetQueryTimeoutCommand(); c.Execute(context, args); StopTimer(CR.setquerytimeout + " " + args); return; } if (CR.setvariable.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetVariableCommand(); c.Execute(context, args); StopTimer(CR.setvariable + " " + args); return; } if (CR.setverbose.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetVerboseCommand(); c.Execute(context, args); StopTimer(CR.setverbose + " " + args); return; } if (CR.sync.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); context.Sync(); StopTimer(CR.sync + " " + args); return; } if (CR.time.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { time = true; ParseCommand(args); return; } if (CR.transaction.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new TransactionCommand(); c.Execute(context, args); StopTimer(CR.transaction + " " + args); return; } if (CR.upgradecontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new UpgradeContainerCommand(); c.Execute(context, args); StopTimer(CR.upgradecontainer + " " + args); return; } Warn("Command not recognized: {0}", cmd); }
static void Main(string[] args) { try { Director director = new Director(); HeroBuilder builder = new ElfHeroBuilder(); Hero myHero = director.create(builder); Console.WriteLine(myHero.ToString()); IHero friendlyHero = myHero.Clone(); Console.WriteLine(friendlyHero.ToString()); Console.Write("Введите кол-во создаваемых объектов -> "); var counter = int.Parse(Console.ReadLine()); Console.Write("Введите тип создаваемых объектов ( 1 - пешие воины, 2 - всадники ) -> "); var type = int.Parse(Console.ReadLine()); if (type != 1 && type != 2) { throw new Exception("Введен неверный тип юнита"); } ArmyOfEnemies army = new ArmyOfEnemies(); if (type == 1) { for (int i = 0; i < counter; i++) { army.AddNewEnemy(new Unit(new FootEnemyFactory())); } } else if (type == 2) { for (int i = 0; i < counter; i++) { army.AddNewEnemy(new Unit(new EquestrianEnemyFactory())); } } foreach (var item in army.list) { Console.WriteLine(item.ToString()); } // Lab02 start here Console.WriteLine(); Console.WriteLine(); Horse horse = new Horse(); myHero.Move(horse); Ally ally = new Ally(); AllyAdapter adapter = new AllyAdapter(ally); myHero.Move(adapter); Personage personage = new ElfPersonage(); Console.WriteLine(personage.Name); personage = new ExtraArmorPers(personage); Console.WriteLine(personage.Name); string nameOfMap = "Пустыня"; Map map = new Map(nameOfMap); map.Draw(); map.AddComponent(myHero); IComponent component = map.Find("Main Hero"); Console.WriteLine(component.Title); Console.WriteLine(); // Lab03 start here GameHistory game = new GameHistory(); Command jumpCommand = new JumpCommand(myHero); Command runCommand = new RunCommand(myHero); while (true) { char Symbol = Char.Parse(Console.ReadLine()); if (Symbol == 'q') { jumpCommand.Execute(); myHero.HandleInput(Symbol); } else if (Symbol == 'w') { runCommand.Execute(); myHero.HandleInput(Symbol); } else if (Symbol == 's') { game.History.Push(myHero.SaveState()); } else { break; } } myHero.RestoreState(game.History.Pop()); Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } }