Beispiel #1
0
        public IComponentLibrarySearchResult <VFComponent> Search(IComponentLibraryFilter filter)
        {
            IComponentLibrarySearchResult <VFComponent> result = null;

            if (!this.CheckTreeForCategory(filter))
            {
                return(result);
            }

            Dictionary <string, object> searchQuery = new Dictionary <string, object>();

            searchQuery["category_name"] = filter.Category;
            searchQuery["rows"]          = filter.NumberOfResults;
            searchQuery["startPos"]      = filter.StartPosition;

            var content = "filters=" +
                          Newtonsoft.Json.JsonConvert.SerializeObject(
                (filter as VFExchangeFilter).ParameterList,
                new Newtonsoft.Json.JsonSerializerSettings()
            {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            });

            string contentType = WebClient.ContentType.FormEncoded;

            try
            {
                result = this.m_vfWebClient.SendPostRequest <VFExchangeSearchResult>("/rest/exchange/search/components", searchQuery, content, contentType);
            }
            catch (System.Net.WebException ex)
            {
                // TODO: response/exception is already disposed; need to figure out how to get the type of HTTP error, e.g. 404, 500, ...
                throw new VehicleForge.VFExchangeSearchException();

                //switch ((ex.Response as System.Net.HttpWebResponse).StatusCode)
                //{
                //    case System.Net.HttpStatusCode.NotFound:
                //        throw new VehicleForge.VFExchangeSearchException();
                //        //throw new VehicleForge.VFInvalidURLException();
                //    case System.Net.HttpStatusCode.InternalServerError:
                //        throw new VehicleForge.VFExchangeSearchException();
                //        //throw new VehicleForge.VFInvalidURLException();
                //    default:
                //        throw ex;
                //}
            }

            return(result);
        }
Beispiel #2
0
        public bool CheckTreeForCategory(IComponentLibraryFilter filter)
        {
            bool CategoryExists = false;

            try
            {
                VFOntologyTreeNode vfOntologyTree = this.m_vfWebClient.SendGetRequest <VFOntologyTreeNode>("/rest/exchange/ontology/domain/root/json_tree");

                CategoryExists = this.searchTreeRecursive(vfOntologyTree, filter.Category);
            }
            catch (Exception)
            {
                throw;
            }

            return(CategoryExists);
        }
Beispiel #3
0
        public bool CheckForCategory(IComponentLibraryFilter filter)
        {
            bool CategoryExists = false;

            try
            {
                VFOntologyList vfOntologyList = this.m_vfWebClient.SendGetRequest <VFOntologyList>("/rest/exchange/ontology/term/");

                foreach (VFOntologyInstance instance in vfOntologyList.instances)
                {
                    if (instance.label == filter.Category)
                    {
                        CategoryExists = true;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(CategoryExists);
        }