public async Task <TNDEntityItem[]> SearchTerm(TNDMetaEntity metaEntity, string searchTerm, string emails, string emailDomains) { var configuration = this._ApplicationBuis.LoadConfiguration(false); var metaSource = metaEntity?.MetaSource; if (metaSource == null) { var tasksSearchTerm = new List <Task <TNDEntityItem[]> >(); foreach (var metaEnt in configuration.MetaEntities) { var sourceBuis = metaEnt?.MetaSource.SourceBuis; if (sourceBuis != null) { var taskSearchTerm = sourceBuis.SearchTerm(metaEnt, searchTerm, emails, emailDomains); tasksSearchTerm.Add(taskSearchTerm); } } if (tasksSearchTerm.Any()) { var taskWhenAll = Task.WhenAll(tasksSearchTerm); TNDEntityItem[][] results = null; try { results = await taskWhenAll; } catch (Exception exception) { throw; } // flatten var result = new List <TNDEntityItem>(); foreach (var r in results) { if (r != null && r.Any()) { result.AddRange(r); } } return(SortHelper.Sort(result.ToArray())); } return(new TNDEntityItem[0]); } else { var sourceBuis = metaSource.SourceBuis; if (sourceBuis != null) { var taskSearchTerm = sourceBuis.SearchTerm(metaEntity, searchTerm, emails, emailDomains); TNDEntityItem[] result = null; try { result = await taskSearchTerm; } catch (Exception exception) { throw; } return(result); //metaSource.Configuration; } } return(null); }
public async Task <TNDEntityItem[]> Query(TNDMetaEntity metaEntity, string ids, bool returnParent, bool returnThis, bool returnChildren) { if (string.IsNullOrEmpty(ids)) { return(new TNDEntityItem[0]); } string spName = $"Query{metaEntity.MetaEntityName}"; // var result = new List <TNDEntityItem>(); // System.Data.SqlClient.SqlConnectionStringBuilder csb = this.getConnectionString(); using (var con = new System.Data.SqlClient.SqlConnection(csb.ConnectionString)) { var taskOpen = con.OpenAsync(); try { await taskOpen; } catch (Exception exception) { throw; } using (var cmd = new System.Data.SqlClient.SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = spName; cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ids", System.Data.SqlDbType.NVarChar, -1) { Value = (ids == null) ? DBNull.Value : (object)ids }); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@returnParent", System.Data.SqlDbType.Bit) { Value = returnParent }); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@returnThis", System.Data.SqlDbType.Bit) { Value = returnThis }); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@returnChildren", System.Data.SqlDbType.Bit) { Value = returnChildren }); var taskExecuteReaderAsync = cmd.ExecuteReaderAsync(); System.Data.SqlClient.SqlDataReader sqlDataReader = null; try { sqlDataReader = await taskExecuteReaderAsync; } catch (Exception exception) { throw; } var taskReadFromDataReader = this.readFromDataReader(metaEntity, result, sqlDataReader); try { await taskReadFromDataReader; } catch (Exception exception) { throw; } } } return(result.ToArray()); }
public async Task <TNDEntityItem[]> SearchTerm(TNDMetaEntity metaEntity, string searchTerm, string emails, string emailDomains) { if (searchTerm == null) { searchTerm = string.Empty; } if (searchTerm.Length > 4000) { searchTerm = searchTerm.Substring(0, 4000); } string spName = $"SearchTerm{metaEntity.MetaEntityName}"; // var result = new List <TNDEntityItem>(); // System.Data.SqlClient.SqlConnectionStringBuilder csb = this.getConnectionString(); using (var con = new System.Data.SqlClient.SqlConnection(csb.ConnectionString)) { var taskOpen = con.OpenAsync(); try { await taskOpen; } catch (Exception exception) { throw; } using (var cmd = new System.Data.SqlClient.SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = spName; cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@term", System.Data.SqlDbType.NVarChar, -1) { Value = (searchTerm == null) ? DBNull.Value : (object)searchTerm }); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@emails", System.Data.SqlDbType.NVarChar, -1) { Value = (emails == null) ? DBNull.Value : (object)emails }); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@emailDomains", System.Data.SqlDbType.NVarChar, -1) { Value = (emailDomains == null) ? DBNull.Value : (object)emailDomains }); var taskExecuteReaderAsync = cmd.ExecuteReaderAsync(); System.Data.SqlClient.SqlDataReader sqlDataReader = null; try { sqlDataReader = await taskExecuteReaderAsync; } catch (Exception exception) { throw; } var taskReadFromDataReader = this.readFromDataReader(metaEntity, result, sqlDataReader); try { await taskReadFromDataReader; } catch (Exception exception) { throw; } } } return(result.ToArray()); }
public async Task SearchTermTest_Kunde() { var sut = new TNDSQLSourceBuis(); ITNDApplicationBuis applicationBuis = A.Fake <ITNDApplicationBuis>(); TNDConfiguration configuration = new TNDConfiguration(); var metaSourceKunde = new TNDMetaSource() { MetaSourceName = "SourceKunde", Configuration = (new System.Data.SqlClient.SqlConnectionStringBuilder() { DataSource = ".", InitialCatalog = "TagNDropDB", IntegratedSecurity = true }).ConnectionString, AssemblyQualifiedName = "", SourceBuis = sut }; var metaStorageKunde = new TNDMetaStorage() { MetaStorageName = "", RootPath = "", AssemblyQualifiedName = "", StorageBuis = null }; var metaEntityKunde = new TNDMetaEntity() { MetaEntityLevel = 0, MetaEntityParent = null, MetaEntityName = "Kunde", MetaEntityParentName = null, MetaEntityParentNamePropertyName = null, MetaSource = metaSourceKunde, MetaSourceName = "SourceKunde", MetaStorage = metaStorageKunde, MetaStorageName = "StorageKunde" }; configuration.MetaEntities = new TNDMetaEntity[] { metaEntityKunde }; configuration.MetaSources = new TNDMetaSource[] { metaSourceKunde }; configuration.MetaStorages = new TNDMetaStorage[] { metaStorageKunde }; sut.Init(applicationBuis, metaSourceKunde); var result = await sut.SearchTerm(metaEntityKunde, "k", null, null); Assert.IsNotNull(result); Assert.IsTrue(result.Length > 0); result = await sut.SearchTerm(metaEntityKunde, "aa", null, null); Assert.IsNotNull(result); Assert.IsTrue(result.Length > 0); }
/// <summary>Query for entities by id</summary> /// <param name="metaEntity">default metaEntity.</param> /// <param name="ids">the ids</param> /// <param name="returnParent">true to return also parent.</param> /// <param name="returnThis">true to return this entity type.</param> /// <param name="returnChildren">true to return children.</param> /// <returns>the search result</returns> public virtual async Task <TNDEntityItem[]> Query(TNDMetaEntity metaEntity, string ids, bool returnParent, bool returnThis, bool returnChildren) { var configuration = this._ApplicationBuis.LoadConfiguration(false); var metaSource = metaEntity?.MetaSource; var sourceBuis = metaSource.SourceBuis; if (sourceBuis != null) { var taskQuery = sourceBuis.Query(metaEntity, ids, returnParent, returnThis, returnChildren); TNDEntityItem[] result = null; try { result = await taskQuery; } catch (Exception exception) { throw; } //SortHelper.Sort(result); return(result); } return(null); }
/// <summary>Query for entities by id</summary> /// <param name="targetModel">the taget</param> /// <param name="metaEntity">default metaEntity.</param> /// <param name="addOrReplace">true to add; false to replace</param> /// <param name="ids">the ids</param> /// <param name="returnParent">true to return also parent.</param> /// <param name="returnThis">true to return this entity type.</param> /// <param name="returnChildren">true to return children.</param> /// <returns>the search result</returns> public virtual async Task Query(TNDTargetModel targetModel, TNDMetaEntity metaEntity, bool addOrReplace, System.Collections.IEnumerable ids, bool returnParent, bool returnThis, bool returnChildren) { string idsText = getIds(ids); idsText = idsText.Trim(); var entityItems = targetModel.EntityItems; var checkedItems = targetModel.CheckedItems; var taskSearchResult = this._ApplicationBuis.GetDataAccess().Query( metaEntity, idsText, true, true, true); TNDEntityItem[] arrSearchResults = null; try { arrSearchResults = await taskSearchResult; } catch (Exception exception) { throw; #warning exception } if (addOrReplace) { addEntityItems(entityItems, checkedItems, arrSearchResults); } else { replaceEntityItems(entityItems, checkedItems, arrSearchResults); } #if false if (arrSearchResults == null || !arrSearchResults.Any()) { entityItems.Clear(); } else { entityItems.Clear(); var dictCheckedItems = checkedItems.ToDictionary(_ => _); // var newCheckedItems = new List <TNDEntityItem>(); // add the found ones - uses the found. foreach (var searchResult in arrSearchResults) { if (dictCheckedItems.Remove(searchResult)) { searchResult.IsChecked = true; newCheckedItems.Add(searchResult); } } // add the not found ones - reuse the old. newCheckedItems.AddRange(dictCheckedItems.Keys); // var sortedNewCheckedItems = newCheckedItems .OrderBy(_ => _.MetaEntity.MetaEntityLevel) .ThenBy(_ => _.MetaEntityName) .ThenBy(_ => _.Name) .ToArray(); checkedItems.Replace(newCheckedItems); entityItems.Replace(arrSearchResults); } #endif }
public async Task SearchTermTest_Produkt() { var sut = new TNDSQLSourceBuis(); ITNDApplicationBuis applicationBuis = A.Fake <ITNDApplicationBuis>(); TNDConfiguration configuration = new TNDConfiguration(); var metaSourceKunde = new TNDMetaSource() { MetaSourceName = "SourceKunde", Configuration = TestConnectionString, AssemblyQualifiedName = "", SourceBuis = sut }; var metaSourceProdukt = new TNDMetaSource() { MetaSourceName = "SourceProdukt", Configuration = TestConnectionString, AssemblyQualifiedName = "", SourceBuis = sut }; var metaStorageKunde = new TNDMetaStorage() { MetaStorageName = "Kunde", RootPath = "", AssemblyQualifiedName = "", StorageBuis = null }; var metaStorageProdukt = new TNDMetaStorage() { MetaStorageName = "Produkt", RootPath = "", AssemblyQualifiedName = "", StorageBuis = null }; var metaEntityKunde = new TNDMetaEntity() { MetaEntityLevel = 0, MetaEntityParent = null, MetaEntityName = "Kunde", MetaEntityParentName = null, MetaEntityParentNamePropertyName = null, MetaSource = metaSourceKunde, MetaSourceName = "SourceKunde", MetaStorage = metaStorageKunde, MetaStorageName = "StorageKunde" }; var metaEntityProdukt = new TNDMetaEntity() { MetaEntityLevel = 0, MetaEntityParent = null, MetaEntityName = "Produkt", MetaEntityParentName = null, MetaEntityParentNamePropertyName = null, MetaSource = metaSourceProdukt, MetaSourceName = "SourceProdukt", MetaStorage = metaStorageProdukt, MetaStorageName = "StorageProdukt" }; // configuration.MetaEntities = new TNDMetaEntity[] { metaEntityKunde, metaEntityProdukt }; configuration.MetaSources = new TNDMetaSource[] { metaSourceKunde, metaSourceProdukt }; configuration.MetaStorages = new TNDMetaStorage[] { metaStorageKunde, metaStorageProdukt }; sut.Init(applicationBuis, metaSourceProdukt); var result = await sut.SearchTerm(metaEntityProdukt, "k%", null, null); Assert.IsNotNull(result); Assert.IsTrue(result.Length > 0); result = await sut.SearchTerm(metaEntityProdukt, "a", null, null); Assert.IsNotNull(result); Assert.IsTrue(result.Length > 0); }
private async Task readFromDataReader(TNDMetaEntity metaEntity, List <TNDEntityItem> result, System.Data.SqlClient.SqlDataReader sqlDataReader) { // loop over NextResult bool next = true; while (next) { var fieldCount = sqlDataReader.FieldCount; string[] names = new string[fieldCount]; Type[] types = new Type[fieldCount]; TNDPropertyCache[] caches = new TNDPropertyCache[fieldCount]; object[] values = new object[fieldCount]; int idxMetaEntityName = -1; for (int idx = 0; idx < fieldCount; idx++) { names[idx] = sqlDataReader.GetName(idx); types[idx] = sqlDataReader.GetFieldType(idx); caches[idx] = new TNDPropertyCache(); if (string.Equals(names[idx], "MetaEntityName", StringComparison.Ordinal)) { idxMetaEntityName = idx; } } // loop over Read bool read = true; while (read) { var taskReadAsync = sqlDataReader.ReadAsync(); try { read = await taskReadAsync; } catch (Exception exception) { throw; } if (read) { sqlDataReader.GetValues(values); var item = new TNDEntityItem(); for (int idx = 0; idx < fieldCount; idx++) { if (idx == idxMetaEntityName) { item.MetaEntityName = values[idx] as string; } else { var property = new TNDProperty(names[idx], types[idx], values[idx]); if (caches[idx] != null) { property = caches[idx].GetOrCreate(property); } item.Property.Add(property); } } if (item.MetaEntityName != null) { item.MetaEntity = this._ApplicationBuis.ApplicationModel.Configuration.FindMetaEntity(item.MetaEntityName); } if (item.MetaEntity == null) { item.MetaEntity = metaEntity; item.MetaEntityName = metaEntity.MetaEntityName; } result.Add(item); } } var taskNextResult = sqlDataReader.NextResultAsync(); try { next = await taskNextResult; } catch (Exception exception) { throw; } } }
/// <summary> /// Query for entities by id /// </summary> /// <param name="metaEntity">default metaEntity.</param> /// <param name="ids">the ids</param> /// <param name="returnParent">true to return also parent.</param> /// <param name="returnThis">true to return this entity type.</param> /// <param name="returnChildren">true to return children.</param> /// <returns>the search result</returns> public Task <TNDEntityItem[]> Query(TNDMetaEntity metaEntity, string ids, bool returnParent, bool returnThis, bool returnChildren) { return(Task.FromResult(new TNDEntityItem[0])); }
/// <summary> /// Search for the term. /// </summary> /// <param name="metaEntity">default metaEntity.</param> /// <param name="searchTerm">the terms to search.</param> /// <param name="emails">the emails</param> /// <param name="emailDomains">the emails domains</param> /// <returns>the search result</returns> public Task <TNDEntityItem[]> SearchTerm(TNDMetaEntity metaEntity, string searchTerm, string emails, string emailDomains) { return(Task.FromResult(new TNDEntityItem[0])); }