示例#1
0
        /// <inheritDoc />
        public override bool Equals(BaseEntity other)
        {
            DataServiceInfo otherService = other as DataServiceInfo;

            if (otherService == null)
            {
                return(base.Equals(other));
            }
            else
            {
                return(EndpointURL.Equals(otherService.EndpointURL));
            }
        }
        private async Task <string> ExecuteWithTimeout(AsyncCodeActivityContext context, CancellationToken cancellationToken = default)
        {
            ///////////////////////////

            // Get inputs from context
            var endpointURL = EndpointURL.Get(context);
            var apiKey      = APIKey.Get(context);
            var queryData   = QueryData.Get(context);

            /* Build request body (feature dictionary) */
            // -> here we assume that the queryData is a json string with keys corresponding to features
            JArray  jsonDataArray = JArray.Parse(queryData);
            JObject jsonData      = (JObject)jsonDataArray.First;
            // -> we build the feature dictionary just by putting all keys into it
            var jsonQuery = new JObject();

            jsonQuery.Add("features", jsonData);
            // -> StringContent is required for HTTP POST call
            var stringContent = new StringContent(jsonQuery.ToString());

            /* Initialize HttpClient object */
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(endpointURL);

            // -> Add an Accept header for JSON format.
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            // -> Handle authentication
            var authToken = Encoding.ASCII.GetBytes(apiKey + ":"); // don't forget the colon!!

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                                                                                       Convert.ToBase64String(authToken));


            /* Post query to DSS API Node */
            HttpResponseMessage response = await client.PostAsync(String.Empty, stringContent);

            response.EnsureSuccessStatusCode();
            var resp = await response.Content.ReadAsStringAsync();

            // Dispose once all HttpClient calls are complete. This is not necessary if the containing object will be disposed of; for example in this case the HttpClient instance will be disposed automatically when the application terminates so the following call is superfluous.
            client.Dispose();

            // Outputs
            return(resp);
        }
示例#3
0
        /// <summary>
        /// Find the API endpoint that this request is directed to. Returns null if none is found.
        /// </summary>
        /// <param name="Request"></param>
        /// <returns></returns>
        public Type FindEndpoint(RequestProvider Request)
        {
            //Search through endpoints
            foreach (Type T in Program.Endpoints)
            {
                //Get endpoint info attribute. If the attribute is missing, show an error in console and continue to the next.
                EndpointURL Info = (EndpointURL)Attribute.GetCustomAttribute(T, typeof(EndpointURL));
                if (Info == null)
                {
                    Log.Error("Endpoint " + T.Name + " has no EndpointURL attribute");
                    continue;
                }

                //Check if this is the correct endpoint. If it is, execute it.
                if (Info.URL == Request.Url.LocalPath.ToLower())
                {
                    return(T);
                }
            }
            return(null);
        }
示例#4
0
 /// <inheritDoc />
 public override int GetHashCode()
 {
     return(EndpointURL.GetHashCode());
 }