Example #1
0
        /// <summary>
        /// Execute the clarizen query.
        /// Throw exception if error is returned
        /// </summary>
        internal static Data.query ExecuteQuery(BaseContext context, string query)
        {
            var q       = new Ekin.Clarizen.Data.Request.query(query);
            var results = context.Api.ExecuteQuery(q);

            Assert.True(string.IsNullOrEmpty(results?.Error), results?.Error);
            return(results);
        }
Example #2
0
        public query(string serverLocation, string sessionId, Request.query request, bool isBulk = false)
        {
            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/data/query";

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Post, request, typeof(Result.query));
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Post(request);

            // Return result
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    this.Data = JsonConvert.DeserializeObject <Result.query>(response.Content);
                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else if (response.InternalError != null)
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
            else
            {
                this.IsCalledSuccessfully = false;
            }
        }