public void TestFixtureSetup() { _target = new FindBuilder(); string metaUrl = ConfigurationManager.AppSettings["V1Url"] + "meta.v1/"; var metaConnector = new VersionOneAPIConnector(metaUrl); _metaModel = new MetaModel(metaConnector); }
/// <summary> /// obter todos os registros de tipo TType no banco de dados /// </summary> /// <param name="camposSelect"></param> /// <returns></returns> public async Task <JsonResult> GetAsync(string[] camposSelect) { //verifica parâmetros que são de preenchimento obrigatório. if (camposSelect == null || camposSelect.Length == 0) { throw new Exception("Parâmetros inválidos!"); } //conectar no banco de dados. CouchClient couchClient = new CouchClient(connectionString); CouchDatabase couchDataBase = await couchClient.GetDatabaseAsync(dataBase); //É preciso informar rquais campos serão retornados na consulta ao CouchDB FindBuilder findBuilder = new FindBuilder().Fields(camposSelect); //obtem registros em banco de dados. CouchResponse couchResponse = await couchDataBase.SelectAsync(findBuilder); //valida o status do retorno a consulta ao CouchDB if (couchResponse.StatusCode == HttpStatusCode.OK) { //transforma o resultado em JsonTextReader JsonTextReader jsonTextReader = new JsonTextReader(new StringReader(couchResponse.Docs.ToString())); //transforma o reader em objeto do tipo TType. TType[] result = new JsonSerializer().Deserialize(jsonTextReader, typeof(TType[])) as TType[]; return(new JsonResult(result)); } else { //retorna o erro ocorrido durante a pesquisa do CouchDB return(new JsonResult(couchResponse.Content)); } }
/// <summary> /// http://docs.couchdb.org/en/2.0.0/api/database/find.html /// </summary> /// <param name="expression"></param> /// <returns></returns> public async Task <CouchResponse> SelectAsync(FindBuilder expression) { var request = new RestSharp.RestRequest("/_find", RestSharp.Method.POST); request.AddParameter("application/json", expression.ToString(), RestSharp.ParameterType.RequestBody); return(await client.http.ExecuteAsync(request)); }
/// <summary> /// http://docs.couchdb.org/en/2.0.0/api/database/bulk-api.html#api-db-all-docs /// </summary> /// <param name="json"></param> /// <returns></returns> public async Task <CouchResponse> BulkInsertAsync(dynamic[] documentsObjects) { var request = new RestSharp.RestRequest("_bulk_docs", RestSharp.Method.POST); FindBuilder expression = new FindBuilder(); expression.Docs(documentsObjects); request.AddParameter("application/json", expression.ToString(), ParameterType.RequestBody); return(await client.http.ExecuteAsync(request)); }
public async Task <CouchResponse> SelectAsync(string[] ids) { var request = new RestSharp.RestRequest("_all_docs", RestSharp.Method.POST); FindBuilder expression = new FindBuilder(); expression.Keys(ids); request.AddParameter("application/json", expression.ToString(), RestSharp.ParameterType.RequestBody); return(await client.http.ExecuteAsync(request)); }
public static TEntity Find <TEntity>(this ISqlServerDbContext dbContext, object[] ids, Action <FindBuilder <TEntity> > findAction) where TEntity : class { if (findAction == null) { throw new ArgumentNullException(nameof(findAction)); } var entity = (dbContext ?? throw new ArgumentNullException(nameof(dbContext))).Find <TEntity>(ids); if (entity != null) { var builder = new FindBuilder <TEntity>(dbContext.Specific.Entry(entity)); findAction(builder); } return(entity); }
public async Task <JsonResult> GetAsync(string _id, string[] camposSelect) { try { //verifica parâmetros que são de preenchimento obrigatório. if (camposSelect == null || camposSelect.Length == 0 || string.IsNullOrEmpty(_id)) { throw new Exception("Parâmetros inválidos!"); } //conectar no banco de dados. CouchClient couchClient = new CouchClient(connectionString); CouchDatabase couchDataBase = await couchClient.GetDatabaseAsync(dataBase); /*Cria condição (FindBuilder.Selector) que será adicionada ao select*/ FindBuilder findBuilder = (new FindBuilder()).Selector("_id", SelectorOperator.Equals, _id); //obtem registros no CouchDB CouchResponse couchResponse = await couchDataBase.SelectAsync(findBuilder); //valida o status do retorno a consulta ao CouchDB if (couchResponse.StatusCode == HttpStatusCode.OK) { //transforma o resultado em JsonTextReader JsonTextReader jsonTextReader = new JsonTextReader(new StringReader(couchResponse.Docs[0].ToString())); //transforma o reader em objeto do tipo TType. TType result = (TType) new JsonSerializer().Deserialize(jsonTextReader, typeof(TType)); return(new JsonResult(result)); } else { //retorna o erro ocorrido durante a pesquisa do CouchDB return(new JsonResult(couchResponse.Content)); } } catch (Exception ex) { return(new JsonResult(ex.Message)); } }
public BindingDetail Find() { BindingDetail bindingDetail = new BindingDetail(); QueryLog.Write(QueryType.Find, EntityType.BindingTemplate); // // Validate find parameters. // Utility.IsValidKey(EntityType.BusinessService, ServiceKey); // // Process each find constraint. // FindBuilder find = new FindBuilder(EntityType.BindingTemplate, FindQualifiers, ServiceKey); // // If no search arguments are specified, return an empty result // set. // if (Utility.CollectionEmpty(TModelBag)) { return(bindingDetail); } try { int rows = 1; // // Find entities with matching parent key. // if (!Utility.StringEmpty(ServiceKey)) { rows = find.FindByParentKey(ServiceKey); } // // Find entities with matching TModel bag items. // if (!Utility.CollectionEmpty(TModelBag)) { rows = find.FindByTModelBag(TModelBag); } // // Process the find result set. // if (0 == rows) { // // Cleanup any temporary tables. // find.Abort(); } else if (0 == MaxRows) { bindingDetail.Truncated = Truncated.True; return(bindingDetail); } else { // // Read in the find results. // SqlDataReaderAccessor reader; SqlStoredProcedureAccessor sp; sp = find.RetrieveResults(MaxRows); reader = sp.ExecuteReader(); try { while (reader.Read()) { bindingDetail.BindingTemplates.Add(reader.GetGuidString("entityKey")); } } finally { reader.Close(); } if (sp.Parameters.GetBool("@truncated")) { bindingDetail.Truncated = Truncated.True; } else { bindingDetail.Truncated = Truncated.False; } foreach (BindingTemplate bindingTemplate in bindingDetail.BindingTemplates) { bindingTemplate.Get(); } } } catch (Exception) { find.Abort(); throw; } return(bindingDetail); }
public void TearDown() { _target = null; _context = null; }
public void Setup() { _target = new FindBuilder(); _context = new EnvironmentContext(); }
/// **************************************************************** /// public Find /// ---------------------------------------------------------------- /// <summary> /// </summary> /// **************************************************************** /// public RelatedBusinessList Find() { if (MaxRows < 0) { throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_FINDRELATEDBE_MAXROWSLESSTHANZERO"); } RelatedBusinessList relatedBusinessList = new RelatedBusinessList(); // // Process each find constraint. // FindBuilder find = new FindBuilder(EntityType.BusinessEntity, FindQualifiers); // // If no search arguments are specified, return an empty result // set. // // // Validate find parameters. // Utility.IsValidKey(EntityType.BusinessEntity, BusinessKey); // TODO: Override may be better for these calls to KeyedReference.Validate because no parent key is used // // TODO: This not an Assertion so we should not pass KeyedReferenceType.Assertion. // if (null != KeyedReference) { KeyedReference.Validate("", KeyedReferenceType.IdentifierBag); } try { // // Read in the find results. // SqlDataReaderAccessor reader; SqlStoredProcedureAccessor sp; sp = find.FindRelatedBusinesses( BusinessKey, KeyedReference, MaxRows); reader = sp.ExecuteReader(); try { while (reader.Read()) { relatedBusinessList.RelatedBusinessInfos.Add( reader.GetString("entityKey")); } } finally { reader.Close(); } if (sp.Parameters.GetBool("@truncated")) { relatedBusinessList.Truncated = Truncated.True; } else { relatedBusinessList.Truncated = Truncated.False; } relatedBusinessList.BusinessKey = BusinessKey; foreach (RelatedBusinessInfo relatedBusinessInfo in relatedBusinessList.RelatedBusinessInfos) { relatedBusinessInfo.Get(BusinessKey); } } catch (Exception) { find.Abort(); throw; } return(relatedBusinessList); }
public BusinessList Find() { BusinessList businessList = new BusinessList(); QueryLog.Write(QueryType.Find, EntityType.BusinessEntity); // // Process each find constraint. // FindBuilder find = new FindBuilder(EntityType.BusinessEntity, FindQualifiers); // // If no search arguments are specified, return an empty result // set. // if (Utility.CollectionEmpty(Names) && Utility.CollectionEmpty(DiscoveryUrls) && Utility.CollectionEmpty(IdentifierBag) && Utility.CollectionEmpty(CategoryBag) && Utility.CollectionEmpty(TModelBag)) { return(businessList); } // // Validate find parameters. // if (!Utility.CollectionEmpty(Names)) { Names.ValidateForFind(); } else { Debug.Verify(!find.CaseSensitiveMatch && !find.ExactNameMatch, "UDDI_ERROR_UNSUPPORTED_FINDBE_NAMEFQNONAMES", ErrorType.E_unsupported); } // // TODO: Override may be better for these calls to KeyedReference.Validate because no parent key is used // if (!Utility.CollectionEmpty(IdentifierBag)) { IdentifierBag.Validate("", KeyedReferenceType.IdentifierBag); } if (!Utility.CollectionEmpty(CategoryBag)) { CategoryBag.Validate("", KeyedReferenceType.CategoryBag); } try { int rows = 1; // // Find entities with matching identifier bag items. // if (!Utility.CollectionEmpty(IdentifierBag)) { rows = find.FindByKeyedReferences(KeyedReferenceType.IdentifierBag, IdentifierBag); } // // Find entities with matching category bag items. // if (rows > 0 && !Utility.CollectionEmpty(CategoryBag)) { rows = find.FindByKeyedReferences(KeyedReferenceType.CategoryBag, CategoryBag); } // // Find entities with matching TModel bag items. // if (rows > 0 && !Utility.CollectionEmpty(TModelBag)) { rows = find.FindByTModelBag(TModelBag); } // // Find entities with matching discovery URLs // if (rows > 0 && !Utility.CollectionEmpty(DiscoveryUrls)) { rows = find.FindByDiscoveryUrls(DiscoveryUrls); } // // Find entities with matching names // if (rows > 0 && !Utility.CollectionEmpty(Names)) { rows = find.FindByNames(Names); } // // Process the find result set. // if (0 == rows) { // // Cleanup any temporary tables. // find.Abort(); } // TODO: review else if (0 == MaxRows) { businessList.Truncated = Truncated.True; return(businessList); } else { // // Read in the find results. // SqlDataReaderAccessor reader; SqlStoredProcedureAccessor sp; sp = find.RetrieveResults(MaxRows); // // TODO: return reader, not the whole SPA // reader = sp.ExecuteReader(); try { if (find.ServiceSubset) { // // For a service subset search, we limit the result set // to those services that matched the category bag // search criteria. // BusinessInfo businessInfo = null; string prevKey = null; while (reader.Read()) { string businessKey = reader.GetString("entityKey"); if (prevKey != businessKey) { businessInfo = new BusinessInfo(businessKey); businessList.BusinessInfos.Add(businessInfo); } businessInfo.ServiceInfos.Add( reader.GetString("subEntityKey"), businessKey); prevKey = businessKey; } } else { // // For non-service subset searches, we will simply // return a list of businesses with all services. // while (reader.Read()) { businessList.BusinessInfos.Add(reader.GetString("entityKey")); } } } finally { reader.Close(); } if (sp.Parameters.GetBool("@truncated")) { businessList.Truncated = Truncated.True; } else { businessList.Truncated = Truncated.False; } // // Get the actual business info and service info data. For // a service subset, we'll grab just those services that we // populated. For all other searches, we'll get all service // infos. // if (find.ServiceSubset) { foreach (BusinessInfo businessInfo in businessList.BusinessInfos) { businessInfo.Get(false); foreach (ServiceInfo serviceInfo in businessInfo.ServiceInfos) { serviceInfo.Get(); } } } else { foreach (BusinessInfo businessInfo in businessList.BusinessInfos) { businessInfo.Get(true); } } } } catch (Exception) { find.Abort(); throw; } return(businessList); }