Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        public async Task <EntityListResult <BaseEntity> > GetAsyncReferenceFields(IRequestContext context, string apiEntityName, IList <QueryPhrase> queryPhrases, List <String> fields, string orderBy, int?limit)
        {
            string url = context.GetPath() + "/" + apiEntityName;

            string queryString = QueryBuilder.Create().SetQueryPhrases(queryPhrases).SetFields(fields).SetOrderBy(orderBy).SetLimit(limit).Build();

            ResponseWrapper response = await rc.ExecuteGetAsync(url, queryString).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext);

            if (response.Data != null)
            {
                EntityListResult <BaseEntity> result = jsonSerializer.Deserialize <EntityListResult <BaseEntity> >(response.Data);
                return(result);
            }
            return(null);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public async Task <Attachment> AttachToEntityAsync(IRequestContext context, BaseEntity entity, string fileName, byte[] content, string contentType, string[] fieldsToReturn)
        {
            string queryString      = QueryBuilder.Create().SetFields(fieldsToReturn).Build();
            string url              = context.GetPath() + "/attachments?" + queryString;
            string attachmentEntity = null;

            if (entity != null)
            {
                attachmentEntity = string.Format("{0}\"name\":\"{2}\",\"owner_{3}\":{0}\"type\":\"{3}\",\"id\":\"{4}\"{1}{1}",
                                                 "{", "}", fileName, entity.AggregateType, entity.Id.ToString());
            }
            ResponseWrapper response = await rc.SendMultiPartAsync(url, content, contentType, fileName, attachmentEntity).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext);

            EntityListResult <Attachment> result = jsonSerializer.Deserialize <EntityListResult <Attachment> >(response.Data);

            return(result.data[0]);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public async Task <T> CreateAsync <T>(IRequestContext context, T entity, IList <string> fieldsToReturn = null) where T : BaseEntity
        {
            EntityListResult <T> result = await CreateAsync <T>(context, EntityList <T> .Create(entity), fieldsToReturn).ConfigureAwait(RestConnector.AwaitContinueOnCapturedContext);

            return(result.data[0]);
        }