Beispiel #1
0
        /// <summary>
        /// Finds all objects that match the filter and returns the first
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public T FindOne(ISearchFilter filter)
        {
            string response = ReqManager.Get(EndPoint, filter);
            var    result   = JsonConvert.DeserializeObject <ResponseCollection <T> >(response);

            return(result?.Rows?.FirstOrDefault());
        }
Beispiel #2
0
        public IRequestResponse Delete(int id)
        {
            string response = ReqManager.Delete($"{EndPoint}/{id}");
            var    result   = JsonConvert.DeserializeObject <RequestResponse>(response);

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Search for Assets that match filters defined in an ISearchFilter object.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public IResponseCollection <T> FindAll(ISearchFilter filter)
        {
            string response = ReqManager.Get(EndPoint, filter);
            var    results  = JsonConvert.DeserializeObject <ResponseCollection <T> >(response);

            return(results);
        }
Beispiel #4
0
        public IRequestResponse Update(T toUpdate)
        {
            string response = ReqManager.Put($"{EndPoint}/{toUpdate.Id}", toUpdate);
            var    result   = JsonConvert.DeserializeObject <RequestResponse>(response);

            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Creates a new object from the provided CommonResponseObject
        /// </summary>
        /// <param name="toCreate"></param>
        /// <returns></returns>
        public IRequestResponse Create(T toCreate)
        {
            string res      = ReqManager.Post(EndPoint, toCreate);
            var    response = JsonConvert.DeserializeObject <RequestResponse>(res);

            return(response);
        }
Beispiel #6
0
        /// <summary>
        /// Attempts to get a given object by it's ID
        /// </summary>
        /// <param name="id">ID of the object to find</param>
        /// <returns></returns>
        public T Get(int id)
        {
            // TODO: Find better way to deal with objects that are not found
            string response = ReqManager.Get($"{EndPoint}/{id}");
            var    result   = JsonConvert.DeserializeObject <T>(response);

            return(result);
        }
        protected override IResponseCollection <T> GetAllInternal()
        {
            // If there are more than 1000 assets split up the requests to avoid timeouts
            string response = ReqManager.Get(EndPoint);
            var    results  = JsonConvert.DeserializeObject <ResponseCollection <T> >(response);

            return(results);
        }
Beispiel #8
0
        public IRequestResponse Update(T toUpdate)
        {
            string response = ReqManager.Put($"{EndPoint}/{toUpdate.Id}", toUpdate);

            //var result = JsonConvert.DeserializeObject<RequestResponse>(response);
            // Currently there is an error in deserializing the response, related to the new
            // Assignment object.
            return(null);
        }
Beispiel #9
0
        /// <summary>
        /// Creates a new object from the provided CommonResponseObject
        /// </summary>
        /// <param name="toCreate"></param>
        /// <returns></returns>
        public IRequestResponse Create(T toCreate)
        {
            System.Console.WriteLine("Attempting to create type: " + typeof(T).ToString());
            System.Console.WriteLine("Instance name: " + toCreate.Name.ToString());

            // Update functionality could be put in here
            SearchFilter filter   = new SearchFilter(toCreate.Name);
            T            existing = this.FindOne(filter);

            if (existing != null)
            {
                System.Console.WriteLine("Already exists in DB", typeof(T).ToString());
                return(null);
            }
            else
            {
                // TODO: Properly parse and log request response.
                string res = ReqManager.Post(EndPoint, toCreate);
                return(null);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Creates a new object from the provided CommonResponseObject
        /// </summary>
        /// <param name="toCreate"></param>
        /// <returns></returns>
        public IRequestResponse Create(T toCreate)
        {
            System.Console.WriteLine("Attempting to create type: " + typeof(T).ToString());
            System.Console.WriteLine("Instance name: " + toCreate.Name.ToString());

            // Update functionality could be put in here
            SearchFilter filter   = new SearchFilter(toCreate.Name);
            T            existing = this.FindOne(filter);

            if (existing != null)
            {
                System.Console.WriteLine("Already exists in DB", typeof(T).ToString());
                return(null);
            }
            else
            {
                // TODO: Make json properly here
                string res      = ReqManager.Post(EndPoint, toCreate);
                var    response = JsonConvert.DeserializeObject <RequestResponse>(res);
                return(response);
            }
        }
Beispiel #11
0
        protected virtual IResponseCollection <T> GetAllInternal()
        {
            // Figure out how many rows the results will return so we can splitup requests
            var count = FindAll(new SearchFilter {
                Limit = 1
            });

            // If there are more than 1000 assets split up the requests to avoid timeouts
            if (count.Total < 1000)
            {
                string response = ReqManager.Get(EndPoint);
                var    results  = JsonConvert.DeserializeObject <ResponseCollection <T> >(response);

                return(results);
            }

            var finalResults = new ResponseCollection <T>
            {
                Total = count.Total
            };

            int offset = 0;

            while (finalResults.Rows.Count < count.Total)
            {
                var batch = FindAll(new SearchFilter
                {
                    Limit  = 1000,
                    Offset = offset
                });

                finalResults.Rows.AddRange(batch.Rows);
                offset = finalResults.Rows.Count;
            }

            return(finalResults);
        }