private Connection CreateConnectionAndWireOnLocalCandidate(PeerClient remoteClient, string remoteUserId) { Connection Con = CreateConnection.Invoke(remoteClient); Con.OnLocalCandidate += (Connection, Candidate) => { try { Client.Publish(new PublishArgs(RemoteUserChannel(remoteUserId), Candidate.ToJson(), CandidateTag) { OnSuccess = (PublishSuccessArgs) => { Log.Info("Published candidate to remote peer."); }, OnFailure = (e) => { Log.Error("Could not publish candidate to remote peer.", e.Exception); } }); } catch (Exception ex) { Log.Error("Could not publish candidate to remote peer."); } }; return(Con); }
public async Task ShouldSelectFromStockItemsWithParameters(CreateConnection dbConnection, string query) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When var results = await context .CreateCommand(query) .WithParameter("supplierId", 2) .WithParameter("brand", null) // not in query .WithParameter("taxRate", 15.0) .ToListAsync <StockItem>(); //Then Assert.NotNull(results); Assert.NotEmpty(results); Assert.Equal(3, results.Count); var first = results.First(); Assert.Equal(150, first.StockItemID); Assert.Equal("Pack of 12 action figures (variety)", first.StockItemName); var last = results.Last(); Assert.Equal(152, last.StockItemID); Assert.Equal("Pack of 12 action figures (female)", last.StockItemName); }
public async Task ShouldSelectFromStockItems(CreateConnection dbConnection, string query) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When var results = await context .CreateCommand(query) .ToListAsync <StockItem>(); //Then Assert.NotNull(results); Assert.NotEmpty(results); Assert.Equal(10, results.Count); var first = results.First(); Assert.Equal(1, first.StockItemID); Assert.Equal("USB missile launcher (Green)", first.StockItemName); var last = results.Last(); Assert.Equal(10, last.StockItemID); Assert.Equal("USB food flash drive - chocolate bar", last.StockItemName); Assert.Equal("USB food flash drive - chocolate bar", last.StockItemName); }
private Database(Type connectionType, params object[] arguments) : this() { var constructor = ReflectionHelper.GetConstructor(connectionType, arguments); _createConnection = () => (IDbConnection)constructor.Invoke(arguments); Variant = DetermineVariant(connectionType); }
public ToadstoolBenchmark() { _connectionCreator = () => new NpgsqlConnection("Host=localhost;Database=wide_world_importers_pg;Username=toadstool;Password=toadstool"); _context = new DbContext(_connectionCreator); _select = @"SELECT purchase_order_id, supplier_id, order_date, delivery_method_id, contact_person_id, expected_delivery_date, supplier_reference, is_order_finalized, comments, internal_comments, last_edited_by, last_edited_when FROM purchasing.purchase_orders;"; }
protected override unsafe int OnCreateConnection( CorDebugProcess pProcess, uint dwConnectionId, ReadOnlySpan <char> pConnName) { CreateConnection?.Invoke(this, pProcess, dwConnectionId, pConnName); return(Continue()); }
public async Task <IActionResult> Post([FromBody] CreateConnection command) { command.CreatedAt = DateTime.UtcNow; command.UserId = Guid.Parse(User.Identity.Name); await _busClient.PublishAsync(command); return(Accepted("points/" + command.Id)); }
private async Task <ExternalAccount> DangerouslyCreateExternalConnection(CreateConnection dto, Guid profileId) { var externalAccount = new ExternalAccount(dto.Provider, dto.Name, dto.ExternalId, profileId); await context.AddAsync(externalAccount); await authorizationService.AddPermission(profileId, AuthorizationHelper.GenerateARN(typeof(ExternalAccount), externalAccount.Id.ToString(), Shared.Permissions.ExternalAccount.Delete)); return(externalAccount); }
public async Task MultipleQueriesInTransaction(CreateConnection dbConnection) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When using (var transaction = context.BeginTransaction()) { Assert.Same(transaction, context.CurrentTransaction); var results = await context .Select("1 as alpha") .SingleAsync <Bar>(); Assert.Same(transaction, context.CurrentTransaction); var results2 = await context .Select("2 as alpha") .SingleAsync <Bar>(); Assert.Same(transaction, context.CurrentTransaction); Assert.Equal(1, results.Alpha); Assert.Equal(2, results2.Alpha); transaction.Commit(); var resultsZ = await context .Select("1 as alpha") .SingleAsync <Bar>(); } Assert.Null(context.CurrentTransaction); var results3 = await context .Select("3 as alpha") .SingleAsync <Bar>(); Assert.Equal(3, results3.Alpha); using (var transaction = context.BeginTransaction()) { var results4 = await context .Select("4 as alpha") .SingleAsync <Bar>(); //Then Assert.Equal(4, results4.Alpha); // TRANSACTION NOT COMMITTED }; var results5 = await context .Select("5 as alpha") .SingleAsync <Bar>(); Assert.Equal(5, results5.Alpha); }
public void NestedTransactionThrows(CreateConnection dbConnection) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When Assert.Throws <InvalidOperationException>(() => { var transaction = context.BeginTransaction(); var transaction2 = context.BeginTransaction(); }); }
public Database(Action <IDatabaseBuilder> configure) : this() { if (configure == null) { throw new ArgumentNullException(nameof(configure)); } var databaseBuilder = new DatabaseBuilder(); configure(databaseBuilder); _createConnection = databaseBuilder.CreateConnection; _handler = databaseBuilder.BuildHandler(this); Variant = databaseBuilder.Variant; }
public async Task SingleOrDefaultAsyncIsNull(CreateConnection dbConnection) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When var bar = await context .CreateCommand("select 7 as alpha, 'foo' as beta, 'something' as charlie, 'delta' as delta where 1 = 2") .SingleOrDefaultAsync <Bar>(); //Then Assert.Null(bar); }
public async Task FirstAsyncThrows(CreateConnection dbConnection) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When await Assert.ThrowsAsync <System.InvalidOperationException>(async() => { var bar = await context .CreateCommand("select 7 as alpha, 'foo' as beta, 'something' as charlie, 'delta' as delta where 1 = 2") .FirstAsync <Bar>(); }); }
public async Task ToListAsyncIsEmpty(CreateConnection dbConnection) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When IList <Bar> results = await context .CreateCommand("select 7 as alpha, 'foo' as beta, 'something' as charlie, 'delta' as delta where 1 = 2") .ToListAsync <Bar>(); //Then Assert.NotNull(results); Assert.Empty(results); }
public ServerConnection(CreateConnection creator) { _thread = new Thread(() => { while (true) { IConnection connection = creator(); OnConnection?.Invoke(this, new ConnectionEventArgs { Socket = connection }); } }); _thread.Start(); }
public async Task ShouldSelectBoolean(CreateConnection dbConnection, string query) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When var results = await context .CreateCommand(query) .ToListAsync <StockItem>(); //Then Assert.NotNull(results); Assert.NotEmpty(results); Assert.All(results, si => { Assert.True(si.IsChillerStock); }); }
public async Task ShouldHandleNullableInt(CreateConnection dbConnection, string query) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When var results = await context .CreateCommand(query) .ToListAsync <StockItem>(); //Then Assert.NotNull(results); Assert.NotEmpty(results); Assert.All(results, si => { Assert.Null(si.ColorId); }); }
public async Task FirstOrDefaultAsync(CreateConnection dbConnection) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When var bar = await context .CreateCommand("select 7 as alpha, 'foo' as beta, 'something' as charlie, 'delta' as delta") .FirstOrDefaultAsync <Bar>(); //Then Assert.NotNull(bar); Assert.Equal(7, bar.Alpha); Assert.Equal("foo", bar.Beta); Assert.Equal("Can't set me", bar.Charlie); }
public async Task MultipleQueries(CreateConnection dbConnection) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When var results = await context .CreateCommand("select 1") .ExecuteAsync <int>(); var results2 = await context .CreateCommand("select 'hello, there'") .ExecuteAsync <string>(); //Then Assert.Equal(1, results); Assert.Equal("hello, there", results2); }
public async Task ToListAsync(CreateConnection dbConnection) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When IList <Bar> results = await context .CreateCommand("select 7 as alpha, 'foo' as beta, 'something' as charlie, 'delta' as delta") .ToListAsync <Bar>(); //Then Assert.NotNull(results); Assert.NotEmpty(results); var bar = results.Single(); Assert.Equal(7, bar.Alpha); Assert.Equal("foo", bar.Beta); Assert.Equal("Can't set me", bar.Charlie); }
public async Task <ServiceResult> CreateConnection(CreateConnection createDto) { var result = new ServiceResult(); Guid profileId; if (!Guid.TryParse(createDto.UserId, out profileId) || !context.UserProfiles.Any(p => p.Id.Equals(profileId))) { result.Error = Shared.ErrorKey.UserProfile.UserNotFound; } if (string.IsNullOrEmpty(createDto.ExternalId)) { result.Error = Shared.ErrorKey.UserProfile.InvalidExternalId; } else if (string.IsNullOrEmpty(createDto.Name)) { result.Error = Shared.ErrorKey.UserProfile.InvalidExternalName; } if (result.Error != null) { return(result); } // Look for a matching external account if (context.ExternalAccount.Any(ea => ea.Provider == createDto.Provider && ea.ExternalId.Equals(createDto.ExternalId))) { result.Error = Shared.ErrorKey.UserProfile.ExternalAccountExists; return(result); } await DangerouslyCreateExternalConnection(createDto, profileId); result.Succeed(); return(result); }
public async Task SimultaneousQueries(CreateConnection dbConnection) { //Given var context = new DbContext() .WithCreateConnection(dbConnection); //When var results = context .CreateCommand("select 1") .ExecuteAsync <int>(); var results2 = context .CreateCommand("select 2") .ExecuteAsync <int>(); var results3 = context .CreateCommand("select 3") .ExecuteAsync <int>(); //Then Assert.Equal(1, await results); Assert.Equal(2, await results2); Assert.Equal(3, await results3); }
internal Database(CreateConnection createConnection) : this() { _createConnection = createConnection; }
public DbContext(CreateConnection createConnection) : this() { _createConnection = createConnection; }
public NpgsqlConnection getDBInfo() { NpgsqlConnection result = new NpgsqlConnection(); try { this.FILEPATH = Environment.ExpandEnvironmentVariables("%APPDATA%\\PersonelIcraTakipProgrami"); this.FILENAME = "ConnectionInfo.xml"; Directory.CreateDirectory(this.FILEPATH); String server = "", port = "", username = "", password = "", database = ""; if (!File.Exists(this.FILEPATH + "\\" + this.FILENAME)) { CreateConnection form = new CreateConnection(); form.ShowDialog(); if (!File.Exists(this.FILEPATH + "\\" + this.FILENAME)) { Application.Exit(); } } if (File.Exists(this.FILEPATH + "\\" + this.FILENAME)) { XmlTextReader reader = new XmlTextReader(this.FILEPATH + "\\" + this.FILENAME); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Server": { reader.Read(); server = reader.Value; break; } case "Port": { reader.Read(); port = reader.Value; break; } case "Username": { reader.Read(); username = reader.Value; break; } case "Password": { reader.Read(); password = reader.Value; break; } case "Database": { reader.Read(); database = reader.Value; break; } } } } reader.Close(); result.ConnectionString = "Server=" + this.decryptText(server) + ";" + "Port=" + this.decryptText(port) + ";" + "User Id=" + this.decryptText(username) + ";" + "Password="******";" + "Database=" + this.decryptText(database) + ";"; } } catch (Exception) { throw; } return(result); }
public DbContext WithCreateConnection(CreateConnection createConnection) { _createConnection = createConnection; return(this); }
public void UpdateAris([FromBody] MappingList model) { var token = model.Token; // deserialize the whole json to object var mappingData = model.modelToSave;// JsonConvert.DeserializeObject<List<Mapping>>(modelToSave); var locationAttributeGuid = GetAppSettings("LocationAttributeGuid"); var supervisorAttributeGuid = GetAppSettings("SupervisorAttributeGuid"); var createdItems = mappingData.Where(i => i.Status == "New").ToList(); var deletedItems = mappingData.Where(i => i.Status == "Deleted").ToList(); #region Delete data from ARIS // call the occ id connection api if there is any data in deleted items if (deletedItems != null && deletedItems.Count > 0) { // get connection id from the database for this database and model guid var modelConnectionUrl = ApiHelper.UrlBuilder(ApiTypeEnum.ModelConnection); var responseJson = GetRawResponse(token, modelConnectionUrl); var data = JsonConvert.DeserializeObject <OccsRootObject>(responseJson); //var parsed = JObject.Parse(responseJson); //var modelConnectionsJson = parsed["items"]["modelconnections"]; var modelConnections = new List <OccurenceConnection>(); foreach (var item in data.items) { foreach (var mc in item.modelconnections) { modelConnections.Add(new OccurenceConnection { kind = mc.kind, occid = mc.occid, //type = mc.type, typename = mc.typename, apiname = mc.apiname, target_guid = mc.target_guid, source_guid = mc.source_guid, //source_link = mc.source_link, //target_link = mc.target_link, source_occid = mc.source_occid, target_occid = mc.target_occid }); } } // loop through the deleted items foreach (var deletedItem in deletedItems) { var personGuid = deletedItem.PersonId; // person to job will be deleted here if (!string.IsNullOrEmpty(deletedItem.JobId)) { var jobGuid = deletedItem.JobId; var occId = modelConnections.Where(i => string.Equals(i.source_guid, personGuid, StringComparison.InvariantCultureIgnoreCase) && string.Equals(i.target_guid, jobGuid, StringComparison.InvariantCultureIgnoreCase)) .Select(i => i.occid).FirstOrDefault(); var encodedOccId = HttpUtility.UrlEncode(occId); if (!string.IsNullOrEmpty(occId)) { var jobDeleteurl = ApiHelper.UrlBuilder(ApiTypeEnum.DeleteData, encodedOccId); var response = GetRawResponse(token, jobDeleteurl, HttpTypeEnum.Delete); } } // person to role model will be deleted here if (!string.IsNullOrEmpty(deletedItem.RoleId) && string.IsNullOrEmpty(deletedItem.BackupId)) { var roleGuid = deletedItem.RoleId; var occId = modelConnections.Where(i => string.Equals(i.source_guid, personGuid, StringComparison.InvariantCultureIgnoreCase) && string.Equals(i.target_guid, roleGuid, StringComparison.InvariantCultureIgnoreCase)) .Select(i => i.occid).FirstOrDefault(); var encodedOccId = HttpUtility.UrlEncode(occId); if (!string.IsNullOrEmpty(occId)) { var roleDeleteUrl = ApiHelper.UrlBuilder(ApiTypeEnum.DeleteData, encodedOccId); var response = GetRawResponse(token, roleDeleteUrl, HttpTypeEnum.Delete); } } // role to backup will be deleted here if (!string.IsNullOrEmpty(deletedItem.BackupId)) { var roleGuid = deletedItem.RoleId; var backupId = deletedItem.BackupId; var occId = modelConnections.Where(i => string.Equals(i.source_guid, roleGuid, StringComparison.InvariantCultureIgnoreCase) && string.Equals(i.target_guid, backupId, StringComparison.InvariantCultureIgnoreCase)) .Select(i => i.occid).FirstOrDefault(); var encodedOccId = HttpUtility.UrlEncode(occId); if (!string.IsNullOrEmpty(occId)) { var roleDeleteUrl = ApiHelper.UrlBuilder(ApiTypeEnum.DeleteData, encodedOccId); var response = GetRawResponse(token, roleDeleteUrl, HttpTypeEnum.Delete); } } } } #endregion foreach (var createdItem in createdItems) { // model object for the person var modelObject = new Models.Connections.Modelobject { kind = "MODELOBJECT", occid = "#1", type = 46, symbol = (int)2, guid = createdItem.PersonId, attributes = new List <Models.Connections.Attribute> { new Models.Connections.Attribute { kind = "ATTRIBUTE", type = 1, value = createdItem.Person }, // location update new Models.Connections.Attribute { kind = "ATTRIBUTE", type = locationAttributeGuid, value = createdItem.Location }, // supervisor update new Models.Connections.Attribute { kind = "ATTRIBUTE", type = supervisorAttributeGuid, value = createdItem.Supervisor } } }; if (!string.IsNullOrEmpty(createdItem.JobId)) { var createConnections = new List <CreateConnection>(); // model for job will be created // create model object for the job here var modelObjectJob = new Models.Connections.Modelobject { kind = "MODELOBJECT", occid = "#2", type = 44, symbol = (int)299, guid = createdItem.JobId, attributes = new List <Models.Connections.Attribute> { new Models.Connections.Attribute { kind = "ATTRIBUTE", type = 1, value = createdItem.JobName } } }; var modelConnection = new Models.Connections.Modelconnection { kind = "MODELCONNECTION", type = 395, source_occid = "#1", target_occid = "#2" }; var createdConnection = new CreateConnection { modelconnections = new List <Models.Connections.Modelconnection> { modelConnection }, }; if (createdConnection.modelobjects == null) { createdConnection.modelobjects = new List <Models.Connections.Modelobject>(); } createdConnection.modelobjects.Add(modelObject); createdConnection.modelobjects.Add(modelObjectJob); createConnections.Add(createdConnection); var updateData = JsonConvert.SerializeObject(createConnections); // remove first [ updateData = updateData.Substring(1); // remove last ] updateData = updateData.Remove(updateData.Length - 1); var createUrl = UrlBuilder(ApiTypeEnum.CreateData); using (var stringContent = new StringContent(updateData, Encoding.UTF8, "application/json")) { var response = GetRawResponse(token, createUrl, HttpTypeEnum.Put, stringContent); } } // person to role model will be created here if (!string.IsNullOrEmpty(createdItem.RoleId) && string.IsNullOrEmpty(createdItem.BackupId)) { var createConnections = new List <CreateConnection>(); // model for job will be created // create model object for the job here var modelObjectRole = new Models.Connections.Modelobject { kind = "MODELOBJECT", occid = "#2", type = 78, symbol = "80f76b81-35b8-11e3-51cf-c1dbe7832b20", guid = createdItem.RoleId, attributes = new List <Models.Connections.Attribute> { new Models.Connections.Attribute { kind = "ATTRIBUTE", type = 1, value = createdItem.RoleName } } }; var modelConnection = new Models.Connections.Modelconnection { kind = "MODELCONNECTION", type = 480, source_occid = "#1", target_occid = "#2" }; var createdConnection = new CreateConnection { modelconnections = new List <Models.Connections.Modelconnection> { modelConnection }, }; if (createdConnection.modelobjects == null) { createdConnection.modelobjects = new List <Models.Connections.Modelobject>(); } createdConnection.modelobjects.Add(modelObject); createdConnection.modelobjects.Add(modelObjectRole); createConnections.Add(createdConnection); var updateData = JsonConvert.SerializeObject(createConnections); // remove first [ updateData = updateData.Substring(1); // remove last ] updateData = updateData.Remove(updateData.Length - 1); var createUrl = ApiHelper.UrlBuilder(ApiTypeEnum.CreateData); using (var stringContent = new StringContent(updateData, Encoding.UTF8, "application/json")) { var response = GetRawResponse(token, createUrl, HttpTypeEnum.Put, stringContent); } } if (!string.IsNullOrEmpty(createdItem.BackupId)) { var createConnections = new List <CreateConnection>(); // model object for the person var modelObjectRole = new Models.Connections.Modelobject { kind = "MODELOBJECT", occid = "#1", type = 46, symbol = (int)2, guid = createdItem.BackupId, attributes = new List <Models.Connections.Attribute> { new Models.Connections.Attribute { kind = "ATTRIBUTE", type = 1, value = createdItem.Backup } } }; // create the connection for the backup here // model for job will be created // create model object for the job here var modelObjectBackup = new Models.Connections.Modelobject { kind = "MODELOBJECT", occid = "#2", type = 78, symbol = "80f76b81-35b8-11e3-51cf-c1dbe7832b20", guid = createdItem.RoleId, attributes = new List <Models.Connections.Attribute> { new Models.Connections.Attribute { kind = "ATTRIBUTE", type = 1, value = createdItem.RoleName } } }; var modelConnectionBackup = new Models.Connections.Modelconnection { kind = "MODELCONNECTION", type = 61, source_occid = "#2", target_occid = "#1" }; var createdConnectionBackup = new CreateConnection { modelconnections = new List <Models.Connections.Modelconnection> { modelConnectionBackup }, }; if (createdConnectionBackup.modelobjects == null) { createdConnectionBackup.modelobjects = new List <Models.Connections.Modelobject>(); } createdConnectionBackup.modelobjects.Add(modelObjectRole); createdConnectionBackup.modelobjects.Add(modelObjectBackup); createConnections.Add(createdConnectionBackup); var updateData = JsonConvert.SerializeObject(createConnections); // remove first [ updateData = updateData.Substring(1); // remove last ] updateData = updateData.Remove(updateData.Length - 1); var createUrl = UrlBuilder(ApiTypeEnum.CreateData); using (var stringContent = new StringContent(updateData, Encoding.UTF8, "application/json")) { var response = GetRawResponse(token, createUrl, HttpTypeEnum.Put, stringContent); } } } }