public async Task <IActionResult> Post(TokenCommand command) { var result = await _mediator.Send(command); return(Created(string.Empty, new HttpServiceResponseBase <string> { Data = result, Code = HttpStatusCode.Created })); }
public void EngineToken_Execute_ReturnsNotFoundMessage() { var command = new TokenCommand(_console, LoggerMock.GetLogger <TokenCommand>().Object, _tokenService.Object, _engineService.Object) { Name = "Engine02" }; var resultMessage = command.Execute(); Assert.Equal("Engine Engine02 was not found", resultMessage); }
public void EngineToken_Execute_ReturnsSuccessMessage() { var command = new TokenCommand(_console, LoggerMock.GetLogger <TokenCommand>().Object, _tokenService.Object, _engineService.Object) { Name = "Engine01" }; var resultMessage = command.Execute(); Assert.StartsWith("Token: testToken", resultMessage); }
public void ParseCommand_SingleNounToken_CanParse() { var cmd = new TokenCommand(); var tokens = new TokenSet(new[] { new Token { MorphType = MorphType.Noun, Value = "map" } }); tokens.MoveNext(); _parser.ParseCommand(tokens, cmd); cmd.Subjects.Should().HaveCount(1); cmd.Subjects[0].Noun.Should().Be("map"); }
/// <summary> /// Sends a command to the Token API endpoint. /// </summary> /// <param name="command">The command to send. It can be "Request" (Requests a session token) or "Reset" (Resets the provided session token)</param> /// <param name="sessionToken">Resets the provided session token, only if one is passed and command is set to "Reset".</param> /// <returns>A <see cref="SessionTokenResponse"/> object.</returns> public static SessionTokenResponse SendSessionTokenCommand(TokenCommand command, string sessionToken = "") { string query = $"command={command.ToString().ToLowerInvariant()}"; if (command == TokenCommand.Reset) { if (string.IsNullOrEmpty(sessionToken)) { throw new ArgumentException("You must pass a session token when requesting a reset.", nameof(sessionToken)); } query += $"&token={sessionToken}"; } string json; using (var wc = new WebClient()) { json = wc.DownloadString($"{ApiTokenEndpoint}?{query}"); } return(JsonConvert.DeserializeObject <SessionTokenResponse>(json)); }
public async Task <IActionResult> Post(TokenCommand command) { var response = await _mediator.Send(command); return(Result(response, HttpStatusCode.OK)); }
private void TrackToken <RECORD>(TokenStore <RECORD> tokenStore, TokenCommand <RECORD> tokenCommand) where RECORD : Org.Neo4j.Kernel.impl.store.record.TokenRecord { Track(tokenStore, tokenCommand.After); Track(tokenStore.NameStore, tokenCommand.After.NameRecords); }
public virtual void ReplacePronounsAndProcessDobjNameList() { RetCode rc; if (gGameState.EnhancedParser) { for (LoopCounter = 0; true; LoopCounter++) { if (LoopCounter >= 250) // "Can't happen" { throw new GeneralParsingErrorException(); } CurrInputStr = string.Format(" {0} ", ParserInputStr); DobjNameStr = ""; IobjNameStr = ""; CurrToken = 0; NameIndex = -1; PrepTokenIndex = -1; Globals.Buf.SetFormat("{0}", CurrInputStr.Trim()); Globals.Buf.SetFormat("{0}", gEngine.ReplacePrepositions(Globals.Buf).ToString()); Tokens = Globals.Buf.ToString().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (CurrToken < Tokens.Length) { if (Tokens.Length == 1) { Globals.Buf.SetFormat("{0}", Tokens[CurrToken]); Tokens[CurrToken] = Globals.Buf.TrimEndPunctuationMinusUniqueChars().ToString().Trim(); } if (Tokens[CurrToken].Length == 0) { Tokens[CurrToken] = "???"; } else if (Tokens[CurrToken].Equals("at", StringComparison.OrdinalIgnoreCase)) { Tokens[CurrToken] = "a"; } TokenCommand = gEngine.GetCommandUsingToken(gCharMonster, Tokens[CurrToken]); if (TokenCommand != null && TokenCommand.IsSentenceParserEnabled) { CurrToken++; if (TokenCommand.IsDobjPrepEnabled || TokenCommand.IsIobjEnabled) { Predicate <string> prepFindFunc = token => gEngine.Preps.FirstOrDefault(prep => prep.Name.Equals(token, StringComparison.OrdinalIgnoreCase) && TokenCommand.IsPrepEnabled(prep)) != null; PrepTokenIndex = TokenCommand.IsDobjPrepEnabled ? Array.FindIndex(Tokens, prepFindFunc) : TokenCommand.IsIobjEnabled ? Array.FindLastIndex(Tokens, prepFindFunc) : -1; } if (TokenCommand.IsDobjPrepEnabled && PrepTokenIndex == CurrToken) { CurrToken++; NumDobjNameTokens = Tokens.Length - CurrToken; DobjNameStr = string.Join(" ", Tokens.Skip((int)CurrToken).Take((int)NumDobjNameTokens)); CurrToken += NumDobjNameTokens; } else if (TokenCommand.IsIobjEnabled && PrepTokenIndex >= CurrToken) { NumDobjNameTokens = PrepTokenIndex - CurrToken; DobjNameStr = string.Join(" ", Tokens.Skip((int)CurrToken).Take((int)NumDobjNameTokens)); CurrToken += (NumDobjNameTokens + 1); NumIobjNameTokens = Tokens.Length - CurrToken; IobjNameStr = string.Join(" ", Tokens.Skip((int)CurrToken).Take((int)NumIobjNameTokens)); CurrToken += NumIobjNameTokens; } else { DobjNameStr = string.Join(" ", Tokens.Skip((int)CurrToken)); CurrToken = Tokens.Length; } if (!string.IsNullOrWhiteSpace(DobjNameStr)) { DobjNameStr = string.Format(" {0} ", DobjNameStr); NameIndex = CurrInputStr.IndexOf(DobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CommandFormatStr = CurrInputStr.Substring(0, (int)NameIndex) + "{0}" + CurrInputStr.Substring((int)NameIndex + DobjNameStr.Length); DobjNameTokens = DobjNameStr.IndexOf(" , ") >= 0 ? DobjNameStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { DobjNameStr }; DobjNameTokens = DobjNameTokens.Where(dobjNameToken => !string.IsNullOrWhiteSpace(dobjNameToken) && Array.FindIndex(Constants.CommandSepTokens, token => !Char.IsPunctuation(token[0]) ? dobjNameToken.IndexOf(" " + token + " ") >= 0 : token[0] != ',' && dobjNameToken.IndexOf(token) >= 0) < 0).ToArray(); for (var j = 0; j < DobjNameTokens.Length; j++) { _mySeen = false; Globals.Buf.SetFormat("{0}", DobjNameTokens[j].Trim()); rc = gEngine.StripPrepsAndArticles(Globals.Buf, ref _mySeen); Debug.Assert(gEngine.IsSuccess(rc)); DobjNameTokens[j] = string.Format(" {0} ", Globals.Buf.ToString().Trim()); } DobjNameStr = string.Join(",", DobjNameTokens); CurrInputStr = string.Format(CommandFormatStr, DobjNameStr); ParserInputStrList[0] = CurrInputStr.Trim(); } if (!string.IsNullOrWhiteSpace(IobjNameStr)) { IobjNameStr = string.Format(" {0} ", IobjNameStr); NameIndex = CurrInputStr.LastIndexOf(IobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CommandFormatStr = CurrInputStr.Substring(0, (int)NameIndex) + "{0}" + CurrInputStr.Substring((int)NameIndex + IobjNameStr.Length); IobjNameTokens = IobjNameStr.IndexOf(" , ") >= 0 ? IobjNameStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { IobjNameStr }; IobjNameTokens = IobjNameTokens.Where(iobjNameToken => !string.IsNullOrWhiteSpace(iobjNameToken) && Array.FindIndex(Constants.CommandSepTokens, token => !Char.IsPunctuation(token[0]) ? iobjNameToken.IndexOf(" " + token + " ") >= 0 : token[0] != ',' && iobjNameToken.IndexOf(token) >= 0) < 0).ToArray(); for (var j = 0; j < IobjNameTokens.Length; j++) { _mySeen = false; Globals.Buf.SetFormat("{0}", IobjNameTokens[j].Trim()); rc = gEngine.StripPrepsAndArticles(Globals.Buf, ref _mySeen); Debug.Assert(gEngine.IsSuccess(rc)); IobjNameTokens[j] = string.Format(" {0} ", Globals.Buf.ToString().Trim()); } IobjNameStr = string.Join(",", IobjNameTokens); CurrInputStr = string.Format(CommandFormatStr, IobjNameStr); ParserInputStrList[0] = CurrInputStr.Trim(); } if (!string.IsNullOrWhiteSpace(DobjNameStr) && DobjNameStr.IndexOf(" him ") >= 0 && !string.IsNullOrWhiteSpace(gCommandParser.LastHimNameStr)) { NameIndex = CurrInputStr.IndexOf(DobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CurrInputStr = string.Format("{0}{1}{2}", CurrInputStr.Substring(0, (int)NameIndex), DobjNameStr.Replace(" him ", " " + gCommandParser.LastHimNameStr + " "), CurrInputStr.Substring((int)NameIndex + DobjNameStr.Length)); ParserInputStrList[0] = CurrInputStr.Trim(); } else if (!string.IsNullOrWhiteSpace(DobjNameStr) && DobjNameStr.IndexOf(" her ") >= 0 && !string.IsNullOrWhiteSpace(gCommandParser.LastHerNameStr)) { NameIndex = CurrInputStr.IndexOf(DobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CurrInputStr = string.Format("{0}{1}{2}", CurrInputStr.Substring(0, (int)NameIndex), DobjNameStr.Replace(" her ", " " + gCommandParser.LastHerNameStr + " "), CurrInputStr.Substring((int)NameIndex + DobjNameStr.Length)); ParserInputStrList[0] = CurrInputStr.Trim(); } else if (!string.IsNullOrWhiteSpace(DobjNameStr) && (DobjNameStr.IndexOf(" it ") >= 0 || DobjNameStr.IndexOf(" that ") >= 0) && !string.IsNullOrWhiteSpace(gCommandParser.LastItNameStr)) { NameIndex = CurrInputStr.IndexOf(DobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CurrInputStr = string.Format("{0}{1}{2}", CurrInputStr.Substring(0, (int)NameIndex), DobjNameStr.Replace(" it ", " " + gCommandParser.LastItNameStr + " ").Replace(" that ", " " + gCommandParser.LastItNameStr + " "), CurrInputStr.Substring((int)NameIndex + DobjNameStr.Length)); ParserInputStrList[0] = CurrInputStr.Trim(); } else if (!string.IsNullOrWhiteSpace(DobjNameStr) && (DobjNameStr.IndexOf(" them ") >= 0 || DobjNameStr.IndexOf(" those ") >= 0) && !string.IsNullOrWhiteSpace(gCommandParser.LastThemNameStr)) { NameIndex = CurrInputStr.IndexOf(DobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CurrInputStr = string.Format("{0}{1}{2}", CurrInputStr.Substring(0, (int)NameIndex), DobjNameStr.Replace(" them ", " " + gCommandParser.LastThemNameStr + " ").Replace(" those ", " " + gCommandParser.LastThemNameStr + " "), CurrInputStr.Substring((int)NameIndex + DobjNameStr.Length)); ParserInputStrList[0] = CurrInputStr.Trim(); } else if (!string.IsNullOrWhiteSpace(IobjNameStr) && IobjNameStr.IndexOf(" him ") >= 0 && !string.IsNullOrWhiteSpace(gCommandParser.LastHimNameStr)) { NameIndex = CurrInputStr.LastIndexOf(IobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CurrInputStr = string.Format("{0}{1}{2}", CurrInputStr.Substring(0, (int)NameIndex), IobjNameStr.Replace(" him ", " " + gCommandParser.LastHimNameStr + " "), CurrInputStr.Substring((int)NameIndex + IobjNameStr.Length)); ParserInputStrList[0] = CurrInputStr.Trim(); } else if (!string.IsNullOrWhiteSpace(IobjNameStr) && IobjNameStr.IndexOf(" her ") >= 0 && !string.IsNullOrWhiteSpace(gCommandParser.LastHerNameStr)) { NameIndex = CurrInputStr.LastIndexOf(IobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CurrInputStr = string.Format("{0}{1}{2}", CurrInputStr.Substring(0, (int)NameIndex), IobjNameStr.Replace(" her ", " " + gCommandParser.LastHerNameStr + " "), CurrInputStr.Substring((int)NameIndex + IobjNameStr.Length)); ParserInputStrList[0] = CurrInputStr.Trim(); } else if (!string.IsNullOrWhiteSpace(IobjNameStr) && (IobjNameStr.IndexOf(" it ") >= 0 || IobjNameStr.IndexOf(" that ") >= 0) && !string.IsNullOrWhiteSpace(gCommandParser.LastItNameStr)) { NameIndex = CurrInputStr.LastIndexOf(IobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CurrInputStr = string.Format("{0}{1}{2}", CurrInputStr.Substring(0, (int)NameIndex), IobjNameStr.Replace(" it ", " " + gCommandParser.LastItNameStr + " ").Replace(" that ", " " + gCommandParser.LastItNameStr + " "), CurrInputStr.Substring((int)NameIndex + IobjNameStr.Length)); ParserInputStrList[0] = CurrInputStr.Trim(); } else if (!string.IsNullOrWhiteSpace(IobjNameStr) && (IobjNameStr.IndexOf(" them ") >= 0 || IobjNameStr.IndexOf(" those ") >= 0) && !string.IsNullOrWhiteSpace(gCommandParser.LastThemNameStr)) { NameIndex = CurrInputStr.LastIndexOf(IobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } CurrInputStr = string.Format("{0}{1}{2}", CurrInputStr.Substring(0, (int)NameIndex), IobjNameStr.Replace(" them ", " " + gCommandParser.LastThemNameStr + " ").Replace(" those ", " " + gCommandParser.LastThemNameStr + " "), CurrInputStr.Substring((int)NameIndex + IobjNameStr.Length)); ParserInputStrList[0] = CurrInputStr.Trim(); } else if (!string.IsNullOrWhiteSpace(DobjNameStr) && DobjNameStr.IndexOf(" , ") >= 0) { NameIndex = CurrInputStr.IndexOf(DobjNameStr); if (NameIndex < 0) { throw new GeneralParsingErrorException(); } if (Array.FindIndex(Constants.CommandSepTokens, token => !Char.IsPunctuation(token[0]) ? DobjNameStr.IndexOf(" " + token + " ") >= 0 : token[0] != ',' && DobjNameStr.IndexOf(token) >= 0) < 0 && Array.FindIndex(Constants.PronounTokens, token => DobjNameStr.IndexOf(" " + token + " ") >= 0) < 0) { gCommandParser.LastThemNameStr = Globals.CloneInstance(DobjNameStr.Trim()); } CommandFormatStr = CurrInputStr.Substring(0, (int)NameIndex) + "{0}" + CurrInputStr.Substring((int)NameIndex + DobjNameStr.Length); DobjNameTokens = DobjNameStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (var j = DobjNameTokens.Length - 1; j >= 0; j--) { NewCommandStr = string.Format(CommandFormatStr, DobjNameTokens[j]).Trim(); if (ParserInputStrList.Count > 0) { ParserInputStrList.Insert(0, NewCommandStr); } else { ParserInputStrList.Add(NewCommandStr); } } ParserInputStrList.RemoveAt(DobjNameTokens.Length); } else { break; } } else { break; } } else { break; } } } }