public async Task AddPostOfficeAsync(PostOffice Office) { var connect = _connection.Connect(connectionString); await connect.ExecuteAsync("INSERT INTO PostOffices (OfficeId, Name, Adress, Latitude, Longitude) VALUES(@OfficeId, @Name, @Adress, @Latitude, @Longitude)", new { Office.OfficeId, Office.Name, Office.Adress, Office.Latitude, Office.Longitude }); }
internal async Task Connect(IConnectionFactory connectionFactory, IIrcIdentity identity) { lock (this) { State state = _state; if (state == State.Connected) throw new InvalidOperationException("Already connected"); else if (state == State.Connecting) throw new InvalidOperationException("Already connecting"); _state = State.Connecting; } ClearAll(); _logger.Debug("Initializing connection"); _stream = await connectionFactory.Connect(_hostname, _port, _useSsl); if (_stream == null) throw new IrcException(Resources.ConnectionIsNull); _logger.Debug("Connected to server"); var encoding = new UTF8Encoding(false); _reader = new StreamReader(_stream, encoding); _writer = new StreamWriter(_stream, encoding); _writer.NewLine = CRLF; StartOutboundThread(); if (_password != null) await SendCommand("PASS", _password); await SendCommand("NICK", identity.Nick); await SendCommand("USER", identity.Login, "8", "*", VERSION.AsMultiParameter()); _nick = identity.Nick; _login = identity.Login; //OnRawMessageIn(await _reader.ReadLineAsync()); //await Task.Delay(TimeSpan.FromSeconds(10)); // Read stuff back from the server to see if we connected. string line; int tries = 0; Command cmd = default(Command); while ((line = await _reader.ReadLineAsync()) != null) { OnRawMessageIn(line); cmd = ParseCmd(line); switch (cmd._command) { //Check for both a successful connection. Inital connection (001-4), user stats (251-5), or MOTD (375-6) case "001": case "002": case "003": case "004": case "005": case "251": case "252": case "253": case "254": case "255": case "375": case "376": goto end; case "433": var tmpNick = identity.Nick + (++tries); await SendCommand("NICK", tmpNick); _nick = tmpNick; break; case "439": //EXAMPLE: PircBotX: Target change too fast. Please wait 104 seconds // No action required. break; default: if (cmd._command.StartsWith("5") || cmd._command.EndsWith("4")) { _stream.Dispose(); throw new IrcException(String.Format(Resources.CouldNotConnect, cmd)); } break; } } _stream.Dispose(); throw new IrcException(String.Format(Resources.CouldNotConnect, cmd)); end: _logger.Debug("Logged in"); lock (this) _state = State.Connected; if (cmd._parameters != null) await HandleCmd(cmd); StartInboundThread(); }
public async Task AddRegionAsync(Region Region) { var connect = _connection.Connect(connectionString); await connect.ExecuteAsync("INSERT INTO Regions (RegionId, PostOfficeId, RegionName) VALUES (@RegionId, @PostOfficeId, @RegionName)", new { Region.RegionId, Region.PostOfficeId, Region.RegionName }); }
public async Task AddUserAsync(User User) { var connect = _connection.Connect(connectionString); await connect.ExecuteAsync("INSERT INTO [dbo].[Users] ([UserId], [UserName], [Email], [Password], [Salt], [FullName], [Role], [CreatedAt]) VALUES (@UserId, @Username, @Email, @Password, @Salt, @FullName, @Role, @CreatedAt)", new { User.UserId, User.UserName, User.Email, User.Password, User.Salt, User.FullName, User.Role, User.CreatedAt }); }
public async Task AddCompanyAsync(Company Company) { var connect = _connection.Connect(connectionString); await connect.ExecuteAsync("INSERT INTO Companies (CompanyId, RegionId, Name, Adress, Longitude, Latitude, StartHour, FinishHour) VALUES (@CompanyId, @RegionId, @Name, @Adress, @Longtitude, @Latitude, @StartHour@, @FinishHour) FROM Companies c INNER JOIN Regions r ON c.RegionId = r.REgionId", new { Company.CompanyId, Company.RegionId, Company.Name, Company.Adress, Company.Longitude, Company.Latitude, Company.StartHour, Company.FinishHour }); }
internal async Task Connect(IConnectionFactory connectionFactory, IIrcIdentity identity) { lock (this) { State state = _state; if (state == State.Connected) { throw new InvalidOperationException("Already connected"); } else if (state == State.Connecting) { throw new InvalidOperationException("Already connecting"); } _state = State.Connecting; } ClearAll(); _logger.Debug("Initializing connection"); _stream = await connectionFactory.Connect(_hostname, _port, _useSsl); if (_stream == null) { throw new IrcException(Resources.ConnectionIsNull); } _logger.Debug("Connected to server"); var encoding = new UTF8Encoding(false); _reader = new StreamReader(_stream.InputStream, encoding); _writer = new StreamWriter(_stream.OutputStream, encoding); _writer.NewLine = CRLF; StartOutboundThread(); if (_password != null) { await SendCommand("PASS", _password); } await SendCommand("NICK", identity.Nick); await SendCommand("USER", identity.Login, "8", "*", VERSION.AsMultiParameter()); _nick = identity.Nick; _login = identity.Login; //OnRawMessageIn(await _reader.ReadLineAsync()); //await Task.Delay(TimeSpan.FromSeconds(10)); // Read stuff back from the server to see if we connected. string line; int tries = 0; Command cmd = default(Command); while ((line = await _reader.ReadLineAsync()) != null) { OnRawMessageIn(line); cmd = ParseCmd(line); switch (cmd._command) { //Check for both a successful connection. Inital connection (001-4), user stats (251-5), or MOTD (375-6) case "001": case "002": case "003": case "004": case "005": case "251": case "252": case "253": case "254": case "255": case "375": case "376": goto end; case "433": var tmpNick = identity.Nick + (++tries); await SendCommand("NICK", tmpNick); _nick = tmpNick; break; case "439": //EXAMPLE: PircBotX: Target change too fast. Please wait 104 seconds // No action required. break; default: if (cmd._command.StartsWith("5") || cmd._command.EndsWith("4")) { _stream.Dispose(); throw new IrcException(String.Format(Resources.CouldNotConnect, cmd)); } break; } } _stream.Dispose(); throw new IrcException(String.Format(Resources.CouldNotConnect, cmd)); end: _logger.Debug("Logged in"); lock (this) _state = State.Connected; if (cmd._parameters != null) { await HandleCmd(cmd); } StartInboundThread(); }