Exemple #1
0
        /// <summary>
        /// Get a specific resource.
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="resourceName"></param>
        /// <param name="versionContentType">Specify if a specific version of the model should be requested, if null, versionless will be used</param>
        /// <returns></returns>
        public virtual GetResponse Get(Guid guid, string resourceName, string versionContentType)
        {
            if (resourceName == null)
            {
                throw new Exception("ResourcePluralName missing. Unable to identify resource name : [" + resourceName + "]");
            }

            bool authenticated = Authenticate().Result;

            if (authenticated)
            {
                NameValueCollection headers = new NameValueCollection();
                ConstructAcceptHeader(headers, versionContentType);
                var resource = ConstructResourceUri("api", resourceName, guid.ToString());
                var response = ExecuteRequest(HttpMethod.Get, null, resource, null, headers);

                if (response.IsSuccessStatusCode)
                {
                    GetResponse getResponse = new GetResponse();
                    getResponse.Data = response.Content.ReadAsStringAsync().Result;

                    if (response.Headers.Contains(Media_Type_Header))
                    {
                        getResponse.Version = response.Headers.GetValues(Media_Type_Header).FirstOrDefault();
                    }

                    getResponse.TotalCount = 1;

                    return(getResponse);
                }
                else
                {
                    //throw exception
                    throw new Exception();
                }
            }
            else
            {
                //throw exception
                throw new Exception();
            }
        }
        /// <summary>
        /// This method will use Ethos Integration to lookup many individual GUIDS with the persons resource and report an average of how long it takes.
        /// </summary>
        /// <returns></returns>
        internal static async Task TimeSinglePersonsSync()
        {
            // Print out the configuration used to generate the numbers for this run
            Console.WriteLine("Method: Start TimeSinglePersonsSync()");
            Console.WriteLine("  ** numGUIDIterations: " + numGUIDIterations);
            Console.WriteLine("  ** resourceName: " + resourceName);
            Console.WriteLine("  ** criteria: " + criteria);
            Console.WriteLine("  ** Time of run: " + DateTime.Now.ToString("MM/dd/yyyy h:mm:ss"));

            string[] guids = new string[numGUIDIterations];

            // Setup as parameters on the URL query for the GetAll call
            Dictionary <string, string> searchParams = new Dictionary <string, string>();

            searchParams.Add("criteria", criteria);

            if (await ec.Authenticate())
            {
                // First, lookup a large group of GUIDs so we can look them up individually
                var         watch         = System.Diagnostics.Stopwatch.StartNew();
                GetResponse GUIDsResponse = ec.GetAll(resourceName, searchParams, offset: 0, limit: numGUIDIterations); // Get an array of results from Ethos
                watch.Stop();
                Console.WriteLine("  Wait time for lookup on criteria ** " + criteria + " **: " + watch.ElapsedMilliseconds + " msec.");

                JArray a = JArray.Parse(GUIDsResponse.Data);

                if (a.Count < numGUIDIterations)
                {
                    Console.WriteLine("    Based on the search criteria, only " + a.Count + " records were returned.");
                }

                // Put the returned GUIDs in an array
                for (int i = 0; i < numGUIDIterations && i < a.Count; i++)
                {
                    JObject o = (JObject)a[i];

                    string guid = (string)o["id"];

                    guids[i] = guid;
                }

                long totalGUIDLookupTime = 0;
                int  j = 1;

                // Now, one by one, let's look them up and time each run. Add those together as we go and get the average.
                for (j = 0; j < numGUIDIterations && j < a.Count; j++)
                {
                    watch = System.Diagnostics.Stopwatch.StartNew();
                    GetResponse singlePersonResponse = ec.Get(new Guid(guids[j]), resourceName, "application/vnd.hedtech.integration.v12+json"); // Get a single result from Ethos, for version 12
                    watch.Stop();
                    totalGUIDLookupTime += watch.ElapsedMilliseconds;

                    JObject o = JObject.Parse(singlePersonResponse.Data);

                    string fullname = (string)o["names"][0]["fullName"];

                    Console.WriteLine("  Wait time for lookup on GUID " + guids[j] + ": " + watch.ElapsedMilliseconds + " msec - name: " + fullname);

                    if (j == 0)
                    {
                        Console.WriteLine(o); // I used this during my testing of Ethos Extend to make sure the extensions were active
                    }
                }

                Console.WriteLine("  Average wait time for call to Ethos: " + totalGUIDLookupTime / j + " msec.");
            }
            else
            {
                Console.WriteLine("  Didn't authenticate");
            }

            ec.Dispose();

            Console.WriteLine("Method: End TimeSinglePersonsSync()");
        }
Exemple #3
0
        /// <summary>
        /// Get a page of resources from the authoritative source starting at offset
        /// </summary>
        /// <param name="resourceName"></param>
        /// <param name="urlParameters"></param>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        /// <param name="versionContentType">Specify if a specific version of the model should be requested, if null, versionless will be used</param>
        /// <returns></returns>
        public virtual GetResponse GetAll(string resourceName, Dictionary <string, string> urlParameters = null, int offset = 0, int limit = -1, string versionContentType = null)
        {
            if (resourceName == null)
            {
                throw new Exception("ResourcePluralName missing. Unable to identify resource name : [" + resourceName + "]");
            }


            bool authenticated = Authenticate().Result;

            if (authenticated)
            {
                var resource = ConstructResourceUri("api", resourceName);
                NameValueCollection headers = new NameValueCollection();
                ConstructAcceptHeader(headers, versionContentType);

                if (urlParameters == null)
                {
                    urlParameters = new Dictionary <string, string>();
                }


                urlParameters[Offset_Param] = offset.ToString();

                if (limit > 0)
                {
                    urlParameters[Limit_Param] = limit.ToString();
                }

                var response = ExecuteRequest(HttpMethod.Get, null, resource, urlParameters, headers);

                if (response.IsSuccessStatusCode)
                {
                    GetResponse getAllResponse = new GetResponse();
                    getAllResponse.Data = response.Content.ReadAsStringAsync().Result;
                    if (response.Headers.Contains(Media_Type_Header))
                    {
                        getAllResponse.Version = response.Headers.GetValues(Media_Type_Header).FirstOrDefault();
                    }
                    if (response.Headers.Contains(Total_Count_Header))
                    {
                        var countHeader = response.Headers.GetValues(Total_Count_Header).FirstOrDefault();
                        if (!string.IsNullOrWhiteSpace(countHeader))
                        {
                            getAllResponse.TotalCount = Int32.Parse(countHeader);
                        }
                    }
                    else
                    {
                        // Todo: Temp workaround for the Mock API Server until it returns the header record count
                        //throw new HttpRequestFailedException("Missing X-Total-Count header", response.StatusCode);
                        getAllResponse.TotalCount = 0;
                    }

                    return(getAllResponse);
                }
                else
                {
                    //throw exception
                    throw new Exception();
                }
            }
            else
            {
                //throw exception
                throw new Exception();
            }
        }