コード例 #1
0
        private Uri SaveResource <T>(T participant, string resourceUri) where T : class
        {
            this.LastApiMessage = string.Empty;

            StatusMessage message;
            RestAdapter   adapter = GetAdapter();

            try
            {
                message = adapter.Post <T>(new Uri(this.apiUriBase + resourceUri), participant);
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
            finally
            {
                ReleaseAdapter(adapter);
            }


            if (message.Code != (int)HttpStatusCode.Created)
            {
                throw new ApiException(new RestException(message));
            }

            this.LastApiMessage = message.Message;
            return(new Uri(message.Link.HRef));
        }
コード例 #2
0
 private void ReleaseAdapter(RestAdapter adapter)
 {
     lock (adapterLock)
     {
         adapter.IsAssigned = false;
     }
 }
コード例 #3
0
        private T GetResource <T>(string resourceUri) where T : class
        {
            RestAdapter adapter = GetAdapter();

            try
            {
                return(adapter.Get <T>(new Uri(this.apiUriBase + resourceUri)));
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
            finally
            {
                ReleaseAdapter(adapter);
            }
        }
コード例 #4
0
        private IList <TItem> GetResourceList <TContainer, TItem>(string resourceUri)
            where TContainer : class, IEnumerable <TItem>
            where TItem : class
        {
            RestAdapter adapter = GetAdapter();

            try
            {
                TContainer items = adapter.Get <TContainer>(new Uri(this.apiUriBase + resourceUri));
                return(new List <TItem>(items));
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
            finally
            {
                ReleaseAdapter(adapter);
            }
        }
コード例 #5
0
        private RestAdapter GetAdapter()
        {
            lock (adapterLock)
            {
                if (null == this.adapters)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }

                RestAdapter adapter = this.adapters.FirstOrDefault(a => a.IsBusy == false && a.IsAssigned == false);
                if (adapter == null)
                {
                    adapter             = new RestAdapter(this.username, this.password);
                    adapter.ContentType = this.ContentType;
                    this.adapters.Add(adapter);
                }

                adapter.IsAssigned = true;
                return(adapter);
            }
        }
コード例 #6
0
        private object Get(string resourceUri)
        {
            if (null == resourceUri)
            {
                throw new ArgumentNullException("resourceUri");
            }

            RestAdapter adapter = GetAdapter();

            try
            {
                return(adapter.Get(new Uri(this.apiUriBase + resourceUri)));
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
            finally
            {
                ReleaseAdapter(adapter);
            }
        }
コード例 #7
0
        /// <summary>
        /// Gets a resource where the expected type is not know.
        /// </summary>
        /// <param name="resourceUri">The resourceUri</param>
        /// <exception cref="ApiException">The request failed. See inner exception for details.</exception>
        /// <returns>The resource</returns>
        public object Get(Uri resourceUri)
        {
            if (null == resourceUri)
            {
                throw new ArgumentNullException("resourceUri");
            }

            RestAdapter adapter = GetAdapter();

            try
            {
                return(adapter.Get(resourceUri));
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
            finally
            {
                ReleaseAdapter(adapter);
            }
        }
コード例 #8
0
        private bool DeleteResource(string resourceUri)
        {
            this.LastApiMessage = string.Empty;

            StatusMessage message;
            RestAdapter   adapter = GetAdapter();

            try
            {
                message = adapter.Delete(new Uri(this.apiUriBase + resourceUri));
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
            finally
            {
                ReleaseAdapter(adapter);
            }

            this.LastApiMessage = message.Message;
            return(message.Code == (int)HttpStatusCode.OK);
        }
コード例 #9
0
        private bool UpdateResource <T>(T competition, string resourceUri) where T : class
        {
            this.LastApiMessage = string.Empty;

            StatusMessage message;
            RestAdapter   adapter = GetAdapter();

            try
            {
                message = adapter.Put <T>(new Uri(this.apiUriBase + resourceUri), competition);
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
            finally
            {
                ReleaseAdapter(adapter);
            }


            this.LastApiMessage = message.Message;
            return(message.Code == (int)HttpStatusCode.OK);
        }