Example #1
0
        public virtual List <T> Search <T>(SearchFilter filter) where T : IHasId
        {
            Condition.Requires(filter).IsNotNull();
            List <T> list = new List <T>();

            this.JSONObject.WithEach(x =>
            {
                try
                {
                    //get the store item
                    SerializedIHasId item = JsonSerializer.DeserializeFromString <SerializedIHasId>(x.Value);

                    //test the nested object
                    if (item != null)
                    {
                        T t = (T)item.GetStoredItem();

                        if (filter.Filter(t))
                        {
                            list.Add(t);
                        }
                    }
                }
                catch { }
            });
            return(list);
        }
Example #2
0
        public virtual List <T> Search <T>(SearchFilter filter) where T : IHasId
        {
            Condition.Requires(filter).IsNotNull();

            List <T> returnValue = new List <T>();
            Type     filterType  = typeof(T);

            //lock and retrieve the values
            List <IHasId> vals = this.SearchStrategy(filter);

            vals.WithEach(x =>
            {
                //if the item is the wrong type, skip it
                var type = x.GetType();
                if (filterType.IsAssignableFrom(type))
                {
                    if (filter.Filter((T)x))
                    {
                        returnValue.Add((T)x);
                    }
                }
            });

            return(returnValue);
        }
Example #3
0
        void OnGUI()
        {
            if (GUILayout.Button("Search"))
            {
                if (filter != null)
                {
                    List <GameObject> results = GetAllGameObjects();
                    filter.Filter(results);
                    ResultsWindow.DisplayResult(results, filter, dockOutputWindow);
                }
            }
#if UNITY_2019_OR_NEWER
            dockOutputWindow = EditorGUILayout.ToggleLeft("Dock results window", dockOutputWindow);
#else
            GUI.enabled      = false;
            dockOutputWindow = EditorGUILayout.ToggleLeft("Dock results window (available in 2019 or newer)", dockOutputWindow);
            GUI.enabled      = true;
#endif
            using (var scope = new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Filter");
                filter = (SearchFilter)EditorGUILayout.ObjectField(filter, typeof(SearchFilter), true);
                if (filter != null)
                {
                    SearchFilterGroup filterGroup = (filter as SearchFilterGroup);
                    if (filterGroup == null)
                    {
                        filterGroup = CreateInstance <SearchFilterGroup>();
                        filterGroup.AddSearchFilter(filter);
                        filter = filterGroup;
                    }
                }
                else
                {
                    filter = CreateInstance <SearchFilterGroup>();
                }
            }
            if (filter != null)
            {
                using (var scrollScope = new GUILayout.ScrollViewScope(scrollPos))
                {
                    scrollPos    = scrollScope.scrollPosition;
                    filterEditor = Editor.CreateEditor(filter);
                    filterEditor.OnInspectorGUI();
                }
            }
        }
Example #4
0
        public GetCustomerListResponse Search([FromBody] GetCustomerListRequest request)
        {
            const string message = "Could not find customer.";

            try
            {
                var response = new GetCustomerListResponse();

                using (var db = new EntityDb()) {
                    var customerList = db.Customers.AsQueryable();

                    // This is the two lines needed from the Expression Builder project
                    // to build the Lambda query.
                    var search = new SearchFilter <Customer>();
                    Filter <Customer> filter = search.Filter(request.SearchCriteria);

                    var results = customerList.Where(filter)
                                  .Select(c => new CustomerDto
                    {
                        CustomerId           = c.CustomerID,
                        CustomerName         = c.CustomerName,
                        PhoneNumber          = c.PhoneNumber,
                        DeliveryAddressLine1 = c.DeliveryAddressLine1,
                        DeliveryAddressLine2 = c.DeliveryAddressLine2,
                        DeliveryPostalCode   = c.DeliveryPostalCode,
                        PostalAddressLine1   = c.PostalAddressLine1,
                        PostalAddressLine2   = c.PostalAddressLine2
                    }).ToList();

                    response.CustomerList = results;
                }

                response.Success = true;
                return(response);
            }
            catch (Exception)
            {
                return(new GetCustomerListResponse {
                    Success = false, Message = message
                });
            }
        }