public async Task DeleteConnection(ConnectionPayload currentConnection) { var client = new MongoClient(this.settings); var db = client.GetDatabase(database); var coll = db.GetCollection <ConnectionPayload>(collectionName); await coll.DeleteOneAsync(x => x.Id == currentConnection.Id); }
public async Task SetConnection(ConnectionPayload connection) { var client = new MongoClient(this.settings); var db = client.GetDatabase(database); var coll = db.GetCollection <ConnectionPayload>(collectionName); var foundConnection = await coll.Find(x => x.AccessToken == connection.AccessToken).SingleOrDefaultAsync(); if (foundConnection == null) { if (connection.Password != null) { connection.Password = VinzClortho.Encrypt(connection.Password, secKey + connection.Salt); } connection.InsertedOn = DateTime.UtcNow; await coll.InsertOneAsync(connection); return; } var currentPwd = connection.Password == null ? foundConnection.Password : VinzClortho.Encrypt(connection.Password, secKey + connection.Salt); var filter = Builders <ConnectionPayload> .Filter.Eq("Id", foundConnection.Id); var update = Builders <ConnectionPayload> .Update .Set("IsEnabled", connection.IsEnabled) .Set("Password", currentPwd) .Set("Port", connection.Port) .Set("Role", connection.Role) .Set("Server", connection.Server) .Set("UpdatedOn", DateTime.UtcNow); await coll.UpdateOneAsync(filter, update); }
public async Task TouchConnection(ConnectionPayload connection) { var client = new MongoClient(this.settings); var db = client.GetDatabase(database); var coll = db.GetCollection <ConnectionPayload>(collectionName); var foundConnection = await coll.Find(x => x.AccessToken == connection.AccessToken).SingleOrDefaultAsync(); if (foundConnection == null) { return; } var filter = Builders <ConnectionPayload> .Filter.Eq("Id", connection.Id); var update = Builders <ConnectionPayload> .Update.Set("TouchedOn", DateTime.UtcNow); await coll.UpdateOneAsync(filter, update); }
public async Task <ConnectionPayload> GetConnectionPayload() { string server = req.Query["server"]; string port = req.Query["port"]; string password = req.Query["password"]; string accessToken = req.Query["accessToken"]; string salt = req.Query["salt"]; string isEnabled = req.Query["isEnabled"]; string role = req.Query["role"]; accessToken = accessToken ?? req.Headers["accessToken"]; salt = salt ?? req.Headers["salt"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var data = JsonConvert.DeserializeObject <JObject>(requestBody); if (data != null) { server = server ?? (data.ContainsKey("server") ? data.GetValue("server").ToString() : null); port = port ?? (data.ContainsKey("port") ? data.GetValue("port").ToString() : null); password = password ?? (data.ContainsKey("password") ? data.GetValue("password").ToString() : null); isEnabled = isEnabled ?? (data.ContainsKey("isEnabled") ? data.GetValue("isEnabled").ToString() : null); role = role ?? (data.ContainsKey("role") ? data.GetValue("role").ToString() : null); } int tempInt; int? portNumber = Int32.TryParse(port, out tempInt) ? Int32.Parse(port) : (int?)null; long tempLong; long?saltNumber = Int64.TryParse(salt, out tempLong) ? Int64.Parse(salt) : (long?)null; var result = new ConnectionPayload { AccessToken = accessToken, Server = server, Port = portNumber, Password = password, Salt = saltNumber, IsEnabled = Convert.ToBoolean(isEnabled), Role = role }; result.IsValid = this.isValid(result); return(result); }
public RconService(ConnectionPayload connection, CosmosDbContext context) { this.connection = connection; this.context = context; }