// [END video_object_tracking] public static void Main(string[] args) { var verbMap = new VerbMap <object>() .Add((AnalyzeShotsOptions opts) => AnalyzeShotsGcs(opts.Uri)) .Add((AnalyzeExplicitContentOptions opts) => AnalyzeExplicitContentGcs(opts.Uri)) .Add((AnalyzeLabelsOptions opts) => IsStorageUri(opts.Uri) ? AnalyzeLabelsGcs(opts.Uri) : AnalyzeLabels(opts.Uri)) .Add((TranscribeOptions opts) => TranscribeVideo(opts.Uri)) .Add((DetectTextOptions opts) => IsStorageUri(opts.Uri) ? DetectTextGcs(opts.Uri) : DetectText(opts.Uri)) .Add((TrackObjectOptions opts) => IsStorageUri(opts.Uri) ? TrackObjectGcs(opts.Uri) : TrackObject(opts.Uri)) .Add((DetectLogoOptions opts) => IsStorageUri(opts.Uri) ? DetectLogoGcs(opts.Uri) : DetectLogo(opts.Uri)) .SetNotParsedFunc((errs) => 1); verbMap.Run(args); }
public static int Main(string[] args) { var verbMap = new VerbMap <object>(); verbMap .Add((CreateOptions opts) => Create( opts.projectId, opts.instanceId, opts.databaseId)) .Add((InsertOptions opts) => Insert( opts.projectId, opts.instanceId, opts.databaseId, opts.insertType)) .Add((QueryOptions opts) => Query( opts.projectId, opts.instanceId, opts.databaseId, opts.timespan)) .NotParsedFunc = (err) => 1; return((int)verbMap.Run(args)); }
public static int Main(string[] args) { var verbMap = new VerbMap <object>(); verbMap .Add((CreateSampleDatabaseOptions opts) => CreateSampleDatabase(opts.projectId, opts.instanceId, opts.databaseId)) .Add((InsertPlayerOptions opts) => InsertPlayers( opts.projectId, opts.instanceId, opts.databaseId)) .Add((InsertScoresOptions opts) => InsertScores( opts.projectId, opts.instanceId, opts.databaseId)) .NotParsedFunc = (err) => 1; return((int)verbMap.Run(args)); }
/// <summary> /// Creates the verb map which represent the commands implemented by the server. /// </summary> /// <returns>The <see cref="IVerbMap"/> with registered verbs for the commands.</returns> protected virtual IVerbMap CreateVerbMap() { VerbMap verbMap = new VerbMap(); verbMap.SetVerbProcessor("HELO", new HeloVerb()); verbMap.SetVerbProcessor("EHLO", new EhloVerb()); verbMap.SetVerbProcessor("QUIT", new QuitVerb()); verbMap.SetVerbProcessor("MAIL", new MailVerb()); verbMap.SetVerbProcessor("RCPT", new RcptVerb()); verbMap.SetVerbProcessor("DATA", new DataVerb()); verbMap.SetVerbProcessor("RSET", new RsetVerb()); verbMap.SetVerbProcessor("NOOP", new NoopVerb()); return(verbMap); }
private IVerbMap GetVerbMap() { var verbMap = new VerbMap(); verbMap.SetVerbProcessor("HELO", new HeloVerb()); verbMap.SetVerbProcessor("EHLO", new EhloVerb()); verbMap.SetVerbProcessor("QUIT", new QuitVerb()); verbMap.SetVerbProcessor("MAIL", new MailVerb()); verbMap.SetVerbProcessor("RCPT", new RcptVerb()); verbMap.SetVerbProcessor("DATA", new DataVerb()); verbMap.SetVerbProcessor("RSET", new RsetVerb()); verbMap.SetVerbProcessor("NOOP", new NoopVerb()); return(verbMap); }
private static bool MethodAllowed(ContainmentQuery query, ContainmentQuerySuffix suffix, RequestVerb verb) { if (query.SetExpected) { if (suffix != ContainmentQuerySuffix.None) { AstoriaTestLog.FailAndThrow("Only the NONE suffix can be used when a set is expected"); } return(verb == RequestVerb.Get || verb == RequestVerb.Post); } else { return(VerbMap.Valid(suffix, verb)); } }
public static int Main(string[] args) { var verbMap = new VerbMap <object>(); verbMap .Add((CreateSampleDatabaseOptions opts) => CreateSampleDatabase(opts.projectId, opts.instanceId, opts.databaseId)) .Add((InsertPlayerOptions opts) => InsertPlayers( opts.projectId, opts.instanceId, opts.databaseId)) .Add((InsertScoresOptions opts) => InsertScores( opts.projectId, opts.instanceId, opts.databaseId)) .Add((QueryTopTenAllTimeOptions opts) => QueryTopTenAllTime( opts.projectId, opts.instanceId, opts.databaseId)) .Add((QueryTopTenWithTimespanOptions opts) => QueryTopTenWithTimespan( opts.projectId, opts.instanceId, opts.databaseId, opts.timespan)) return((int)verbMap.Run(args)); }
public Connection(Server server, TcpClient tcpClient) { VerbMap = new VerbMap(); Session = new Session() { ClientAddress = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address, StartDate = DateTime.Now }; Server = server; _tcpClient = tcpClient; _tcpClient.ReceiveTimeout = Server.Behaviour.GetReceiveTimeout(this); ReaderEncoding = new ASCIISevenBitTruncatingEncoding(); _stream = tcpClient.GetStream(); SetupReaderAndWriter(); SetupVerbs(); }
public static int Main(string[] args) { var verbMap = new VerbMap <object>(); verbMap .Add((CreatePlanetsDatabaseOptions opts) => CreatePlanetsDatabase(opts.projectId, opts.instanceId, opts.databaseId)) .Add((InsertPlanetOptions opts) => InsertPlanet(opts.projectId, opts.instanceId, opts.databaseId, opts.planetName, opts.planetValue)) .Add((BatchInsertPlanetsOptions opts) => BatchInsertPlanets(opts.projectId, opts.instanceId, opts.databaseId, opts.csvFile)) .Add((BatchInsertPlayersOptions opts) => BatchInsertPlayers(opts.projectId, opts.instanceId, opts.databaseId)) .Add((RunPlanetAuctionOptions opts) => RunPlanetAuction(opts.projectId, opts.instanceId, opts.databaseId, opts.numberOfShares, opts.showConsoleOutput)) .NotParsedFunc = (err) => 1; return((int)verbMap.Run(args)); }
public void GetVerbProcessor_NoRegisteredVerb_ReturnsNull() { VerbMap verbMap = new VerbMap(); Assert.Null(verbMap.GetVerbProcessor("VERB")); }
public void Start() { try { Server.Behaviour.OnSessionStarted(this, Session); if (Server.Behaviour.IsSSLEnabled(this)) { SslStream sslStream = new SslStream(_stream); sslStream.AuthenticateAsServer(Server.Behaviour.GetSSLCertificate(this)); Session.SecureConnection = true; _stream = sslStream; SetupReaderAndWriter(); } WriteResponse(new SmtpResponse(StandardSmtpResponseCode.ServiceReady, Server.Behaviour.DomainName + " smtp4dev ready")); while (_tcpClient.Client.Connected) { SmtpCommand command = new SmtpCommand(ReadLine()); Server.Behaviour.OnCommandReceived(this, command); if (command.IsValid) { IVerb verbProcessor = VerbMap.GetVerbProcessor(command.Verb); if (verbProcessor != null) { try { verbProcessor.Process(this, command); } catch (SmtpServerException exception) { WriteResponse(exception.SmtpResponse); } } else { WriteResponse(new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorCommandUnrecognised, "Command unrecognized")); } } else if (command.IsEmpty) { } else { WriteResponse(new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorCommandUnrecognised, "Command unrecognized")); } } } catch (IOException ioException) { Session.SessionError = ioException.Message; } CloseConnection(); Session.EndDate = DateTime.Now; Server.Behaviour.OnSessionCompleted(this, Session); }
public async Task ProcessAsync() { try { Server.Behaviour.OnSessionStarted(this, Session); SetReaderEncoding(Server.Behaviour.GetDefaultEncoding(this)); if (Server.Behaviour.IsSSLEnabled(this)) { await ConnectionChannel.ApplyStreamFilterAsync(async s => { SslStream sslStream = new SslStream(s); await sslStream.AuthenticateAsServerAsync(Server.Behaviour.GetSSLCertificate(this)); return(sslStream); }); Session.SecureConnection = true; } await WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.ServiceReady, Server.Behaviour.DomainName + " smtp4dev ready")); int numberOfInvalidCommands = 0; while (ConnectionChannel.IsConnected) { bool badCommand = false; SmtpCommand command = new SmtpCommand(await ReadLineAsync()); Server.Behaviour.OnCommandReceived(this, command); if (command.IsValid) { IVerb verbProcessor = VerbMap.GetVerbProcessor(command.Verb); if (verbProcessor != null) { try { await verbProcessor.ProcessAsync(this, command); } catch (SmtpServerException exception) { await WriteResponseAsync(exception.SmtpResponse); } } else { badCommand = true; } } else if (command.IsEmpty) { } else { badCommand = true; } if (badCommand) { numberOfInvalidCommands++; if (Server.Behaviour.MaximumNumberOfSequentialBadCommands > 0 && numberOfInvalidCommands >= Server.Behaviour.MaximumNumberOfSequentialBadCommands) { await WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.ClosingTransmissionChannel, "Too many bad commands. Bye!")); await CloseConnectionAsync(); } else { await WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorCommandUnrecognised, "Command unrecognised")); } } } } catch (IOException ioException) { Session.SessionError = ioException; Session.SessionErrorType = SessionErrorType.NetworkError; } catch (Exception exception) { Session.SessionError = exception; Session.SessionErrorType = SessionErrorType.UnexpectedException; } await CloseConnectionAsync(); Session.EndDate = DateTime.Now; Server.Behaviour.OnSessionCompleted(this, Session); }
public RcptVerb() { SubVerbMap = new VerbMap(); SubVerbMap.SetVerbProcessor("TO", new RcptToVerb()); }
public MailVerb() { SubVerbMap = new VerbMap(); SubVerbMap.SetVerbProcessor("FROM", new MailFromVerb()); }
// gets a verb for this action from default verbs map private static string GetVerb(string action) { var verb = VerbMap.FirstOrDefault(i => i.Value.Contains(action)).Key; return(verb == default ? "on" : verb); }