Exemple #1
0
        private bool EnrichAccountData(Guid accountId, SearchInfoRequest requestBody)
        {
            var           request = _restClient.CreateJsonRequest(SearchMethodName, requestBody);
            IRestResponse response;

            try {
                response = _restClient.Post(request);
            } catch (Exception ex) {
                throw new HttpException((int)HttpStatusCode.InternalServerError, ex.Message);
            }
            HandleRestClientError(response);
            SearchInfoResponse responseInfo = ServiceStackTextHelper.Deserialize <SearchInfoResponse>(response.Content);

            if (responseInfo.Status == "error")
            {
                throw new HttpException((int)HttpStatusCode.InternalServerError, responseInfo.Message);
            }
            if (responseInfo.CommunicationInfo == null)
            {
                var message = $"CommunicationInfo is null. StatusCode = '{response.StatusCode}' " +
                              $"ResponseStatus = '{response.ResponseStatus}' ErrorMessage = '{response.ErrorMessage}' " +
                              $"Content: {response.Content}";
                throw new HttpException((int)HttpStatusCode.InternalServerError, message);
            }
            bool result = UpdateEnrichedData(accountId, responseInfo.CommunicationInfo);

            return(result);
        }
Exemple #2
0
        public async Task <List <ShortCompanyInfo> > SuggestCompanies(string name)
        {
            GetRequiredParameters(out string serviceUrl, out string apiKey);
#if NETFRAMEWORK
            _restClient.BaseUrl = serviceUrl;
#else
            _restClient.BaseUrl = new Uri(serviceUrl);
#endif
            _restClient.AddDefaultHeader("ApiKey", apiKey);
            IRestRequest request = _restClient.CreateRequest(SuggestCompaniesMethodName);
            request.AddParameter(CompanyNameParameter, name);
            request.AddParameter(ApiKeyParameter, apiKey);
            IRestResponse response;
            try {
                response = await _restClient.ExecutePostTaskAsync(request).ConfigureAwait(false);
            } catch (Exception ex) {
                throw new HttpException((int)HttpStatusCode.InternalServerError, ex.Message);
            }
#if !NETFRAMEWORK
            if (!response.IsSuccessful)
            {
                string message = response.Content.IsNotNullOrEmpty() ? response.Content : response.StatusDescription;
                throw new HttpException((int)HttpStatusCode.InternalServerError, message);
            }
#endif
            var responseInfo = ServiceStackTextHelper.Deserialize <CloudRestResponse>(response.Content);
            if (responseInfo?.CompaniesInfo == null)
            {
                throw new HttpException((int)HttpStatusCode.InternalServerError, response.Content);
            }
            return(responseInfo.CompaniesInfo);
        }
Exemple #3
0
        /// <summary>
        /// Returns allowed activity results.
        /// </summary>
        /// <param name="userConnection">User connection.</param>
        /// <param name="activityId">ID of the activity.</param>
        /// <returns>Allowed values of the activity result.</returns>
        public static string GetAllowedActivityResults(UserConnection userConnection, Guid activityId)
        {
            var select = (Select) new Select(userConnection)
                         .Column("AllowedResult")
                         .From("Activity")
                         .Where("Id").IsEqual(Column.Parameter(activityId));
            var allowedResult = select.ExecuteScalar <string>();

            if (string.IsNullOrEmpty(allowedResult))
            {
                return("[]");
            }
            EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager;
            EntitySchema        entitySchema        = entitySchemaManager.GetInstanceByName("ActivityResult");
            var esq = new EntitySchemaQuery(entitySchemaManager, entitySchema.Name)
            {
                UseAdminRights = false
            };

            esq.PrimaryQueryColumn.IsAlwaysSelect = true;
            string columnName = entitySchema.GetPrimaryDisplayColumnName();

            esq.AddColumn(columnName);
            esq.AddColumn("Category");
            EntitySchemaQueryFilterCollection filters = esq.Filters;
            var allowedResultIds = ServiceStackTextHelper.Deserialize <string[]>(allowedResult);
            var columnParameters = new object[allowedResultIds.Length];

            for (int i = 0; i < allowedResultIds.Length; i++)
            {
                var resultId = new Guid(allowedResultIds[i]);
                columnParameters[i] = resultId;
            }
            filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Id", columnParameters));
            EntityCollection entityCollection = esq.GetEntityCollection(userConnection);
            bool             isFirstItem      = true;
            var sb = new StringBuilder("[");

            foreach (Entity entity in entityCollection)
            {
                if (!isFirstItem)
                {
                    sb.Append(",");
                }
                else
                {
                    isFirstItem = false;
                }
                sb.AppendFormat("{{\"resultId\":\"{0}\",\"caption\":\"{1}\",\"categoryId\":\"{2}\"}}",
                                entity.GetTypedColumnValue <Guid>("Id"), entity.GetTypedColumnValue <string>(columnName),
                                entity.GetTypedColumnValue <Guid>("CategoryId"));
            }
            sb.Append("]");
            return(sb.ToString());
        }