public async Task DeleteByIdAsync <T>(IRequestContext context, EntityId entityId) where T : BaseEntity { string collectionName = EntityTypeRegistry.GetInstance().GetCollectionName(typeof(T)); string url = context.GetPath() + "/" + collectionName + "/" + entityId; ResponseWrapper response = await rc.ExecuteDeleteAsync(url).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext); }
public async Task DeleteByFilterAsync <T>(IRequestContext context, IList <QueryPhrase> queryPhrases) where T : BaseEntity { string collectionName = EntityTypeRegistry.GetInstance().GetCollectionName(typeof(T)); string queryString = QueryBuilder.Create().SetQueryPhrases(queryPhrases).Build(); string url = context.GetPath() + "/" + collectionName + "?" + queryString; ResponseWrapper response = await rc.ExecuteDeleteAsync(url).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext); }
private async Task <BaseEntity> GetByIdInternalAsync(IRequestContext context, EntityId id, Type entityType, IList <string> fields) { string collectionName = EntityTypeRegistry.GetInstance().GetCollectionName(entityType); string url = context.GetPath() + "/" + collectionName + "/" + id; string queryString = QueryBuilder.Create().SetFields(fields).Build(); ResponseWrapper response = await rc.ExecuteGetAsync(url, queryString).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext); BaseEntity result = (BaseEntity)jsonSerializer.Deserialize(response.Data, entityType); return(result); }
public async Task <EntityListResult <T> > UpdateEntitiesAsync <T>(IRequestContext context, EntityList <T> entities) where T : BaseEntity { string collectionName = EntityTypeRegistry.GetInstance().GetCollectionName(typeof(T)); string url = context.GetPath() + "/" + collectionName; string data = jsonSerializer.Serialize(entities); ResponseWrapper response = await rc.ExecutePutAsync(url, null, data).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext); EntityListResult <T> result = jsonSerializer.Deserialize <EntityListResult <T> >(response.Data); return(result); }
private async Task <BaseEntity> UpdateInternalAsync(IRequestContext context, BaseEntity entity, Type entityType, Dictionary <string, string> serviceArguments, IList <string> fieldsToReturn) { string collectionName = EntityTypeRegistry.GetInstance().GetCollectionName(entityType); string queryString = QueryBuilder.Create().SetFields(fieldsToReturn).SetServiceArguments(serviceArguments).Build(); string url = context.GetPath() + "/" + collectionName + "/" + entity.Id; string data = jsonSerializer.Serialize(entity); ResponseWrapper response = await rc.ExecutePutAsync(url, queryString, data).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext); BaseEntity result = (BaseEntity)jsonSerializer.Deserialize(response.Data, entityType); return(result); }
/// <summary> /// Search for all entities of given type that satify the search criteria /// </summary> public async Task <EntityListResult <T> > SearchAsync <T>(IRequestContext context, string searchString, List <string> subTypes, int limit = 30) where T : BaseEntity { if (context == null) { throw new ArgumentNullException("context"); } if (string.IsNullOrEmpty(searchString)) { throw new ArgumentException("searchString parameter is null or empty"); } if (limit <= 0) { throw new ArgumentException("search limit should be greater than 0"); } string url = context.GetPath() + "/" + EntityTypeRegistry.GetInstance().GetCollectionName(typeof(T)); List <QueryPhrase> query = null; if (subTypes != null && subTypes.Count > 0) { query = new List <QueryPhrase> { new InQueryPhrase("subtype", subTypes) }; } var serviceArguments = new Dictionary <string, string> { { "text_search", "{\"type\":\"global\",\"text\":\"" + searchString + "\"}" } }; var queryString = QueryBuilder.Create().SetQueryPhrases(query).SetOrderBy("id").SetLimit(limit).SetServiceArguments(serviceArguments).Build(); ResponseWrapper response = await rc.ExecuteGetAsync(url, queryString).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext); EntityListResult <T> result = jsonSerializer.Deserialize <EntityListResult <T> >(response.Data); foreach (var entity in result.data) { var searchResult = entity.GetValue("global_text_search_result") as BaseEntity; if (searchResult == null) { continue; } entity.SetValue("name", searchResult.GetValue("name")); entity.SetValue("description", searchResult.GetValue("description")); } return(result); }
public async Task <EntityListResult <T> > GetAsync <T>(IRequestContext context, IList <QueryPhrase> queryPhrases, List <string> fields, int?limit) where T : BaseEntity { string collectionName = EntityTypeRegistry.GetInstance().GetCollectionName(typeof(T)); string url = context.GetPath() + "/" + collectionName; string queryString = QueryBuilder.Create().SetQueryPhrases(queryPhrases).SetFields(fields).SetLimit(limit).Build(); ResponseWrapper response = await rc.ExecuteGetAsync(url, queryString).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext); if (response.Data != null) { EntityListResult <T> result = jsonSerializer.Deserialize <EntityListResult <T> >(response.Data); return(result); } return(null); }
private string GetCollectionName <T>() where T : BaseEntity { CustomCollectionPathAttribute customCollectionPathAttribute = (CustomCollectionPathAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(CustomCollectionPathAttribute)); String collectionName = null; if (customCollectionPathAttribute != null) { collectionName = customCollectionPathAttribute.Path; } else { collectionName = EntityTypeRegistry.GetInstance().GetCollectionName(typeof(T)); } return(collectionName); }
public async Task <EntityListResult <T> > CreateAsync <T>(IRequestContext context, EntityList <T> entityList, IList <string> fieldsToReturn = null) where T : BaseEntity { String collectionName = EntityTypeRegistry.GetInstance().GetCollectionName(typeof(T)); string queryParams = ""; if (fieldsToReturn != null && fieldsToReturn.Count > 0) { queryParams += "fields=" + string.Join(",", fieldsToReturn); } string url = context.GetPath() + "/" + collectionName; String data = jsonSerializer.Serialize(entityList); ResponseWrapper response = await rc.ExecutePostAsync(url, queryParams, data).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext); EntityListResult <T> result = jsonSerializer.Deserialize <EntityListResult <T> >(response.Data); return(result); }
public async Task <GroupResult> GetWithGroupByAsync <T>(IRequestContext context, IList <QueryPhrase> queryPhrases, String groupBy) where T : BaseEntity { String collectionName = EntityTypeRegistry.GetInstance().GetCollectionName(typeof(T)); string url = context.GetPath() + "/" + collectionName + "/groups"; // Octane group API now return logical name by default as ID field, // this parameter change this to return numeric ID. var serviceArgs = new Dictionary <string, string>(); serviceArgs.Add("use_numeric_id", "true"); string queryString = QueryStringBuilder.BuildQueryString(queryPhrases, null, null, null, null, groupBy, serviceArgs); ResponseWrapper response = await rc.ExecuteGetAsync(url, queryString).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext); if (response.Data != null) { GroupResult result = jsonSerializer.Deserialize <GroupResult>(response.Data); return(result); } return(null); }
public async Task <BaseEntity> UpdateAsync(IRequestContext context, BaseEntity entity, string type, Dictionary <string, string> serviceArguments = null, IList <string> fieldsToReturn = null) { Type entityType = EntityTypeRegistry.GetInstance().GetTypeByEntityTypeName(type); return(await UpdateInternalAsync(context, entity, entityType, serviceArguments, fieldsToReturn).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext)); }
public async Task <BaseEntity> GetByIdAsync(IRequestContext context, EntityId id, string type, IList <string> fields) { Type entityType = EntityTypeRegistry.GetInstance().GetTypeByEntityTypeName(type); return(await GetByIdInternalAsync(context, id, entityType, fields).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext)); }
public async Task <BaseEntity> GetByIdAsync(IRequestContext context, EntityId id, string type, IList <String> fields) { Type entityType = EntityTypeRegistry.GetInstance().GetTypeByEntityTypeName(type); return(await GetByIdInternalAsync(context, id, entityType, fields)); }