Beispiel #1
0
 public SearchItem(string id, string displayName, SearchableItem item, string highlighting)
 {
     this.Id           = id;
     this.DisplayName  = displayName;
     this.Item         = item;
     this.Highlighting = highlighting;
 }
Beispiel #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="trackViewer">Trackviewer so we can perform a callback</param>
        /// <param name="searchItem">Type of item that needs to be searched</param>
        public SearchControl(TrackViewer trackViewer, SearchableItem searchItem)
        {
            InitializeComponent();
            this.trackViewer = trackViewer;
            this.searchItem  = searchItem;
            textboxIndex.Focus();
            this.Top  = trackViewer.Window.ClientBounds.Top + 20;
            this.Left = trackViewer.Window.ClientBounds.Left + 0;
            switch (searchItem)
            {
            case SearchableItem.TrackNode:
                labelType.Content = "trackNode index = ";
                break;

            case SearchableItem.TrackItem:
                labelType.Content = "trackItem index = ";
                break;

            case SearchableItem.TrackNodeRoad:
                labelType.Content = "road trackNode index = ";
                break;

            case SearchableItem.TrackItemRoad:
                labelType.Content = "road trackItem index = ";
                break;
            }
        }
        public ActionResponse <SearchableItem> Execute(Request <string> request)
        {
            if (string.IsNullOrWhiteSpace(request.Parameter))
            {
                return new ActionResponse <SearchableItem> {
                           Result = null
                }
            }
            ;

            var searchableItem = new SearchableItem
            {
                Title = request.Parameter,
                Id    = System.Guid.NewGuid().ToString()
            };

            _repository.Save(searchableItem);

            var response = new ActionResponse <SearchableItem> {
                Result = searchableItem
            };

            return(response);
        }
    }
Beispiel #4
0
 /*********
 ** Public methods
 *********/
 /// <summary>Get whether a given item matches the rules for this category.</summary>
 /// <param name="item">The item to check.</param>
 public bool IsMatch(SearchableItem item)
 {
     return
         (this.When != null &&
          this.When.IsMatch(item) &&
          this.Except?.IsMatch(item) != true);
 }
        /*********
        ** Public methods
        *********/
        /// <summary>Get whether a given item matches the rules for this category.</summary>
        /// <param name="entry">The searchable item to check.</param>
        public bool IsMatch(SearchableItem entry)
        {
            Item   item = entry.Item;
            Object obj  = item as Object;

            // match criteria
            if (this.Class.Any() && this.GetClassFullNames(item).Any(className => this.Class.Contains(className)))
            {
                return(true);
            }
            if (this.ObjCategory.Any() && this.ObjCategory.Contains(item.Category))
            {
                return(true);
            }
            if (this.ObjType.Any() && obj != null && this.ObjType.Contains(obj.Type))
            {
                return(true);
            }
            if (this.ItemId.Any() && this.ItemId.Contains($"{entry.Type}:{item.ParentSheetIndex}"))
            {
                return(true);
            }

            return(false);
        }
 private Task <int> SaveSearchableItemAsync(SearchableItem item)
 {
     if (Database.Table <SearchableItem>().Where(i => i.Name == item.Name).FirstOrDefaultAsync().Result != null)
     {
         return(Database.UpdateAsync(item));
     }
     else
     {
         return(Database.InsertAsync(item));
     }
 }
Beispiel #7
0
 /// <summary>Create a searchable item if valid.</summary>
 /// <param name="type">The item type.</param>
 /// <param name="id">The unique ID (if different from the item's parent sheet index).</param>
 /// <param name="createItem">Create an item instance.</param>
 private SearchableItem TryCreate(ItemType type, int id, Func <SearchableItem, Item> createItem)
 {
     try
     {
         var item = new SearchableItem(type, id, createItem);
         item.Item.getDescription(); // force-load item data, so it crashes here if it's invalid
         return(item);
     }
     catch
     {
         return(null); // if some item data is invalid, just don't include it
     }
 }
 private SearchableItem TryCreate(ItemType type, int id, Func <SearchableItem, Item> createItem)
 {
     try
     {
         var item = new SearchableItem(type, id, createItem);
         item.Item.getDescription();
         return(item);
     }
     catch
     {
         return(null);
     }
 }
        public void The_Search_url_searches_google()
        {
            // Arrange
            const string text = "something bad";

            var item = new SearchableItem(text);

            // Act
            var result = item.SearchUrl;

            // Assert
            Assert.That(result, Is.StringContaining("google.com/search"));
        }
        public void The_Search_url_searches_for_the_text()
        {
            // Arrange
            var text = "something bad";

            var item = new SearchableItem(text);

            // Act
            var result = item.SearchUrl;

            // Assert
            Assert.That(result, Is.StringContaining(HttpUtility.UrlEncode(text)));
        }
Beispiel #11
0
        /// <summary>Handle the command.</summary>
        /// <param name="monitor">Writes messages to the console and log file.</param>
        /// <param name="command">The command name.</param>
        /// <param name="args">The command arguments.</param>
        public override void Handle(IMonitor monitor, string command, ArgumentParser args)
        {
            // validate
            if (!Context.IsWorldReady)
            {
                monitor.Log("You need to load a save to use this command.", LogLevel.Error);
                return;
            }

            // read arguments
            if (!args.TryGet(0, "item type", out string type, oneOf: this.ValidTypes))
            {
                return;
            }
            if (!args.TryGetInt(2, "count", out int count, min: 1, required: false))
            {
                count = 1;
            }
            if (!args.TryGetInt(3, "quality", out int quality, min: Object.lowQuality, max: Object.bestQuality, required: false))
            {
                quality = Object.lowQuality;
            }

            // find matching item
            SearchableItem match = Enum.TryParse(type, true, out ItemType itemType)
                ? this.FindItemByID(monitor, args, itemType)
                : this.FindItemByName(monitor, args);

            if (match == null)
            {
                return;
            }

            // apply count
            match.Item.Stack = count;

            // apply quality
            if (match.Item is Object obj)
            {
                obj.Quality = quality;
            }
            else if (match.Item is Tool tool)
            {
                tool.UpgradeLevel = quality;
            }

            // add to inventory
            Game1.player.addItemByMenuIfNecessary(match.Item);
            monitor.Log($"OK, added {match.Name} ({match.Type} #{match.ID}) to your inventory.", LogLevel.Info);
        }
Beispiel #12
0
        /// <summary>Handle the command.</summary>
        /// <param name="monitor">Writes messages to the console and log file.</param>
        /// <param name="command">The command name.</param>
        /// <param name="args">The command arguments.</param>
        public override void Handle(IMonitor monitor, string command, ArgumentParser args)
        {
            // read arguments
            if (!args.TryGet(0, "item type", out string rawType, oneOf: Enum.GetNames(typeof(ItemType))))
            {
                return;
            }
            if (!args.TryGetInt(1, "item ID", out int id, min: 0))
            {
                return;
            }
            if (!args.TryGetInt(2, "count", out int count, min: 1, required: false))
            {
                count = 1;
            }
            if (!args.TryGetInt(3, "quality", out int quality, min: Object.lowQuality, max: Object.bestQuality, required: false))
            {
                quality = Object.lowQuality;
            }
            ItemType type = (ItemType)Enum.Parse(typeof(ItemType), rawType, ignoreCase: true);

            // find matching item
            SearchableItem match = this.Items.GetAll().FirstOrDefault(p => p.Type == type && p.ID == id);

            if (match == null)
            {
                monitor.Log($"There's no {type} item with ID {id}.", LogLevel.Error);
                return;
            }

            // apply count
            match.Item.Stack = count;

            // apply quality
            if (match.Item is Object obj)
            {
                obj.quality = quality;
            }
            else if (match.Item is Tool tool)
            {
                tool.UpgradeLevel = quality;
            }

            // add to inventory
            Game1.player.addItemByMenuIfNecessary(match.Item);
            monitor.Log($"OK, added {match.Name} ({match.Type} #{match.ID}) to your inventory.", LogLevel.Info);
        }
Beispiel #13
0
        /*********
        ** Private methods
        *********/
        /// <summary>Get a matching item by its ID.</summary>
        /// <param name="monitor">Writes messages to the console and log file.</param>
        /// <param name="args">The command arguments.</param>
        /// <param name="type">The item type.</param>
        private SearchableItem FindItemByID(IMonitor monitor, ArgumentParser args, ItemType type)
        {
            // read arguments
            if (!args.TryGetInt(1, "item ID", out int id, min: 0))
            {
                return(null);
            }

            // find matching item
            SearchableItem item = this.Items.GetAll().FirstOrDefault(p => p.Type == type && p.ID == id);

            if (item == null)
            {
                monitor.Log($"There's no {type} item with ID {id}.", LogLevel.Error);
            }
            return(item);
        }
Beispiel #14
0
        public async Task <bool> Index <T>(SearchableItem <T> item)
        {
            var result = await _client.IndexAsync(
                item,
                x => x.Id(new Id(item.Id))
                .Version(item.Version)
                .VersionType(VersionType.External)
                .Index(_configuration.Index)
                );

            if (result.IsValid)
            {
                return(true);
            }
            // Check if version error and log as info
            // LOG
            Log.Error(result.OriginalException, "Error indexing to elastic. Item id: {id}, version {version}", item.Id, item.Version);
            return(false);
        }
 public void SaveProfileDetail(SearchableItem item)
 {
     if (item is Language language)
     {
         EnterLanguageDetails(language);
     }
     else if (item is Skill skill)
     {
         EnterSkillDetails(skill);
     }
     else if (item is Education education)
     {
         EnterEducationDetails(education);
     }
     else if (item is Certification certification)
     {
         EnterCertificationDetails(certification);
     }
     else
     {
         throw new ArgumentException($"Unknown item type : {item.GetType()} with its values : {item}");
     }
 }
Beispiel #16
0
 public void SaveProfileDetail(IWebDriver driver, SearchableItem item)
 {
     if (item is Language language)
     {
         EnterLanguageDetails(driver, language);
     }
     else if (item is Skill skill)
     {
         EnterSkillDetails(driver, skill);
     }
     else if (item is Education education)
     {
         EnterEducationDetails(driver, education);
     }
     else if (item is Certification certification)
     {
         EnterCertificationDetails(driver, certification);
     }
     else
     {
         throw new ArgumentException("Unknown item type : " + item.GetType().ToString() + " with its values : " + item.ToString());
     }
 }
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="item">The item metadata.</param>
 /// <param name="category">The item's category filter label for the spawn menu.</param>
 public SpawnableItem(SearchableItem item, string category)
     : base(item)
 {
     this.Category = category;
 }
Beispiel #18
0
        public IEnumerable <SearchableItem> GetAll()
        {
            IEnumerable <SearchableItem> GetAllRaw()
            {
                // get tools
                for (int quality = Tool.stone; quality <= Tool.iridium; quality++)
                {
                    yield return(this.TryCreate(ItemType.Tool, ToolFactory.axe, () => ToolFactory.getToolFromDescription(ToolFactory.axe, quality)));

                    yield return(this.TryCreate(ItemType.Tool, ToolFactory.hoe, () => ToolFactory.getToolFromDescription(ToolFactory.hoe, quality)));

                    yield return(this.TryCreate(ItemType.Tool, ToolFactory.pickAxe, () => ToolFactory.getToolFromDescription(ToolFactory.pickAxe, quality)));

                    yield return(this.TryCreate(ItemType.Tool, ToolFactory.wateringCan, () => ToolFactory.getToolFromDescription(ToolFactory.wateringCan, quality)));

                    if (quality != Tool.iridium)
                    {
                        yield return(this.TryCreate(ItemType.Tool, ToolFactory.fishingRod, () => ToolFactory.getToolFromDescription(ToolFactory.fishingRod, quality)));
                    }
                }
                yield return(this.TryCreate(ItemType.Tool, this.CustomIDOffset, () => new MilkPail())); // these don't have any sort of ID, so we'll just assign some arbitrary ones

                yield return(this.TryCreate(ItemType.Tool, this.CustomIDOffset + 1, () => new Shears()));

                yield return(this.TryCreate(ItemType.Tool, this.CustomIDOffset + 2, () => new Pan()));

                yield return(this.TryCreate(ItemType.Tool, this.CustomIDOffset + 3, () => new Wand()));

                // wallpapers
                for (int id = 0; id < 112; id++)
                {
                    yield return(this.TryCreate(ItemType.Wallpaper, id, () => new Wallpaper(id)
                    {
                        Category = SObject.furnitureCategory
                    }));
                }

                // flooring
                for (int id = 0; id < 40; id++)
                {
                    yield return(this.TryCreate(ItemType.Flooring, id, () => new Wallpaper(id, isFloor: true)
                    {
                        Category = SObject.furnitureCategory
                    }));
                }

                // equipment
                foreach (int id in Game1.content.Load <Dictionary <int, string> >("Data\\Boots").Keys)
                {
                    yield return(this.TryCreate(ItemType.Boots, id, () => new Boots(id)));
                }
                foreach (int id in Game1.content.Load <Dictionary <int, string> >("Data\\hats").Keys)
                {
                    yield return(this.TryCreate(ItemType.Hat, id, () => new Hat(id)));
                }
                foreach (int id in Game1.objectInformation.Keys)
                {
                    if (id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange)
                    {
                        yield return(this.TryCreate(ItemType.Ring, id, () => new Ring(id)));
                    }
                }

                // weapons
                foreach (int id in Game1.content.Load <Dictionary <int, string> >("Data\\weapons").Keys)
                {
                    yield return(this.TryCreate(ItemType.Weapon, id, () => (id >= 32 && id <= 34)
                        ? (Item) new Slingshot(id)
                        : new MeleeWeapon(id)
                                                ));
                }

                // furniture
                foreach (int id in Game1.content.Load <Dictionary <int, string> >("Data\\Furniture").Keys)
                {
                    if (id == 1466 || id == 1468)
                    {
                        yield return(this.TryCreate(ItemType.Furniture, id, () => new TV(id, Vector2.Zero)));
                    }
                    else
                    {
                        yield return(this.TryCreate(ItemType.Furniture, id, () => new Furniture(id, Vector2.Zero)));
                    }
                }

                // craftables
                foreach (int id in Game1.bigCraftablesInformation.Keys)
                {
                    yield return(this.TryCreate(ItemType.BigCraftable, id, () => new SObject(Vector2.Zero, id)));
                }

                // secret notes
                foreach (int id in Game1.content.Load <Dictionary <int, string> >("Data\\SecretNotes").Keys)
                {
                    yield return(this.TryCreate(ItemType.Object, this.CustomIDOffset + id, () =>
                    {
                        SObject note = new SObject(79, 1);
                        note.name = $"{note.name} #{id}";
                        return note;
                    }));
                }

                // objects
                foreach (int id in Game1.objectInformation.Keys)
                {
                    if (id == 79)
                    {
                        continue; // secret note handled above
                    }
                    if (id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange)
                    {
                        continue; // handled separated
                    }
                    // spawn main item
                    SObject item;
                    {
                        SearchableItem main = this.TryCreate(ItemType.Object, id, () => new SObject(id, 1));
                        yield return(main);

                        item = main?.Item as SObject;
                    }
                    if (item == null)
                    {
                        continue;
                    }

                    // fruit products
                    if (item.Category == SObject.FruitsCategory)
                    {
                        // wine
                        yield return(this.TryCreate(ItemType.Object, this.CustomIDOffset * 2 + id, () =>
                        {
                            SObject wine = new SObject(348, 1)
                            {
                                Name = $"{item.Name} Wine",
                                Price = item.Price * 3
                            };
                            wine.preserve.Value = SObject.PreserveType.Wine;
                            wine.preservedParentSheetIndex.Value = item.ParentSheetIndex;
                            return wine;
                        }));

                        // jelly
                        yield return(this.TryCreate(ItemType.Object, this.CustomIDOffset * 3 + id, () =>
                        {
                            SObject jelly = new SObject(344, 1)
                            {
                                Name = $"{item.Name} Jelly",
                                Price = 50 + item.Price * 2
                            };
                            jelly.preserve.Value = SObject.PreserveType.Jelly;
                            jelly.preservedParentSheetIndex.Value = item.ParentSheetIndex;
                            return jelly;
                        }));
                    }

                    // vegetable products
                    else if (item.Category == SObject.VegetableCategory)
                    {
                        // juice
                        yield return(this.TryCreate(ItemType.Object, this.CustomIDOffset * 4 + id, () =>
                        {
                            SObject juice = new SObject(350, 1)
                            {
                                Name = $"{item.Name} Juice",
                                Price = (int)(item.Price * 2.25d)
                            };
                            juice.preserve.Value = SObject.PreserveType.Juice;
                            juice.preservedParentSheetIndex.Value = item.ParentSheetIndex;
                            return juice;
                        }));

                        // pickled
                        yield return(this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, () =>
                        {
                            SObject pickled = new SObject(342, 1)
                            {
                                Name = $"Pickled {item.Name}",
                                Price = 50 + item.Price * 2
                            };
                            pickled.preserve.Value = SObject.PreserveType.Pickle;
                            pickled.preservedParentSheetIndex.Value = item.ParentSheetIndex;
                            return pickled;
                        }));
                    }

                    // flower honey
                    else if (item.Category == SObject.flowersCategory)
                    {
                        yield return(this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, () =>
                        {
                            SObject honey = new SObject(Vector2.Zero, 340, $"{item.Name} Honey", false, true, false, false)
                            {
                                Name = $"{item.Name} Honey",
                                preservedParentSheetIndex = { item.ParentSheetIndex }
                            };
                            honey.Price += item.Price * 2;
                            return honey;
                        }));
                    }
                }
            }

            return(GetAllRaw().Where(p => p != null));
        }
Beispiel #19
0
        /// <summary>
        ///     Compiles the query expression for the class using the request.
        /// </summary>
        /// <param name="searchClass">The build class.</param>
        /// <param name="request">The request.</param>
        /// <param name="item">The item.</param>
        /// <returns>
        ///     A <see cref="string" /> for the corresponding fields and values; otherwise null when no fields are present.
        /// </returns>
        protected virtual string CompileExpression(ITable searchClass, TSearchableRequest request, SearchableItem item)
        {
            if (item.Fields.Any(f => f.Equals(SearchableField.Any)))
            {
                return(searchClass.CreateExpression(request.Keyword, request.ComparisonOperator, request.LogicalOperator));
            }

            var fields = item.Fields.OrderBy(f => !f.Visible && !string.IsNullOrEmpty(f.Value));

            return(this.CompileExpression(searchClass, request, fields.ToArray()));
        }